Skip to content

fix(state): renew maintenance leases during synchronous work - #134880

Merged
steipete merged 6 commits into
mainfrom
codex/release-8.1-feedback-native
Sep 1, 2026
Merged

steipete merged 6 commits into
mainfrom
codex/release-8.1-feedback-native

Conversation

@steipete

@steipete steipete commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Doctor can lose its database maintenance lease when a synchronous SQLite scan or migration blocks the parent event loop beyond the existing 60-second expiry. The timer cannot renew during that operation. The real maintenance-owner reproduction failed before this repair, matching the release feedback; the blocked-timer path exists in v2026.8.1 and main.

Why This Change Was Made

The existing lease owner starts an independent Worker heartbeat only for agent-database maintenance, implementing the approved design. Acquisition and renewal retain one canonical policy: the same schema, 60-second expiry, exact scope/key/owner tuple, and refusal to renew expired, deleted, or replaced ownership. Other leases keep their timer path.

SQLite remains authoritative. Parent assertions read the exact unexpired row, request a fresh Worker acknowledgement, and recheck ownership afterward. Acknowledgement performs no SQLite access, including when the caller already holds a write transaction. Completion, failure, and cancellation await Worker termination before release; process exit fences shared state before synchronous release. Worker loss and ownership loss fail closed.

The runtime-entry registry now supplies packaged workers, test artifacts, and executable audit roots. A plugin-free core build map lets the Doctor fixture include its worker without importing plugin-private code; the full build composes that map with the existing plugin-owned entry. This removes the hard-coded audit inventory. The shared declaration fixture copies both resolver modules so import.meta.url stays within its isolated tree; its root-escape guard remains intact.

Long synchronous maintenance therefore retains its writer fence without extending expiry. A healthy Worker can also retain a stuck parent's lease until that process is stopped: it measures liveness, not progress. The database schema reference documents that accepted tradeoff. This PR changes no schema version, migration content, public configuration, environment option, or dependency.

Candidate and Change Size

Committed and pushed efbf78adcb4568a8b5d32d60944ce1b75bb7d6cd integrates main 2bd12c77bab9c76752ec8dbc1e8679e791a2f282. All 21 candidate hashes match the committed manifest. Main owns canonical packaged Doctor readiness from #134812; the earlier duplicate Gateway test is removed.

Area Files Added Removed Net
Runtime production 9 354 100 +254
Build/check tooling 4 35 19 +16
Tests/support 7 318 114 +204
Documentation 1 4 0 +4
Total 21 711 233 +478

Runtime growth implements the explicitly approved independent renewal and lifecycle boundary; the existing shared lease owner is net -1. The final declaration integration repair adds three net test-support lines and no runtime code.

Final Proof

Boundary Observed result at unchanged efbf78a
Declaration fixture and callers Existing SDK metadata case failed before the copy repair. All 11 SDK and five unified declaration cases then passed; the fixture changed gate exited 0. All 14 precommit proof hashes match the final files.
Worker, lease, and generation 14 lease/heartbeat cases, one real borrower-generation case, and two filesystem-transform cases passed. These cover blocked-parent renewal, transaction-held acknowledgement, failure fencing, ownership replacement/expiry/deletion, terminal cleanup, generation sharing, and real source/config edits.
Packaged Doctor/Gateway One canonical readiness case passed in 3.554 seconds, with a 21.718-second managed run after 14.737 seconds of preparation. It started a real Gateway, checked /readyz, retained the valid automation, and verified both invalid legacy records were quarantined in SQLite. Existing 30-second readiness and 45-second test bounds stayed intact.
Actual source Worker Direct source execution passed on Node 22.22.3, the exact supported floor, and Node 24.19.0. Both resolved the actual .ts Worker through production --import tsx, reached lease readiness, acknowledged inside a real SQLite write transaction, and released the row. No Vitest or built-worker substitution was used.
Windows inventory/cleanup 28 individually logged passes and five explicit platform skips on Node 22.23.2, win32 x64. Real generation sharing, cancellation cleanup, and disconnect cleanup passed. Exact Windows job.

