fix(gateway): log terminal persistence failures in chat abort cleanup#97856
fix(gateway): log terminal persistence failures in chat abort cleanup#97856hanZeng-08 wants to merge 2 commits into
Conversation
Previously, a rejected projectSessionTerminalPersistence promise was silently swallowed, making it impossible for operators to detect terminal state persistence failures. Add an optional SubsystemLogger to registerChatAbortController and emit log.error before cleanup. Pass context.logGateway from both chat-send and agent run registration paths. Fixes openclaw#97795
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: this PR now covers the previously flagged paths, but it does so by adding multiple diagnostics for the same terminal-persistence promise, while #97839 is open, mergeable, proof-positive, and owns the cleaner single owner-boundary fix. Canonical path: Land one formatted owner-boundary diagnostic via #97839 or an equivalent narrow branch, and keep downstream cleanup consumers focused on cleanup and recovery state. So I’m closing this here and keeping the remaining discussion on #97839. Review detailsBest possible solution: Land one formatted owner-boundary diagnostic via #97839 or an equivalent narrow branch, and keep downstream cleanup consumers focused on cleanup and recovery state. Do we have a high-confidence way to reproduce the issue? Yes from source. Current main creates the terminal persistence promise in Is this the best way to solve the issue? No. The best fix is one owner-boundary diagnostic; this branch also logs in downstream cleanup consumers, while #97839 implements the cleaner canonical path with proof. Security review: Security review cleared: No concrete security or supply-chain regression was found; the diff adds no dependency, workflow, package, permission, or secret-handling surface, and uses existing redaction-aware error formatting/logging paths. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 6de357ad4772. |
…re logs Extends the previous chat-abort fix to also log terminal persistence rejections in the remaining two boundaries ClawSweeper identified: - src/gateway/server-runtime-subscriptions.ts: delayed cleanup ordering when persistence is attached after cleanup() was requested. - src/gateway/server-chat.ts: owner-side terminal lifecycle persistence fallback catch. Both boundaries receive the injected SubsystemLogger. The existing server-chat.agent-events test now asserts log.error is called on persistence failure.
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
🦞✅ Reason: structured ClawSweeper close marker: close-required (sha=9aa0b9251acc368ecdfb9f577d8d5ec951110cd1) Closed:
|
Fixes #97795
Summary
Fix silent swallowing of terminal-state persistence failures across three Gateway boundaries:
src/gateway/chat-abort.ts— cleanup catch blocksrc/gateway/server-runtime-subscriptions.ts— delayed cleanup ordering (persistence attached aftercleanup()was requested)src/gateway/server-chat.ts— owner-side terminal lifecycle persistence fallback catchReal Behavior Proof
Environment: Linux, Node v22.23.1, pnpm 11.2.2, worktree SHA 1052652
Before fix (new regression test on old code):
After fix:
$ node scripts/run-vitest.mjs src/gateway/chat-abort.test.ts src/gateway/server-chat.agent-events.test.ts Test Files 6 passed (6) Tests 326 passed (326)Real behavior proof (chat-abort cleanup path):
The script creates a
registerChatAbortControllerregistration with a reallog.errorlogger, attaches a rejectingprojectSessionTerminalPersistencepromise, callscleanup(), and observes the diagnostic log plus correct controller removal.Lint / Format checks (changed files):
Regression Test Plan
src/gateway/chat-abort.test.tslogs an error and still removes the registration when terminal persistence failssrc/gateway/server-chat.agent-events.test.tsbroadcasts a terminal fallback snapshot when persistence failsto assertlog.erroris calledRoot Cause
Three separate
.catch(() => { ... })handlers discarded the rejection reason:src/gateway/chat-abort.ts:176src/gateway/server-runtime-subscriptions.ts:100src/gateway/server-chat.ts:714Implementation Plan Details
log?: SubsystemLoggertoregisterChatAbortController;log?: SubsystemLoggertostartGatewayEventSubscriptionsand pass it tocreateAgentEventHandler;log?: SubsystemLoggertocreateAgentEventHandler;context.logGatewayfromagent.ts/chat.tstoregisterChatAbortController;logfromserver.impl.tstostartGatewayEventSubscriptions;log?.error(...)in all three catch blocks, usingformatErrorMessage(err);Change Details
src/gateway/chat-abort.tsformatErrorMessage,SubsystemLoggerregisterChatAbortControllerparams gainlog?: SubsystemLoggersrc/gateway/server-methods/agent.ts/chat.tsregisterChatAbortController(...)calls addlog: context.logGatewaysrc/gateway/server-chat.tsformatErrorMessage,SubsystemLoggerAgentEventHandlerOptionsgainslog?: SubsystemLoggercreateAgentEventHandlerdestructureslogsrc/gateway/server-runtime-subscriptions.tsformatErrorMessage,SubsystemLoggerstartGatewayEventSubscriptionsparams gainlog?: SubsystemLoggerlogtocreateAgentEventHandlersrc/gateway/server.impl.tsstartGatewayEventSubscriptions(...)call addslogsrc/gateway/chat-abort.test.tssrc/gateway/server-chat.agent-events.test.tscreateHarnesscreates a mock logger and passes it tocreateAgentEventHandlerlog.erroris calledTest Points
log.errorand passespnpm tsgo:core,pnpm tsgo:core:test,pnpm check:import-cyclespassNext Steps
@clawsweeper re-review.