Skip to content

fix(crabbox): dispose heartbeat generations - #128957

Merged
steipete merged 1 commit into
mainfrom
steipete/fix-crabbox-heartbeat-disposal
Aug 25, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/fix-crabbox-heartbeat-disposal

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #128948

What Problem This Solves

Crabbox lease heartbeats were owned only per lease. The bundled plugin registered a worker provider but no plugin service that could dispose the provider generation, so Gateway shutdown or plugin-generation replacement could leave pending heartbeat timers and in-flight Crabbox commands alive. Late completions could then reschedule work from a retired generation alongside its replacement.

Why This Change Was Made

The existing Gateway lifecycle already stops worker-environment sidecars before plugin services. Crabbox now registers a small cleanup service that disposes the same provider generation it registered. The heartbeat manager has one irreversible generation fence: disposal clears every pending timer, removes every entry, aborts every in-flight command, ignores late starts, and makes late completions unable to reschedule. A newly constructed provider generation owns a new independent manager.

The disposal method remains private to the bundled Crabbox implementation; the public WorkerProvider contract, core registry, protocol, config, provider command semantics, and per-lease destroy path are unchanged. This reuses the existing plugin-service lifecycle pattern rather than adding a core-wide provider shutdown API.

Production LOC: +37/-20 (net +17) | Tests: +148/-0 (net +148)

The production growth adds the missing generation owner and folds all timer/controller cleanup through the existing per-entry stop path.

AI-assisted: yes. I reviewed plugin service replacement/shutdown ordering, worker-environment sidecar ordering, heartbeat timer/controller ownership, late completion behavior, per-lease destroy, and replacement-generation isolation.

User Impact

Gateway shutdown, restart, and plugin replacement no longer leave retired Crabbox keepalive work running. Active heartbeat commands are aborted, pending timers are cleared, and a replacement generation continues heartbeating without overlap from the old one.

Evidence

  • Pre-fix regressions: all three new lifecycle cases failed because no cleanup service was registered, in-flight heartbeat signals remained unaborted, and the retired generation continued heartbeating after replacement.
  • Focused owner proof: node scripts/run-vitest.mjs extensions/crabbox extensions/mxc/test/plugin.test.ts passed 143 tests across five files on the exact rebased head.
  • Full changed-file gate: node scripts/check-changed.mjs passed, including extension production/test typechecks, type-aware lint, formatting, doctor contract guards, plugin boundaries, dead exports, database-first, and import cycles.
  • Coverage uses the real Crabbox plugin entry and provider with a mocked process runner. It proves pending timers and late starts are fenced, multiple in-flight heartbeats are aborted, late completions do not reschedule, disposal is generation-local, and a replacement provider keeps running.
  • Fresh P0/P1 autoreview: no accepted/actionable findings (0.94).
  • No live Machine0, Crabbox API/CLI, or provider request was made: another campaign session exclusively owns the current Machine0 proof lease. This repair is process-local lifecycle ownership and is deterministically covered without external side effects.

@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 25, 2026 01:37
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Aug 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 24, 2026, 9:42 PM ET / August 25, 2026, 01:42 UTC.

ClawSweeper review

What this changes

Adds a Crabbox plugin lifecycle service that disposes generation-owned heartbeat timers and in-flight commands during shutdown or replacement.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This maintainer-authored PR remains necessary: current main has only per-lease heartbeat cleanup, while this patch adds the missing provider-generation owner and fence. No actionable correctness or security finding was identified.

Priority: P2
Reviewed head: ee580ecdcaf20506b6aae324c676b5475e0ea237

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, owner-local repair with boundary tests and no actionable review findings.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its focused mocked-process lifecycle tests are supplemental evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its focused mocked-process lifecycle tests are supplemental evidence.
Evidence reviewed 6 items Current-main gap: Current main registers only the worker provider; its heartbeat manager has per-lease stop but no generation disposal, so the reported lifecycle gap remains.
Patch owner boundary: The PR keeps cleanup in the Crabbox plugin by registering a service that disposes the same provider generation it registered.
Lifecycle fence: Disposal makes the manager inert, removes each entry, clears timers, aborts commands, and existing current-entry checks prevent late completions from scheduling again.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/crabbox/index.test.ts