The worker/lease/generation and packaged-readiness rows contain 18 executed cases, separately from the declaration suites, two source probes, and Windows cases. Two initial transform filters selected zero cases; corrected filters each executed one existing case. Empty selections contribute zero proof, and no product failure, timeout, assertion, or runtime setting was retried or weakened.

Canonical preparation rebuilt the prior runtime and produced OpenClaw 2026.8.1 (efbf78a); the build stamp, runtime-postbuild stamp, and build metadata agree. All 21 candidate and five additional test/dependency hashes remained unchanged, and the checkout stayed clean. Source probes also retained the expanded dependency hashes. The Node 22 binary came from the official archive, verified against its published SHA-256 checksums.

Reviews, CI, and ClawSweeper Disposition

The complete candidate passed P0-scoped Codex autoreview with no accepted findings (0.95 confidence; lower priorities excluded). A separate independent review reported no actionable correctness or security findings across all 21 committed files, verifying the exact head, merge parents, hashes, and clean checkout. It directly inspected Node Worker handling, termination/lifecycle, Node SQLite, and SQLite transactions.

The efbf78a CI rollup, recorded September 1 at 09:52 UTC, is 225 successes, 44 skips, one neutral result, and no failed or pending checks. Windows evidence is bound to tested merge 8a8fffda4800572bb10d4f9433d148e096f7a1f4, incorporating this exact PR head.

The latest ClawSweeper review, reviewed at 09:47:41 UTC on efbf78a, raised a late P1 about missing Node 22 source-worker resolver registration. Rejected for the supported runtime and pinned dependency: both unchanged-source probes pass, and tsx 4.23.12 automatically registers in non-internal Workers. Its synchronous-hook feature floors are Node 22.22.3, 24.11.1, and 25.1.0; OpenClaw's supported floors meet them. Node 22 loads import preloads before the entry point, and direct inspection confirms the registerHooks resolve/load path. The older archive-worker comment does not establish a failure under this current contract.

Both rank-up moves have explicit dispositions:

  • Source resolver registration and Node 22 regression: the reported failure does not reproduce at the supported floor. Retained direct-source proof and dependency inspection establish the existing path; no additional loader or regression test was added for a failure absent under the current supported runtime/dependency contract.
  • Exact-head Windows inventory and cleanup: completed by the logged 28-pass suite, including generation sharing and cancellation/disconnect cleanup. Five POSIX process-group cases were explicitly skipped. The dedicated heartbeat lifecycle suite was not selected by the fixed Windows inventories; that remains a coverage limit, not an uncompleted inventory/cleanup claim. No additional Windows routing change is needed for this rank-up.

Final native landing verification remains separate from these completed results.

Historical proof and validation limits

Earlier repair checkpoints retain a real 61,003 ms parent block with a 60,000 ms lease and a competing writer refused at +60,201 ms. A generated 90,050,560-byte, 10,000-session database migrated from schema 18 to 19 with payload, integrity, foreign-key, backup, and subsequent writer-admission checks. SIGKILL stopped renewal and allowed reacquisition after expiry. This is not performance proof for the reporter's 18 GB database.

The original 154 focused tests and four existing platform skips, later overlapping lease/migration cases, and plain-Node compiled Worker/preload-isolation proof retain their original source checkpoints. Three existing Doctor cases passed with a 256 MiB old-space setting, including 100,000-message history and public health flow; those runs predate core-map extraction and do not measure process RSS. The prior 5dfb87f canonical readiness result was 11.106 seconds; the removed duplicate's 5.203-second result is historical only.

Earlier test/tooling deadlines passed unchanged in isolation; load causation was not established. An initial full build hit a baseline UI-budget failure. A prior 5dfb87f-associated CI run exposed the repaired declaration-fixture escape; its two Linux failure causes remain unknown because log capture failed. These are historical outcomes, not current CI failures. The two empty transform selections are excluded from final proof.

