Skip to content

fix: preserve maintenance leases during slow heartbeat renewal - #157696

Merged
fuller-stack-dev merged 2 commits into
mainfrom
fix/heartbeat-slow-renewal-157160
Sep 25, 2026
Merged

fuller-stack-dev merged 2 commits into
mainfrom
fix/heartbeat-slow-renewal-157160

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Related: #157160

What Problem This Solves

Fixes false maintenance lease loss when a valid heartbeat worker takes more than one second to finish a native SQLite renewal.

User Impact

Maintenance can wait for a slow renewal without treating an occupied worker as dead. Expired or replaced owners and workers that do not acknowledge the request still fail closed. No settings, schema or migration changes are required.

This addresses a reproduced post-acquisition heartbeat failure. It does not establish the cause of the reported incident or replace the separate Gateway acquisition work in #157413.

Why This Change Was Made

The heartbeat now publishes renewal progress so response checks can distinguish native work from an idle unresponsive worker. Progress only permits bounded waiting; it never grants ownership. Fresh replies, lease expiry and the caller's durable ownership recheck remain mandatory. Async requests recheck at bounded intervals so renewal finishing without a reply cannot leave a request asleep until lease expiry.

Synchronous wait tradeoff — accepted

The final ClawSweeper review confirms the async finding is resolved and reports no actionable code defects. Its remaining decision is resolved here: retain the existing durable lease as the synchronous wait ceiling. If a worker exits abruptly while its renewal-progress marker is in flight, the caller can stall until that observed lease expires (up to the 60-second maintenance lease), because JavaScript cannot deliver the exit callback during the synchronous wait.

This is an explicit bounded availability tradeoff in this repair, not a claim that worker death is always detected within one second. A shorter unmeasured cap would restore false lease loss for valid slow storage. Progress never grants authority: a fresh acknowledgment and a final durable-owner check are mandatory, and the expiry control rejects an occupied worker at the original observed deadline. No indefinite wait, lease extension from progress, configuration change, or weakening of write authorization is introduced. Internal scheduling and lifecycle selection are within the authorized repair-and-land scope.

Evidence

  • Original actual-worker regression: assertion failed after 1,002 ms with 18,894 ms left on the durable lease.
  • Initial exact-source native matrix: eight cases passed, including a slow COMMIT during synchronous assertion, verification and explicit renewal, plus healthy/dead/expired/replaced-owner controls. Public lease/write-transaction proof also passed with the final write retained, worker joined and lease row removed.
  • Addressed ClawSweeper's async finish-without-reply finding: both new deterministic cases fail on the original PR head and pass with bounded rechecks. The full canonical lifetime file passes 20/20, and the canonical real-worker heartbeat sibling file passes 17/17. Deferred activation passes 1/1; its worker source is unchanged by the follow-up.
  • Full touched-test audits preserve distinct failure/lifecycle cases. New cases use fake time, with no real sleeps or added process boots.
  • Original Doctor acquisition-refusal control invokes zero callbacks and leaves the protected database unchanged. That ingress remains separate from this fix.
  • Requalified the public path against advanced main 0484d7a3ecf52589b0d3d98741e58e5f6b5bf661 with the three published production blobs: real maintenance scope, one callback, two SQLite write transactions, 1,505 ms delayed-COMMIT wait, final write retained, worker joined, and zero lease rows. Parent/worker source hashes verify the published fix and new maintenance-scope/cache implementations; private fixtures were removed.
  • Independent API-only reviews cover the initial change and the correction; final full-file follow-up review is scoped-clean with no actionable findings. The correction's exact-head CI passed: all 205 substantive jobs plus the final aggregate, including production/test types and both changed heartbeat test files.

Measured test cost

Canonical macOS arm64 runs with repository-pinned pnpm and --maxWorkers=1:

File Command wall time CI case execution Detail
openclaw-state-lease-heartbeat.lifetime.test.ts 83.705 s 0.060 s 20 tests pass; 64.888 s cold worker-runtime preparation; seven added cases total about 27 ms of test execution.
openclaw-state-lease-heartbeat.activation.test.ts 43.739 s 3.012 s 1 test passes, 1.673 s test execution; 27.660 s cold worker-runtime preparation. This existing native commit-boundary proof retains its integration fixture.

Commands: pnpm test src/state/<file> --maxWorkers=1. CI values are sums of rounded per-case reporter times, not file wall time; they exclude import/setup. Both jobs passed on f307fbb8cc8804807367a18ed2c941a8df3fc02f. The shared lifetime job took 359 s and the shared activation job took 675 s, including other files and setup.

