Skip to content

fix(claws): recover lifecycle state safely - #123254

Merged
giodl73-repo merged 7 commits into
openclaw:mainfrom
giodl73-repo:user/giodl/claws-final-exam-runtime
Aug 15, 2026
Merged

giodl73-repo merged 7 commits into
openclaw:mainfrom
giodl73-repo:user/giodl/claws-final-exam-runtime

Conversation

@giodl73-repo

@giodl73-repo giodl73-repo commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes issues where Claw runtime ownership could become stale across processes, rejected or concurrent MCP mutations could leave incorrect provenance, and retries could trust completed MCP and cron resources after ownership changed.

Why This Change Was Made

The runtime refreshes provenance at each authority snapshot, serializes MCP ownership and config mutation per server name, restores provenance after known rejected writes, and reconciles completed MCP and cron references against current live definitions and ownership. Completed cron ownership that is missing from Gateway inventory fails closed and requires explicit remove/add recovery.

User Impact

Claw add, update, retry, rollback, and removal operations recover more reliably without silently widening tool authority, recreating completed owned resources, or deleting shared configuration. Initial and pending cron creation retain the existing Gateway convergence contract; this PR does not change Cron's owner API.

Evidence

  • Focused exact-head ownership/recovery suite: 122 passed
  • Deterministic lifecycle red/green control: the lifecycle-ordering regression fails on base 493a3e46b3f2921269cfb0af5dfc86efb569ceaa because the ordinary mutation enters the canonical config writer while the Claw lease is held, and passes on this PR head because it remains blocked until release
  • Deterministic completed-cron recovery red/green: on prior head d5f50cf244732f5bb7090f274bdf1dc21095d3ed, a missing completed scheduler job proceeds toward cron.add; on this head it returns cron_reconcile_conflict, does not call cron.add, and preserves the completed ownership record for explicit removal
  • Pagination regression: completed-reference recovery scans a stable, bounded Gateway snapshot; the canonical suite covers 201 jobs across pages and rejects a drifted completed job beyond the first 200 without calling cron.add
  • Scoped formatting, type-aware lint, and git diff --check
  • Final codex review --base 621220aea9baa22b002be1f4cd10230be2767f3d: no actionable correctness defects

Proof disposition

This maintainer-authored repair coordinates local ownership/config writers around a shared SQLite lease. The deterministic proof uses the canonical mutation function as the observation point. Completed cron recovery is tested at the Gateway adapter boundary. The pending-reference list-to-add behavior is unchanged from main; this PR neither claims nor introduces a Gateway conditional-create protocol. It does not claim live provider, channel, or remote-service coverage. Exact-head hosted CI remains the integrated-environment gate.

Exact-head proof

  • Head c89425d006b24d9d4ddd6cf2f417d2e7c1b92124
  • Ordinary MCP set, update, tool-update, and unset operations share the same per-server lifecycle lease as Claw ownership reconciliation
  • Claw-internal mutations bypass nested acquisition only while already holding the non-reentrant lease
  • The deterministic interleaving regression observes the canonical config writer directly; base fails and head passes
  • Completed cron recovery consumes the canonical stable-snapshot paginated inventory and fails closed on drifted or missing completed ownership
  • A missing completed cron job preserves its ownership record and requires explicit remove/add recovery; no automatic cron.add is attempted
  • Initial and pending cron creation are unchanged from main; atomic conditional create is outside this PR
  • Focused exact-head ownership/recovery proof: 122 passed

@clawsweeper

clawsweeper Bot commented Aug 13, 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 cli CLI command changes size: L maintainer Maintainer-authored PR labels Aug 13, 2026
@giodl73-repo giodl73-repo self-assigned this Aug 13, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 13, 2026
@clawsweeper

clawsweeper Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 11:37 PM ET / August 15, 2026, 03:37 UTC.

ClawSweeper review

What this changes

