Repository navigation
fix(crabbox): keep coordinator retry deadline monotonic across clock skew - #165889
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
Codex review: needs maintainer review before merge. What this changesThe PR uses monotonic time for Crabbox coordinator retry and Azure stop-recovery budgets. Example: The wall clock rewinds 90 seconds during a stop command with a 1,005,000 ms budget.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a concrete deadline-accounting bug still present on current main, with no actionable correctness findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Crabbox plugin translates Gateway worker lifecycle requests into CLI subprocesses and returns their results; its command owner shares elapsed-time budgets across coordinator retries and Azure recovery. flowchart TD
A[Gateway lifecycle request] --> B[Worker environment service]
B --> C[Crabbox provider]
C --> D[Stop and retry owner]
D --> E[Process runtime]
E --> F[Crabbox CLI]
F --> D
Technical reviewBest possible solution: Land the focused monotonic-clock correction in the existing Crabbox command owner. Do we have a high-confidence way to reproduce the issue? Current-main deadline arithmetic directly establishes the rewind failure, and the contributor supplies a matching before/after Gateway trace; this read-only review did not rerun it. Is this the best way to solve the issue? Using one monotonic clock for each deadline and remaining-budget read repairs the accounting at its existing owner without changing configured durations, retry classification or recovery policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d07bd8b6ad7b. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests +72. Total +72 across 3 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 HistoryReview history (11 earlier review cycles; latest 8 shown)
Reviewed October 14, 2026, 3:28 AM ET / 07:28 UTC (Revision 12). |
02526bf to
efb8a00
Compare
efb8a00 to
577e99f
Compare
|
🦞👀 Re-review progress:
|
f291fe9 to
735245a
Compare
735245a to
338c2dc
Compare
…skew runCrabboxCommandWithCoordinatorRetry and stopCrabboxLease seed their deadline with Date.now() and read remaining budget with Date.now(), then pass the remaining to runCommand which feeds setTimeout (monotonic) via resolveTimerTimeoutMs. When the wall clock rewinds (NTP step-back or suspend-resume), the remaining is amplified by the rewind delta, so lease commands hang far longer than the configured timeout. Switch all five Date.now() calls in crabbox-worker-command.ts to performance.now(), which is monotonic and immune to wall-clock skew. The existing 'keeps the stop deadline' test spy moves from Date.now to performance.now to match. A new regression test spies Date.now to rewind the wall clock between seed and read and asserts every retry timeoutMs stays within the original budget; pre-fix this fails with 94000 > 5000.
338c2dc to
20961bc
Compare
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
@fuller-stack-dev Thanks~ |
…skew (openclaw#165889) * fix(crabbox): keep coordinator retry deadline monotonic across clock skew runCrabboxCommandWithCoordinatorRetry and stopCrabboxLease seed their deadline with Date.now() and read remaining budget with Date.now(), then pass the remaining to runCommand which feeds setTimeout (monotonic) via resolveTimerTimeoutMs. When the wall clock rewinds (NTP step-back or suspend-resume), the remaining is amplified by the rewind delta, so lease commands hang far longer than the configured timeout. Switch all five Date.now() calls in crabbox-worker-command.ts to performance.now(), which is monotonic and immune to wall-clock skew. The existing 'keeps the stop deadline' test spy moves from Date.now to performance.now to match. A new regression test spies Date.now to rewind the wall clock between seed and read and asserts every retry timeoutMs stays within the original budget; pre-fix this fails with 94000 > 5000. * test(crabbox): prove shared budgets across independent clock steps --------- Co-authored-by: Jason (Json) <[email protected]>
…skew (openclaw#165889) * fix(crabbox): keep coordinator retry deadline monotonic across clock skew runCrabboxCommandWithCoordinatorRetry and stopCrabboxLease seed their deadline with Date.now() and read remaining budget with Date.now(), then pass the remaining to runCommand which feeds setTimeout (monotonic) via resolveTimerTimeoutMs. When the wall clock rewinds (NTP step-back or suspend-resume), the remaining is amplified by the rewind delta, so lease commands hang far longer than the configured timeout. Switch all five Date.now() calls in crabbox-worker-command.ts to performance.now(), which is monotonic and immune to wall-clock skew. The existing 'keeps the stop deadline' test spy moves from Date.now to performance.now to match. A new regression test spies Date.now to rewind the wall clock between seed and read and asserts every retry timeoutMs stays within the original budget; pre-fix this fails with 94000 > 5000. * test(crabbox): prove shared budgets across independent clock steps --------- Co-authored-by: Jason (Json) <[email protected]> (cherry picked from commit 9a7d4d1) Co-authored-by: RomneyDa <[email protected]>
…skew (#165889) * fix(crabbox): keep coordinator retry deadline monotonic across clock skew runCrabboxCommandWithCoordinatorRetry and stopCrabboxLease seed their deadline with Date.now() and read remaining budget with Date.now(), then pass the remaining to runCommand which feeds setTimeout (monotonic) via resolveTimerTimeoutMs. When the wall clock rewinds (NTP step-back or suspend-resume), the remaining is amplified by the rewind delta, so lease commands hang far longer than the configured timeout. Switch all five Date.now() calls in crabbox-worker-command.ts to performance.now(), which is monotonic and immune to wall-clock skew. The existing 'keeps the stop deadline' test spy moves from Date.now to performance.now to match. A new regression test spies Date.now to rewind the wall clock between seed and read and asserts every retry timeoutMs stays within the original budget; pre-fix this fails with 94000 > 5000. * test(crabbox): prove shared budgets across independent clock steps --------- Co-authored-by: Jason (Json) <[email protected]> (cherry picked from commit 9a7d4d1)
What Problem This Solves
When a laptop wakes from sleep or an NTP correction steps the system clock backward,
crabbox stopcommands hang far longer than their configured timeout, delaying cloud lease reclamation. The retry deadline is seeded withDate.now()and remaining budget is read withDate.now(), then passed torunCommand→setTimeout(monotonic). On wall-clock rewind,remaining = deadline - Date.now()is amplified by the rewind delta, so a lease stop configured forCRABBOX_STOP_TIMEOUT_MS(~16 min) can hang ~18× longer.Date.now()calls withperformance.now(), which is monotonic and immune to wall-clock skew.crabbox-worker-command.ts— 5 calls at L181/196/201 (retry loop) and L285/308 (stop + Azure recovery);crabbox-worker-command.test.ts— spy moves toperformance.now, plus a new rewind regression test;crabbox-worker-stop-lifetime.test.ts— Azure recovery spy moves toperformance.now, plus a new Azure recovery rewind regression test.resolveTimerTimeoutMs,CRABBOX_STOP_TIMEOUT_MS, retry/backoff constants, error messages, coordinator-failure classification. No new imports (Node 16+ exposesperformanceglobally). SiblingDate.now()deadline patterns incrabbox-worker-provider.ts,crabbox-worker-warm-image.ts, andcrabbox-worker-node-process.tsare out of scope; separate budgets, tracked by fix(crabbox): use monotonic clock for provision deadline budget #162813/fix(crabbox): measure warm-image cleanup deadlines on the monotonic clock #169908.Why This Change Was Made
The fix puts the deadline seed and remaining-budget read on the same monotonic clock as the
setTimeoutconsumer, soremainingis always bounded by the original budget.performance.now()is the canonical monotonic clock in Node and matches thesetTimeoutconsumer's clock domain. Mechanical, line-for-line replacement with no logic change.process.hrtime.bigint()is also monotonic but returns nanoseconds and requires conversion.User Impact
After a laptop wakes from sleep or an NTP correction steps the clock back, Crabbox lease stop commands now respect the configured timeout and give up on time, so workers and cloud leases are reclaimed within their expected cleanup window.
Evidence
Dispatcher-triggered teardown (running Gateway, real client, shipped dispatcher)
The real Gateway is started via
startGatewayServer(shipped server kernel + RPC dispatcher); a real GatewayClient completes the token-authenticated handshake.client.request("environments.destroy")is routed through the running Gateway's shipped dispatcher to theenvironments.destroyhandler, which calls the shippedcreateCrabboxWorkerProviderfactory →provider.destroy(lease)→stopLease()→stopCrabboxLease()→runCrabboxCommandWithCoordinatorRetry().performance.now()is native (not mocked);Date.now()is rewound 90 s between the deadline seed and the budget read.Date.now())performance.now())client.request("environments.destroy")through shipped dispatcher, shippedcreateCrabboxWorkerProvider→provider.destroy→stopCrabboxLease, 90s rewindCRABBOX_STOP_TIMEOUT_MS(FAIL)CRABBOX_STOP_TIMEOUT_MS(PASS)Focused test suite (pre-fix fail / post-fix pass)
Includes
"keeps the coordinator retry deadline bounded when the wall clock rewinds"(pre-fix fails94000 > 5000, post-fix passes) and"keeps Azure recovery bounded when the wall clock rewinds"(pre-fix fails with amplifiedrecoveryTimeoutMs, post-fix passes).What was not tested
runCommandWithTimeoutwith real child processes; only the Crabbox CLI binary is substituted.Date.nowrewind). The proof confirms correct native monotonic behavior with the real Gateway dispatcher; the rewind confirms the bug's credible failure and fix.