diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c2f13520..4e2c36987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ determines which versions can connect. ### Fixed +- Preserved the upload handler's failure phase and cause when control is invalidated during an upload, while retaining conservative effect uncertainty, replay protection, and structured guard-failure diagnostics (#756). - Added `--max-tokens` (`max_tokens` in MCP) to `bsk step`, `bsk plan`, `bsk_interact` (with `sync_after` or `until_visible`), and `bsk_plan`, forwarding it to the post-action `tool.cooperate` sync instead of hardcoding `None` so `--max-tokens` baselines stay reusable across `delta` and `unchanged` syncs without forcing an unbounded page re-capture (#755). - Ignored internal `data-bsk-*` attributes and `` (`[data-bsk-overlay]`) ShadowHost mutations in `cooperation-capture.ts` so active recording and sensitive-field markers no longer advance `FrameState.structure`, excluded extension ShadowRoot UI controls (`HelpRequestOverlay`, `RecordOverlay`, `BorrowConfirmationOverlay`) across `record-capture.ts`, `record-hover-surface.ts`, and `cooperation-capture.ts` so overlay interactions and hover surfaces are never mis-recorded as webpage steps, and re-evaluated tab control ownership after awaiting `ensureOverlayInjected` so mid-injection tab detachments never flash stale `control` state. - VOM token estimation now handles unpaired UTF-16 surrogates without combining them with the following symbol or throwing a `RangeError`; valid emoji pairs retain their existing estimates. diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index e3d6cd302..2a0fd0081 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -29,6 +29,7 @@ CLI 和扩展可以分别发布,能否连接由协议兼容性决定。更新 ### 修复 +- 修复上传期间控制上下文失效时,通用控制错误覆盖上传处理器失败阶段与原因的问题;现在会保留具体上传诊断,同时维持保守的效果不确定性、防重放保护与结构化前置条件错误(#756)。 - 为 `bsk step`、`bsk plan`、MCP `bsk_interact`(搭配 `sync_after` 或 `until_visible`)及 `bsk_plan` 补齐 `--max-tokens`(MCP 为 `max_tokens`)参数并透传至后置 `tool.cooperate` 同步请求,解决此前硬编码 `None` 导致带预算会话在后续动作触发 `token_budget_changed` 并回退为整页无上限重采的问题(#755)。 - 在 `cooperation-capture.ts` 中忽略扩展内部私有 `data-bsk-*` 属性与 ``(`[data-bsk-overlay]`)ShadowHost 变更以消除录制/敏感字段标记对 `FrameState.structure` 的自污染,在 `record-capture.ts`、`record-hover-surface.ts` 与 `cooperation-capture.ts` 中统一过滤扩展自身 ShadowRoot 浮层控件(`HelpRequestOverlay`、`RecordOverlay`、`BorrowConfirmationOverlay`)防止浮层内点击/输入或悬停面被误录为网页操作,并在 `ensureOverlayInjected` 异步注入完成后二次校验标签页受控归属以杜绝注入途中断开控制导致的陈旧浮层闪现。 - VOM Token 估算现在能处理未配对的 UTF-16 代理字符,不会再误合并后续符号或抛出 `RangeError`;有效 emoji 代理对的估算保持不变。 diff --git a/apps/extension/src/cooperation/controller.ts b/apps/extension/src/cooperation/controller.ts index 8cd1aa881..6c125a8a2 100644 --- a/apps/extension/src/cooperation/controller.ts +++ b/apps/extension/src/cooperation/controller.ts @@ -2519,8 +2519,24 @@ export class CooperationController implements ControlAuthority { (!completed && !isRpcError(result) && detachedByHandler ? "The observed page or control state changed; synchronize" : undefined); - if (checkFailure || reason) - return reportFailure(checkFailure?.message ?? reason!, sent ? "unknown" : "none"); + if (checkFailure || reason) { + const controlFailure = reportFailure( + checkFailure?.message ?? reason!, + sent ? "unknown" : "none", + ); + // The upload handler has the useful failure phase and cause. Control + // still owns effect uncertainty and recovery after a revoked context. + if (!checkFailure && req.method === "tool.upload" && isRpcError(result)) + return { + ...result, + data: { + ...result.data, + effect_state: controlFailure.data?.effect_state ?? (sent ? "unknown" : "none"), + recovery: controlFailure.data?.recovery ?? result.data?.recovery, + }, + }; + return controlFailure; + } if (isRpcError(result)) { const effect = result.data?.effect_state ?? (sent ? "unknown" : "none"); if (targetPolicy && (effect === "unknown" || detachedByHandler || postRefreshFailed)) diff --git a/apps/extension/src/cooperation/target-policy.test.ts b/apps/extension/src/cooperation/target-policy.test.ts index e3ccff702..6f0594e36 100644 --- a/apps/extension/src/cooperation/target-policy.test.ts +++ b/apps/extension/src/cooperation/target-policy.test.ts @@ -448,6 +448,50 @@ describe.each(["strict", "target"] as const)("completed action receipts (%s)", ( expect(next.context_id).not.toBe(f.first.context_id); }); + it("preserves a phased upload failure without hiding control-side uncertainty", async () => { + const f = await fixture(policy); + const refusal = { + code: "cdp_failed" as const, + message: "Page interaction coverage changed; wait and synchronize", + data: { + reason: "file_input_probe_failed", + phase: "resolve_input", + effect_state: "none" as const, + recovery: "Inspect the upload target before retrying.", + }, + }; + + const result = await f.run({ ref: "e1" }, "tool.upload", async (runner) => { + await runner.send(7, "Page.setInterceptFileChooserDialog", { enabled: true }); + f.controller.invalidate(7); + await expect( + runner.send(7, "Runtime.callFunctionOn", { + objectId: "trigger", + functionDeclaration: "function() { return null; }", + }), + ).rejects.toThrow("Page interaction coverage changed; wait and synchronize"); + return refusal; + }); + + expect(result).toEqual({ + ...refusal, + data: { + ...refusal.data, + effect_state: "unknown", + recovery: expect.stringContaining("Never replay"), + }, + }); + expect(await f.run()).toMatchObject({ + code: "permission_denied", + data: { + reason: policy === "target" ? "control_context_invalid" : "cooperation_sync_required", + effect_state: "none", + }, + }); + const next = await f.sync(); + expect(next.context_id).not.toBe(f.first.context_id); + }); + it("preserves file_drop_failed with effect_state none when drag_enter is rejected", async () => { const f = await fixture(policy); const refusal = { @@ -500,6 +544,50 @@ describe.each(["strict", "target"] as const)("completed action receipts (%s)", ( }); describe("negotiated target control", () => { + it("keeps structured guard failures ahead of an upload handler wrapper", async () => { + const f = await fixture(); + const checks = [{ target: "#price", field: "text" as const, equals: "$100" }]; + const guardFailure = { + code: "permission_denied" as const, + message: "Price changed before upload", + data: { + reason: "precondition_failed" as const, + phase: "precondition" as const, + effect_state: "none" as const, + target: "#price", + field: "text", + expected: "$100", + actual: "$200", + recovery: "Synchronize the price before choosing another action.", + }, + }; + vi.mocked(checkExpectations) + .mockResolvedValueOnce(undefined) + .mockResolvedValueOnce(guardFailure); + + const result = await f.run({ ref: "e1", expect: checks }, "tool.upload", async (runner) => { + await runner.send(7, "Page.setInterceptFileChooserDialog", { enabled: true }); + await expect( + runner.send(7, "Runtime.callFunctionOn", { + objectId: "trigger", + functionDeclaration: "function() { return null; }", + }), + ).rejects.toThrow("Price changed before upload"); + return { + code: "cdp_failed", + message: "Price changed before upload", + data: { + reason: "file_input_probe_failed", + phase: "resolve_input", + effect_state: "none", + }, + }; + }); + + expect(result).toEqual(guardFailure); + expect(checkExpectations).toHaveBeenCalledTimes(2); + }); + it("allows repeated actions beside live fields without any private VOM captures", async () => { const f = await fixture(); for (let tick = 1; tick <= 3; tick++) { diff --git a/evals/browser/cases/regression/cooperation/run.mjs b/evals/browser/cases/regression/cooperation/run.mjs index 0f4c17cab..bacbec443 100644 --- a/evals/browser/cases/regression/cooperation/run.mjs +++ b/evals/browser/cases/regression/cooperation/run.mjs @@ -254,7 +254,14 @@ try { frameObservability = await runFrameObservabilityScenarios({ send, bsk: runBsk, base }); if (framesOnly) return; if (!compatibilityOnly) { - targetPolicy = await runTargetPolicyScenarios({ send, bsk: runBsk, cli, env, base }); + targetPolicy = await runTargetPolicyScenarios({ + send, + bsk: runBsk, + cli, + env, + base, + directory, + }); plan = await runPlanScenarios({ send, bsk: runBsk, cli, env, base }); recipes = await runRecipeScenarios(scenarios); } diff --git a/evals/browser/cases/regression/cooperation/target-policy.html b/evals/browser/cases/regression/cooperation/target-policy.html index 8096bbaa9..27c1347e4 100644 --- a/evals/browser/cases/regression/cooperation/target-policy.html +++ b/evals/browser/cases/regression/cooperation/target-policy.html @@ -10,6 +10,8 @@
Tick 0 + + 0 @@ -19,12 +21,17 @@