The PR serializes Claw and ordinary MCP configuration changes, refreshes Claw provenance between processes, and reconciles completed cron ownership before recovery.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep open for maintainer review: current main still skips reconciliation for completed cron ownership, while this PR adds the missing safe recovery path. No concrete patch defect was found, but the intentional fail-closed recovery behavior, stale base, and pending exact-head checks need maintainer acceptance.

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

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The owner-boundary repair and focused regression coverage are solid, with merge readiness dependent on rebase and exact-head CI.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies this as a maintainer-member PR, so the external-contributor proof gate does not apply; the body still documents deterministic regression evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies this as a maintainer-member PR, so the external-contributor proof gate does not apply; the body still documents deterministic regression evidence.
Evidence reviewed 7 items Current-main gap: Current main unconditionally skips a completed cron reference, so a deleted or drifted Gateway job is never checked during recovery.
Completed-cron repair: The PR lists the live Gateway inventory for a completed reference and returns cron_reconcile_conflict without cron.add when the job is missing or no longer matches.
Regression coverage: Focused tests cover missing and drifted completed jobs and assert that recovery does not call cron.add.
Findings None None.
Security None None.

How this fits together

Claw lifecycle commands persist ownership of MCP servers and scheduled jobs, then coordinate with shared configuration and the Gateway. The resulting status determines whether an operator can safely retry, remove, or recreate a resource.

flowchart LR
  A[Claw lifecycle command] --> B[Persisted ownership]
  B --> C[MCP lifecycle lease]
  C --> D[Shared MCP configuration]
  B --> E[Completed cron reconciliation]
  E --> F[Gateway job inventory]
  D --> G[Operator recovery result]
  F --> G
Loading

Decision needed

Question Recommendation
After rebasing and green exact-head checks, should this maintainer-owned repair land with missing completed cron jobs requiring explicit remove/add recovery? Land after rebase and green checks: Accept the documented fail-closed recovery behavior once the rebased exact head passes required validation.

Why: The protected maintainer label and the intentional recovery-contract change require an explicit maintainer merge judgment even though no patch defect was found.

Before merge

  • Resolve merge risk (P1) - Existing installations with a completed cron record whose Gateway job was removed will now require explicit remove/add recovery instead of silently recreating the job.
  • Resolve merge risk (P1) - Ordinary MCP operations for the same server name may wait up to ten minutes while lifecycle reconciliation holds its lease.
  • Resolve merge risk (P1) - The branch is behind current main and hosted checks are still incomplete, so the rebased exact head needs green merge validation.
  • Resolve merge risk (P1) - This bug-fix branch adds a net 259 production lines; source review found no safe net-neutral refactor because the shared lease and reconciliation must span independent lifecycle owners, but the added surface warrants maintainer scrutiny.
Agent review details

Security

None.

PR surface

Source +239, Tests +640, Docs +20. Total +899 across 19 files.

View PR surface stats
Area Files Added Removed Net
Source 9 468 229 +239
Tests 8 659 19 +640
Docs 2 20 0 +20
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 19 1147 248 +899

Review metrics

Metric Value Why it matters
Production versus test delta production +468/-229 (net +239); docs +20/-0; tests +659/-19 (net +640) The repair adds coordinated lifecycle behavior across several owners, so its positive production growth merits explicit merge scrutiny.

Stored data model

Persistent data-model change detected: database schema: src/claws/provenance-runtime-read.test.ts, database schema: src/cli/claws-cli.test.ts, persistent cache schema: src/claws/provenance-runtime-read.test.ts, serialized state: src/claws/cron.ts, serialized state: src/claws/mcp.ts, serialized state: src/cli/claws-cli.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Rebase and verify the exact merge candidate (recommended)
    Rebase onto current main and require green exact-head checks before accepting the changed recovery behavior.
  2. Accept explicit manual cron recovery
    Maintainers may accept the compatibility tradeoff that a missing completed cron job now stops safely until the operator removes and adds the Claw again.

