Skip to content

fix(state): explain lease ownership loss - #183178

Closed
ooiuuii wants to merge 2 commits into
openclaw:mainfrom
ooiuuii:fix/state-lease-loss-diagnostics
Closed

ooiuuii wants to merge 2 commits into
openclaw:mainfrom
ooiuuii:fix/state-lease-loss-diagnostics

Conversation

@ooiuuii

@ooiuuii ooiuuii commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #183154. Related to #182476.

What Problem This Solves

Native state-lease renewal and ownership verification collapse three persisted loss states into the same OPENCLAW_STATE_LEASE_LOST message: expired lease, replacement owner, and missing row. A failed update/repair can therefore retain a correct refusal but not the evidence needed to diagnose why it happened.

User Impact

Lease-loss receipts now include a safe reason when the database supports one:

state lease synthetic/diagnostics was lost (lease expired 1000 ms ago; last heartbeat 2000 ms ago)
state lease synthetic/diagnostics was lost (lease owner was replaced)
state lease synthetic/diagnostics was lost (lease record is missing)

The replacement owner token is never included. Error codes, lease duration, renewal cadence, acquisition, ownership, fencing, cleanup, and recovery behavior are unchanged. Existing callers that only match the established message prefix retain it.

Why This Change Was Made

An observed Windows 2026.10.7 update repair spent 1,427,442 ms in final Doctor and 637,736 ms in plugin finalization, then retained only plugin lifecycle lease core:plugin-lifecycle/global was lost. That receipt could not distinguish event-loop starvation from a competing owner or missing state.

After a failed renewal, this change reads the row inside the same write transaction. Ownership verification uses the same database read boundary. A small structured reason is passed to the existing error owner, which formats only elapsed timing or a redacted state classification. If timestamps are incomplete or the row cannot support a safe conclusion, the existing generic message remains.

This follows the diagnostic-only approach used by #170835 and #154878: it makes the next incident actionable without claiming to fix the long-running work that caused the lease loss.

Evidence

  • Before production changes, the new renewal cases all failed with the same mismatch: expected an expired/replaced/missing reason, received state lease synthetic/diagnostics was lost.
  • After the patch on current main 696f70f31, the focused state-lease diagnostics file passed: 1 file / 14 tests, including renewal and verification for all three loss states. The related worker regression set also passed with the repository unit config: 3 files / 23 tests.
  • Type-aware lint and TypeScript diagnostics passed for all seven changed files.
  • Targeted formatting and git diff --check passed.
  • Production delta: +64/-5 lines. Test delta: +109/-8 lines. No schema, config, protocol, or dependency changes.
  • Manual diff review covered transaction boundaries, replacement-owner redaction, compatibility, and focused test coverage; no actionable finding remained.

Real behavior proof

  • Behavior or issue addressed: persisted state-lease loss reasons were discarded from OPENCLAW_STATE_LEASE_LOST, including the receipt retained by update repair.
  • Real environment tested: the original symptom was observed on Windows 11 10.0.26200.x, OpenClaw 2026.10.7, Node.js 26.12.1. The after-fix source proof ran on macOS against current main plus this patch with Node.js 24.22.1 and a real temporary OpenClaw SQLite state database.
  • Exact steps or command run after this patch: acquired a real native lease, mutated the persisted row to expired/replaced/missing, then invoked both renewOpenClawStateLease() and verifyOpenClawStateLeaseOwnership() through src/state/openclaw-state-lease-diagnostics.test.ts. Regression command: /tmp/openclaw-node-runtime/bin/node node_modules/vitest/vitest.mjs run --config test/vitest/vitest.unit.config.ts src/state/openclaw-state-lease-diagnostics.test.ts src/state/openclaw-state-lease-worker.test.ts src/state/openclaw-state-lease-worker.transaction-group.test.ts.
  • Evidence after fix: Test Files 3 passed (3); Tests 23 passed (23); completed in 16.34 s. Type proof: ./node_modules/.bin/oxlint --type-aware --type-check --deny-warnings <seven changed files> exited 0.
  • Observed result after fix: all six new production-storage cases emit the expected redacted reason while the existing diagnostics and worker ownership tests remain green.
  • What was not tested: this branch was not deployed to the Windows host, a full Windows update was not rerun, and the complete repository test suite was not run locally. PR CI provides the broad repository lanes. This PR does not fix or benchmark the long-running Doctor/plugin work itself.

Shipped CLI proof added after review

  • Exact head and entry point: built commit 1aa0cb7856fd09e5cf5fc6bc36b2cd3f7ffbced7; node openclaw.mjs plugins install --link ./test/fixtures/web-output-provider --force --no-enable --accept-capabilities reported OpenClaw 2026.10.7 (1aa0cb7) from the shipped CLI bootstrap.
  • Isolated environment: the command used fresh temporary HOME and OPENCLAW_STATE_DIR directories, a repository fixture plugin, and no real account, Gateway, credentials, or network endpoint.
  • Controlled loss injection: a separate local SQLite client waited for the active core:plugin-lifecycle/global row, then changed only its owner to a synthetic value. This reproduces replacement by another owner while the real CLI command is inside the production plugin-lifecycle lease path.
  • Observed terminal output (7.9 s wall time):
WARNING - Installing plugin from local path: ./test/fixtures/web-output-provider
INJECTOR: replaced core:plugin-lifecycle/global owner
plugin lifecycle lease core:plugin-lifecycle/global was lost (lease owner was replaced)
CLI_EXIT=1 WATCHER_EXIT=0
  • Safety and interpretation: the synthetic replacement owner never appears in CLI output. The shipped command rejects the mutation, preserves the established message prefix, retains the new redacted reason through the CLI error formatter, and exits nonzero. The isolated state directory was disposable and contained no private data.

