Repository navigation
fix(crabbox): dispose heartbeat generations - #128957
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 24, 2026, 9:42 PM ET / August 25, 2026, 01:42 UTC. ClawSweeper reviewWhat this changesAdds a Crabbox plugin lifecycle service that disposes generation-owned heartbeat timers and in-flight commands during shutdown or replacement. Merge readinessThis 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 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherThe 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +17, Tests +148. Total +165 across 4 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Land-ready proof for exact head
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. |
|
Merged via squash.
|
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
node scripts/run-vitest.mjs extensions/crabbox extensions/mxc/test/plugin.test.tspassed 143 tests across five files on the exact rebased head.node scripts/check-changed.mjspassed, including extension production/test typechecks, type-aware lint, formatting, doctor contract guards, plugin boundaries, dead exports, database-first, and import cycles.