Skip to content
Merged
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
14 changes: 13 additions & 1 deletion src/chrome/src/run-reconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ function requestMatches(value, requestId) {
return value != null && String(value) === String(requestId);
}

function hasPlannerRequestFailure(updates) {
return updates.some(update => (
update?.type === 'warning'
&& update?.data?.code === 'planner_request_failed'
));
}

function runResponseFromSnapshot(snapshot, {
reconnected = false,
resumed = false,
Expand All @@ -21,7 +28,12 @@ function runResponseFromSnapshot(snapshot, {
const updates = (Array.isArray(snapshot?.events) ? snapshot.events : [])
.filter(event => event?.type && event.type !== 'run_complete')
.map(event => ({ type: event.type, data: event.data }));
if (snapshot?.status === 'failed' && !updates.some(update => update.type === 'error')) {
// Planner request failures already render an actionable Retry/Providers card.
// Treat that warning as the terminal presentation so recovery cannot append
// a second generic error card for the same failed snapshot.
if (snapshot?.status === 'failed'
&& !updates.some(update => update.type === 'error')
&& !hasPlannerRequestFailure(updates)) {
updates.push({
type: 'error',
data: {
Expand Down
14 changes: 13 additions & 1 deletion src/firefox/src/run-reconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ function requestMatches(value, requestId) {
return value != null && String(value) === String(requestId);
}

function hasPlannerRequestFailure(updates) {
return updates.some(update => (
update?.type === 'warning'
&& update?.data?.code === 'planner_request_failed'
));
}

function runResponseFromSnapshot(snapshot, {
reconnected = false,
resumed = false,
Expand All @@ -21,7 +28,12 @@ function runResponseFromSnapshot(snapshot, {
const updates = (Array.isArray(snapshot?.events) ? snapshot.events : [])
.filter(event => event?.type && event.type !== 'run_complete')
.map(event => ({ type: event.type, data: event.data }));
if (snapshot?.status === 'failed' && !updates.some(update => update.type === 'error')) {
// Planner request failures already render an actionable Retry/Providers card.
// Treat that warning as the terminal presentation so recovery cannot append
// a second generic error card for the same failed snapshot.
if (snapshot?.status === 'failed'
&& !updates.some(update => update.type === 'error')
&& !hasPlannerRequestFailure(updates)) {
updates.push({
type: 'error',
data: {
Expand Down
48 changes: 48 additions & 0 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,15 @@ const {
const {
isBackgroundConnectionError: isBackgroundConnectionErrorCh,
runDetachedWithReconnect: runDetachedWithReconnectCh,
runResponseFromSnapshot: runResponseFromSnapshotCh,
sendPlanResponseWithReconnect: sendPlanResponseWithReconnectCh,
} = await import(
'file://' + path.join(ROOT, 'src/chrome/src/run-reconnect.js').replace(/\\/g, '/')
);
const {
isBackgroundConnectionError: isBackgroundConnectionErrorFx,
runDetachedWithReconnect: runDetachedWithReconnectFx,
runResponseFromSnapshot: runResponseFromSnapshotFx,
sendPlanResponseWithReconnect: sendPlanResponseWithReconnectFx,
} = await import(
'file://' + path.join(ROOT, 'src/firefox/src/run-reconnect.js').replace(/\\/g, '/')
Expand Down Expand Up @@ -55933,6 +55935,52 @@ test('sidepanel run errors dedupe streamed, returned, and restored copies by tab
}
});

test('failed planner snapshots keep the actionable warning as the only error presentation', () => {
for (const [label, runResponseFromSnapshot] of [
['chrome', runResponseFromSnapshotCh],
['firefox', runResponseFromSnapshotFx],
]) {
const plannerMessage = 'Planner request failed before a valid response was available. No tools ran.';
const plannerResponse = runResponseFromSnapshot({
status: 'failed',
requestId: `${label}-planner-failure`,
finalContent: plannerMessage,
events: [{
type: 'warning',
data: {
code: 'planner_request_failed',
message: plannerMessage,
failureKind: 'request',
},
}],
});
assert.deepEqual(
plannerResponse.updates.map(update => update.type),
['warning'],
`${label}: planner failure card should not be followed by a synthesized generic error`,
);

const ordinaryResponse = runResponseFromSnapshot({
status: 'failed',
requestId: `${label}-ordinary-failure`,
finalContent: 'Error: Ordinary provider failure.',
events: [],
});
assert.equal(ordinaryResponse.updates.length, 1, `${label}: ordinary failed snapshot should synthesize one error`);
assert.equal(ordinaryResponse.updates[0]?.type, 'error', `${label}: ordinary failure should remain an error update`);
assert.equal(ordinaryResponse.updates[0]?.data?.message, 'Ordinary provider failure.', `${label}: synthesized error copy`);

const recordedResponse = runResponseFromSnapshot({
status: 'failed',
requestId: `${label}-recorded-failure`,
finalContent: 'Error: Recorded provider failure.',
events: [{ type: 'error', data: { message: 'Recorded provider failure.' } }],
});
assert.equal(recordedResponse.updates.length, 1, `${label}: recorded error should not be duplicated`);
assert.equal(recordedResponse.updates[0]?.type, 'error', `${label}: recorded error should be preserved`);
}
});

test('sidepanel routes every run-error path through request-scoped deduplication', () => {
for (const [label, panelRel] of [
['chrome', 'src/chrome/src/ui/sidepanel.js'],
Expand Down
Loading