Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Guard policy: a done downgraded to partial ends its run as partial

Barack Sokullufb05f1357e5d
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 4569b43ad..7485d4942 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -7320,7 +7320,7 @@ export class Agent extends LoopDetector {
this._throwIfAborted(this._runAbortSignal(tabId));
if (!current()) return null;
}
- return { content: result.value, status: 'done' };
+ return { content: result.value, status: result.endStatus || 'done' };
}
} catch (error) {
if (this._checkAbort(tabId) || error?.name === 'AbortError' || this._isCostAllowanceError(error)) throw error;
@@ -16698,12 +16698,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// done_json is always a success claim; its result carries no outcome.
const claimsSuccess = toolResult.outcome === 'success' || (fnName === 'done_json'
&& toolResult.doneJson === true && toolResult.cloudFailed !== true && toolResult.outcome === undefined);
+ let doneEndStatus = null;
if (!scheduledResume && claimsSuccess && this._completionOutcomeDowngraded(tabId)) {
// Accepted over a guard that knows the claim is wrong: end the run,
// but as partial so schedules, watches and Cloud runs do not count a
// success. Before the chat ending below, so a chat run gets the
// same partial contract (runEnded, no auto-resume, the notice).
toolResult.outcome = 'partial';
+ // The run itself ends as partial too (trace status, run_status,
+ // onRunFinished), as a plain final over such a guard does. Not a
+ // batch status: a correction that arrived meanwhile still reopens
+ // this done like any other.
+ doneEndStatus = 'partial';
}
if (!scheduledResume && runOptions?.scheduledRun !== true && this.chatSessions.has(tabId)
&& ['partial', 'failed'].includes(toolResult.outcome)) {
@@ -16767,7 +16773,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// rawSummary is the model-authored done text before the progress
// ledger is appended for display; research sharing stores it as the
// response instead of mislabeling local presentation as provider output.
- return { action: 'return', value: finalResponse, rawSummary: rawDoneSummary };
+ return { action: 'return', value: finalResponse, rawSummary: rawDoneSummary,
+ ...(doneEndStatus ? { endStatus: doneEndStatus } : {}) };
}
// Loop detection — exact calls, semantic AX reads, and coordinates run
@@ -52954,9 +52961,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (typeof batchResult.rawSummary === 'string' && batchResult.rawSummary.trim()) {
shareRawResponse = batchResult.rawSummary;
}
- if (batchResult.status) {
- _traceStatus = batchResult.status;
- onUpdate('run_status', { status: batchResult.status, message: batchResult.value });
+ const endStatus = batchResult.status || batchResult.endStatus;
+ if (endStatus) {
+ _traceStatus = endStatus;
+ onUpdate('run_status', { status: endStatus, message: batchResult.value });
}
return finalResponse;
}
@@ -54357,10 +54365,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (typeof batchResult.rawSummary === 'string' && batchResult.rawSummary.trim()) {
shareRawResponse = batchResult.rawSummary;
}
- if (batchResult.status) {
- onUpdate('run_status', { status: batchResult.status, message: batchResult.value });
+ const endStatus = batchResult.status || batchResult.endStatus;
+ if (endStatus) {
+ onUpdate('run_status', { status: endStatus, message: batchResult.value });
}
- return finish(batchResult.value, batchResult.status);
+ return finish(batchResult.value, endStatus);
}
if (batchResult.action === 'deliver') {
const recovery = await this._recoverDeliveryCheckpointTurn(
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 16ab5c3c2..51210de51 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -6866,7 +6866,7 @@ export class Agent extends LoopDetector {
this._throwIfAborted(this._runAbortSignal(tabId));
if (!current()) return null;
}
- return { content: result.value, status: 'done' };
+ return { content: result.value, status: result.endStatus || 'done' };
}
} catch (error) {
if (this._checkAbort(tabId) || error?.name === 'AbortError' || this._isCostAllowanceError(error)) throw error;
@@ -14965,12 +14965,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// done_json is always a success claim; its result carries no outcome.
const claimsSuccess = toolResult.outcome === 'success' || (fnName === 'done_json'
&& toolResult.doneJson === true && toolResult.cloudFailed !== true && toolResult.outcome === undefined);
+ let doneEndStatus = null;
if (!scheduledResume && claimsSuccess && this._completionOutcomeDowngraded(tabId)) {
// Accepted over a guard that knows the claim is wrong: end the run,
// but as partial so schedules, watches and Cloud runs do not count a
// success. Before the chat ending below, so a chat run gets the
// same partial contract (runEnded, no auto-resume, the notice).
toolResult.outcome = 'partial';
+ // The run itself ends as partial too (trace status, run_status,
+ // onRunFinished), as a plain final over such a guard does. Not a
+ // batch status: a correction that arrived meanwhile still reopens
+ // this done like any other.
+ doneEndStatus = 'partial';
}
if (!scheduledResume && runOptions?.scheduledRun !== true && this.chatSessions.has(tabId)
&& ['partial', 'failed'].includes(toolResult.outcome)) {
@@ -15034,7 +15040,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// rawSummary is the model-authored done text before the progress
// ledger is appended for display; research sharing stores it as the
// response instead of mislabeling local presentation as provider output.
- return { action: 'return', value: finalResponse, rawSummary: rawDoneSummary };
+ return { action: 'return', value: finalResponse, rawSummary: rawDoneSummary,
+ ...(doneEndStatus ? { endStatus: doneEndStatus } : {}) };
}
// Loop detection — exact calls, semantic AX reads, and coordinates run
@@ -44617,9 +44624,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (typeof batchResult.rawSummary === 'string' && batchResult.rawSummary.trim()) {
shareRawResponse = batchResult.rawSummary;
}
- if (batchResult.status) {
- _traceStatus = batchResult.status;
- onUpdate('run_status', { status: batchResult.status, message: batchResult.value });
+ const endStatus = batchResult.status || batchResult.endStatus;
+ if (endStatus) {
+ _traceStatus = endStatus;
+ onUpdate('run_status', { status: endStatus, message: batchResult.value });
}
return finalResponse;
}
@@ -45854,10 +45862,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (typeof batchResult.rawSummary === 'string' && batchResult.rawSummary.trim()) {
shareRawResponse = batchResult.rawSummary;
}
- if (batchResult.status) {
- onUpdate('run_status', { status: batchResult.status, message: batchResult.value });
+ const endStatus = batchResult.status || batchResult.endStatus;
+ if (endStatus) {
+ onUpdate('run_status', { status: endStatus, message: batchResult.value });
}
- return finish(batchResult.value, batchResult.status);
+ return finish(batchResult.value, endStatus);
}
if (batchResult.action === 'deliver') {
const recovery = await this._recoverDeliveryCheckpointTurn(
diff --git a/test/guard-advisory-completion.mjs b/test/guard-advisory-completion.mjs
index 8ff1d859e..84a6a8bdf 100644
--- a/test/guard-advisory-completion.mjs
+++ b/test/guard-advisory-completion.mjs
@@ -274,6 +274,45 @@ for (const build of ['chrome', 'firefox']) {
}
});
+ test(`${label}: a done accepted over a check that knows the task is not done ends the run as partial`, async () => {
+ // As for a plain final: the done's own outcome is downgraded, and the
+ // run reports partial too (trace status, run_status, onRunFinished).
+ for (const decided of [true, false]) {
+ const tab = nextTab++;
+ let n = 0;
+ const agent = loopAgent(Agent, async () => {
+ n++;
+ if (!decided && n === 1) return call('save', 'click_ax', { ref_id: 'ref_save' });
+ return call('done', 'done', { summary: 'Wrote the post.', outcome: 'success' });
+ });
+ if (decided) {
+ agent._richTextToolbarGuard.hasPending = () => true;
+ agent._richTextToolbarGuard.completionAction = () => ({ name: 'type_ax', ref_id: 'ref_bold' });
+ }
+ const runStatuses = [];
+ const doneOutcomes = [];
+ let finished = null;
+ const onUpdate = (type, data) => {
+ if (type === 'run_status') runStatuses.push(data?.status);
+ if (type === 'tool_result' && data?.name === 'done' && data.result?.done) doneOutcomes.push(data.result.outcome);
+ };
+ const options = { detachedRequestId: `guard-${tab}`, onRunFinished: status => { finished = status; } };
+ const result = streaming
+ ? await agent.processMessageStream(tab, 'Write the post.', onUpdate, 'act', options)
+ : await agent.processMessage(tab, 'Write the post.', onUpdate, 'act', [], options);
+ assert.ok(String(result).startsWith(`Wrote the post.\n\n${CAVEAT}`), `${label}: the done is accepted with its caveat`);
+ if (decided) {
+ assert.deepEqual(doneOutcomes, ['partial'], `${label}: the done's own outcome was not downgraded`);
+ assert.equal(finished, 'partial', `${label}: the run finished as a success over a check that knows it is not done`);
+ assert.deepEqual(runStatuses, ['partial'], `${label}: the scheduler did not hear the partial ending`);
+ } else {
+ assert.deepEqual(doneOutcomes, ['success']);
+ assert.equal(finished, 'done', `${label}: missing evidence alone must not downgrade the run`);
+ assert.deepEqual(runStatuses, []);
+ }
+ }
+ });
+
test(`${label}: a plain final accepted over unfinished progress rows ends the run as partial`, async () => {
for (const status of ['pending', 'acted']) {
const tab = nextTab++;
@@ -493,6 +532,7 @@ for (const build of ['chrome', 'firefox']) {
assert.equal(second.action, 'return');
const doneResult = updates.filter(update => update.type === 'tool_result' && update.data.name === 'done').at(-1)?.data.result;
assert.equal(doneResult?.outcome, 'success', `${build}: missing evidence alone must not downgrade the outcome`);
+ assert.equal(second.endStatus, undefined, `${build}: missing evidence alone must not end the run as partial`);
});
test(`${build}: a chat run's success accepted over a decided check ends with the chat partial contract`, async () => {
@@ -566,6 +606,8 @@ for (const build of ['chrome', 'firefox']) {
assert.ok(String(accepted.value).includes(`${CAVEAT}1 of 2 items in the task's progress list were not finished.`));
const doneResult = updates.filter(update => update.type === 'tool_result' && update.data.name === 'done').at(-1)?.data.result;
assert.equal(doneResult?.outcome, 'partial', `${build} ${status}: a success with an item unfinished was not downgraded`);
+ assert.equal(accepted.status, undefined, `${build} ${status}: a correction can still reopen the done`);
+ assert.equal(accepted.endStatus, 'partial', `${build} ${status}: the run must end as partial too`);
}
});
diff --git a/test/run.js b/test/run.js
index aaa0b0ac1..2648c52ef 100644
--- a/test/run.js
+++ b/test/run.js
@@ -51004,7 +51004,10 @@ test('agent propagates status-bearing terminal tool-batch returns to callers', (
['firefox', 'src/firefox/src/agent/agent.js'],
]) {
const source = fs.readFileSync(path.join(ROOT, rel), 'utf8');
- const emissions = source.match(/onUpdate\('run_status', \{ status: batchResult\.status, message: batchResult\.value \}\);/g) || [];
+ // A batch status, or the end status of a done downgraded to partial.
+ const statuses = source.match(/const endStatus = batchResult\.status \|\| batchResult\.endStatus;/g) || [];
+ const emissions = source.match(/onUpdate\('run_status', \{ status: endStatus, message: batchResult\.value \}\);/g) || [];
+ assert.equal(statuses.length, 2, `${label}: streaming and non-streaming terminal returns must both read the run status`);
assert.equal(emissions.length, 2, `${label}: streaming and non-streaming terminal returns must both propagate run status`);
}
});