fix: settle busy sessions after managed OpenCode restart (#3002)

* fix: reconcile busy sessions after managed OpenCode restart

Forced health-check restarts previously rebound the event stream without
settling in-flight turns, so sessions stayed busy with no terminal state.
Interrupt those sessions, classify health failures, and retain bounded
process diagnostics for post-restart diagnosis.

Fixes #2943

Co-authored-by: serkraser <serkraser@gmail.com>

* fix: surface interrupted chats after OpenCode restart

Complete unfinished assistant turns as aborted once the session is
authoritatively idle, and show a persistent toast so users can continue
instead of remaining silently stranded.

Fixes #2943

Co-authored-by: serkraser <serkraser@gmail.com>

* fix: redact Basic auth credentials in restart diagnostics

The key/value sanitizer stopped at whitespace, so Authorization: Basic
credentials survived in stderr tails and health snapshots. Redact the
scheme token before that rule runs.

Co-authored-by: serkraser <serkraser@gmail.com>
This commit is contained in:
Serhii Dziupin
2026-08-19 11:53:30 +03:00
committed by GitHub
parent 13a45aa5a5
commit 14d7a0ca9b
24 changed files with 806 additions and 80 deletions
@@ -179,6 +179,80 @@ describe('session runtime', () => {
expect(runtime.getActiveSessionCount()).toBe(0);
});
it('interrupts busy sessions after restart and broadcasts terminal events once', () => {
const events = [];
const runtime = createSessionRuntime({
writeSseEvent() {},
getNotificationClients: () => new Set(),
broadcastEvent: (event) => events.push(event),
});
runtimes.push(runtime);
const status = (sessionID, type) => runtime.processOpenCodeSsePayload({
type: 'session.status',
properties: { sessionID, status: { type } },
});
status('session-busy-1', 'busy');
status('session-busy-2', 'retry');
status('session-busy-3', 'busy');
status('session-idle', 'idle');
expect(runtime.getActiveSessionCount()).toBe(3);
events.length = 0;
expect(runtime.interruptBusySessionsAfterRestart()).toEqual({
sessionIds: ['session-busy-1', 'session-busy-2', 'session-busy-3'],
});
expect(runtime.getActiveSessionCount()).toBe(0);
expect(runtime.getSessionActivitySnapshot()).toEqual({
'session-busy-1': { type: 'idle' },
'session-busy-2': { type: 'idle' },
'session-busy-3': { type: 'idle' },
'session-idle': { type: 'idle' },
});
expect(runtime.getSessionStateSnapshot()).toEqual({
'session-busy-1': expect.objectContaining({
status: 'idle',
metadata: expect.objectContaining({
message: 'Interrupted by OpenCode restart',
reason: 'opencode-restart',
}),
}),
'session-busy-2': expect.objectContaining({ status: 'idle' }),
'session-busy-3': expect.objectContaining({ status: 'idle' }),
'session-idle': expect.objectContaining({ status: 'idle' }),
});
const terminalEvents = events.filter((event) => (
event.type === 'openchamber:session-status' || event.type === 'session.error'
));
expect(terminalEvents).toHaveLength(6);
for (const sessionId of ['session-busy-1', 'session-busy-2', 'session-busy-3']) {
expect(terminalEvents).toContainEqual({
type: 'openchamber:session-status',
properties: expect.objectContaining({
sessionID: sessionId,
status: 'idle',
}),
});
expect(terminalEvents).toContainEqual({
type: 'session.error',
properties: {
sessionID: sessionId,
error: {
name: 'MessageAbortedError',
message: 'The running turn was interrupted when OpenCode restarted.',
},
},
});
}
expect(terminalEvents.some((event) => event.properties.sessionID === 'session-idle')).toBe(false);
events.length = 0;
expect(runtime.interruptBusySessionsAfterRestart()).toEqual({ sessionIds: [] });
expect(events).toEqual([]);
});
it('restores activity when busy interrupts cooldown without timer underflow', () => {
vi.useFakeTimers();
const runtime = createSessionRuntime({