Skip to content

Commit 360f612

Browse files
committed
fix(web): restore active status on reconnect
1 parent ba8e927 commit 360f612

File tree

4 files changed

+284
-248
lines changed

4 files changed

+284
-248
lines changed

runtime/test/web/app-sse-events.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function createDeps() {
1616
const toastCalls: Array<[string, string | null | undefined, string | undefined, number | undefined]> = [];
1717
const clearQueueCalls: number[] = [];
1818
let refreshQueueCalls = 0;
19+
let agentStatus: any = null;
1920

2021
const deps: HandleAppSseEventDependencies = {
2122
currentChatJid: 'chat:alpha',
@@ -46,7 +47,9 @@ function createDeps() {
4647
setFloatingWidget: () => undefined,
4748
clearLastActivityFlag: () => undefined,
4849
handleUiVersionDrift: () => false,
49-
setAgentStatus: () => undefined,
50+
setAgentStatus: (next) => {
51+
agentStatus = applyUpdate(agentStatus, next);
52+
},
5053
setAgentDraft: () => undefined,
5154
setAgentPlan: () => undefined,
5255
setAgentThought: () => undefined,
@@ -98,6 +101,7 @@ function createDeps() {
98101
getToastCalls: () => toastCalls,
99102
getClearQueueCalls: () => clearQueueCalls,
100103
getRefreshQueueCalls: () => refreshQueueCalls,
104+
getAgentStatusState: () => agentStatus,
101105
};
102106
}
103107

@@ -129,6 +133,35 @@ test('handleAppSseEvent removes followup rows on removal events and schedules qu
129133
expect(state.getRefreshQueueCalls()).toBe(1);
130134
});
131135

136+
test('handleAppSseEvent restores active agent status on reconnect', async () => {
137+
const state = createDeps();
138+
state.deps.getAgentStatus = async () => ({
139+
status: 'active',
140+
data: {
141+
chat_jid: 'chat:alpha',
142+
type: 'intent',
143+
title: 'Compacting context',
144+
intent_key: 'compaction',
145+
turn_id: 'turn-42',
146+
started_at: '2026-03-30T21:00:00.000Z',
147+
},
148+
thought: { text: 'thought preview', totalLines: 2 },
149+
draft: { text: 'draft preview', totalLines: 3 },
150+
});
151+
152+
handleAppSseEvent('connected', { app_asset_version: 'test' }, state.deps);
153+
await Promise.resolve();
154+
155+
expect(state.getAgentStatusState()).toEqual({
156+
chat_jid: 'chat:alpha',
157+
type: 'intent',
158+
title: 'Compacting context',
159+
intent_key: 'compaction',
160+
turn_id: 'turn-42',
161+
started_at: '2026-03-30T21:00:00.000Z',
162+
});
163+
});
164+
132165
test('handleAppSseEvent maps extension notify events into intent toasts', () => {
133166
const state = createDeps();
134167

runtime/web/src/ui/app-sse-events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ export function handleAppSseEvent(
226226
const payload = response.data;
227227
const activeTurn = readAgentTurnId(payload);
228228
if (activeTurn) setActiveTurn(activeTurn);
229+
setAgentStatus(payload);
229230
noteAgentActivity({ clearSilence: true });
230231
showLastActivity(payload);
231232

runtime/web/static/dist/app.bundle.js

Lines changed: 238 additions & 236 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/web/static/dist/app.bundle.js.map

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)