fix: clear live agent status on cancel

Clear only active agent statuses when a session reaches idle, and keep the terminal cancelled/error run cleanup in place. Add regression coverage for idle cleanup after cancellation-like flows.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
David Kaya
2026-03-25 22:20:57 +01:00
co-authored by Copilot
parent c9cc2fd8e7
commit 628fdff29e
2 changed files with 39 additions and 1 deletions
+4
View File
@@ -46,6 +46,10 @@ export function applySessionEventActivity(
if (event.status === 'running') {
return removeSessionActivity(current, event.sessionId);
}
if (event.status === 'idle') {
return clearActiveSessionActivity(current, event.sessionId);
}
}
if (
+35 -1
View File
@@ -149,7 +149,7 @@ describe('session activity helpers', () => {
});
});
test('keeps the last observed status after completion or error', () => {
test('preserves completed activity on idle and error', () => {
const current: SessionActivityMap = {
'session-1': {
architect: {
@@ -179,6 +179,40 @@ describe('session activity helpers', () => {
).toEqual(current);
});
test('clears only active agent states when a session becomes idle', () => {
const current: SessionActivityMap = {
'session-1': {
architect: {
agentId: 'architect',
agentName: 'Architect',
activityType: 'completed',
},
reviewer: {
agentId: 'reviewer',
agentName: 'Reviewer',
activityType: 'thinking',
},
},
};
expect(
applySessionEventActivity(current, {
sessionId: 'session-1',
kind: 'status',
occurredAt: '2026-03-23T00:00:01.000Z',
status: 'idle',
}),
).toEqual({
'session-1': {
architect: {
agentId: 'architect',
agentName: 'Architect',
activityType: 'completed',
},
},
});
});
test('clears only active agent states when a run is cancelled', () => {
const current: SessionActivityMap = {
'session-1': {