Current proof covers local packaged process/SQLite behavior, source Workers, and the specified Windows artifact cases. It does not claim live-provider/channel traffic, a reporter-database reproduction, dedicated Windows heartbeat lifecycle execution, a repeated full stress/heap suite, clean-install acceptance, or a full release validation.

@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: L maintainer Maintainer-authored PR labels Sep 1, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed September 1, 2026, 5:47 AM ET / 09:47 UTC.

ClawSweeper review

What this changes

This PR moves Doctor’s shared SQLite maintenance-lease renewal into a dedicated worker and updates runtime-worker build and test inventories.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 6 items remain

Keep open: the new heartbeat cannot start from a Node 22 source checkout because its worker loader does not register the resolver required for the worker’s .js source imports. This member-authored, maintainer-labeled PR also requires explicit maintainer handling.

Priority: P1
Reviewed head: efbf78adcb4568a8b5d32d60944ce1b75bb7d6cd
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The concurrency design and reported exercise are substantial, but a supported source-runtime path has a blocking loader defect.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: The contributor-proof gate does not apply because repository state identifies this as a member-authored PR; the body reports real built-worker runs, but those do not cover the introduced Node 22 source-worker failure.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The contributor-proof gate does not apply because repository state identifies this as a member-authored PR; the body reports real built-worker runs, but those do not cover the introduced Node 22 source-worker failure.
Evidence reviewed 7 items Introduced source-worker trigger: The introduced heartbeat starts its source .ts worker with the generic --import tsx arguments.
Existing Node 22 source-worker contract: The analogous archive worker documents that --import tsx does not register tsx’s ESM resolver inside a Node 22 Worker and programmatically registers tsx/esm/api instead.
Unresolvable source imports: The new worker imports local modules through .js specifiers, which require that resolver when its entry is the source .ts file.
Findings 1 actionable finding [P1] Register tsx’s Worker resolver for source execution
Security None None.

How this fits together

Doctor holds a shared-state lease while it scans or migrates agent databases, preventing other writers from entering maintenance-sensitive paths. The new worker is intended to renew that lease independently while the Doctor process is synchronously blocked.

flowchart LR
  A[Doctor maintenance] --> B[Shared SQLite lease]
  B --> C[Heartbeat worker]
  C --> D[Lease renewal record]
  A --> E[Synchronous scan or migration]
  D --> F[Final ownership check]
  E --> F
  F --> G[Commit or release]
Loading

Decision needed

Question Recommendation
Should this member-owned, maintainer-labeled PR be updated to preserve Node 22 source-checkout Doctor operation before merge? Repair source-worker loading: Register tsx’s Worker resolver for source-mode heartbeat execution, add focused Node 22 coverage, and then rerun the outstanding Windows proof.

Why: The source-loader failure is mechanical, but the protected maintainer label requires explicit maintainer handling and the prior Windows lifecycle rank-up remains unresolved.

Before merge

  • Register tsx’s Worker resolver for source execution (P1) - resolveRuntimeWorkerArgv supplies only --import tsx here, but the analogous source Worker documents that Node 22 does not register tsx’s ESM resolver that way. This new worker imports local .js specifiers, so source-mode Doctor cannot reach ready before maintenance begins. This was visible at the earlier reviewed head; add the programmatic resolver registration and a Node 22 source-mode regression.
  • Resolve merge risk (P1) - On supported Node 22 source checkouts, Doctor waits for a heartbeat worker that cannot resolve its local .js imports, turning maintenance into a startup failure.
  • Resolve merge risk (P1) - The PR adds core runtime +354/-100 lines; the independent worker is justified by blocked event-loop renewal, but the source-runtime repair must be proven before accepting that added lifecycle boundary.
  • Resolve merge risk (P1) - The PR body retains an exact-head Windows worker-inventory and cleanup verification gap; current-main source could not be independently read in this partial clone.
  • Complete next step (P2) - A concrete P1 repair exists, but the protected maintainer label and prior platform-proof gap require explicit maintainer handling rather than automated repair dispatch.

