Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<browser-skill-overlay>` (`[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.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-*` 属性与 `<browser-skill-overlay>`(`[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 代理对的估算保持不变。
Expand Down
20 changes: 18 additions & 2 deletions apps/extension/src/cooperation/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
88 changes: 88 additions & 0 deletions apps/extension/src/cooperation/target-policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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++) {
Expand Down
9 changes: 8 additions & 1 deletion evals/browser/cases/regression/cooperation/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions evals/browser/cases/regression/cooperation/target-policy.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<form onsubmit="return false">
<span id="clock">Tick 0</span>
<button id="apply" type="button">Apply</button>
<button id="upload" type="button">Upload receipt</button>
<input id="upload-file" type="file" hidden>
<button id="human" type="button">Human change</button>
<output id="count">0</output>
<label>Note <input id="note" aria-label="Note"></label>
Expand All @@ -19,12 +21,17 @@
<div style="height: 1800px" aria-hidden="true"></div>
<script>
window.applied = 0;
window.uploadTriggers = 0;
window.ticks = 0;
window.humanChanged = false;
setInterval(() => document.querySelector('#clock').textContent = 'Tick ' + ++ticks, 40);
document.querySelector('#apply').onclick = () => {
document.querySelector('#count').value = String(++applied);
};
document.querySelector('#upload').onclick = () => {
window.uploadTriggers++;
history.pushState({}, '', location.href);
};
document.querySelector('#human').onclick = () => { window.humanChanged = true; };
window.rotatePromo = (slide) => new Promise((resolve) => {
const frame = document.querySelector('#promo');
Expand Down
49 changes: 48 additions & 1 deletion evals/browser/cases/regression/cooperation/target-policy.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import assert from "node:assert/strict";
import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { runIntentScenarios } from "./intent-signals.mjs";
import { createMcpRegressionClient } from "./mcp-client.mjs";

/** Exercise both shipped defaults through the installed extension, including real human input. */
export async function runTargetPolicyScenarios({ send, bsk, cli, env, base }) {
export async function runTargetPolicyScenarios({ send, bsk, cli, env, base, directory }) {
const results = [];
for (const client of ["cli", "mcp"]) {
const mcp = client === "mcp" ? await createMcpRegressionClient(cli, env) : undefined;
Expand Down Expand Up @@ -122,6 +124,50 @@ export async function runTargetPolicyScenarios({ send, bsk, cli, env, base }) {
sync,
click,
});
let uploadControlInvalidation;
if (!mcp) {
const file = join(directory, "target-policy-upload.txt");
await writeFile(file, "control context invalidation regression");
const uploadSync = await sync();
const uploadRef = uploadSync.observation.text.match(/(@e\d+) button "Upload receipt"/)?.[1];
assert(uploadRef, JSON.stringify(uploadSync));
const pathname = await read("location.pathname");
const upload = await bsk(
["upload", uploadRef, "--file", file, ...scope, "--context", uploadSync.context_id],
"file_input_probe_failed",
);
assert.equal(upload.code, "cdp_failed");
assert.equal(upload.data.phase, "resolve_input");
assert.equal(upload.data.effect_state, "unknown");
assert.equal(await read("uploadTriggers"), 1, "upload trigger did not run exactly once");
assert.equal(
await read("document.querySelector('#upload-file').files.length"),
0,
"failed upload assigned a file",
);
assert.equal(await read("location.pathname"), pathname);
const blockedReplay = await bsk(
["click", ref, ...scope, "--context", uploadSync.context_id],
"uncertain_prior_effect",
);
assert.equal(blockedReplay.data.dispatched, false);
const recovered = await sync();
assert.notEqual(recovered.context_id, uploadSync.context_id);
const stale = await bsk(
["click", ref, ...scope, "--context", uploadSync.context_id],
"control_context_invalid",
);
assert.equal(stale.data.effect_state, "none");
uploadControlInvalidation = {
reason: upload.data.reason,
phase: upload.data.phase,
effectState: upload.data.effect_state,
triggerCount: 1,
fileCount: 0,
uncertainReplayBlocked: true,
staleContextRejected: true,
};
}
results.push({
client,
policy: "target",
Expand All @@ -131,6 +177,7 @@ export async function runTargetPolicyScenarios({ send, bsk, cli, env, base }) {
humanRevokedContext: true,
finalClicks: 4,
intentSignals,
...(uploadControlInvalidation ? { uploadControlInvalidation } : {}),
});
} finally {
if (session) {
Expand Down