Repository navigation
fix(state): avoid false worktree lease loss after parent stalls - #168214
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThe heartbeat worker publishes request completion so delayed parent delivery does not falsely invalidate a healthy lease. Example: A completed verification reply arrives after 1,506 ms with 58,494 ms remaining on its lease.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR fixes a current asynchronous heartbeat race, and no actionable defects were found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherManaged worktree allocation uses shared-state leases whose worker verifies SQLite ownership; the parent consumes replies and shared observations before continuing guarded allocation. flowchart TD
A[Gateway session creation] --> B[Worktree allocation]
B --> C[State lease owner]
C --> D[Heartbeat worker]
D --> E[SQLite lease row]
D --> F[Completion observation and reply]
F --> C
C --> G[Guarded worktree publication]
Technical reviewBest possible solution: Land the shared heartbeat completion repair while preserving durable-owner checks and existing expiry bounds. Do we have a high-confidence way to reproduce the issue? Current-main source rejects completed asynchronous replies after the response deadline despite remaining lease validity; the PR supplies base-failing regressions and a matching Gateway scenario, which were not rerun during this read-only review. Is this the best way to solve the issue? Publishing completion in the existing worker fixes the completion-versus-delivery race at its shared owner without extending lease duration or treating completion as authorization. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against bb7d32e55d48. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +11, Tests +122. Total +133 across 5 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 10, 2026, 2:19 AM ET / 06:19 UTC (Revision 3). |
What Problem This Solves
Fixes: managed worktree allocation reports lease loss when the parent delivers an already-completed heartbeat reply more than one second late, even though the same owner still has a valid lease.
User Impact
Worktree allocation survives short parent-thread stalls without weakening rejection of expired leases or unresponsive workers. No configuration, schema, lease-duration, or operator-action changes.
Why This Change Was Made
Publish asynchronous request completion before notifying the parent. The existing reply handler and deadline timer can then distinguish queued delivery from an unanswered request. Completion does not grant ownership: the actual reply, running worker state, lease expiry, and fixed operation bound still apply.
Evidence
withWorktreeAllocationLeaseproof: worker verifies within 1 ms; parent stalls 1,504 ms; original owner retains 58,474 ms; allocation completes. Healthy control completes; expired-owner and unanswered-worker controls reject. All four release their leases. No live Gateway used.node scripts/check-changed.mjspassed, including production/test types, formatting, lint, dead exports, import cycles, and ownership guards.pnpm test src/state/openclaw-state-lease-heartbeat.lifetime.test.ts --maxWorkers=1takes 24.63 s wall time (16.04 s compiled-worker preparation; about 0.17 s test execution). New cases use fake clocks; no added CI sleeps or process boots. Existing real-worker suite takes 45.57 s, reused as worker-contract proof. Hosted CI timing was not measured.Also ran the native
qaRuntimebuild and built-Gateway E2E below. The full packaging build and full test suite were not run.Built Gateway E2E proof
Pinned reviewed head:
f0d5acb3eb7748da51f49e2639cb4812652ae4cc.OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build qaRuntimepasses; the manual proof runner exits 0.The maintained QA Lab lifecycle boots the actual built
dist/index.js gateway run, authenticates a real WebSocket RPC client, and callssessions.createwith an initial message andworktree: true. Allocation therefore runs through the deferred admitted-first-turn path, not a direct allocator call.agent.wait,sessions.list,worktrees.list, real Git branch/base-commit checks, and checkout file contents establish the outcome.agent.wait: okagent.wait: okagent.wait: errornaming the allocation lease lossagent.wait: okFor the stalled case, the real SQLite worker completed verification inside the original one-second response budget. A proof-only preload then blocked the parent for 1,503 ms. The successful reply was delivered 1,506 ms after request publication, with 58,494 ms remaining on the verified lease grant. The preload neither fabricates replies nor changes SQLite, product completion state, ownership checks, or product deadlines. The negative control withholds one verification request and produces the exact public error:
One isolated Gateway serves all four cases with a loopback-only synthetic model service; no live provider or operator Gateway is used. Native cleanup deletes all four synthetic sessions, verifies zero active managed worktrees and zero capacity lease rows, and confirms the Gateway stopped. Existing removed-worktree snapshot records and template-cache retention are honored. Adding this proof does not change the reviewed code head or add production hooks or CI tests.
Sanitized receipt, reproducer and isolation details, complete artifact manifest. All seven uploaded files and the manifest were downloaded and verified; file SHA-256 values match the locally tested bundle. Download links expire on 2026-10-17 UTC; the observed result stays inline below.
Observed Gateway RPC output
To reproduce, place the three harness files from the artifact bundle in
.local/lease-gateway-e2e/in a clean, task-owned checkout at the pinned head, with the repository-declared toolchain and dependencies:This is built-Gateway RPC evidence, not package-install, live-provider, cross-platform, or full-suite validation. The manual proof adds no hosted-CI seconds.