Result: PASS (completed)

node scripts/run-vitest.mjs extensions/crabbox/index.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128957-LuIS6B/target$ node scripts/run-vitest.mjs extensions/crabbox/index.test.ts
node scripts/run-vitest.mjs extensions/crabbox/index.test.ts
[test] starting test/vitest/vitest.extensions.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128957-LuIS6B/target

 ✓  extensions  extensions/crabbox/index.test.ts (3 tests) 36ms

 Test Files  1 passed (1)
      Tests  3 passed (3)
   Start at  01:43:43
   Duration  7.58s (transform 5.87s, setup 967ms, import 6.22s, tests 36ms, environment 0ms)

[test] passed 1 Vitest shard in 13.76s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128957-LuIS6B/target$ node scripts/run-vitest.mjs extensions/crabbox/index.test.ts



































Assertions:

  • PASS expect_output: 3 passed

How this fits together

The Crabbox plugin supplies Gateway’s cloud-worker provider. Lease inspection starts local heartbeat commands; plugin-service teardown must retire that generation’s background work before a replacement can run.

flowchart LR
  A[Cloud worker lease] --> B[Crabbox provider]
  B --> C[Heartbeat manager]
  C --> D[Timers and CLI commands]
  E[Plugin service lifecycle] --> F[Generation cleanup]
  F --> C
  C --> G[Retired work fenced]
  G --> H[Replacement generation]
Loading

Before merge

  • Resolve merge risk (P1) - This bug fix has a net production increase of 17 lines; it is justified by the previously absent generation owner and fence, and should remain plugin-local rather than expanding the WorkerProvider SDK.
  • Complete next step (P2) - The protected maintainer PR has no mechanical repair finding; rebase and review exact-head CI before landing.
Agent review details

Security

None.

PR surface

Source +17, Tests +148. Total +165 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 37 20 +17
Tests 1 148 0 +148
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 185 20 +165

Review metrics

Metric Value Why it matters
Production vs test LOC production +17, tests +148 The small production increase creates the missing lifecycle owner and fence; the tests cover pending, in-flight, late-completion, and replacement-generation cases.

Stored data model

Persistent data-model change detected: persistent cache schema: extensions/crabbox/index.test.ts, serialized state: extensions/crabbox/index.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #128948
Summary: This PR is the linked candidate fix for the canonical Crabbox provider-generation heartbeat leak.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the cleanup service and irreversible manager fence local to Crabbox, then rebase and land after exact-head checks complete.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the cleanup service and irreversible manager fence local to Crabbox, then rebase and land after exact-head checks complete.

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

Yes, source-reproducible: current main starts heartbeats per lease but exposes no generation disposal path, and the PR’s focused lifecycle cases exercise the missing boundary with the real plugin entry and provider.

Is this the best way to solve the issue?

Yes. Reusing the existing plugin-service lifecycle keeps provider-specific cleanup in its owning plugin and avoids an unnecessary core-wide shutdown API.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: The defect can leave duplicate Crabbox heartbeat work after provider replacement or shutdown, but is limited to the optional cloud-worker provider.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool 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: This MEMBER-authored PR is exempt from the external-contributor proof gate; its focused mocked-process lifecycle tests are supplemental evidence.

Label justifications:

  • P2: The defect can leave duplicate Crabbox heartbeat work after provider replacement or shutdown, but is limited to the optional cloud-worker provider.
  • 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: This MEMBER-authored PR is exempt from the external-contributor proof gate; its focused mocked-process lifecycle tests are supplemental evidence.

Evidence

