fix(gateway): log errors when terminal persistence rejects in chat-abort cleanup#97813
fix(gateway): log errors when terminal persistence rejects in chat-abort cleanup#97813SunnyShu0925 wants to merge 0 commit into
Conversation
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. This PR has the right owner-boundary idea, but it is now superseded by an open sibling that targets the same Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Canonical path: Close this branch and review the formatted, proof-positive owner-boundary implementation in So I’m closing this here and keeping the remaining discussion on #97839 and #97795. Review detailsBest possible solution: Close this branch and review the formatted, proof-positive owner-boundary implementation in Do we have a high-confidence way to reproduce the issue? Yes. Source inspection shows a rejected Is this the best way to solve the issue? No. The owner-boundary location is the right fix shape, but this branch is no longer the best landing path because the sibling PR uses Security review: Security review needs attention: The diff adds a low-severity log-boundary concern by rendering unknown persistence errors without the gateway formatter.
AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 6de357ad4772. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
87f37e8 to
4d29d9b
Compare
4d29d9b to
803e4d5
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
803e4d5 to
6de357a
Compare
|
@clawsweeper re-review |
|
🦞🧹 Reason: re-review requires an open issue or PR. |
Related to #97795.
What Problem This Solves
persistGatewaySessionLifecycleEventfailures increateAgentEventHandlerare silently swallowed — the terminal lifecycle handler catches rejection only to broadcast a fallback session snapshot, without logging the failure. Operators cannot observe session-store write failures in production.Why This Change Was Made
Log the rejected persistence at the owner boundary (
server-chat.ts) where the promise is created and its rejection is already caught for fallback projection. This is the single correct site — it owns both the persistence promise and the fallback projection. Logging in cleanup consumers (chat-abort.ts,server-runtime-subscriptions.ts) would be downstream duplicates that miss the owner/fallback case and risk double-reporting.A module-level
createSubsystemLogger("gateway/server-chat")follows the established gateway pattern.Root Cause
introduced bycommit7c47904bb42d(joshavant). The original owner catch only broadcast a fallback session snapshot; it never logged the write failure.Confidence: clear — the
.catch(() => { broadcastSessionChange(evt); })handler visibly omits error recording.User Impact
None — this is an observability fix for operators.
Evidence
Behavior addressed: When
persistGatewaySessionLifecycleEventrejects, the gateway logs the failure with the run ID and error before broadcasting the fallback session snapshot. Logging happens once at the persistence owner boundary.Real environment tested: Linux (kernel 4.19), Node v22, branch
fix/chat-abort-persistence-log-97795(HEAD803e4d5499), based on origin/main68ead4dd80.Exact steps or command run after this patch:
Evidence after fix:
persistGatewaySessionLifecycleEventresolvesmarkPersisted()+ broadcast (existing)persistGatewaySessionLifecycleEventrejectslog.error→ then fallback broadcastTest output — assertion added to existing fallback test:
The existing test "broadcasts a terminal fallback snapshot when persistence fails" now additionally asserts
mockLogErrorwas called with"gateway: failed to persist terminal session lifecycle event for run run-failed-write: Error: disk full".Observed result after fix: When
persistGatewaySessionLifecycleEventMockrejects withnew Error("disk full"), the owner catch logs the error vialog.errorand still broadcasts the fallbacksessions.changedsnapshot. ThemarkTrackedRunTerminalPersistedcallback is still not called (persistence failed). All 95 existing tests pass.What was not tested:
createAgentEventHandlerproduction code and asserts the log is emitted from the exact same.catch()block that the compiled gateway runsRegression Test Plan
Modified test
broadcasts a terminal fallback snapshot when persistence fails:persistGatewaySessionLifecycleEventMockrejects withnew Error("disk full")handler({...})sessions.changedbroadcast (existing)mockLogErrorcalled with message containing run ID and error text (new)Changes
src/gateway/server-chat.ts: +8/−1 lines —createSubsystemLoggerimport, module-level logger,log.errorin the persistence owner.catch()src/gateway/server-chat.agent-events.test.ts: +11 lines —vi.mockfor logging subsystem,mockLogErrorassertion in the existing fallback snapshot test