Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(chat): match the async row by its exact core id, not any task-id row

M3gA-Mind51561b2bdd0a
diff --git a/app/src/store/__tests__/chatRuntimeSlice.test.ts b/app/src/store/__tests__/chatRuntimeSlice.test.ts
index e578b6d2a3..0f63658853 100644
--- a/app/src/store/__tests__/chatRuntimeSlice.test.ts
+++ b/app/src/store/__tests__/chatRuntimeSlice.test.ts
@@ -1457,6 +1457,41 @@ describe('subagent event reducers (Phase 3)', () => {
expect(again.toolTimelineByThread['t1'][0].status).toBe('success');
});
+ it('subagentDone also settles the hydrated core row of the same delegation, and only it', () => {
+ // After its turn settles, an async delegation's live row is the completed
+ // snapshot's, under the core's id. A row that merely carries the same task
+ // id under any other id is a different card (`continue_subagent` reuses
+ // task ids) and must not take this run's outcome.
+ const row = (id: string) => ({
+ id,
+ name: 'subagent:researcher',
+ round: 0,
+ seq: 0,
+ status: 'running' as const,
+ subagent: { taskId: 'task-1', agentId: 'researcher', toolCalls: [] },
+ });
+ const state = reducer(
+ undefined,
+ setToolTimelineForThread({
+ threadId: 't1',
+ entries: [row('subagent:task-1'), row('earlier-card')],
+ })
+ );
+ const done = reducer(
+ state,
+ subagentDone({
+ threadId: 't1',
+ rowId: 't1:subagent:task-1:researcher',
+ taskId: 'task-1',
+ success: true,
+ })
+ );
+ expect(done.toolTimelineByThread['t1'].map(e => [e.id, e.status])).toEqual([
+ ['subagent:task-1', 'success'],
+ ['earlier-card', 'running'],
+ ]);
+ });
+
it('subagentCancelResolved settles a spinning row by task id from the cancel answer', () => {
// Aborted: the run was cancelled.
const aborted = reducer(spawn(), subagentCancelResolved({ taskId: 'task-1', cancelled: true }));
diff --git a/app/src/store/chatRuntimeSlice.ts b/app/src/store/chatRuntimeSlice.ts
index c39776366a..86a4c806cb 100644
--- a/app/src/store/chatRuntimeSlice.ts
+++ b/app/src/store/chatRuntimeSlice.ts
@@ -1951,18 +1951,21 @@ const chatRuntimeSlice = createSlice({
// paused for input that then completes must not stay stuck at
// awaiting_user). Already-terminal rows are left as-is.
//
- // Also matched by task id: a detached (`async`) child outlives its turn,
- // and that turn's `chat_done` replaces the live timeline with the
- // completed snapshot, whose row id is the core's `subagent:<task>`, not
- // this socket `rowId`. Matching the id alone left that row running, and
- // a background delivery (a `chat_done` with no `inference_start`) then
- // froze it as its own trail: a card that spun forever under the reply
- // announcing the child's result.
+ // Also the same delegation under the core's row id: a detached (`async`)
+ // child outlives its turn, and that turn's `chat_done` replaces the live
+ // timeline with the completed snapshot, whose row is `subagent:<task>`,
+ // not this socket `rowId`. Matching the socket id alone left that row
+ // running, and a background delivery (a `chat_done` with no
+ // `inference_start`) then froze it as its own trail: a card that spun
+ // forever under the reply announcing the child's result. Exactly that
+ // id, not any row with this task id: `continue_subagent` reuses a task
+ // id, and a run it continues must not settle an earlier turn's card.
+ const coreRowId = taskId !== undefined ? `subagent:${taskId}` : undefined;
const entries = subagentRows(
state,
threadId,
e =>
- (e.id === rowId || (taskId !== undefined && e.subagent?.taskId === taskId)) &&
+ (e.id === rowId || e.id === coreRowId) &&
(e.status === 'running' || e.status === 'awaiting_user')
);
for (const entry of entries) {