Findings

  • [P1] Register tsx’s Worker resolver for source execution — src/state/openclaw-state-lease-heartbeat.ts:34
Agent review details

Security

None.

PR surface

Source +254, Tests +204, Docs +4, Other +16. Total +478 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 9 354 100 +254
Tests 7 318 114 +204
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 4 35 19 +16
Total 21 711 233 +478

Review metrics

Metric Value Why it matters
Production versus validation delta core runtime +354/-100; tooling +35/-19; tests/support +318/-114; docs +4 The positive core growth creates an independent renewal lifecycle that cannot be implemented by the event loop being repaired.
Source-worker coverage 0 explicit Node 22 source-mode heartbeat cases Existing new tests and the added memory fixture do not establish the failing source-loader path.

Merge-risk options

Maintainer options:

  1. Fix the Node 22 source worker (recommended)
    Use programmatic tsx resolver registration for the heartbeat’s source Worker and prove Doctor reaches maintenance from a source checkout.
  2. Pause the worker heartbeat
    Keep the current timer implementation until the worker lifecycle is proven on every supported source runtime.

Technical review

Best possible solution:

Use the existing programmatic tsx/esm/api source-worker registration pattern, preferably as a shared runtime-worker helper, and add a Node 22 source-mode heartbeat regression before rechecking the Windows lifecycle result.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: on Node 22, run Doctor from a source checkout so the maintenance heartbeat starts its .ts Worker. The repository’s analogous worker documents the missing resolver behavior, although this read-only review did not execute it.

Is this the best way to solve the issue?

No: the independent heartbeat is the right ownership boundary for a blocked event loop, but this implementation must use the repository’s programmatic Worker resolver before it is a supported source-runtime solution.

Full review comments:

  • [P1] Register tsx’s Worker resolver for source execution — src/state/openclaw-state-lease-heartbeat.ts:34
    resolveRuntimeWorkerArgv supplies only --import tsx here, but the analogous source Worker documents that Node 22 does not register tsx’s ESM resolver that way. This new worker imports local .js specifiers, so source-mode Doctor cannot reach ready before maintenance begins. This was visible at the earlier reviewed head; add the programmatic resolver registration and a Node 22 source-mode regression.
    Confidence: 0.97
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against f2646be7a983.

Labels

Label changes:

  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The contributor-proof gate does not apply because repository state identifies this as a member-authored PR; the body reports real built-worker runs, but those do not cover the introduced Node 22 source-worker failure.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P1: The introduced loader failure prevents Doctor maintenance from starting in a supported source-runtime workflow.
  • merge-risk: 🚨 availability: The new worker determines whether a core database maintenance operation can acquire and retain its lease.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The contributor-proof gate does not apply because repository state identifies this as a member-authored PR; the body reports real built-worker runs, but those do not cover the introduced Node 22 source-worker failure.

Evidence

What I checked:

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Register the source Worker resolver and add a Node 22 source-mode heartbeat regression.
  • Complete the exact-head Windows worker-inventory and cleanup verification with redacted lifecycle output.

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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-01T05:41:59.083Z sha 6ad462c :: needs maintainer review before merge. :: none
  • reviewed 2026-09-01T07:11:33.141Z sha 8091f76 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-01T08:15:36.554Z sha e83feee :: needs maintainer review before merge. :: none
  • reviewed 2026-09-01T09:07:00.221Z sha 5dfb87f :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label Sep 1, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime scripts Repository scripts size: XL and removed size: L labels Sep 1, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 1, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed gateway Gateway runtime size: XL labels Sep 1, 2026
Integrate main and copy both runtime build-entry modules into the isolated declaration graph. The core entry module must resolve its import.meta.url-owned inputs inside that graph; keep the existing path-escape guard intact.
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 1, 2026
@steipete
steipete merged commit dfd2e74 into main Sep 1, 2026
276 checks passed
@steipete
steipete deleted the codex/release-8.1-feedback-native branch September 1, 2026 10:12
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant