Repository navigation
fix: skip idle chats when checking for stranded turns - #205835
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. |
|
The hosted On that base, the model logout schema accepts the optional literal |
|
Codex review: needs maintainer review before merge. What this changesThis PR reuses parked-session keys across unchanged projection revisions so periodic recovery skips ordinary idle chats. Example: A quiet Gateway contains 1,470 ordinary sessions.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it is a useful, maintainer-authored optimization that preserves stranded-turn recovery, with no actionable correctness findings. Reviewed head: Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway maintenance supplies the session projection to the yield sweep, which checks live continuation sources and records failures for unreachable parked turns. flowchart TD
A[Gateway maintenance] --> B[Prepare session projection]
B --> C[Projection revision and parked keys]
C --> D[Select candidate sessions]
D --> E[Check live wake sources]
E --> F[Preserve valid waits]
E --> G[Record unreachable turn failure]
Technical reviewBest possible solution: Retain this focused revision-keyed optimization and preserve the existing live wake checks and lifecycle failure owner. Do we have a high-confidence way to reproduce the issue? Current main selects the full session roster before checking parked eligibility, matching the reported recurring idle work; this read-only review ran no target code. Is this the best way to solve the issue? The small cache reuses the projection's publication identity and indexed lookup, retains only keys, and continues checking mutable wake sources on every selected waiter. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a40778940382. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +15, Tests +59, Other +12. Total +86 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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 Reviewed November 26, 2026, 3:07 AM ET / 08:07 UTC. |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…elded session (#204801) ## Problem `src/gateway/session-yield-sweep.test.ts` > "settles only an unreachable parked lifecycle (exec-completion)" fails intermittently on scheduled `main` (run 45403387860): `expected undefined to be 'failed'` at the final status check. Since #204265, the yield sweep keeps a yielded session waiting while it has a stored owed exec result (`shouldWake`, `session-yield-sweep.ts:45`). When the exec completion's wake settles as `cancelled`, `settleOwedExecWake` withholds the owed row asynchronously: `readPendingOwed` and then `withhold` on the database worker. The test resolved the wake and advanced the fake clock straight away. When the sweep tick ran before `withhold` committed, the sweep still saw the pending row and correctly left the session waiting, so the status stayed unset. ## Solution Test-only change. After the wake settles, the test waits until `shouldWake` (the stored-row check the sweep itself uses) reports no owed result, then advances the clock. Product behavior is unchanged: the next sweep tick settles the session. #204609 and #204621 do not touch this path. #204609 changes only `session-restart-resume-custody.ts`, which only the restart path imports. #204621 changes reply-operation backend readiness, which none of these modules use; the test's wake is mocked. ## Impact No change to production code or user behavior. ## Evidence - Before: intermittent red on scheduled `main` with the assertion above: run 45403387860, and again in run 45849028735 (2026-11-26, `checks-node-compact-large-14`, after #205835), `expected undefined to be 'failed'` in the exec-completion case. The race mechanism (`settleOwedExecWake` withholds the owed row after the wake settles) is unchanged on current `main`. - Negative control (deterministic): with a 500 ms delay inserted before that `withhold` (local throwaway change), current `main` fails the exec-completion case 3/3 with the same assertion; with this change it passes 3/3. - Without the delay, interleaved runs of `session-yield-sweep.test.ts` with this change applied to current `main`: 20/20 green (main alone was also 20/20 locally; the natural race is rare). ## Merge danger Two-way door: test-only, a revert fully undoes it. Blast radius: one test file. Co-authored-by: Ayaan Zaidi <[email protected]>
…elded session (openclaw#204801) ## Problem `src/gateway/session-yield-sweep.test.ts` > "settles only an unreachable parked lifecycle (exec-completion)" fails intermittently on scheduled `main` (run 45403387860): `expected undefined to be 'failed'` at the final status check. Since openclaw#204265, the yield sweep keeps a yielded session waiting while it has a stored owed exec result (`shouldWake`, `session-yield-sweep.ts:45`). When the exec completion's wake settles as `cancelled`, `settleOwedExecWake` withholds the owed row asynchronously: `readPendingOwed` and then `withhold` on the database worker. The test resolved the wake and advanced the fake clock straight away. When the sweep tick ran before `withhold` committed, the sweep still saw the pending row and correctly left the session waiting, so the status stayed unset. ## Solution Test-only change. After the wake settles, the test waits until `shouldWake` (the stored-row check the sweep itself uses) reports no owed result, then advances the clock. Product behavior is unchanged: the next sweep tick settles the session. openclaw#204609 and openclaw#204621 do not touch this path. openclaw#204609 changes only `session-restart-resume-custody.ts`, which only the restart path imports. openclaw#204621 changes reply-operation backend readiness, which none of these modules use; the test's wake is mocked. ## Impact No change to production code or user behavior. ## Evidence - Before: intermittent red on scheduled `main` with the assertion above: run 45403387860, and again in run 45849028735 (2026-11-26, `checks-node-compact-large-14`, after openclaw#205835), `expected undefined to be 'failed'` in the exec-completion case. The race mechanism (`settleOwedExecWake` withholds the owed row after the wake settles) is unchanged on current `main`. - Negative control (deterministic): with a 500 ms delay inserted before that `withhold` (local throwaway change), current `main` fails the exec-completion case 3/3 with the same assertion; with this change it passes 3/3. - Without the delay, interleaved runs of `session-yield-sweep.test.ts` with this change applied to current `main`: 20/20 green (main alone was also 20/20 locally; the natural race is rare). ## Merge danger Two-way door: test-only, a revert fully undoes it. Blast radius: one test file. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Every minute, a gateway with many idle chats selected all their metadata to find turns that had yielded. In a 1,470-session fixture that returned 88,200 ordinary rows an hour after startup, even with zero new turns. This work came from the generic recovery sweep added in #202338.
User Impact
A quiet gateway still checks for stranded turns every minute. After the first scan it can skip ordinary sessions until a row changes. A parked turn with a live child, controller, exec, or retained continuation keeps waiting. A turn that loses its last wake source still receives its recorded failure.
Why This Change Was Made
The recovery sweep remembers the parked keys under the projection's existing row-publication revision. It still prepares metadata on each tick and checks live wake sources for every selected waiter. Clearing a pending final delivery invalidates the candidate set even when the ordinary session-list fields look the same. The cache retains keys only and uses the existing identity lookup.
Evidence
Five alternating before/after pairs on an exclusive Linux x64 AWS host with Node 24.19.0 and 1,470 synthetic sessions. Each arm ran 100 warm ticks per pair against the same hydrated projection. Wall and CPU times were recorded separately from allocation sampling. The acceptance rule was zero ordinary rows on an unchanged idle tick, while a newly eligible or stranded turn is still handled.
Reproduce with the committed session-read fixture and yield benchmark. Run from the candidate checkout, using a new fixture directory and a new output path for each pass.
Repeat the last command with
--allocationand a fresh output filename to sample allocations. AWS comparisonThe red regression selected both ineligible rows on the second tick. The patched sweep passed all seven focused cases, including recovery after final-delivery state clears and a held continuation releases. All eleven sibling restart cases passed. The gateway TypeScript check, scoped lint, formatting, and runtime build also passed. Focused tests and typecheck
The built gateway ran with 23 synthetic agents and 1,470 sessions, using one PID. Readiness returned HTTP 200 at 0, 65, 125, and 185 seconds. By 65 seconds, the broad selection had returned 1,470 rows once. Both its call count and row count stayed fixed through 125 and 185 seconds. The gateway exited with status 0. Restart tests, build, and gateway run
Independent autoreview of
31627710a8..395e5e444ffound no actionable P0–P2 findings. The review covered the sweep, row-revision invalidation, candidate lookup, tests, and benchmark. Production changed by +15 net lines, tests by +59, and the benchmark by +12.The September field report predates this sweep. It remains open for the offered same-PID, post-GC retainer evidence. Idle field investigation