@clawsweeper

clawsweeper Bot commented Oct 25, 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR adds redacted expired, replaced, or missing-row reasons to existing state-lease ownership-loss errors.

Example: Another process replaces the core:plugin-lifecycle/global lease during plugin installation.

  • Before: plugin lifecycle lease core:plugin-lifecycle/global was lost
  • After: plugin lifecycle lease core:plugin-lifecycle/global was lost (lease owner was replaced)

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused diagnostic repair with shipped CLI evidence and no actionable findings; the separate recurring UI failure leaves the CI gate red.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): At the reviewed head, the shipped plugins-install CLI used isolated temporary state and a real lifecycle lease; replacing its persisted owner produced the new redacted reason and exit 1, satisfying the previous review's requested CLI receipt proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Operators receive identical lease-loss receipts for different persisted failure states and cannot distinguish the cause.
Reason: The linked diagnostic issue is bounded and independently source-verifiable, and earlier merged heartbeat diagnostics do not provide these row-state distinctions.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes a concrete diagnostic gap without changing lease ownership behavior; no actionable patch findings remain, though the CI gate is failing.

Priority: P2
Reviewed head: 1aa0cb7856fd09e5cf5fc6bc36b2cd3f7ffbced7

Before merge

None.

Findings

None.

Agent review details

How this fits together

Plugin lifecycle and maintenance callers use shared-state lease storage to verify ownership; failed checks become typed errors retained by CLI and recovery reporting.

flowchart TD
A[Plugin install CLI] --> B[Plugin lifecycle lease]
B --> C[Lease storage]
C --> D[State lease table]
D --> E[Redacted loss classification]
E --> F[Existing error formatter]
F --> G[CLI failure receipt]
Loading

Technical review

Best possible solution:

Retain the focused classification at the existing storage and error owners while preserving lease rejection and recovery behavior.

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

Current-main source deterministically collapses missing, replaced, and expired rows into the same error; contributor evidence reports failing base regressions, and this read-only review executed no target code.

Is this the best way to solve the issue?

The patch is a small complete diagnostic repair using existing owners, with no competing state, new configuration, or unrelated production changes.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5181de212c10.

Provenance checked

  • Native renewal and verification keeps the original intent (65bc5f6: The merged worker migration retained exact ownership, expiry, and live admission checks; later operation attribution preserved those contracts.)
  • Shared lease error formatting keeps the original intent (e5478ff: The shared error owner consolidated existing failures without intended behavioral changes; this PR retains its code, prefix, and cause handling.)
  • Worker regression fixtures keeps the original intent (94c6b20: Verification must release its snapshot before host admission and recheck current ownership afterward; added fixture columns support diagnostic reads without weakening those assertions.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e05265f adds src/state/openclaw-state-lease-storage.ts:109 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e05265fc8126; files: src/state/openclaw-state-lease-storage.ts)

PR surface

Source +59, Tests +101. Total +160 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 64 5 +59
Tests 3 109 8 +101
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 173 13 +160

Review metrics

Metric Value Why it matters
Production versus test changes Production +64/-5; tests +109/-8 Growth is focused on one shared loss classifier, existing error formatting, distinct storage regressions, and affected worker fixtures.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This improves diagnosis of genuine lease failures without changing availability, ownership policy, or recovery.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-25T03:23:08.181Z sha 1aa0cb7 :: needs real behavior proof before merge. :: none

Reviewed October 24, 2026, 11:57 PM ET / October 25, 2026, 03:57 UTC (Revision 2).

@ooiuuii

ooiuuii commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 25, 2026
steipete added a commit that referenced this pull request Oct 25, 2026
OPENCLAW_STATE_LEASE_LOST reported the same generic message whether the lease expired, was replaced by another owner, or no longer existed, so Windows update repairs that failed with a lost plugin lifecycle lease (#182476) could not be diagnosed. The lease owner now classifies the loss as expired, replaced or missing from the persisted row and carries that reason through the error and the update failure report. Lease duration, renewal cadence, fencing and ownership are unchanged.

Fixes #183154. Thanks @ooiuuii for the report and the diagnostic-only fix in #183178.

Co-authored-by: luyifan <[email protected]>
@steipete

Copy link
Copy Markdown
Contributor

Thank you, @ooiuuii! This landed as #183279 (9db139f). OPENCLAW_STATE_LEASE_LOST and the update failure report now say whether the lease expired, was replaced by another owner, or was missing, and lease duration, renewal, fencing and ownership are unchanged, as you proposed. You're credited as a co-author on the merge commit. Closing this one as superseded.

@steipete steipete closed this Oct 25, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
OPENCLAW_STATE_LEASE_LOST reported the same generic message whether the lease expired, was replaced by another owner, or no longer existed, so Windows update repairs that failed with a lost plugin lifecycle lease (openclaw#182476) could not be diagnosed. The lease owner now classifies the loss as expired, replaced or missing from the persisted row and carries that reason through the error and the update failure report. Lease duration, renewal cadence, fencing and ownership are unchanged.

Fixes openclaw#183154. Thanks @ooiuuii for the report and the diagnostic-only fix in openclaw#183178.

Co-authored-by: luyifan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

[Bug]: OPENCLAW_STATE_LEASE_LOST hides the persisted loss reason

2 participants