Repository navigation
Conversation
The embedded run failover controller measured the 15s shared-organization TPM retry window with Date.now() (wall clock). When the wall clock jumps inside the window, the elapsed budget is distorted and a still-valid retry is rejected with retry_delay_unavailable, pushing the request to model fallback. Seed and read the window on performance.now() so a pure difference of two monotonic reads is immune to wall-clock drift. The provider-rate-limit comparisons against the now-monotonic retryDeadline switch to performance.now() to stay on the same clock. The watchdog-facing onRetryWait deadline is left on the wall clock because its consumer (session-controller.watchdog) compares on the wall clock. Adds a regression test that seeds the window, jumps the wall clock +60s, and asserts a second shared-TPM retry is still admitted.
|
🦞👀 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. |
e648bf0 to
f134dcb
Compare
|
Codex review: needs maintainer review before merge. What this changesThis PR measures retry budgets and shared provider admission with monotonic time while preserving epoch timestamps for status consumers. Example: A Gateway receives two TPM-limit HTTP 429 responses with two-second retry floors while Date.now advances by 90 seconds.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes a current clock-domain bug, resolves both earlier findings, and introduces no actionable defect found in this review. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe embedded retry controller supplies a deadline to the shared provider queue, which admits physical transport requests and exposes epoch-valued waiting and saturation status. flowchart TD
A[Gateway turn] --> B[Retry controller]
B --> C[Shared provider queue]
C --> D[HTTP transport]
D --> E[Provider response]
E --> B
C --> F[Epoch status consumers]
Technical reviewBest possible solution: Keep elapsed-time arithmetic in the existing monotonic retry and admission owners, converting to epoch time only at established status boundaries. Do we have a high-confidence way to reproduce the issue? The supplied built Gateway comparison reproduces premature fallback on the pinned main implementation using a process-local 90-second wall-clock step; current source confirms the same responsible arithmetic. Is this the best way to solve the issue? The patch repairs both deadline production and queue consumption at their existing owners, preserves external timestamp semantics, and adapts affected consumers without adding a parallel retry mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f76e79be6a8f. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +17, Tests -2. Total +15 across 6 files. Added test files: 0. View PR surface stats
Review metrics
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 (1 earlier review cycle)
Reviewed October 27, 2026, 10:16 PM ET / October 28, 2026, 02:16 UTC (Revision 2). |
# Conflicts: # src/agents/embedded-agent-runner/run/failover-retry-controller.test.ts
Built Gateway shared-TPM clock-step proofBaseline current main: Both refs were built in secretless Linux/Node 24.22.1 isolation. Real Gateway session RPCs run the OpenClaw harness against a recording local HTTP/SSE provider. Primary requests receive real HTTP 429 responses identifying organization TPM exhaustion and a two-second Retry-After floor; the third primary request succeeds. A configured fallback returns a distinct completion marker. A preload advances only the Gateway process's Date.now by 90 seconds when its first real host retry backoff completes. The host/VM clock is never changed, and no retry/admission callback is mocked.
Main prematurely abandons the recoverable primary after about two seconds of real backoff. The candidate reaches the third physical primary request 4.438 s and 4.411 s after the first request, inside the existing fifteen-second window. Its measured retry gaps are 2.159/2.279 s and 2.155/2.256 s, respecting the provider's floor. No-step request spans are 5.187 s on main and 5.009 s on the candidate; no fallback is needed on either. The expiry fixture delays the second failed provider response for sixteen real seconds. Main and candidate then reach fallback 18.418 s and 18.582 s after the first primary request, preserving genuine elapsed exhaustion rather than replenishing the window. The built status reader also observes epoch-valued retryAt/expiresAt after the clock step, not process uptime. One candidate sample has wall time 1793152461324, uptime 17160.412 ms, retryAt 1793152463136.998 and expiresAt 1793152523136.998. The queue suite separately checks the actual onWait notification's epoch value with deliberately different epoch and uptime origins. Auxiliary recap calls are recorded separately and excluded from turn request counts. Repair and checks
All measured turns completed and returned their actual primary/fallback marker. This is deterministic local-provider proof, not a live-provider quota or billing claim. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in dafda2f. Thanks @SunnyShu0925. TPM retry windows now ignore clock jumps. |
|
@obviyus Thanks! |
…(#186390) fix(agents): keep the shared TPM retry window on the monotonic clock The shared tokens-per-minute retry window was measured with the wall clock, so a clock step during a rate-limit wait ended the window early and the turn fell back to another model after a single primary request. The provider queue now keeps its windows on monotonic time, with status still reported as wall-clock times through a private projection. Evidence: built Gateway turns hitting a TPM rate limit from a local provider fixture, with a clock step inside the process during the retry window. On main the turn fell back after one primary request (twice); with this change it recovered on the primary after three real requests over 4.4s (twice). No-step runs and genuinely expired windows behave as expected on both refs. Details: openclaw/openclaw#186390 (comment). Thanks @SunnyShu0925. Co-authored-by: SunnyShu <0668000539@local> Co-authored-by: Ayaan Zaidi <[email protected]>
…(#186390) fix(agents): keep the shared TPM retry window on the monotonic clock The shared tokens-per-minute retry window was measured with the wall clock, so a clock step during a rate-limit wait ended the window early and the turn fell back to another model after a single primary request. The provider queue now keeps its windows on monotonic time, with status still reported as wall-clock times through a private projection. Evidence: built Gateway turns hitting a TPM rate limit from a local provider fixture, with a clock step inside the process during the retry window. On main the turn fell back after one primary request (twice); with this change it recovered on the primary after three real requests over 4.4s (twice). No-step runs and genuinely expired windows behave as expected on both refs. Details: openclaw/openclaw#186390 (comment). Thanks @SunnyShu0925. Co-authored-by: SunnyShu <0668000539@local> Co-authored-by: Ayaan Zaidi <[email protected]>
…(#186390) fix(agents): keep the shared TPM retry window on the monotonic clock The shared tokens-per-minute retry window was measured with the wall clock, so a clock step during a rate-limit wait ended the window early and the turn fell back to another model after a single primary request. The provider queue now keeps its windows on monotonic time, with status still reported as wall-clock times through a private projection. Evidence: built Gateway turns hitting a TPM rate limit from a local provider fixture, with a clock step inside the process during the retry window. On main the turn fell back after one primary request (twice); with this change it recovered on the primary after three real requests over 4.4s (twice). No-step runs and genuinely expired windows behave as expected on both refs. Details: openclaw/openclaw#186390 (comment). Thanks @SunnyShu0925. Co-authored-by: SunnyShu <0668000539@local> Co-authored-by: Ayaan Zaidi <[email protected]>
The outage window has used performance.now since #186390, but this fixture only advanced Date.now. Advance the clock the retry owner consumes so the no-progress case actually exhausts its window while productive turns still recover.
…penclaw#186390) fix(agents): keep the shared TPM retry window on the monotonic clock The shared tokens-per-minute retry window was measured with the wall clock, so a clock step during a rate-limit wait ended the window early and the turn fell back to another model after a single primary request. The provider queue now keeps its windows on monotonic time, with status still reported as wall-clock times through a private projection. Evidence: built Gateway turns hitting a TPM rate limit from a local provider fixture, with a clock step inside the process during the retry window. On main the turn fell back after one primary request (twice); with this change it recovered on the primary after three real requests over 4.4s (twice). No-step runs and genuinely expired windows behave as expected on both refs. Details: openclaw#186390 (comment). Thanks @SunnyShu0925. Co-authored-by: SunnyShu <0668000539@local> Co-authored-by: Ayaan Zaidi <[email protected]>
The outage window has used performance.now since openclaw#186390, but this fixture only advanced Date.now. Advance the clock the retry owner consumes so the no-progress case actually exhausts its window while productive turns still recover.
What Problem This Solves
Wall-clock corrections can prematurely exhaust or extend the shared organization TPM retry window. The original monotonic-controller correction also left the provider queue comparing uptime-valued deadlines against epoch-valued floors, rejecting otherwise valid retries before transport.
Why This Change Was Made
SunnyShu's monotonic retry-window producer is retained, and the conversion is completed at the shared admission owner:
performance.now()consistently.onWaitand rate-limit state timestamps are projected back to epoch time at their status boundaries. Absolute HTTP-date Retry-After parsing still uses wall time. No SDK fields, names or source paths change.User Impact
An in-budget shared-TPM retry reaches the provider queue and actual transport despite a wall-clock correction. Genuine elapsed exhaustion still moves to configured fallback. Retry counts, provider floors, pacing, cancellation, model/account scope, authentication, permissions and existing fallback policy remain unchanged.
Evidence
Built Gateway proof and captured transport/status results compare current main
b3aa84d0d79e3bfe7f2ef697fec3f5bf15b634fdwith the candidate implementation, through real Gateway turns and a recording local HTTP/SSE provider. The fixture returns two primary HTTP 429 TPM responses with a two-second Retry-After floor, then succeeds. A process-local preload advances only the Gateway'sDate.now()by ninety seconds during the first real retry backoff; the system/VM clock is untouched.Candidate retries reach the third primary HTTP request 4.438 s and 4.411 s after the first request, within the existing fifteen-second budget and respecting the two-second floor. The expiry control holds the second failed provider response for sixteen real seconds; main and candidate then reach fallback after 18.418 s and 18.582 s. Built status reads remain epoch-shaped after the clock step, and the queue suite verifies actual
onWaitnotifications with distinct epoch and uptime origins. Auxiliary recap requests are excluded from turn counts.These are deterministic local-provider results, not live-provider quota or billing claims.
Merge Risk
Two-way door: reverting the code with a Gateway restart restores the former clock handling; no persisted-format, schema or configuration migration is involved. Blast radius is transient retry budgeting, shared-provider admission and its health/status consumers. A wrong conversion could delay or prematurely reject requests; public timestamp semantics and existing retry/fallback policies are preserved.