Skip to content

The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.

fix(ego-browser): stop attributing finished or handed-off tasks to the user

Zhuowei Wang655d4bea4c00
diff --git a/package/ego-browser/skill-body/SKILL.md b/package/ego-browser/skill-body/SKILL.md
index 9713faa..d1a3d8e 100644
--- a/package/ego-browser/skill-body/SKILL.md
+++ b/package/ego-browser/skill-body/SKILL.md
@@ -491,9 +491,11 @@ const userPage = task.userPage();
Adopt `userPage` if it is unmanaged. Use `waitForControl()` only when the current
script must wait in place. Claim a user-owned or inactive space only when the
-user explicitly asks. Find its numeric id first; names may be duplicated.
-`listTaskSpaces()` entries expose that id as `id` (`spaceId` exists only on a
-TaskSpace handle), so pass `entry.id` to `claimTaskSpace()` or `taskSpace()`:
+user explicitly asks; this includes a space you finished with kept Pages, which
+`takeOverTaskSpace()` cannot resume. Find its numeric id first; names may be
+duplicated. `listTaskSpaces()` entries expose that id as `id` (`spaceId` exists
+only on a TaskSpace handle), so pass `entry.id` to `claimTaskSpace()` or
+`taskSpace()`:
```js
const spaces = await listTaskSpaces();
diff --git a/package/ego-browser/src/browser-runtime.test.mjs b/package/ego-browser/src/browser-runtime.test.mjs
index 77bccdb..45bad57 100644
--- a/package/ego-browser/src/browser-runtime.test.mjs
+++ b/package/ego-browser/src/browser-runtime.test.mjs
@@ -1333,7 +1333,10 @@ test("a failed permission probe falls back to generic user-control guidance", as
await assert.rejects(
() => browserCdp("Browser.getVersion", {}, undefined, 1000),
(error) => {
- assert.match(error.message, /The user has taken control/);
+ assert.match(
+ error.message,
+ /Control of this task space is with the user/,
+ );
assert.doesNotMatch(error.message, /probe transport failed/);
return true;
},
diff --git a/package/ego-browser/src/ego-errors.test.mjs b/package/ego-browser/src/ego-errors.test.mjs
index 2045558..3196d73 100644
--- a/package/ego-browser/src/ego-errors.test.mjs
+++ b/package/ego-browser/src/ego-errors.test.mjs
@@ -81,7 +81,7 @@ test("user-control reason lookup ignores inherited object properties", () => {
error: "constructor",
error_code: "EGO_TASK_SPACE_USER_IN_CONTROL",
});
- assert.match(message, /The user has taken control/);
+ assert.match(message, /Control of this task space is with the user/);
assert.doesNotMatch(message, /constructor/);
});
@@ -90,7 +90,7 @@ test("unknown user-control reasons fall back without exposing the raw key", () =
error: "future_permission_reason",
error_code: "EGO_TASK_SPACE_USER_IN_CONTROL",
});
- assert.match(message, /The user has taken control/);
+ assert.match(message, /Control of this task space is with the user/);
assert.doesNotMatch(message, /future_permission_reason/);
});
@@ -99,7 +99,7 @@ test("the retired site-dialog handoff reason uses generic user-control guidance"
error: "fallback_site_dialog_required_notice",
error_code: "EGO_TASK_SPACE_USER_IN_CONTROL",
});
- assert.match(message, /The user has taken control/);
+ assert.match(message, /Control of this task space is with the user/);
assert.doesNotMatch(message, /dialog that requires review/);
assert.doesNotMatch(message, /fallback_site_dialog_required_notice/);
});
@@ -165,6 +165,23 @@ test("resolveEgoError overrides the native error message with the owned wording
assert.doesNotMatch(message, /\b7\b/);
});
+test("inactive guidance does not attribute an agent-finished task to the user", () => {
+ // task.finish({ keep: [...] }) leaves the space user-owned; a later
+ // takeOverTaskSpace() gets this code without any user action.
+ const { message } = resolveEgoError("EGO_TASK_SPACE_INACTIVE");
+ assert.doesNotMatch(message, /user has taken control/i);
+ assert.match(message, /task\.finish\(\)/);
+ assert.match(message, /takeOverTaskSpace\(\) cannot resume/);
+ assert.match(message, /claimTaskSpace\(spaceId\)/);
+});
+
+test("user-control guidance names both the agent handoff and a browser takeover", () => {
+ const { message } = resolveEgoError("EGO_TASK_SPACE_USER_IN_CONTROL");
+ assert.doesNotMatch(message, /user has taken control/i);
+ assert.match(message, /task\.handOff\(\)/);
+ assert.match(message, /takeover in the browser/);
+});
+
test("resolveEgoError keeps the native error message for an unknown future code", () => {
assert.deepEqual(
resolveEgoError({
@@ -205,7 +222,7 @@ test("resolveEgoError falls back to the raw code for a bare non-owned code", ()
test("resolveEgoError uses the id-less guidance block for a bare user-control code", () => {
const { code, message } = resolveEgoError("EGO_TASK_SPACE_USER_IN_CONTROL");
assert.equal(code, "EGO_TASK_SPACE_USER_IN_CONTROL");
- assert.match(message, /taken control of this task space/);
+ assert.match(message, /Control of this task space is with the user/);
assert.match(message, /takeOverTaskSpace\(spaceId\)/);
assert.doesNotMatch(message, /<id>/);
});
diff --git a/package/ego-browser/src/ego-errors.ts b/package/ego-browser/src/ego-errors.ts
index b93d14b..a35edae 100644
--- a/package/ego-browser/src/ego-errors.ts
+++ b/package/ego-browser/src/ego-errors.ts
@@ -46,16 +46,19 @@ export type EgoErrorCode = (typeof EGO_ERROR_CODES)[number];
* specific than any static line.
*/
const EGO_ERROR_MESSAGES: Partial<Record<EgoErrorCode, string>> = {
+ // The native code does not say who ended the task or moved control: the
+ // agent's own task.finish() / task.handOff() produce the same codes as user
+ // actions in the browser. Keep this wording neutral about the cause.
EGO_TASK_SPACE_INACTIVE: [
- "The user has taken control of this task space and ended the task, so it is no longer assigned to the agent and browser commands are paused.",
- "This is a hard stop, not an obstacle to route around — do not retry and do not take ownership back on your own.",
- "Wait until the user explicitly asks you to continue, then claim the space and resume:",
+ "This task space is no longer assigned to the agent: its task has ended, either through task.finish() or by the user, so browser commands are paused.",
+ "This is a hard stop, not an obstacle to route around — do not retry and do not take ownership back on your own. takeOverTaskSpace() cannot resume an ended task.",
+ "Wait until the user explicitly asks you to continue in this space, then claim it and resume:",
" const task = await claimTaskSpace(spaceId)",
"",
- `Offer the user choices like "Continue" or "Finish task" if your harness supports it; otherwise tell them: "You now control this task space. Reply 'continue' when ready and I will resume."`,
+ `Offer the user choices like "Continue" or "Done" if your harness supports it; otherwise tell them: "This task has ended and the space is yours. Reply 'continue' if you want me to resume in it."`,
].join("\n"),
EGO_TASK_SPACE_USER_IN_CONTROL: [
- "The user has taken control of this task space, so browser commands are paused.",
+ "Control of this task space is with the user, either through task.handOff() or a takeover in the browser, so browser commands are paused.",
"This is a hard stop, not an obstacle to route around — do not retry and do not take control back on your own.",
"Wait until the user explicitly asks you to continue, then take control back and resume:",
" const task = await takeOverTaskSpace(spaceId)",
diff --git a/package/ego-browser/src/helpers.test.mjs b/package/ego-browser/src/helpers.test.mjs
index c524559..ce04801 100644
--- a/package/ego-browser/src/helpers.test.mjs
+++ b/package/ego-browser/src/helpers.test.mjs
@@ -774,7 +774,7 @@ test("useOrCreateTaskSpace selects user-owned spaces without claiming and surfac
async () => {
await assert.rejects(
() => useOrCreateTaskSpace("checkout-flow"),
- /useOrCreateTaskSpace: The user has taken control of this task space/,
+ /useOrCreateTaskSpace: Control of this task space is with the user/,
);
},
);
diff --git a/package/ego-browser/src/run-output-sink.test.mjs b/package/ego-browser/src/run-output-sink.test.mjs
index fc0a5ca..fa8b4f5 100644
--- a/package/ego-browser/src/run-output-sink.test.mjs
+++ b/package/ego-browser/src/run-output-sink.test.mjs
@@ -140,7 +140,7 @@ test("a hard stop discards console output together with cliLog output", async ()
ego,
);
- assert.match(result.stdout, /taken control of this task space/);
+ assert.match(result.stdout, /Control of this task space is with the user/);
assert.doesNotMatch(result.stdout, /before|after/);
});
@@ -164,7 +164,7 @@ test("a swallowed user-control hard stop discards all output and prints the guid
assert.equal(result.exitCode, 0);
// Only the owned guidance survives — none of the script's own logging.
- assert.match(result.stdout, /taken control of this task space/);
+ assert.match(result.stdout, /Control of this task space is with the user/);
assert.match(result.stdout, /takeOverTaskSpace\(spaceId\)/);
assert.doesNotMatch(result.stdout, /visiting|failed|ok |summary/);
// Printed exactly once, even though every loop iteration re-reported the hard stop.
@@ -251,7 +251,7 @@ test("a swallowed snapshot hard stop (rejected, not resolved) also collapses to
assert.equal(result.exitCode, 0);
// The owned guidance survives once; the native wording and business logs are dropped.
- assert.match(result.stdout, /taken control of this task space/);
+ assert.match(result.stdout, /Control of this task space is with the user/);
assert.match(result.stdout, /takeOverTaskSpace\(spaceId\)/);
assert.doesNotMatch(result.stdout, /native wording/);
assert.doesNotMatch(result.stdout, /visiting|failed|ok |summary/);
@@ -276,7 +276,10 @@ test("an uncaught hard stop discards output without double-printing the message"
// The thrown Error already surfaces the message (the host prints it), so the sink
// discards the buffer and stays silent rather than printing the guidance a second time.
assert.ok(result.error, "expected runMain to reject");
- assert.match(result.error.message, /taken control of this task space/);
+ assert.match(
+ result.error.message,
+ /Control of this task space is with the user/,
+ );
assert.equal(result.stdout, "");
});
diff --git a/package/ego-browser/src/taskspace-e2e.test.mjs b/package/ego-browser/src/taskspace-e2e.test.mjs
index 872dd40..5b990a4 100644
--- a/package/ego-browser/src/taskspace-e2e.test.mjs
+++ b/package/ego-browser/src/taskspace-e2e.test.mjs
@@ -236,7 +236,7 @@ test("taskspace e2e useOrCreateTaskSpace selects user-owned spaces without claim
await assert.rejects(
() =>
runTaskspaceScript(ego, `await useOrCreateTaskSpace("checkout-flow")`),
- /has taken control of this task space/,
+ /Control of this task space is with the user/,
);
assert.deepEqual(ego.calls, [["listTaskSpaces"], ["useTaskSpace", 7]]);
});