Skip to content

fix(sessions): back off automatic maintenance replans and make warn observe-only - #156583

Merged
steipete merged 1 commit into
mainfrom
upd/session-maintenance-replan-livelock
Sep 23, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/session-maintenance-replan-livelock

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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. warn mode 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

  • Baseline 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.
  • Candidate: 21/21 focused tests passed locally. Six files / 86 tests passed on Testbox, including all direct import matches, real maintenance worker/writer siblings, and canonical-validation readiness.
  • Focused cost: pnpm test src/config/sessions/session-accessor.sqlite-maintenance-kick.test.ts --maxWorkers=1 on 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.
  • Codex autoreview: scoped-clean at P0–P2.
  • Production: +206/-155 lines (net +51; removing the loop also unindents its body). Tests: +87/-0. Docs: +5/-0.

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. /healthz returned 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.

Mode / revision Completed writes Plans during load Input rejections Aggregate sampled WorkerThread ticks Hottest WorkerThread ticks
enforce / baseline 526 3 (0.297/s) 2 (0.198/s) 980 357
enforce / candidate 524 1 (0.100/s) 1 (0.100/s) 809 396
warn / baseline 749 749 (74.64/s) 0 441 354
warn / candidate 766 0 0 405 335

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 /proc samples 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 lane tbx_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 else after 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.

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.
@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 23, 2026 14:48
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M labels Sep 23, 2026
@steipete
steipete enabled auto-merge (squash) September 23, 2026 14:51
@clawsweeper

clawsweeper Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 23, 2026, 10:53 AM ET / 14:53 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 02038187db202f3c617cb8f46b6dbfcafef72d45

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with meaningful regressions and convincing scoped Gateway observations; no blocking defect found.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied isolated Gateway run exercises canonical entry writes through the changed maintenance owner: enforce retries after load stops and archives 2,000 stale rows, while warn constructs no plans. This supports the scoped runtime change; no stored-data contract or migration changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied isolated Gateway run exercises canonical entry writes through the changed maintenance owner: enforce retries after load stops and archives 2,000 stale rows, while warn constructs no plans. This supports the scoped runtime change; no stored-data contract or migration changes.
Evidence reviewed 7 items Pinned scope and current-main necessity: The introduced delta is confined to the maintenance owner, its tests, and session documentation. The baseline and fetched main contain the identical maintenance-owner blob e99d5e5e565345098fb8cf27b549aeb0bd280f86; main retains the while-loop and immediate replan after input invalidation.
Retry lifecycle and safety: Rejected attempts restore pending active keys, use the existing per-store timer, and pause after three rejections. Database disposal cancels scheduled work. Generation, age-capture, preservation, and database-currentness checks remain connected to reclamation commit authorization.
Regression coverage: The two added regressions cover warn-mode construction avoidance and quiet-window coalescing, rejection limits, and eventual archival after a new write. Existing cases retain age deadlines, database disposal, cap pressure, and stale-path checks. The supplied body reports both new regressions failing on the baseline, 21 focused tests passing, and 86 owner/sibling tests passing on Testbox; this read-only review did not execute them.
Findings None None.
Security None None.

How this fits together

Session 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
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +51, Tests +87, Docs +5. Total +143 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 206 155 +51
Tests 1 87 0 +87
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 298 155 +143

Review metrics

Metric Value Why it matters
Automatic retry bound 1-second then 2-second quiet windows; pause after 3 invalidations The retry limit bounds repeated planning without introducing a configuration option or changing cleanup eligibility.

Technical review

Best 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.

Labels

Label changes:

  • add P1: The fix addresses a source-supported maintenance churn path connected to an active user report of sustained resource pressure.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied isolated Gateway run exercises canonical entry writes through the changed maintenance owner: enforce retries after load stops and archives 2,000 stale rows, while warn constructs no plans. This supports the scoped runtime change; no stored-data contract or migration changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.

Label justifications:

  • P1: The fix addresses a source-supported maintenance churn path connected to an active user report of sustained resource pressure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied isolated Gateway run exercises canonical entry writes through the changed maintenance owner: enforce retries after load stops and archives 2,000 stale rows, while warn constructs no plans. This supports the scoped runtime change; no stored-data contract or migration changes.

Evidence

What I checked:

  • Pinned scope and current-main necessity: The introduced delta is confined to the maintenance owner, its tests, and session documentation. The baseline and fetched main contain the identical maintenance-owner blob e99d5e5e565345098fb8cf27b549aeb0bd280f86; main retains the while-loop and immediate replan after input invalidation. (src/config/sessions/session-accessor.sqlite-maintenance-kick.ts:126, b7eb012f643b)
  • Retry lifecycle and safety: Rejected attempts restore pending active keys, use the existing per-store timer, and pause after three rejections. Database disposal cancels scheduled work. Generation, age-capture, preservation, and database-currentness checks remain connected to reclamation commit authorization. (src/config/sessions/session-accessor.sqlite-maintenance-kick.ts:305, 02038187db20)
  • Regression coverage: The two added regressions cover warn-mode construction avoidance and quiet-window coalescing, rejection limits, and eventual archival after a new write. Existing cases retain age deadlines, database disposal, cap pressure, and stale-path checks. The supplied body reports both new regressions failing on the baseline, 21 focused tests passing, and 86 owner/sibling tests passing on Testbox; this read-only review did not execute them. (src/config/sessions/session-accessor.sqlite-maintenance-kick.test.ts:68, 02038187db20)
  • Supplied real Gateway observations: The captured PR body describes isolated development Gateways using canonical entry writes and 2,000 stale rows. During ten seconds of load, enforce planning fell from three attempts to one; the candidate retried after writes stopped and archived all stale rows. Warn planning fell from 749 constructions to zero, with zero archival in both variants. These observations support the changed owner’s behavior; hottest-thread CPU and broader RSS recovery remain explicitly unclaimed. (02038187db20)
  • Discussion establishes the narrow fix boundary: The reporter’s follow-up at [Bug]: OpenClaw 2026.9.5 Turned a Stable Environment Into an 8-Hour Failure Recovery Session #153257 (comment) identifies the generation-change replan loop and proposes preserving pending keys with bounded quiet-window retries. Subsequent discussion explicitly keeps memory growth and recovery of the existing Docker installation unresolved.
  • Release comparison: The latest supplied release, v2026.9.5, also contains the older immediate maintenance loop. Neither that release nor fetched main supplies this bounded retry implementation. (src/config/sessions/session-accessor.sqlite-maintenance-kick.ts:110, ec9c1a13db89)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 2044520 into main Sep 23, 2026
272 checks passed
@steipete
steipete deleted the upd/session-maintenance-replan-livelock branch September 23, 2026 15:07
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 24, 2026
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.
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
roboclaw-bot added a commit that referenced this pull request Sep 27, 2026
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]>
amittell added a commit to amittell/openclaw that referenced this pull request Oct 2, 2026
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)
amittell added a commit to amittell/openclaw that referenced this pull request Oct 2, 2026
… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant