mirror of
https://github.com/davidkaya/aryx.git
synced 2026-08-04 02:48:44 +02:00
fix: clear stale agent activity on cancel
Clear only still-active side-panel agent states when a run ends as cancelled or error, while preserving completed agent statuses. Add a renderer regression test for cancelled runs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -48,6 +48,14 @@ export function applySessionEventActivity(
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
event.kind === 'run-updated'
|
||||
&& event.run
|
||||
&& (event.run.status === 'cancelled' || event.run.status === 'error')
|
||||
) {
|
||||
return clearActiveSessionActivity(current, event.sessionId);
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
@@ -137,6 +145,38 @@ function removeSessionActivity(
|
||||
return next;
|
||||
}
|
||||
|
||||
function clearActiveSessionActivity(
|
||||
current: SessionActivityMap,
|
||||
sessionId: string,
|
||||
): SessionActivityMap {
|
||||
const sessionActivity = current[sessionId];
|
||||
if (!sessionActivity) {
|
||||
return current;
|
||||
}
|
||||
|
||||
let changed = false;
|
||||
const nextSessionActivity = Object.fromEntries(
|
||||
Object.entries(sessionActivity).filter(([, activity]) => {
|
||||
const keep = !isAgentActivityActive(activity);
|
||||
changed ||= !keep;
|
||||
return keep;
|
||||
}),
|
||||
);
|
||||
|
||||
if (!changed) {
|
||||
return current;
|
||||
}
|
||||
|
||||
if (Object.keys(nextSessionActivity).length === 0) {
|
||||
return removeSessionActivity(current, sessionId);
|
||||
}
|
||||
|
||||
return {
|
||||
...current,
|
||||
[sessionId]: nextSessionActivity,
|
||||
};
|
||||
}
|
||||
|
||||
function resolveAgentKey(event: SessionEventRecord): string | undefined {
|
||||
return event.agentId?.trim() || event.agentName?.trim();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user