Repository navigation
fix(gateway): mark a terminal restart-safe admission unread - #159285
wangmiao0668000666 wants to merge 15 commits into
Conversation
|
Codex review: needs real behavior proof before merge. What this changesThis PR carries browser visibility through restart-safe chat admission so visible terminal failures can mark the session unread. Example: A browser sends run live-restart-unread-run to agent:main:dashboard:live-restart-unread, and workspace preparation fails before agent execution.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep open: current main still has the reported visibility omission, and this PR provides a focused repair with meaningful unique work. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherGateway chat admission retains request facts through dispatch settlement; the existing lifecycle writer stores activity timestamps that sessions.list projects into the Control UI unread badge. flowchart LR
A[Browser chat send] --> B[Request preparation]
B --> C[Restart safe admission]
C --> D[Terminal settlement]
D --> E[Session lifecycle writer]
E --> F[Sessions list projection]
F --> G[Control UI unread badge]
Technical reviewBest possible solution: Complete the existing visibility contract at the restart-safe terminal owner while preserving quiet internal work and current claim settlement. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the missing visibility field and its unread consequence, supported by supplied RED/GREEN traces; this read-only review ran no target code. Is this the best way to solve the issue? Carrying the caller's visibility decision into the existing terminal writer fixes the producer without duplicating unread policy or assuming all Goal admissions are visible. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4f3eb4f25466. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +32, Tests +310, Docs +1, Config +1, Other +156. Total +500 across 19 files. Added test files: 2. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (11 earlier review cycles; latest 8 shown)
Reviewed October 11, 2026, 11:57 AM ET / 15:57 UTC (Revision 12). |
6afe925 to
6f18e35
Compare
openclaw#155690 advances lastActivityAt only for terminal writes that carry controlUiVisible, so a Control-UI chat send that a restart-safe admission terminalizes after a Gateway restart is persisted terminal with no activity advance and the session list never shows the unread marker, even though the reply never reached the user. terminalizeRestartSafeChatAdmission synthesizes its own terminal event, and that admission only exists for the browser Control UI (restartRecoverySourceIngress is hardcoded "control-ui" and eligibility is isBrowserOperatorUiClient), so the event now stamps controlUiVisible: true.
Boots a real Gateway, sends a real chat.send from a browser Control-UI client, and terminalizes the restart-safe claim through the Gateway's own dispatch-error writer. On the unfixed base the row is terminal with lastActivityAt undefined and deriveSessionUnread false; with the fix it advances activity and reads unread. Deterministic: no timing race, 3/3 red and 4/4 green locally.
…ion store The rebased branch lands on a main whose session store is SQLite-backed and whose running state lives in the lifecycle snapshot, so the terminal write now goes through the captured target/read-source contract and the fixtures no longer seed a legacy running status. Co-Authored-By: Claude Code <[email protected]>
…tures The restart-safe admission type now carries controlUiVisible; the worker settlement, close-settlement and dispatch-error fixtures that terminalize an admission directly pass the fact explicitly. Co-Authored-By: Claude Code <[email protected]>
…ture Main rejects legacy agents.entries default markers at gateway startup; the canonical roster shape carries the single main entry without one. Co-Authored-By: Claude Code <[email protected]>
dfa25c7 to
26568e6
Compare
96a7ecc to
b499d8d
Compare
Closing without merging — handoffClosing this PR instead of carrying it further. The repair is understood and small; what is missing is the shipped-behavior proof the review now requires (a failed browser turn demonstrated through a running candidate Gateway), and this environment cannot produce a candidate build (see the last section). The defect is still live on Branch state at close —
Proof recipe for whoever revives this (all steps need a build made from this head):
The proof receipts in the body were captured before the last rebase; the "Rebase note" section states which head they belong to. |
Refs #160003 (still open; this PR is closed without merging)
What Problem This Solves
A Control-UI chat send that a restart-safe admission terminalizes is persisted terminal without an unread marker, even though the reply never reached the user. #155690 advances
lastActivityAtonly for terminal writes that carrycontrolUiVisible(src/gateway/session-lifecycle-state.ts:224), andterminalizeRestartSafeChatAdmissionsynthesizes its own terminal event (src/gateway/server-methods/chat-restart-recovery.ts:427) without that field. The row keepslastActivityAtundefined,deriveSessionUnreadstays false, and the session list never shows the failure the user still has to read.Precedent: #155690 (the gate this completes — same owner, same "a visible terminal advances activity" invariant).
Why This Change Was Made
A restart-safe request is not the same thing as a visible turn.
createRestartSafeChatRequestreturns a fingerprint for Goal work before it checks browser eligibility (chat-restart-recovery.ts:121), because internal start/resume must survive a restart too. So the terminal write cannot infer visibility from the admission's existence.The admission now records the decision its caller already made and carries it to the write:
createRestartSafeChatRequesttakescontrolUiVisibleand returns it on every branch, including the Goal branch.RestartSafeChatAdmissionandterminalizeRestartSafeChatAdmissiontake the same field, and the synthetic terminal event stampscontrolUiVisible: params.controlUiVisibleinstead of a literaltrue.chat-send-session.tssupplies the browser-client fact,isBrowserOperatorUiClient(request.clientInfo). Visibility is deliberately not the wholeeligibleconjunction: the remaining terms (no attachments, no reconnect resume, no timeout override, …) describe restart safety, not visibility.Production LOC is
+25/-1across three files. Tests are+262/-1plus two one-line call-site updates, plus the CI inventory line and its doc bullet. No new option, configuration, validator, or persistence surface: the fact lives in memory on the admission.CI cost also moves with it: the ~33 s real-Gateway tour is registered in
RELEASE_ONLY_RUNTIME_TEST_FILES, so ordinary PRs and pushes keep the fast owner contract instead of paying for the full composition (+1inventory line,+1doc bullet, no case or assertion removed).Classification:
behavior-completingUser Impact
Evidence
Rebase note (2026-10-11)
This revision's head is
b499d8deca9c1e6ff21cf1c5dd4d0e5bbbb9a0ef, rebased ontomain@ea576bd11d8because the previous base (dfa25c723a340f18aa39cbac0cd2012f63f412c5) predated a material amount of merged work. The rebase replayed the same commits with no conflicts; the patch is +508/-8 across 19 files (git diff --stat origin/main...HEAD). The extra +6/-1 is one follow-up commit,refactor(gateway): narrow the transcript-state admission to the facts it reads, which repairs a typecheck break our requiredcontrolUiVisibleadmission field introduced for the recovery fixture thatmainadded in #167080 after this branch was cut: the transcript-state serializer now declares exactly the three facts it reads (priorTerminalSourceRunId,requestFingerprint,retryExpectedState) instead of demanding a visibility claim it never consumes. The proof receipts below were captured on the pre-rebase head and were not re-run on this base; CI re-runs on this head.Exact-head proof receipt
6afe925fe687061695e4cb3087933006d46f3931(fix4714841a3e9, CI tierdf07e0e393a, live readback0a2f6b8e524, test splitf0a85cd2a2e, two test-fixture type fixes, the rendered proof6504a8158a9, then itspackage.jsonregistration)2871aef000c(the three production files are byte-identical to current main6ff787d0509; branch merges cleanly with it —git merge-tree --write-tree origin/main HEADreports no conflicts)terminalizeRestartSafeChatAdmission, driven into a real session store created bywithOpenClawTestStatederiveGatewaySessionLifecycleSnapshotinsideterminalizeRestartSafeChatAdmission(chat-restart-recovery.ts:427)lastActivityAtand the projectedunreadfield, read back through the realloadSessionEntry, the realderiveSessionUnread, and a realsessions.listRPCderiveSessionUnread(loadSessionEntry(target))— the same predicate behindsession-utils-row.tsunread— plus the identical value through the Control UI's ownsessions.listcalllastActivityAtundefined andderiveSessionUnreadfalse after a successful terminalization (status: "failed", delivery claim released)sessions.listfalsebefore terminalization, so the assertions cannot pass trivially, and the hidden Goal case asserts the write still terminalizes while visibility stays falsewithOpenClawTestStatestate/config; no production Gateway, session, channel, token, or configuration was touchedInspectable RED -> GREEN terminal traces
Node
v24.18.0.Live end-to-end proof (real Gateway, real RPC, real projection)
src/gateway/server.chat.live-restart-unread.test.tsboots a real in-process Gateway (startGatewayWithClient, real loopback listener, Control-UI origin allowed), seeds an idle session row, and drives a realchat.sendRPC from a browser Control-UI client (GATEWAY_CLIENT_NAMES.CONTROL_UI, modeWEBCHAT, originhttp://localhost:18789), so the request genuinely qualifies for a restart-safe admission. It then reads the row back three ways: the realloadSessionEntry, the realderiveSessionUnread, and the Gateway's ownsessions.listRPC — the exact response the Control UI renders the marker from.The failure trigger is deterministic and needs no timing race: the seeded row carries
pendingProjectGitUrl: "not a repository url", whichprepareSessionWorkspace(chat-send-agent-dispatch.ts:273→session-create-project.ts:241-246) cannot normalize, so dispatch throws before the agent run starts or takes over terminal persistence. The Gateway's own writer (chat-send-dispatch-errors.ts:282→terminalizeRestartSafeChatAdmission) therefore terminalizes the claim — exactly the write this PR fixes.The row is terminal in both runs (
status=failed, claim released), so terminalization itself is not what changes — only the activity fact the #155690 gate reads.chat-send-dispatch-errors.tssets its generic lifecycle patch only when!restartSafeDispatchFailureTerminalized, so once the restart-safe claim terminalizes,lastActivityAton base can only beundefinedbecauseterminalizeRestartSafeChatAdmissionwrote the row withoutcontrolUiVisible.Rendered marker (before / after)
Real Control UI bundle, real Chromium (Playwright), synthetic session and message text only. Reproduce with
node --import ./scripts/tsx.mjs scripts/capture-restart-unread-marker-mock-proof.mts --out <file.png> --mode before|after:What this capture does and does not prove. It varies only the projected
unreadfact, so it proves the render binding in the shipped UI —row.unread→ the sidebar marker — and nothing about how the fact is produced. The producing half is proven separately above, through a real Gateway: realchat.send, the restart-safe terminal write, and a realsessions.listwhose row reportsunread: true. The seam the two halves leave untested is the row delivery between the Gateway and a mounted UI, which is unchanged shared infrastructure and is exercised by the existing Control UI suites.Why there is no single-flow real capture. A real-Gateway Control UI capture was built and booted on this host (
createQaGatewayChild+createControlUiE2eSuite: real Gateway,hello-ok, server buildf0a85cd2a2e, the seeded row rendered in the real sidebar), but it cannot be driven to a composer send here: the session pane's firstchat.startupretries indefinitely withUNAVAILABLE: session changed while reading history; reload the conversationfor a row seeded outside the pane, so the composer parks the message and nochat.sendframe ever reaches the Gateway (reproduced without a browser viagateway.call("chat.startup", …)). Driving that send from a Control UI identity inside the same harness also fails: the harness client isgateway-client/backendand would not setcontrolUiVisible, a freshopenclaw-control-uiclient closes pre-hello, and replaying the page's own handshake in-browser failsDEVICE_AUTH_NONCE_MISMATCH. The live case above therefore drives the same real flow through the realchat.sendRPC rather than the rendered composer.CI routing proof
src/gateway/server.chat.live-restart-unread.test.tsis now inRELEASE_ONLY_RUNTIME_TEST_FILES(scripts/lib/ci-proof-test-inventory.mts), the same tier assrc/gateway/gateway.chat-redaction.test.tsand thesession-row-projection.keyed-marks.benchmark.test.tsdeferral in1dc005c7cb3. The filter only narrows planincludePatterns: the file keeps its canonicaltest/vitest/vitest.gateway-server.config.tsowner, its assertions, and itsagentic-control-plane-agent-chatshard, and a directly edited test file is still re-admitted to its own PR.test/scripts/ci-node-test-plan.test.ts— passes with the new release-inventory entry; its expectations are derived from the inventory itself, so a wrong tier fails it.check-test-types-core-*lanes pass at this head. Two test fixtures construct the request/admission literal directly and had to follow the new required field:chat-send-dispatch-errors.test.ts(late-rejectionterminal) andchat-send-pre-admission.test.ts(durable-fingerprintrestartSafeRequest).checks-node-changed-compact-large-40/ shardagentic-plugin-sdk-hosted-2failed insrc/plugin-sdk/session-store-runtime.conversation.test.tswithTestTeardownError: … AggregateError: Agent database resource drainage failed … SqliteWorkerError: Shared-state admission requires the host broker. The same shard, same file, same error also failed on PR fix(gateway): keep the typed state-contention Stop outcome on sessions.abort #159282 in the same time window, and the lane passes on this head now — a host-level SQLite teardown flake, not a diff-caused failure.test/scripts/ci-changed-node-test-plan.integration.test.ts— 2 cases time out at the file's own 120 s budget on this host ("keeps precise first-signin targets under exclusive Gateway admission", "keeps boundary coverage when only a deferred proof helper changes"). Proven unrelated: reverting this PR's inventory line and re-running the same case in isolation still times out (142.6 s vs 139.9 s).Verification
chat-restart-recovery.unread.test.ts(3 cases) — 1 file / 3 passed; RED 2/2 on unmodified production, RED 2/2 against the previous revision of this fix, GREEN 3/3 on this headchat-restart-recovery.unread.test.ts+chat-send-dispatch-errors.test.ts+server.chat.orphaned-recovery.test.ts— 3 files / 22 passedserver.chat.live-restart-unread.test.ts— 1 passed (~33 s warm, real Gateway boot); RED on unmodified production, GREEN on this headagent-runner-required-maintenance.pending-input.test.ts— 2 passed (the call site that now passes the visibility fact)oxfmt --checkon every changed file — clean10.54.159.54) is powered off and has no out-of-band power interface, so every run above is on this Linux host (Node v24.18.0) rather than the remote Docker lane. The live case exercises the dispatch-error terminalization site (chat-send-dispatch-errors.ts:282); the setup-error site (:103) and the in-flight restart abort (chat-send-handler.ts:219, reachable only through a real process restart) are not covered, and the failure trigger is an unnormalizable saved-repo URL rather than a provider failure. No live channel or credential was exercised.chat-send-dispatch-errors.ts:424-431(persistGatewaySessionLifecycleEventwith a syntheticdata: { phase: "error" }event) has the same literal omission for non-restart-safe Control-UI sends. Whether that path may stamp visibility depends on its own reachability, so it is deliberately left out rather than stamped blind.sessions.list). No single run on this host drives the rendered composer through the real restart-safe terminal write; the concrete blockers are listed in that section.Scope and risk
src/gateway/server-methods/chat-restart-recovery.tscontrolUiVisibleon the request, the admission, and the synthetic terminal event; stamp the passed value instead of a literaltruesrc/gateway/server-methods/chat-send-session.tseligibleconjunctionsrc/gateway/server-methods/chat-send-handler.tsfalse(quiet)src/gateway/server-methods/chat-restart-recovery.unread.test.tssrc/gateway/server.chat.live-restart-unread.test.tschat.send+ real terminalization +loadSessionEntry/deriveSessionUnread/sessions.listreadback)src/gateway/server-methods/chat-send-dispatch-errors.test.ts,src/gateway/server.chat.orphaned-recovery.test.ts,src/auto-reply/reply/agent-runner-required-maintenance.pending-input.test.ts,src/gateway/server-methods/chat-send-pre-admission.test.tsscripts/lib/ci-proof-test-inventory.mts,docs/ci/scope-and-routing/node-test-lanes.mdscripts/capture-restart-unread-marker-mock-proof.mts,package.json(ui:proof:restart-unread-marker),.github/pr-proof/restart-safe-unread-marker/{before,after}.pngderiveSessionUnreadpredicate; no new option, config, validator, or storage surface.