What I checked:

  • Current-main gap: Current main registers only the worker provider; its heartbeat manager has per-lease stop but no generation disposal, so the reported lifecycle gap remains. (extensions/crabbox/index.ts:13, b840a3c84e2c)
  • Patch owner boundary: The PR keeps cleanup in the Crabbox plugin by registering a service that disposes the same provider generation it registered. (extensions/crabbox/index.ts:20, ee580ecdcaf2)
  • Lifecycle fence: Disposal makes the manager inert, removes each entry, clears timers, aborts commands, and existing current-entry checks prevent late completions from scheduling again. (extensions/crabbox/src/crabbox-worker-heartbeat.ts:43, ee580ecdcaf2)
  • Core lifecycle contract: Gateway plugin services retain stop callbacks and invoke them during shutdown and replacement; the PR uses this existing lifecycle seam rather than changing WorkerProvider or protocol contracts. (src/plugins/services.ts:267, b840a3c84e2c)
  • Feature provenance: The current-main heartbeat behavior appears to date to this commit; blame attributes the affected Crabbox lifecycle lines to Peter Steinberger. (extensions/crabbox/src/crabbox-worker-heartbeat.ts:43, 3c2667ca40f1)
  • Release check: No tag contains the PR head, and current main is newer than the latest supplied release; this remains unmerged, unreleased work. (ee580ecdcaf2)

Likely related people:

  • steipete: Git history and blame attribute the Crabbox heartbeat/provider lifecycle to this contributor, including the current repair. (role: initial implementation and recent area contributor; confidence: high; commits: 3c2667ca40f1, 5a0fe2232b46, eb8d90a24645; files: extensions/crabbox/index.ts, extensions/crabbox/src/crabbox-worker-heartbeat.ts, extensions/crabbox/src/crabbox-worker-provider.ts)

Rank-up moves

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

  • Rebase onto current main and let exact-head CI complete before landing.

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

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head ee580ecdcaf20506b6aae324c676b5475e0ea237:

  • CI run 32798253831: exact-head pull_request gates completed successfully. The watcher recovered from one transient GitHub GraphQL TLS handshake timeout; no CI job failed or reran.
  • Focused owner proof: node scripts/run-vitest.mjs extensions/crabbox extensions/mxc/test/plugin.test.ts passed 143 tests across five files.
  • node scripts/check-changed.mjs: passed extension production/test typechecks, type-aware lint, formatting, doctor contract guards, plugin boundaries, dead exports, database-first, and import-cycle checks.
  • Fresh exact-branch P0/P1 autoreview: no accepted/actionable findings (0.94).
  • Native review artifacts validate as READY FOR /prepare-pr with zero findings; OPENCLAW_TESTBOX=1 scripts/pr prepare-run 128957 passed hosted gates.
  • Root cause: Crabbox heartbeat timers/controllers were lease-owned but had no plugin/provider-generation cleanup owner.
  • Canonical repair: the plugin registers a cleanup service for its exact provider generation; disposal clears every timer, aborts every in-flight command, fences late starts/completions, and leaves replacement generations independent.
  • Production LOC: +37/-20 (net +17). Tests: +148/-0.
  • Latest ClawSweeper exact-head comment is the in-progress publisher placeholder and contains no findings or Rank-up moves. Repository policy does not block landing on the publisher.

Proof boundary: no live Machine0 or external Crabbox request was made because another campaign session exclusively owns the current Machine0 proof lease. The repaired behavior is process-local lifecycle ownership and is deterministically covered with the real plugin entry/provider plus a mocked command runner.

@steipete
steipete merged commit 3c7143d into main Aug 25, 2026
178 checks passed
@steipete
steipete deleted the steipete/fix-crabbox-heartbeat-disposal branch August 25, 2026 01:54
@steipete

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

extensions: crabbox maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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]: Crabbox heartbeat timers outlive provider generations

1 participant