Repository navigation
fix(media-understanding): keep provider operation deadline on the monotonic clock - #186134
SunnyShu0925 wants to merge 1 commit into
Conversation
…otonic clock Seed and consume the provider-operation deadline with performance.now() instead of the wall clock, so a host clock jump (NTP correction, VM pause/resume) no longer corrupts the remaining-time budget. This is the canonical owner of the deadline, so it heals all 30+ media-understanding providers at once. Keeps the deadline payload, timeout policy, and downstream provider helpers unchanged.
|
🦞👀 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 real behavior proof before merge. What this changesThis PR measures shared provider-operation deadlines with performance.now() instead of Date.now(). Example: A provider operation has a 60000 ms budget when the host clock advances by 120000 ms.
Review scores
ProductKind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial Merge readiness⛔ Blocked before merge - 3 items remain Keep this PR open: the clock-skew bug remains on main, but the proposed cutover makes ordinary fal video generation fail before its first status request. Priority: P2 Decision needed
Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe shared provider HTTP layer converts operation budgets into request timeouts and polling waits, and exports its deadline helpers through the Plugin SDK. flowchart TD
A[Media generation request] --> B[Provider plugin]
B --> C[Shared operation deadline]
C --> D[Shared timeout resolver]
C --> E[Fal queue budget calculation]
D --> F[Provider HTTP transport]
E --> F
F --> G[Generated media result]
Technical reviewBest possible solution: Keep one shared monotonic budget owner, migrate fal to its resolver, and settle the exported deadline field's compatibility contract. Do we have a high-confidence way to reproduce the issue? Source establishes both the current-main clock-skew failure and the introduced fal failure; no target code was executed during this read-only review. Is this the best way to solve the issue? Monotonic elapsed-time accounting addresses the cause, but this patch is incomplete because a direct deadline consumer remains on the epoch clock. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 24e16034180f. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -4, Tests +9. Total +5 across 2 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 Reviewed October 27, 2026, 1:06 PM ET / 17:06 UTC. |
|
Closing: this change has been absorbed into maintainer PR #186484 (monotonic deadlines cutover). My original commit is preserved there with credit. Thanks! |
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]>
…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
Provider video-generation deadlines were computed on the wall clock (
Date.now()), so a host clock jump (NTP correction, VM pause/resume, manual time change) corrupted the remaining-time budget and could abort perfectly healthy provider requests before their timeout, or silently stretch the timeout for unhealthy ones. This is the canonical owner of the provider-operation deadline, so the fix lands once and heals 30+ providers (byteplus, fal, google, minimax, openai, openrouter, pixverse, runway, together, xai, zai, ...).deadlineAtMswas seeded with a wall-clock timestamp and the remaining budget was recomputed withDate.now(). When the wall clock jumps forward,remaining = deadlineAtMs - Date.now()goes negative and a healthy request is aborted immediately; when it jumps backward,remainingis inflated and real timeouts are stretched.deadlineAtMswithperformance.now() + resolvedTimeoutMsand compute the remaining budget withperformance.now(), keeping the whole deadline on the monotonic clock.src/media-understanding/shared.ts,createProviderOperationDeadlinenow seeds the deadline on the monotonic clock, and both consumers of the deadline (resolveProviderOperationTimeoutMsandwaitProviderOperationPollInterval) read the remaining budget from the same monotonic clock. TheresolveDateTimestampMs/resolveExpiresAtMsFromDurationMswall-clock imports are no longer used there and were dropped.deadlineAtMs,label,timeoutMs), the timeout-resolution policy (resolveTimerTimeoutMs,Math.max(1, Math.min(defaultTimeoutMs, remaining))), the thrown timeout error, and every downstream provider request helper that consumes the resolvedtimeoutMs. No provider signature or wire behavior changed.Why This Change Was Made
The canonical
ProviderOperationDeadlinemixed two clock domains: it was seeded on the wall clock but consumed downstream bybuildTimeoutAbortSignal'ssetTimeout, which runs on the monotonic clock. Crossing clock domains makes the deadline non-monotonic under wall-clock jumps. The minimal, complete fix is to express both the seed and every remaining-budget read on the monotonic clock, which is the same clock the abort signal actually uses. A pure arithmetic difference of two monotonic reads is inherently immune to wall-clock drift.deadlineAtMsvalues are no longer wall-clock timestamps. Nothing in the repo serializes or diagnoses them as such; all call sites only subtract to derive a remaining budget. A temporary debug log that prints the raw value would now show a small monotonic counter instead of an epoch, which is expected.User Impact
Users running media-understanding providers no longer see healthy generation/download requests fail early (or hang too long) whenever the host clock is corrected or a VM is paused and resumed. Deadlines now behave identically regardless of wall-clock jumps, so provider timeouts reflect real elapsed time only.
Evidence
Live runtime proof (drives the shipped production function under a simulated wall-clock jump; pre-fix model uses the wall clock, post-fix uses the monotonic clock, same 60s budget):
Regression test (RED → GREEN) — a new case "keeps the deadline on the monotonic clock across wall-clock jumps" drives a wall-clock jump forward/backward and asserts the remaining budget is unaffected. Against the pre-fix source it fails, against the fixed source it passes:
The pre-fix failure (
expected 120000 to be 60000) is the bug: after the forward wall-clock jump the remaining budget goes negative and the resolver returns the default timeout instead of the healthy remaining 60000ms.Open PR collision check: searched open PR topics for this deadline/clock pattern and scanned changed-file lists of open PRs touching
src/media-understanding/; no open PR modifies this file or the same fix region. (Related, distinct wall-clock fixes already merged: #169908, #165889.)