Repository navigation
fix(discord): keep the gateway READY wait deadline on the monotonic clock - #182064
mikasa0818 wants to merge 1 commit into
Conversation
|
Codex review: needs real behavior proof before merge. What this changesThis PR measures the Discord gateway READY wait with a monotonic clock so wall-clock adjustments cannot distort its timeout. Example: Discord never reaches READY, the timeout is 15000ms, and the wall clock moves backward 60000ms during the wait.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this PR repairs a concrete deadline defect still present on current main, with no actionable correctness findings. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe Discord monitor supplies its gateway and supervisor to the lifecycle owner, which observes readiness and errors, publishes channel status, and initiates reconnects after startup READY timeouts. flowchart LR
A[Discord monitor] --> B[Gateway lifecycle]
C[Monotonic clock] --> B
D[Gateway readiness and errors] --> B
B --> E[Channel status]
B --> F[Disconnect and reconnect]
Technical reviewBest possible solution: Retain the two clock substitutions and focused regression in the existing lifecycle owner. Do we have a high-confidence way to reproduce the issue? Current-main deadline arithmetic establishes the rewind failure, and the contributor reports matching red/green regression results; no target code was executed during this read-only review. Is this the best way to solve the issue? This is the smallest complete repair: elapsed-time deadline arithmetic uses one monotonic clock while status timestamps, timeout settings, retry policy, and cancellation remain unchanged. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 18d7560e2066. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +3, Tests +18. Total +21 across 2 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label 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 24, 2026, 5:37 AM ET / 09:37 UTC (Revision 3). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
fix: measure deadlines and budgets on one monotonic clock owner Many deadline, budget and timeout calculations used Date.now(), so a wall-clock step (NTP correction, VM resume, manual change) made them expire early or run long. Contributors had been fixing these one call site at a time. Core now has one owner, src/shared/monotonic-time.ts, for process-local deadlines and elapsed time, replacing the supervisor-local helper and the per-site variants. Bundled extensions use performance.now() directly. Wall-clock values stay where they are persisted, shown to users or exchanged between processes: the public provider deadline stays epoch-valued, with monotonic enforcement kept privately, and the plugin SDK facade is unchanged. This absorbs the per-site fixes from @SunnyShu0925 (#186039, #186134, #186412, #184716, #184613) and @mikasa0818 (#184576, #184525, #182064), whose original commits are kept. Update, Doctor, Windows-only and security-held sites are listed under "Not fixed here" in the PR. Evidence: built CLI suspend wait, browser Gateway CDP waits, Discord READY wait and node host-stats checkpoint, each with Date.now stepped inside the process only. On main each misbehaved under the clock step (early expiry or a stretched wait); with this change each matched the no-step control. Media generation's guard blocks local fixtures, so that family relies on the shared owner's regression. Production 479 changed lines, tests net 0. Co-authored-by: SunnyShu <0668000539@local> Co-authored-by: mikasa0818 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
|
Thanks @mikasa0818. This is now fixed at the root in #186484 (bf10fbe): process-local deadlines and budgets go through one monotonic clock owner, src/shared/monotonic-time.ts (bundled extensions use performance.now()). Your commit from this PR is kept in that merge and you're credited as co-author, so I'm closing this one as covered. For new deadline code, please use that owner rather than a per-site change. |
…86484) fix: measure deadlines and budgets on one monotonic clock owner Many deadline, budget and timeout calculations used Date.now(), so a wall-clock step (NTP correction, VM resume, manual change) made them expire early or run long. Contributors had been fixing these one call site at a time. Core now has one owner, src/shared/monotonic-time.ts, for process-local deadlines and elapsed time, replacing the supervisor-local helper and the per-site variants. Bundled extensions use performance.now() directly. Wall-clock values stay where they are persisted, shown to users or exchanged between processes: the public provider deadline stays epoch-valued, with monotonic enforcement kept privately, and the plugin SDK facade is unchanged. This absorbs the per-site fixes from @SunnyShu0925 (openclaw#186039, openclaw#186134, openclaw#186412, openclaw#184716, openclaw#184613) and @mikasa0818 (openclaw#184576, openclaw#184525, openclaw#182064), whose original commits are kept. Update, Doctor, Windows-only and security-held sites are listed under "Not fixed here" in the PR. Evidence: built CLI suspend wait, browser Gateway CDP waits, Discord READY wait and node host-stats checkpoint, each with Date.now stepped inside the process only. On main each misbehaved under the clock step (early expiry or a stretched wait); with this change each matched the no-step control. Media generation's guard blocks local fixtures, so that family relies on the shared owner's regression. Production 479 changed lines, tests net 0. Co-authored-by: SunnyShu <0668000539@local> Co-authored-by: mikasa0818 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes: the Discord monitor's bounded wait for the gateway READY event keeps polling past its configured timeout when the system wall clock steps backward during the wait, so a Discord account that never reaches READY stalls in "connecting" for the length of the step instead of timing out and reconnecting with backoff.
User Impact
User impact: a Discord channel whose gateway connection never becomes READY now always moves on to the reconnect-with-backoff path after
DISCORD_GATEWAY_READY_TIMEOUT_MS(default 15s) of real elapsed time, regardless of NTP corrections or VM/laptop resume. Startup and recovery no longer hang on a wall-clock-inflated wait, and status keeps reporting the recovering lifecycle promptly.Why This Change Was Made
waitForGatewayReady's innerwaitUntilReadyseedsdeadlineAt = Date.now() + gatewayReadyTimeoutMsand checksDate.now() >= deadlineAtbetween 250ms polls armed with monotonicsetTimeout. A backward wall-clock step during the wait inflates the remaining budget by the step, so the monitor polls for15s + stepbefore logging the READY timeout and reconnecting; a forward step gives up early.The deadline now lives on
performance.now()— seed and expiry check — which is monotonic and unaffected by wall-clock adjustments. Status timestamps (lastEventAt, transport activity) stay onDate.now()because they are absolute wall-clock facts. This is the same cross-clock-domain pattern already fixed for command process-group teardown in #174151 and the orphaned-process reap grace deadline in #181335; the Discord READY wait is the sibling site left on the wall clock.Related but separate open PRs touch the same file's outer recovery behavior: #162377 bounds the number of consecutive READY recovery attempts, #124162 adds a runtime disconnection watchdog, and #138441 fixes voice bridge selection. This change only moves the per-attempt wait deadline to the monotonic clock and composes with those.
No configuration, protocol, or status-shape change; the env override semantics (a duration in ms) are untouched, and behavior on a clock that never steps is identical.
Evidence
Pre-fix RED — stock main (
97d96e53d22f), regression test only. Fake timers advance 15s of monotonic time past the READY timeout whilevi.setSystemTimerewinds the wall clock 60s mid-wait; the timeout never fires, so no error is logged and no reconnect happens:Post-fix GREEN — the READY wait times out at its 15s monotonic bound, logs the timeout, and reconnects:
Behavior matrix (gateway never READY, wall clock rewound 60s mid-wait, 15s default timeout):
Also verified on the changed tree:
pnpm format:check,pnpm lint, and the extensions typecheck entry. The regression drives the realrunDiscordGatewayLifecyclethrough the existing test harness (mocked gateway/supervisor, real lifecycle state machine); the local bundled-gateway proof path is not runnable on this Windows contributor box and was not used as evidence.Real runtime proof (real timers, lifecycle event trace, in-process wall-clock rewind)
Same scenario executed twice with real timers — no fake clocks: the real
runDiscordGatewayLifecycleruns with hand-rolled real collaborator objects (real EventEmitter, real counters) against a gateway that never reaches READY (OPENCLAW_DISCORD_READY_TIMEOUT_MS=5000). One second into the wait,Date.nowalone is rewound 120s in-process (NTP-correction analogue);performance.now()keeps reporting real elapsed time. The trace identifies the lifecycle boundary events: the READY-timeout log, gateway disconnect, and the reconnect attempt.Stock main never fires the READY timeout during the observation cap (its budget stretches to ~125s by the rewind); with this PR the timeout fires at 5.02s of real time, the gateway is disconnected, and the monitor moves on to reconnect with backoff.