Technical review

Best possible solution:

Rebase and land only after exact-head CI is green, retaining the shared MCP facade lease and the explicit remove/add recovery contract for missing completed cron jobs.

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

Yes: create a completed Claw cron reference, remove or drift its Gateway job, then retry on current main; current source skips reconciliation, while the PR returns a recorded conflict before cron.add.

Is this the best way to solve the issue?

Yes: placing the lease in the shared MCP mutation facade and reconciling completed cron state at its lifecycle owner covers ordinary writers and retries without a new Gateway protocol.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add merge-risk: 🚨 availability: Same-name ordinary MCP mutations can wait behind the new lifecycle lease for up to ten minutes.
  • remove merge-risk: 🚨 security-boundary: Current PR review merge-risk labels are merge-risk: 🚨 compatibility, merge-risk: 🚨 availability.

Label justifications:

  • P1: The PR repairs active Claw lifecycle recovery and shared MCP mutation behavior that can affect existing operators.
  • merge-risk: 🚨 compatibility: Completed cron recovery changes from silent skip/recreation behavior to a fail-closed explicit remove/add recovery path.
  • merge-risk: 🚨 availability: Same-name ordinary MCP mutations can wait behind the new lifecycle lease for up to ten minutes.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool 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 supplied repository state identifies this as a maintainer-member PR, so the external-contributor proof gate does not apply; the body still documents deterministic regression evidence.

Evidence

What I checked:

  • Current-main gap: Current main unconditionally skips a completed cron reference, so a deleted or drifted Gateway job is never checked during recovery. (src/claws/cron.ts:322, 2ebaebd48473)
  • Completed-cron repair: The PR lists the live Gateway inventory for a completed reference and returns cron_reconcile_conflict without cron.add when the job is missing or no longer matches. (src/claws/cron.ts:331, 67258d1ee097)
  • Regression coverage: Focused tests cover missing and drifted completed jobs and assert that recovery does not call cron.add. (src/claws/cron.test.ts:147, 67258d1ee097)
  • Shared MCP ownership boundary: Ordinary MCP mutations acquire the same per-server lease as Claw lifecycle work, while Claw-held calls bypass only nested acquisition. (src/agents/mcp-config-mutation.ts:50, 67258d1ee097)
  • Feature provenance: The original Gateway-backed Claw cron lifecycle commit predates this PR and is authored by the same feature-history contributor. (src/claws/cron.ts:322, 96e3051838f9)
  • Current-main relation: The PR head is not an ancestor of current main; current main therefore does not already contain this repair. (67258d1ee097)

Likely related people:

  • giodl73-repo: Authored the original Gateway-backed Claw cron lifecycle, grouped Claw updates, and all commits on this repair branch. (role: feature-history owner and current repair author; confidence: high; commits: 96e3051838f9, 7d159fdc7700, 67258d1ee097; files: src/claws/cron.ts, src/claws/mcp.ts, src/claws/mcp-update.ts)
  • steipete: The retained current-main history attributes the surrounding Claw, MCP, and cron inventory surfaces to a recent repository refactor. (role: recent current-main contributor; confidence: medium; commits: 2702bcf09df7; files: src/cli/claws-cli.runtime.ts, src/agents/mcp-config-mutation.ts, src/claws/cron.ts)

