Repository navigation
Conversation
…clock The media generation completion handoff retried a pending cron continuation against a 120s budget seeded with Date.now(), while the sleep between retries runs on a libuv monotonic timer. A wall-clock correction therefore moved the budget: a backward jump let a pending handoff retry past 120s, and a forward jump failed a healthy handoff early because the remaining budget went negative. Seed and measure the deadline with performance.now(), the clock the retry sleep already uses, matching the other deadline loops in the repository. The deadline is a process-local closure value, so no dual-clock contract is needed. The retention test that drove the old deadline with a synthetic Date.now() jump now advances performance.now() instead.
|
🦞👀 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 changesMeasure the media completion handoff budget with the monotonic clock and update affected deadline tests. Example: The wall clock advances 180 seconds while generated-image completion encounters a temporary storage refusal.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current-main mixed-clock deadline bug with a minimal production change; both prior review findings are resolved and no actionable defects remain. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherBackground image, music, and video generation pass completed results to the completion lifecycle, which retries unconfirmed handoffs and observes accepted queue work until delivery settles. flowchart TD
A[Media generation] --> B[Completion scheduler]
B --> C[Monotonic handoff budget]
C --> D[Completion wake]
D --> E[Durable delivery queue]
E --> F[Original requester]
C --> G[Blocked result retention]
Technical reviewBest possible solution: Keep the two monotonic clock substitutions and the updated regression fixtures at their existing owners. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the mixed-clock failure, supported by the supplied before/after built-Gateway comparison; no target code was executed during this read-only review. Is this the best way to solve the issue? Using performance.now for both deadline calculations restores the existing elapsed-time contract without adding another timer, state owner, or compatibility path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c147613091ca. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests +35. Total +35 across 4 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 (2 earlier review cycles)
Reviewed October 27, 2026, 7:10 AM ET / 11:10 UTC (Revision 3). |
Built Gateway media-completion handoff proofCompared main The shipped Gateway RPC path creates a session and invokes
Both main runs log A queued-owner control confirmed that a refusal after durable queue admission does not falsely expire either version, consistent with the existing exemption. The remaining Gateway fixture now advances its mocked monotonic clock when deliberately exhausting the deadline, keeping all blocked-retention assertions. Focused Linux checks passed: Gateway consumer 15/15, retention 20/20, shared lifecycle 29/29 (64 total). The former exhaustion timeout completed in 736 ms; queued-delivery cases passed too. Changed-file Oxfmt check passed. This proof covers forward-clock correction through the built image-generation path; the contributor's regression matrix retains backward/zero/forward clock coverage. No broader native-channel claim is made. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in 308ce18. Thanks @SunnyShu0925. Media completion handoff now ignores wall-clock jumps. |
|
@obviyus Thanks! |
…clock (openclaw#185704) fix(media): measure the completion handoff deadline on the monotonic clock The media generation completion handoff measured its retry deadline with the wall clock, so a forward clock step made it give up almost at once and the generated image was never delivered. The deadline now uses monotonic time. Evidence: shipped image_generate through a built Gateway producing a real PNG, with completion queue and transcript writes refused at first and Date.now stepped forward 180 seconds inside the process only. On main the handoff expired 64 ms and 19 ms after the first refusal and no image was delivered (twice); with this change the retries recovered and one image was delivered about 7 seconds after generation (twice), matching the no-step runs on both refs. Details: openclaw#185704 (comment). Production +2/-2. Thanks @SunnyShu0925. Co-authored-by: SunnyShu <0668000539@local> Co-authored-by: Ayaan Zaidi <[email protected]>
…clock (#185704) fix(media): measure the completion handoff deadline on the monotonic clock The media generation completion handoff measured its retry deadline with the wall clock, so a forward clock step made it give up almost at once and the generated image was never delivered. The deadline now uses monotonic time. Evidence: shipped image_generate through a built Gateway producing a real PNG, with completion queue and transcript writes refused at first and Date.now stepped forward 180 seconds inside the process only. On main the handoff expired 64 ms and 19 ms after the first refusal and no image was delivered (twice); with this change the retries recovered and one image was delivered about 7 seconds after generation (twice), matching the no-step runs on both refs. Details: #185704 (comment). Production +2/-2. Thanks @SunnyShu0925. Co-authored-by: SunnyShu <0668000539@local> Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 308ce18) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 9cd8dd324952857419dc9773ceccb55b96f53509)
…clock (#185704) fix(media): measure the completion handoff deadline on the monotonic clock The media generation completion handoff measured its retry deadline with the wall clock, so a forward clock step made it give up almost at once and the generated image was never delivered. The deadline now uses monotonic time. Evidence: shipped image_generate through a built Gateway producing a real PNG, with completion queue and transcript writes refused at first and Date.now stepped forward 180 seconds inside the process only. On main the handoff expired 64 ms and 19 ms after the first refusal and no image was delivered (twice); with this change the retries recovered and one image was delivered about 7 seconds after generation (twice), matching the no-step runs on both refs. Details: #185704 (comment). Production +2/-2. Thanks @SunnyShu0925. Co-authored-by: SunnyShu <0668000539@local> Co-authored-by: Ayaan Zaidi <[email protected]> Beta.5 baseline adaptation: Retain the native beta.5 owners, fixtures and public contracts; add focused regression controls and bounded fixture extraction; apply checkout formatting. (cherry picked from commit 308ce18) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 208c310ba770240a22835251fb2edb597d403f33)
What Problem This Solves
A cron-triggered image generation finishes, the cron continuation is not ready yet, and the handoff keeps retrying against a 120 second budget that is measured on the wall clock while the wait between retries runs on the monotonic timer. When the host clock is corrected mid-handoff, the budget moves: a backward correction leaves the handoff retrying past 120s, a forward correction fails a healthy handoff with
media completion did not settle before the handoff deadlineand the finished media is retained as blocked.wakeMediaGenerationTaskCompletionWithRetryseeds the deadline withDate.now()and computesremainingMsfromDate.now(), whilesleepWithAbortwaits on a libuv monotonic timer, so the two clocks disagree after any wall-clock correction.performance.now(), the clock the retry wait already uses.src/agents/tools/media-generate-background-shared.ts(deadline seed and remaining calculation), its focused test (the deadline test now covers clock rollback, no jump, and clock jump forward), and the consumer test insrc/agents/tools/media-generate-background-retention.test.tsthat used to drive the old deadline with a syntheticDate.now()jump.queueOwnsCompletionrule (once the queue owns delivery the deadline no longer bounds observation), the error text, and the wall-clock fields that report task timestamps.Why This Change Was Made
Both sides of the handoff budget now read the monotonic clock, which is the only clock the retry wait obeys. This matches the deadline loops already shipped in this repository, such as
src/agents/tools/agents-wait-tool.ts, which seeds withperformance.now() + timeoutMs, compares withperformance.now() >= deadline, and sleepsMath.max(0, deadline - performance.now()).The deadline is a local closure value: it is never serialized, persisted, or read from another process, so there is no dual-clock contract to preserve and no reason to keep a wall-clock copy.
sleepWithAbortalready floors and clamps the delay insideresolveSleepDelayMs, so the fractionalperformance.now()value needs noMath.floorat the call site.User Impact
Evidence
Before/after comparison, same scenarios, only the deadline clock source changed (
Date.now()→performance.now()):Date.now()deadline)performance.now()deadline)retains references in the live requester(6 variants)currentvariant never settles (hits the 90s test timeout)currenttakes 35.8s (~39s on the base revision)Fixed code, real process (
node --import tsx/esm) directly calling the exportedscheduleMediaGenerationTaskCompletionwith a real lifecycle and real monotonic timers, with a wall-clock jump injected 300ms after the handoff started:Clock rollback on real elapsed time (130s window, -130s jump). Before the fix the handoff is still retrying 10s past its 120s budget; after the fix it settles on the 120s monotonic mark:
Pre-fix output, test kept and source reverted,
2 failed | 1 passed:Post-fix,
3 passed; full file29 passed(27 before the change, because the single deadline test became three parameterized cases).Consumer test
src/agents/tools/media-generate-background-retention.test.ts,retains references in the live requester(6 variants):6 passedwith the fix, while the same updated test on the base revision does not settle at all and hits the 90s test timeout.Open PR collision check: scanned the full changed-file list of the 358 open PRs created since
media-generate-background-shared.tsexists, plus the newest 500 open PRs of any age; no open PR touchesmedia-generate-background-shared.tsor its test. The only open PR touching media generation files, #184640, changesmedia-generate-background-completion.tsandmedia-generate-background-retention.test.tsfor a different symptom (showing retained images after a blocked delivery) and does not modify the handoff deadline.What was not tested: no real host NTP correction was performed; the wall-clock jump is injected at process level while the monotonic clock and the timers are real. The cron continuation is held
pendingby the harness rather than by a genuinely stalled cron run. The 120s end state was observed for 130s, not across a full generation lifecycle on a clock-corrected host.Additional shipped Gateway Evidence
#185704 (comment)
Built Gateway image generation, main twice/candidate twice, plus no-step controls: with a +180s process-local wall-clock step during transient unconfirmed storage refusal, main falsely expires after 19–64ms and delivers no image. Candidate retries and delivers one image in both runs, matching the controls. No system clock change or real credentials.
The remaining Gateway exhaustion fixture now advances the monotonic clock. Focused Linux validation: 64/64 tests passed; the previous timeout case passed in 736ms, with queued-delivery cases passing. Oxfmt passed. Production delta against merge base: +2/-2 (net 0); tests +58/-23 (net +35), including +14 lines of consumer clock cutover. Simplification pass retained the two substitutions at the existing deadline owner and distinct clock/retention/consumer regressions; no new runtime abstraction or state.
The subsequent exact-head review identified the queued deadline control as another Date-only fixture. It now crosses the mocked monotonic deadline while preserving queue custody assertions. Gateway consumer rerun: 15/15 passed (including all three queued outcomes), with Oxfmt passing. No production behavior changed after the built-Gateway proof.