Skip to content

Commit e8f4c93

Browse files
committed
fix(gateway): log start session persistence failures
The gateway session-lifecycle "start" event persistence (persistGatewaySessionLifecycleEvent, which surfaces write failures via requireWriteSuccess) was fired as void ...catch(() => undefined), swallowing the rejection with zero logging. A failed start-marker write silently dropped the run's start record from restart-recovery accounting, with no operator-visible trace. The sibling terminal-phase catch already logs this since #97839; the start path was the unfixed sibling. Mirror that fix: log the swallowed start-phase persistence failure with the same redacted message shape via formatForLog, keeping the fire-and-forget semantics unchanged. Adds a focused regression test asserting the log fires on start-persist rejection.
1 parent 601b80c commit e8f4c93

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/gateway/server-chat.agent-events.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3174,6 +3174,32 @@ describe("agent event handler", () => {
31743174
);
31753175
});
31763176

3177+
it("logs when start session persistence fails", async () => {
3178+
const { chatRunState, handler, sessionEventSubscribers } = createHarness();
3179+
sessionEventSubscribers.subscribe("conn-1");
3180+
chatRunState.registry.add("run-global-work", {
3181+
sessionKey: "global",
3182+
agentId: "work",
3183+
clientRunId: "client-global-work",
3184+
});
3185+
persistGatewaySessionLifecycleEventMock.mockRejectedValueOnce(new Error("start disk full"));
3186+
3187+
handler({
3188+
runId: "run-global-work",
3189+
seq: 1,
3190+
stream: "lifecycle",
3191+
ts: Date.now(),
3192+
data: { phase: "start" },
3193+
});
3194+
3195+
await vi.waitFor(() => {
3196+
expect(logErrorMock).toHaveBeenCalledTimes(1);
3197+
});
3198+
expect(logErrorMock).toHaveBeenCalledWith(
3199+
"gateway: start session persistence failed session=global run=run-global-work error=Error: start disk full",
3200+
);
3201+
});
3202+
31773203
it("routes hidden selected-agent global chat events only to matching subscribers", () => {
31783204
const { broadcastToConnIds, chatRunState, handler, sessionMessageSubscribers } =
31793205
createHarness();

src/gateway/server-chat.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,14 @@ export function createAgentEventHandler({
14391439
sessionKey,
14401440
agentId: sessionAgentId,
14411441
event: evt,
1442-
}).catch(() => undefined);
1442+
}).catch((err: unknown) => {
1443+
// Surface the swallowed start-phase persistence failure: a silent write
1444+
// failure drops the run's start marker from restart-recovery accounting
1445+
// with no operator trace, matching the terminal-phase log below.
1446+
logError(
1447+
`gateway: start session persistence failed session=${formatForLog(sessionKey)} run=${formatForLog(evt.runId)} error=${formatForLog(err)}`,
1448+
);
1449+
});
14431450
const sessionEventConnIds = sessionEventSubscribers.getAll();
14441451
if (sessionEventConnIds.size > 0) {
14451452
broadcastToConnIds(

0 commit comments

Comments
 (0)