Repository navigation
fix: chat turns fail when session state is briefly busy - #156067
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Inspected real Gateway + Control UI behavior proof captured on 1a99a7c1a869db1dafbe90a5bde5ad3299f94f8f, including main’s worker-backed transcript reports, retained cleanup repair, and lifecycle-owned read cancellation. The recording covers original-request recovery, bounded exhaustion, refresh/Details/Check status without resend, preserved draft, and Stop with an explicitly uncertain warning. Every accepted request has one persisted user turn and one terminal event. All native holders rolled back and exited; the isolated Gateway stopped. Inference is a deterministic loopback fixture, not an external provider. Raw captures are retained with the implementation work. The capture SHA is explicit; subsequent verification is recorded in the PR body rather than relabeling the video. Before — pinned baseline b7f616e, 22.6 seconds: 155975-before.mp4After — integrated recovery, exhaustion, refresh and Stop, 42.08 seconds: 155975-current-behavior-after.mp4 |
|
Codex review: needs maintainer review before merge. Reviewed September 23, 2026, 4:24 PM ET / 20:24 UTC (Revision 9). ClawSweeper reviewWhat this changesThe branch adds an asynchronous wait for busy chat-session database admission and carries typed waiting, failure, and Stop feedback through the Gateway, stored history, native protocol, and Control UI. Merge readiness✅ Ready for maintainer review Current main still has the synchronous cold-admission path, and no merged fix replaces this PR. The refreshed real-flow evidence and reported published-updater check address the prior review’s blockers. The exact cause of the original incident remains unknown. Priority: P2 Review scores
Verification
How this fits togetherA chat request passes through Gateway reply admission, which reads the agent’s SQLite session state before an agent run begins. The Gateway then sends progress or a terminal result to chat clients and stores the outcome for history. flowchart LR
A[Chat request] --> B[Gateway reply admission]
B --> C{State database busy?}
C -->|No| E[One agent run]
C -->|Yes| D[Bounded acquisition wait]
D -->|Clears| E
D -->|Deadline or Stop| F[Status or Stop notice]
E --> G[Answer and history]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +480, Tests +1046, Other +2. Total +1528 across 60 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Land the bounded acquisition-only repair through normal review, retain the no-replay rule, and resolve the paired report after the PR merges. Do we have a high-confidence way to reproduce the issue? Yes. A pinned baseline Gateway and Control UI capture shows the raw failure with a native SQLite holder, and current main retains the same synchronous cold-open path; this read-only review did not execute current main. Is this the best way to solve the issue? Yes. Waiting at the physical acquisition owner avoids replaying a possibly executed turn, while cancellation and current-owner checks guard the resumed admission. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against bdeca1661473. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
d25fe4e to
5bc580b
Compare
5bc580b to
1a99a7c
Compare
Wait at the physical state acquisition owner without replaying the accepted turn. Preserve independent caller deadlines and cancellation, and present certified contention consistently across live chat, restored history, and uncertain Stop acknowledgements. Co-authored-by: jalehman <[email protected]>
Co-authored-by: jalehman <[email protected]>
Co-authored-by: jalehman <[email protected]>
Co-authored-by: jalehman <[email protected]>
Co-authored-by: jalehman <[email protected]>
d3d7c74 to
b118609
Compare
Preserve Guest Stop intent ownership alongside structured contention reporting; use officially regenerated Workboard asset references. Co-authored-by: jalehman <[email protected]>
Keep bounded acquisition deadlines in the existing native monotonic domain through asynchronous validation and cleanup. Preserve original native custody tests and join fixture-owned work without weakening guards or assertions. Co-authored-by: jalehman <[email protected]>
OpenClaw-Publication: c9920138-e70d-4483-bb02-0716c17f7ebe
|
Refreshed real-Gateway proof after the native-clock repair and main integration. The built Gateway and Gateway-served Control UI use a real native SQLite holder; inference uses a credential-free deterministic loopback provider, not an external service.
The 41.960-second recording and screenshots were inspected. Its runtime source is Attached: refreshed recording, successful original turn, persisted warning/details, and Stop warning. 155975-native-clock-after.mp4 |
|
Native land-ready review is complete for
Proceeding through native merge guards under the maintainer’s scoped landing authorization. No deployment or unrelated runtime change. |
|
Merged via squash.
|
) Fix cold chat admission failing during transient session-state contention. Wait asynchronously at the physical acquisition owner with one bounded native-monotonic budget, without replaying agent work. Preserve cancellation, current authority, native cleanup certainty, and independent coalesced callers. Carry safe waiting/failure/Stop feedback through live and restored chat. Verified exact-head CI, original failing CI groups, real Gateway/native-holder UI evidence, and the published2026.9.5-updater recovery/Doctor/restart cell. Historical incident holder remains unknown; no unrelated schema, protocol-version, security-policy, or deployment change. Reported by and implemented at the request of @jalehman. ## Work sessions - [Original discussion with @jalehman](https://team.openclaw.ai/chat/roboclaw/dashboard/767cab96-667e-4062-85ef-1639fb0f12c7) - [Implementation and verification](https://team.openclaw.ai/chat/roboclaw/dashboard/e66496e6-5418-4afa-90d9-3d1a63c3a909) [View the OpenClaw team session](https://team.openclaw.ai/chat/roboclaw/dashboard/e66496e6-5418-4afa-90d9-3d1a63c3a909) Co-authored-by: jalehman <[email protected]>
…s.abort chat.abort preserves the typed state-contention outcome at the RPC boundary (openclaw#156067): when a session read fails while cancellation still takes effect, Stop answers UNAVAILABLE with the contention errorKind instead of replaying or claiming it had no effect. sessions.abort calls the same lifecycle but sat outside that guard, so the same busy-window read failure surfaced as an untyped internal error from the other Stop entry point. Extract the contention response into respondToAbortStateContention and share it through withAbortStateContentionGuard, then wrap the sessions.abort handler so both Stop entry points return the identical typed outcome. The fast dispatch proof covers the guard on both entry points; the real-lock proof (real Gateway, foreign BEGIN EXCLUSIVE on the live shared-state database) joins the release-only runtime inventory. Co-Authored-By: Claude Code <[email protected]>



Related: #155975
What Problem This Solves
Fixes: a chat turn can fail with a raw storage error when opening a cold session database overlaps state-lifecycle contention.
User Impact
User impact: brief contention can clear while the original turn waits, without sending another message; longer contention produces a calm warning with Check status and expandable, redacted details. Stop remains available.
This does not automatically replay an interrupted turn. The historical incident's exact holder and acquisition callsite remain unknown; the reproduction below establishes a specific reachable cold-admission defect, not that historical cause.
Why This Change Was Made
Cold reply admission used a synchronous native acquisition that could prevent the host from servicing the work needed to release contention. Admission now waits asynchronously at the physical database owner's acquisition boundary. Each request retains one bounded five-second acquisition budget, independent cancellation, and request/storage authority checks, even when physical preparation is shared. The operation itself and cleanup are not retried. The host-side native acquisition waits share that retry policy. Their retained worker cleanup does not require new-read admission; the request owners still validate new operations. The executing worker’s newer checked late-custody delegate handoff from main is preserved unchanged.
Reported by and implemented at the request of @jalehman.
Work sessions
Evidence
Before
After
Behavior videos
The refreshed recording uses the integrated runtime at
bcf8fc40375plus the fresh, lockfile-built Workboard manifest subsequently committed in09172c28033—the only source-tree difference. It covers the final runtime behavior, including lifecycle-owned read cancellation, the native monotonic acquisition clock, and current-main Stop intent ownership. Recording and full-resolution states were inspected; the published player decodes/seeks and all three images render.Before — pinned baseline, 22.6 seconds
155975-before.mp4
After — integrated runtime recovery, exhaustion, refresh and Stop, 41.960 seconds
155975-native-clock-after.mp4
Real Gateway/Control UI checks passed:
Every accepted request had exactly one persisted user message and one terminal event. All holder workers rolled back and exited successfully; isolated Gateways were stopped. These execution-count assertions come from real requests/history, not rendered text alone.
Real proof uses an isolated built Gateway and its built Control UI, with a separate native SQLite holder. Inference is a credential-free, deterministic loopback Responses fixture, not an external provider. The memory slot is disabled through supported configuration so the database can become idle/cold; native borrower and eviction guards are unchanged. Scheduling instrumentation is a synthetic trigger, not a reconstruction of the historical holder. The short case schedules the foreign holder’s release on the host to expose synchronous event-loop starvation; the long/Stop cases release independently. Existing broker grant pumping remains unchanged.
An earlier monolithic
check:changedattempt ended with Testbox exit 255 during broad lint and has no complete result; the scoped checks below passed separately. That incomplete attempt is not used as evidence. External-provider inference was not run; hosted native-app CI is reported separately below.Regression, verification commands, and additional captured states
Published-head verification
Current candidate:
09172c28033bb8fe53691358a25a80ce8a261e2d. Exact-head CI checked out merged539b7c9b85935b94a546da1f78cbd352aa8ab96against actual main parentaa9b92a12d87f7c2326c2862114553344afb9154. CI completed successfully on this exact head: 170 jobs passed and 11 were skipped; none failed or remained pending. This includes the corrected build-artifacts job and completed iOS smoke. The full PR check rollup was also re-read with no failing or pending checks; skipped and neutral reports are not counted as executed passes.The measured clock-domain defect (start 0 ms, subsequent read 25,093 ms, deadline 5,000 ms) is repaired by using the native monotonic clock throughout acquisition. Cleanup-certainty/authorization guards and the original conversation-capture fixture remain unchanged. Focused proofs passed: original capture 22, acquisition 9, dreaming 11, waiter budgets 7, recovery/ACP 83, and admission claims 14. Fresh independent P0–P2 reviews found no actionable defects.
All seven original failed CI plan groups passed on the integrated runtime using their original configuration/include selections and worker limits. Current main’s upstream Telegram fixture refactor is retained and its actual HTTP tests passed; this is not a claim that the historical file’s case layout is unchanged. Additional integrated checks passed: 87 UI tests in 8 files, core/UI types, messaging/agents-sessions test-type graphs, scoped typed lint including SDK declaration preparation, and protocol generation/checks. The original batch’s sole failure was its old Workboard manifest; after applying official generator output from a fresh locked-dependency install, all bundled asset checks passed on exact head 09172c2 (wrapper exit 0, 61.07 s).
Historical b118 CI failed seven groups. The subsequent bcf8 build-artifacts failure was traced to a stale local dependency install (TypeBox 1.3.30 versus locked 1.3.32); the official fresh generator—not a hand-edited hash—produced the two corrected asset paths. No assertions, cleanup guards, test pools, or timeout budgets were weakened to conceal failures.
Published-driver × candidate compatibility — passed
The maintained
recovery-cleanupcell passed on isolated Blacksmith Testboxtbx_01m37tjm7cb5xyy80y04508c86(provider run). It used the actual published[email protected]updater, not package replacement, against existing synthetic operator fixture state. No live Team state or live provider credentials were used.09172c28033bb8fe53691358a25a80ce8a261e2d, tree65bc9bd37cfc07b4a2bfda0e81d367d50397b698; carrierb14d3ffee88713ad57f2e43e43a3890863ea51a2. Baseline release buildec9c1a13db89was replaced by candidate buildb14d3ffee887; both retain nominal version2026.9.5, so the distinct build IDs and tarball digest—not a version bump—identify the tested update.38385067deb0c98b7080b2f3db7c3c75bd08ad64629cd5849948438662a46803.ok/succeeded, 18 steps exit 0, including automatic migration Doctor and post-install checks. Automatic-migration assertions passed before standalone Doctor; no separate recovery update was needed.Evidence limitation: this published driver did not provide an independent
firstHopPostCoreexit snapshot. The first invocation’s update result and pre-standalone-Doctor migration assertions supply the convergence evidence; an unavailable capture is not claimed. Expected malformed/protected-fixture warnings, deferred plugin convergence, a DM-collision advisory and noncanonical-state service-management skip were recorded without failing the cell.Reproduction command:
No merge, auto-merge, or deployment is requested.
Earlier implementation checks (before the final compatibility follow-up and generated-asset refresh):
pnpm build,pnpm ui:build,pnpm protocol:check: passed on isolated Blacksmith Testbox (Node 24.19.0).pnpm tsgo:core,pnpm tsgo:ui, andnode scripts/run-tsgo-core-test-shards.mjs --changed-paths-json <changed-tests>: passed across all eight selected canonical test graphs. Four graphs were rechecked after mechanical test lint fixes.run-oxlint.mjson every changed TypeScript file,run-stylelint.mtson touched UI files,ui:i18n:verify, formatting, line-cap/max-lines/assertion-safety ratchets, andgit diff --check: passed.1a99a7c1a869: 42.08 seconds, with counted original requests, inference calls, persisted user turns, terminal outcomes, and native holder cleanup. Baseline recording: 22.6 seconds. Full captures and representative frames were inspected; no Team data or production Gateway was used.Hosted CI follow-up
The first ready-head run exposed two task-related defects, not unrelated main failures. The exact CI merge reproduced 20 subagent-resume failures, while its exact base passed the same ordered shard. A newly added read guard wrongly refused retained worker cleanup after read admission had been revoked. Removing that guard at the custody owner restores cleanup; new chat admission keeps its existing authority checks. A new canonical-close regression failed before the correction and passed afterward (93 ms test body); independent P0–P2 review of the correction is clean.
The repaired exact-merge replay passed the original first CI plan (
agentic-gateway-core-2-hosted-1), preserving both configs and all 83 include patterns/order: 83 files, 1,229 passed / 1 skipped, 161.13 s. Exact-base control: 159.61 s. Both used isolated Blacksmith Testbox, Node 24.19.0 and the original CI plan runner; this is not a full-workflow green claim.Workboard imports the additive chat protocol states into its browser bundle. The official generator leaves the exact CI base unchanged but changes the candidate manifest hash; regenerated output matches between the isolated candidate and this checkout.
The subsequent main integration preserves
b6340c7947b’s worker-backed runtime transcript reports, live write assertion, and startup-only native settlement. Its affected seven-file test set and full build passed. A fresh review then identified a missing lifecycle cancellation signal on the new asynchronous admission read. A deterministic regression failed before the fix; the existing admission owner now supplies its composed signal to the read. 57 tests across the reply-admission and lifecycle-owner/diagnostic suites passed, including cancellation, independent upstream signal, and lifecycle-lock drainage. Fresh P0–P2 review of that correction is clean.CI on
1a99a7c1a869also exposed TS2322 at the existing Gateway agent-admission caller: its custom final-validation callback accepts an optional boolean, not an AbortSignal. The final correction preserves that callback’s original zero-argument contract and supplies the composed signal only to asynchronous validation. It uses no cast or type widening; fresh P0–P2 review is clean. 48 tests across lifecycle admission, the real Gateway late-admission caller, and reply admission passed after that correction.The final fixture-only lint correction rejects with an Error while retaining the same cancellation and lock-drain assertions. The last rebase resolved only generated Workboard hash conflicts and preserved main’s cold-metadata reader and descendant-abort changes.
Measured test cost
Initial implementation per-file measurements (historical): files passed individually via
node scripts/run-vitest.mjs <file> --maxWorkers=1(the repository test runner), with ready dependencies and a shared module-cache path. These are measured wrapper wall times, not CI durations; the integrated plan-group costs above are reported separately.src/config/sessions/session-accessor.sqlite-worker-coordination.test.tspackages/gateway-protocol/src/schema/logs-chat.test.tssrc/auto-reply/reply/reply-turn-admission.database-claim.test.tssrc/gateway/chat-display-projection.state-contention.test.tssrc/gateway/server-chat-state.test.tssrc/gateway/server-chat.agent-events.test.tssrc/gateway/server-methods/chat-send-dispatch-errors.test.tssrc/gateway/server-methods/chat-send-retry.test.tssrc/gateway/server-methods/chat.abort-contention.test.tssrc/infra/state-database-coordinator-acquisition.test.tssrc/state/openclaw-agent-db-write.env-capture.test.tsui/src/pages/chat/chat-gateway.contention.test.tsui/src/pages/chat/chat-history.contention.test.tsui/src/pages/chat/chat-history.run-error.test.tsui/src/pages/chat/chat-view-notices.test.tsui/src/pages/chat/chat-view.contention.test.tsui/src/pages/chat/components/chat-message.startup.test.tsui/src/pages/chat/components/chat-message.test.tsui/src/pages/chat/run-lifecycle.contention.test.tsThe final 15.31s native admission file used ready compiled-worker artifacts and includes about 8s of actual tests. The earlier cold run took 39.08s, including 21.38s of compiled-subprocess preparation. Its real SQLite holder, physical-file identity changes, queue ownership and cancellation cannot be proven by a cheaper mocked layer. The manual Gateway/video composition is not committed into per-PR CI. Other longer entries are existing suites plus the focused regressions, not added wall-clock sleeps.
Refreshed warning and redacted details:
Stop acknowledgement after cancellation:
View the OpenClaw team session