Post-merge CI cleanup

After verified merge, the redundant recovery of the original release-deferred PR run (36076042946, attempt 2) was canceled to retire its remaining duplicate work. Its final census had no failed jobs (40 passed, 95 canceled, 18 skipped). The complete exact-head validation remains 36076724801: success, and the required combined gate 36081896041 passed before merge.

@clawsweeper

clawsweeper Bot commented Sep 24, 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.

@fuller-stack-dev
fuller-stack-dev marked this pull request as ready for review September 24, 2026 23:30
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 24, 2026, 8:15 PM ET / September 25, 2026, 00:15 UTC (Revision 2).

ClawSweeper review

What this changes

The branch lets maintenance lease checks wait for a slow SQLite heartbeat renewal, using worker progress to extend bounded liveness checks and adding regression coverage.

Merge readiness

⛔ Blocked before merge - 3 items remain

The fix remains needed: current main and v2026.9.6 still use a one-second heartbeat response deadline. The earlier async no-reply finding is addressed on this head. A maintainer should resolve the synchronous stall tradeoff before merge.

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

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused repair and regression coverage address the earlier finding, with one explicit availability tradeoff awaiting an owner decision.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The MEMBER-authored PR is exempt from the external contributor proof gate. Its body reports actual-worker slow-commit recovery for the initial fix; the final async no-reply correction is supported by deterministic controlled-worker cases. The new shared progress value is runtime-only, so no stored-data compatibility proof applies.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The MEMBER-authored PR is exempt from the external contributor proof gate. Its body reports actual-worker slow-commit recovery for the initial fix; the final async no-reply correction is supported by deterministic controlled-worker cases. The new shared progress value is runtime-only, so no stored-data compatibility proof applies.
Evidence reviewed 8 items Current main still has the timeout: The fetched main revision gives async requests a fixed one-second deadline and applies the same limit to synchronous responsiveness checks.
Latest release still has the timeout: The latest supplied release retains the fixed one-second checks and has no renewal-progress budget.
Introduced liveness behavior: The PR shares native renewal progress, limits each request by lease and operation deadlines, and rechecks unanswered async requests at one-second intervals.
Findings None None.
Security None None.

How this fits together

OpenClaw uses a dedicated worker to renew maintenance leases stored in SQLite. Lease callers check worker responsiveness and persisted ownership before continuing protected maintenance work.

flowchart LR
  A[Maintenance caller] --> B[Lease owner]
  B --> C[Heartbeat worker]
  C --> D[SQLite lease row]
  C --> E[Renewal progress]
  E --> F[Bounded response check]
  D --> G[Ownership recheck]
  F --> G
Loading

Decision needed

Question Recommendation
May a synchronous maintenance lease check block for the full remaining 60-second lease when a worker exits during renewal? Accept the lease-bound wait: Keep the current behavior and explicitly accept a possible full-lease synchronous stall in exchange for tolerating valid slow renewals.

Why: The change trades false lease loss on slow storage for a longer possible caller stall; source and tests establish the bounds but cannot choose the acceptable Gateway responsiveness policy.

Before merge

  • Resolve merge risk (P1) - If a worker exits abruptly while renewal progress is marked in flight, a synchronous maintenance caller can block its JavaScript thread until the remaining durable lease expires, up to the documented 60-second lease. The acceptable stall bound needs an owner decision.
  • Complete next step (P2) - Have the state owner accept the lease-bound synchronous stall or specify a shorter measured cap before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source +48, Tests +126. Total +174 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 61 13 +48
Tests 2 126 0 +126
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 187 13 +174

Review metrics

Metric Value Why it matters
Production and test growth production net +48 lines; tests +126 lines The production growth implements the stated bounded progress check; the added tests cover distinct reply, timeout, and acknowledgement outcomes.
Measured test cost 7 added cases about 27 ms execution; lifetime file 83.705 s wall The PR reports that cold worker-runtime preparation accounts for most of the measured wall time.

Merge-risk options

Maintainer options:

  1. Accept the full lease bound (recommended)
    Confirm that a stopped worker may hold a synchronous maintenance caller until the remaining lease expires.
  2. Reduce the synchronous ceiling
    Select a measured cap that still covers slow valid renewals and add a stopped-worker regression for that bound.

Technical review

Best possible solution:

Keep the slow-renewal tolerance and final persisted-owner check, with an owner-approved bound for synchronous waits after an unresponsive worker.

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