Rank-up moves

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

  • Rebase onto current main and obtain green exact-head required checks.
  • Confirm maintainer acceptance of the explicit remove/add recovery outcome for missing completed cron jobs.

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 (12 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-14T13:32:18.618Z sha f69dcea5cf28697720593113092d4e323fa583e2 :: found issues before merge. :: [P1] Share the lifecycle lease with ordinary MCP mutations
  • reviewed 2026-08-14T15:40:01.655Z sha ac079035ea73ace91af2d2beee7fa7c4df646a53 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T15:56:22.105Z sha ac079035ea73ace91af2d2beee7fa7c4df646a53 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T19:34:24.717Z sha 4af5b80a5eb4387c7ff32ef99f7cf47b323970e8 :: needs changes before merge. :: [P1] Verify the persisted cron job before recreating it
  • reviewed 2026-08-14T20:37:34.978Z sha d5f50cf244732f5bb7090f274bdf1dc21095d3ed :: found issues before merge. :: [P1] Make cron recovery creation conditional on the inspected snapshot
  • reviewed 2026-08-14T21:57:52.261Z sha ecedcaa5fef7ed976ed23feda11f0a5e1b34fc37 :: found issues before merge. :: [P1] Make cron creation conditional on the inspected snapshot
  • reviewed 2026-08-14T22:41:01.413Z sha ecedcaa5fef7ed976ed23feda11f0a5e1b34fc37 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T23:30:48.948Z sha c89425d006b24d9d4ddd6cf2f417d2e7c1b92124 :: needs maintainer review before merge. :: none

@giodl73-repo

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The prior exact-head review hit bwrap: loopback: Failed RTM_NEWADDR before source inspection. Please replace that infrastructure-limited verdict with a fresh review of current head c2041556c3374cce09fab42c228801cdb06943a6.

@clawsweeper

clawsweeper Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@giodl73-repo
giodl73-repo force-pushed the user/giodl/claws-final-exam-runtime branch from c204155 to f69dcea Compare August 14, 2026 03:56
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 14, 2026
@giodl73-repo
giodl73-repo force-pushed the user/giodl/claws-final-exam-runtime branch from f69dcea to ac07903 Compare August 14, 2026 15:30
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Aug 14, 2026
@giodl73-repo

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@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. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed P2 Normal backlog priority with limited blast radius. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 14, 2026
@giodl73-repo

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Maintainer scope decision: do not add a new Gateway conditional-create protocol in this PR.

The exact-head P1 now points at the pending-reference creation path (src/claws/cron.ts:364-379). That list-to-add / convergent cron.add contract predates this branch on main (the relevant lines trace to 96e3051838f9 and 7d159fdc7700). This PR did not introduce atomicity for initial creation and no longer claims it.

The branch-attributable recovery path was a completed ownership record whose scheduler job disappeared. Head ecedcaa5fef7ed976ed23feda11f0a5e1b34fc37 now fails closed before cron.add, preserves the completed ownership record, and requires explicit remove/add recovery. Its regression fails on prior head d5f50cf244732f5bb7090f274bdf1dc21095d3ed and passes here; exact-head CI is green.

Please assess merge readiness against that delta. A Gateway-owned create-if-absent contract can be handled as a separate owner-level change rather than expanding this lifecycle repair.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@giodl73-repo
giodl73-repo force-pushed the user/giodl/claws-final-exam-runtime branch from c89425d to 67258d1 Compare August 15, 2026 03:30
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Aug 15, 2026
@giodl73-repo
giodl73-repo merged commit 103e1a4 into openclaw:main Aug 15, 2026
211 of 213 checks passed
@giodl73-repo

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@giodl73-repo
giodl73-repo deleted the user/giodl/claws-final-exam-runtime branch August 15, 2026 03:53
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 15, 2026
* fix(claws): preserve runtime lifecycle state

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 34377cd6-beac-4e49-8ab0-22cfaf8b54a5

* fix(claws): harden lifecycle reconciliation

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 34377cd6-beac-4e49-8ab0-22cfaf8b54a5

* fix(mcp): serialize ownership mutations

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 34377cd6-beac-4e49-8ab0-22cfaf8b54a5

* test(mcp): prove lifecycle lease ordering

* fix(claws): page cron recovery inventory

* fix(claws): fail closed on missing cron ownership

* refactor(claws): keep pending cron recovery unchanged

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Gio Della-Libera <[email protected]>
Copilot-Session: 34377cd6-beac-4e49-8ab0-22cfaf8b54a5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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