Repository navigation
fix(sessions): back off automatic maintenance replans and make warn observe-only - #156583
Conversation
Coalesce invalidated automatic maintenance behind the per-store write-quiet timer and pause after three consecutive rejections. Preserve pending keys and commit authority. In warn mode, capture the age fact without creating a reclamation operation. Refs #153257. Thanks to @abuegab1-spec for tracing the generation-change loop and suggesting the explicit warn-mode guard. Validated with failing baseline regressions, 86 owner/sibling tests, isolated Gateway write-load and persisted-state proof, and Codex review.
|
🦞👀 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. |
|
Codex review: needs maintainer review before merge. Reviewed September 23, 2026, 10:53 AM ET / 14:53 UTC. ClawSweeper reviewWhat this changesThe PR delays automatic session cleanup retries until writes become quiet, pauses after three invalidations, and prevents warn mode from constructing cleanup operations. Merge readiness✅ Ready for maintainer review This remains a useful, focused fix: current main still immediately replans invalidated maintenance. No blocking correctness finding emerged, and the supplied Gateway evidence supports the bounded retry behavior without claiming to resolve the broader resource incident. Priority: P1 Review scores
Verification
How this fits togetherSession entry writes trigger background maintenance of each agent’s SQLite store. The maintenance owner schedules cleanup, protects active sessions, and passes eligible work through the existing worker and commit checks. flowchart TD
A[Session entry writes] --> B[Per-store maintenance owner]
B --> C{Maintenance mode}
C -->|Warn| D[Capture age fact only]
C -->|Enforce| E[Plan through existing worker]
E --> F{Inputs still current}
F -->|Yes| G[Commit and finalize cleanup]
F -->|No| H[Quiet-window retry or pause]
H --> B
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +51, Tests +87, Docs +5. Total +143 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep bounded retries in the existing maintenance owner while preserving commit checks, configured retention, and the separate investigation of broader resource recovery. Do we have a high-confidence way to reproduce the issue? Yes: concurrent entry writes invalidate the captured generation, and current main immediately loops into another plan. Source inspection and supplied baseline/candidate observations establish this path; the reviewer did not execute it. Is this the best way to solve the issue? Yes: the patch repairs scheduling within the existing owner, preserves final commit checks, and demonstrates cleanup resuming after contention subsides. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b7eb012f643b. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Coalesce invalidated automatic maintenance behind the per-store write-quiet timer and pause after three consecutive rejections. Preserve pending keys and commit authority. In warn mode, capture the age fact without creating a reclamation operation. Refs openclaw#153257. Thanks to @abuegab1-spec for tracing the generation-change loop and suggesting the explicit warn-mode guard. Validated with failing baseline regressions, 86 owner/sibling tests, isolated Gateway write-load and persisted-state proof, and Codex review.
Use the resolved npm transaction destination for admission rather than probing an unrelated ambient prefix. Coalesce superseded maintenance after a quiet write window, cap repeated replans, and distinguish typed supersession from real or slow Worker failures. Preserve frozen-target ownership and guards. Backports, in dependency order: - #158285 / 564947e - #156583 / 2044520 - #157834 / f583397 Source credit: Peter Steinberger and Ayaan Zaidi. Thanks to abuegab1-spec for the maintenance generation-loop diagnosis and warn-mode guard. Original-production regressions reproduced all three defects. Scoped owner, maintenance/updater sibling, and one real npm fixture passed (715 unique cases after overlap deduplication). Core/owner types, lint, formatting, and frozen eb377ac line-cap/suppression/assertion ratchets pass. Independent autoreview is scoped-clean through P2 on exact tree 4a2c853. No published-driver x packed-candidate qualification claimed. An older installed updater refusing before staging cannot acquire this correction from candidate code. Canonical release and public publication remain held. Implementation and verification: https://team.openclaw.ai/chat/roboclaw/subagent/2580a771-00db-4b52-b995-d05c3bd7a89c Original discussion and integration: https://team.openclaw.ai/chat/roboclaw/dashboard/db4d78ac-b19b-4f64-adfb-0ca7973a62e4 Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vyctorbrzezowski <[email protected]> Co-authored-by: steipete <[email protected]> Co-authored-by: jalehman <[email protected]>
Peter Steinberger's upstream fix, merged to main 2026-09-23, after the 9.6 tag. When writes invalidate an automatic session-maintenance plan, its replacement now waits for a quiet window after the last write (1 s, then 2 s), and three consecutive invalidations pause automatic retries with one warning until a new entry write schedules another attempt. Before, each superseded plan was replanned at once, so a busy store looped on rejected reclamation runs. warn mode captures the age fact without constructing or dispatching reclamation. Applied with cherry-pick -x. The kick module and its test were at the same blobs on this branch and at v2026.9.6 as at the commit's parent, so both now equal upstream's blobs; docs/concepts/session.md auto-merged next to the tag's Incognito text. Tests on the branch: session-accessor.sqlite-maintenance-kick 21/21. (cherry picked from commit 2044520)
… the 9.6 carry Records the three upstream ports (openclaw#156583, openclaw#157834, openclaw#157121), why openclaw#155988 was not carried, the /tools/invoke loop-detection fix, the review left-overs, and the validation run on this branch.
Refs #153257
What Problem This Solves
Concurrent session writes can invalidate automatic SQLite maintenance immediately before commit. The maintenance owner then replans in the same loop, repeatedly spending work on a snapshot that cannot commit.
User Impact
Automatic maintenance waits for a quiet write window after a rejected plan. After three consecutive invalidations it records a warning and waits for another entry write.
warnmode captures its age fact without constructing an automatic reclamation operation; this branch already skipped executing that operation.No config, schema, dependency, retention-policy, or commit-authority changes. This addresses the maintenance retry path only; the report's memory growth and recovery of an existing customized Docker installation remain open.
Why This Change Was Made
The existing per-store maintenance owner now makes one attempt per invocation. Its existing timer and write kicks coalesce retries after one second of quiet, then two seconds on a further rejection. Pending active keys survive rejection, database disposal cancels pending work, and ordinary successful maintenance retains its age-boundary/30-minute cadence.
Thanks to @abuegab1-spec for tracing the generation-change/replan loop and proposing the explicit warn-mode guard.
Already on main: #152621 avoids redundant warm planning; #153161 reduces history reads; #155620 reuses membership snapshots. None removes the stale-plan loop. Canonical-validation certification is separate: #151805 preserves physical-generation receipts across restarts, and the existing unchanged-store/zero-pending test confirms no worker dispatch. Its real-pending-work contention handling is unchanged.
Evidence
668eef75225baeb9fc7ce9d6eadaff5572fbc003: both added regressions fail for the intended reasons (warn constructed one operation; three invalidations produced four plans before yielding). Reproduced locally and on Testbox.pnpm test src/config/sessions/session-accessor.sqlite-maintenance-kick.test.ts --maxWorkers=1on Testbox: 26.26 s runner wall, approximately 0.72 s test time (21 tests). Shared worker preparation dominated wall time. Remote six-file run: 87.04 s wall. No single test exceeded 3.1 s. Hosted PR CI timing is pending.Live proof used a real development Gateway started through
startGatewayServer, a free loopback port and isolated state per variant, 2,000 stale rows, ten seconds of canonical entry writes at a 100 Hz target, then five seconds without writes./healthzreturned 200. Temporary counter instrumentation was identical across revisions and removed afterward; candidate source hashes were rechecked. This proof covers Gateway startup and canonical session writes.The candidate retried once after traffic became quiet (two total plans, one rejection); both enforce variants ultimately archived all 2,000 stale rows. Both warn variants archived zero rows and dispatched zero maintenance workers. Worker ticks are 200 ms
/procsamples and can miss short-lived threads. Aggregate worker CPU improved, but the hottest individual thread did not improve in enforce mode; this is not evidence that the broader CPU/RSS incident is resolved.Testboxes: behavioral/check lane
tbx_01m378k1wnhq5k23mr1t2rsfmj(run); live/timing lanetbx_01m379wyvdg8zrzhmx6h0dkn3m(run). Both use the Blacksmith Testbox provider. Command exit codes and source checks establish the results; lease cleanup can mark the linked hydration runs cancelled.All selected changed-code gate steps passed: core typecheck, all 25 core-test type graphs, formatting, lint, schema/storage/import and other guards. The original invocation found one redundant
elseafter an unconditional return; that mechanical cleanup passed formatting and lint, and the remaining guards completed successfully. The existing type and live proof remains applicable; the final focused file also passed again (21 tests; 26.95 s runner wall). No baseline or suppression changes.