Yes. Current main has the fixed one-second deadline, and the PR reports an actual-worker assertion failure at 1,002 ms with ample durable lease time remaining; this read-only review did not execute it.

Is this the best way to solve the issue?

Unclear. Progress-aware waiting repairs the observed false loss while retaining durable checks, but the acceptable synchronous stall duration requires an owner choice.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The MEMBER-authored PR is exempt from the external contributor proof gate. Its body reports actual-worker slow-commit recovery for the initial fix; the final async no-reply correction is supported by deterministic controlled-worker cases. The new shared progress value is runtime-only, so no stored-data compatibility proof applies.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: False maintenance lease loss can interrupt a real Gateway maintenance workflow on slow SQLite commits.
  • merge-risk: 🚨 availability: The introduced progress-aware synchronous wait can hold a maintenance caller until lease expiry if its worker exits during renewal.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The MEMBER-authored PR is exempt from the external contributor proof gate. Its body reports actual-worker slow-commit recovery for the initial fix; the final async no-reply correction is supported by deterministic controlled-worker cases. The new shared progress value is runtime-only, so no stored-data compatibility proof applies.

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)
  • Vincent Koc: 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.

  • Record the state owner's choice for the worst-case synchronous wait when a worker exits during renewal.

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 (1 earlier review cycle)
  • reviewed September 24, 2026, 7:55 PM ET / 23:55 UTC sha unknown :: blocked before merge. :: [P2] Recheck async liveness when renewal finishes

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Addressed the async renewal-completion finding at f307fbb8cc8804807367a18ed2c941a8df3fc02f: outstanding requests now recheck within the existing response interval, preserving lease and absolute-operation bounds. Added deterministic verify/renew finish-without-reply regressions; both fail on the previous head and pass with the correction. Canonical lifetime tests pass 20/20 and actual-worker heartbeat siblings pass 17/17. Independent full-file review is clean. Canonical single-worker wall times are recorded in the PR body; fresh exact-head CI is running.

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 25, 2026
@fuller-stack-dev
fuller-stack-dev enabled auto-merge (squash) September 25, 2026 01:35
@fuller-stack-dev
fuller-stack-dev merged commit 09e30a1 into main Sep 25, 2026
388 of 390 checks passed
@fuller-stack-dev
fuller-stack-dev deleted the fix/heartbeat-slow-renewal-157160 branch September 25, 2026 02:06
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

vincentkoc added a commit that referenced this pull request Sep 25, 2026
* commit '05edd36e124dc376f63475256f45e82ec437412c': (30 commits)
  refactor(matrix): reuse bounded direct-room cache insertion (#157775)
  fix: preserve channel-owner revocation across recovery (#157709)
  fix(ci): stop blocking CI during release validation (#157757)
  refactor(tlon): remove unreachable DM summary branches (#157789)
  chore: speed up worktree recovery tests with Bun (#157674)
  fix(sessions): release PR caches when pending viewers leave (#157776)
  refactor(twitch): reuse setup account selection (#157787)
  test: skip empty task ledger resets in cron fixtures (#157767)
  perf: reduce gateway and state test startup (#157711)
  fix: preserve maintenance leases during slow heartbeat renewal (#157696)
  fix(channels): match non-TTY setup advice to registered flags (#157551)
  fix: keep failed update report uploads in the CLI (#156633)
  fix: preserve rejected settings reason when opening config (#157731)
  test(update): load real filesystem dependencies in swap fixture
  fix(ci): prevent Security Review checkout retry collisions (#157652)
  fix(ci): recover interrupted Security Review response bodies (#157651)
  test(ui): capture live operator authority in guest question fixture
  refactor(agents): deslop runners, harness and recovery (#157294)
  fix(auth): preserve Copilot tenant credentials during Doctor repair (#139131)
  refactor(msteams): share stored service URL validation (#157706)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
…law#157696)

* fix: preserve maintenance leases during slow heartbeat renewal

* fix: recheck heartbeat responses after native renewal
roboclaw-bot added a commit that referenced this pull request Sep 26, 2026
Backport #157696: 09e30a1
Backport #157733: 136ce55
Selected backport #157730: 942a27d
Required test prerequisite #156037: 1f55d63

Keep heartbeat progress distinct from authority, settle repair-owned
resources before maintenance, and validate complete source content before
reusing decoded Doctor rows. Preserve the frozen runtime-entrypoint owner
and its standalone child protocol. Schema remains v18.

Source-bound targeted/native/built-child proof and independent review pass.
This is not a published-package or native service-recovery qualification.

Co-authored-by: Jason (Json) <[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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant