Skip to content

fix(ui): keep gateway retry backoff on the monotonic clock - #190098

Closed
huwei-xydt wants to merge 4 commits into
openclaw:mainfrom
huwei-xydt:fix/ui-gateway-retry-monotonic
Closed

huwei-xydt wants to merge 4 commits into
openclaw:mainfrom
huwei-xydt:fix/ui-gateway-retry-monotonic

Conversation

@huwei-xydt

@huwei-xydt huwei-xydt commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Control UI reconnect retries store their deadline with Date.now(). When the wall clock jumps forward while a retry is paused (page hidden / visibility change), resume() computes a non-positive remaining delay and fires the reconnect callback immediately instead of honoring the exponential backoff.

User Impact

After a clock correction, the UI can drop the 30s–5min reconnect backoff and hammer the Gateway with an immediate retry. Repair turns and reconnect storms keep their intended spacing across forward and backward wall-clock corrections.

Why This Change Was Made

Use the existing process-local monotonic helpers (monotonicDeadlineAfter / remainingMonotonicMs) for the retry deadline. Wall-clock display and persistence are not involved; the deadline is only used for setTimeout after pause/resume.

Smallest scope: +7/−2 production lines and regressions on the bare owner plus the production context-report path.

Evidence

Owner unit (base red / fix green)

Base (Date.now deadline) red:

FAIL |unit| src/lib/gateway-retry.test.ts > keeps the remaining backoff after a wall-clock jump during pause
AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times

Fix green (4 passed): backs off / cancel / reset / wall-clock jump during pause.

Production path diagnostic (context-report visibility + clock correction)

Drives real sessionContextReportsForGateway (the Control UI owner behind chat-context-report) — not a bare retry-owner mock.

Scenario: retryable sessions.usage UNAVAILABLE → hide (visibilitychange) → wall clock +1h (Date only; monotonic deadline unchanged) → show → assert remaining backoff still holds before the second request.

Fix (5a7bbb601a1) — green with diagnostic recording:

✓ src/lib/session-context-report.clock-jump.test.ts > keeps the production context-report retry backoff across a wall-clock jump while hidden
after fail calls=1 timers=1
after hide+jump+show calls=1 timers=1
visible+20000ms calls=1
visible+40000ms calls=2

Base (578321c3fbd Date.now deadline) — red on the same production path:

FAIL |unit| src/lib/session-context-report.clock-jump.test.ts
AssertionError: expected "vi.fn()" to be called 1 times, but got 2 times

(at visible+20000ms: wall-clock jump made remaining ≤ 0, so the second sessions.usage fired immediately on resume instead of after ~30s.)

Tests

  • ui/src/lib/gateway-retry.test.ts — owner wall-clock jump during pause.
  • ui/src/lib/session-context-report.clock-jump.test.ts — production context-report path: transient failure, visibility pause, wall-clock correction, resumed request honors remaining backoff.
  • Local: vitest run src/lib/gateway-retry.test.ts src/lib/session-context-report.test.ts src/lib/session-context-report.clock-jump.test.ts → 11/11 green on this head.

Merge Danger

Low. ui/src/lib/gateway-retry.ts has no open PR on this path. No schema, workflow, or public API change. Clock helper is already used across Control UI (src/shared/monotonic-time.ts). New test only exercises existing owners.

A wall-clock jump during pause made resume() compute a zero remaining
delay and fire the reconnect callback immediately.

Co-Authored-By: Claude Code <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 1, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 1, 2026
@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR uses monotonic deadlines to preserve Control UI retry backoff across wall-clock corrections.

Example: A context-report request fails, its 30-second retry is paused while hidden, and the wall clock advances one hour.

  • Before: Showing the page schedules the retry immediately.
  • After: Showing the page preserves the remaining monotonic backoff.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch appears correct and the earlier fixture finding is addressed, but mocked diagnostics do not satisfy the external-PR behavior-proof gate.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A wall-clock correction can cause a hidden context panel to retry too early or wait too long after becoming visible.
Reason: The change restores the existing retained-backoff contract without introducing a preference, option, public API, or persisted format.

Regression provenance

Regression provenance — verified: source commit ff63be54cf44 by Vyctor H. Brzezowski; canonical PR #179225 (blame-to-merge-commit).

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR addresses a current retry-timing defect with a focused change to the shared owner; no introduced correctness defect remains identified.

Priority: P2
Reviewed head: 5a7bbb601a184e42225e59fedde85a1be6fb9626

Before merge

  • Add real behavior proof - The context-report owner is exercised in jsdom with fake timers and a replaced client request method, so its diagnostic output does not establish recovery through the shipped UI or real transport; attach the scenario named in missingE2e as redacted logs, terminal diagnostics, or a recording, removing IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: Supply browser diagnostics or a real-transport request trace showing transient failure, hiding, a wall-clock correction, showing, and the correctly delayed retry.
Agent review details

How this fits together

Control UI read owners schedule callbacks through the shared Gateway retry owner, which converts a pending deadline into a browser timer when resumed.

flowchart LR
A[Context report request] --> B[Transient failure]
B --> C[Shared retry owner]
D[Page visibility] --> C
E[Monotonic clock] --> C
C --> F[Browser timer]
F --> A
Loading

Technical review

Best possible solution:

Keep the existing retry owner and use the shared monotonic helpers for its process-local deadline.

Do we have a high-confidence way to reproduce the issue?

Current-main source directly shows that advancing Date.now beyond a retained deadline makes resume schedule a zero-delay retry; the contributor also reports a matching base failure, but this read-only review ran no target code.

Is this the best way to solve the issue?

The production change is the smallest complete repair: deadline creation and subtraction share the existing monotonic clock without adding state owners or changing retry policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7e8ba3d34d10.

Provenance checked

  • Shared Gateway retry ownership keeps the original intent (7bae247: Consolidate reconnect-safe retries under one owner while rejecting stale connection work.)
  • Retained retry deadlines and visibility pause/resume keeps the original intent (ff63be5: Preserve pending context-report backoff and server retry hints while hidden views pause timers.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vyctor H. Brzezowski: Raw commit ff63be5 adds ui/src/lib/gateway-retry.ts:29 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ff63be54cf44; files: ui/src/lib/gateway-retry.ts)

PR surface

Source +5, Tests +91. Total +96 across 3 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 7 2 +5
Tests 2 91 0 +91
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 98 2 +96

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Clock corrections can shorten or prolong paused context-report retries, with limited scope and no demonstrated outage.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach the requested browser or real-transport retry recovery evidence.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-01T05:44:26.247Z sha 3554bbf :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-01T06:26:19.489Z sha 385f187 :: needs real behavior proof before merge. :: [P2] Authorize the context-report fixture before scheduling its retry

Reviewed November 1, 2026, 1:39 AM ET / 06:39 UTC (Revision 3).

ClawSweeper asked for context-report visibility + wall-clock evidence
beyond the bare retry-owner unit. Drive sessionContextReportsForGateway
through a retryable sessions.usage failure, hide, jump Date by one hour,
show, and assert the 30s backoff still holds.

Co-Authored-By: Claude Code <[email protected]>
@huwei-xydt

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Added the requested context-report visibility + wall-clock production-path evidence on head 385f187d7f5:

  • New regression ui/src/lib/session-context-report.clock-jump.test.ts drives real sessionContextReportsForGateway (transient sessions.usage UNAVAILABLE → hide → Date +1h → show).
  • Diagnostic recording in the PR body: fix keeps calls=1 at visible+20s then calls=2 at visible+40s; base Date.now deadline is red on the same production path (second request fires immediately after resume).

@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@huwei-xydt

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

PR body Evidence now includes the production-path diagnostic for head 385f187d7f5 (context-report visibility + wall-clock jump):

  • fix: after hide → Date +1h → show, sessions.usage stays at 1 request through visible+20s and only retries near the remaining ~30s backoff
  • base Date.now deadline: same production path is red (second request fires immediately after resume)

Regression committed: ui/src/lib/session-context-report.clock-jump.test.ts drives real sessionContextReportsForGateway.

@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 1, 2026
Match the existing visibility/backoff test harness (full fake timers,
watch presented before refresh). Partial Date-only fake timers left a
checks-ui shard with request count 0 after refresh.

Co-Authored-By: Claude Code <[email protected]>
@huwei-xydt

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Head 5a7bbb601a1 stabilizes the production-path regression for CI (same harness as the existing context-report visibility/backoff test). PR body Evidence has the context-report visibility + wall-clock production-path diagnostic: fix keeps the retry at 1 request through visible+20s; base Date.now is red on the same path (immediate second request after resume).

@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 1, 2026
obviyus added a commit that referenced this pull request Nov 2, 2026
…ions (#190894)

fix: measure durations, timeouts and cache ages with the monotonic clock

Several timeouts, cache TTLs and retry backoffs measured elapsed time with the wall clock. When the system clock jumped (NTP correction, sleep and resume, manual change), they fired too early, never fired, or ignored server backoff. These callers now use the monotonic clock (`src/shared/monotonic-time.ts` in core, `performance.now()` in extensions). Stored and displayed timestamps stay on the wall clock, and SDK signatures and public epochs are unchanged.

This sweep includes #190846, #190852, #190853, #187703, #187689, #187782, #187765, #189161, #189160 and #190098, with the contributors' commits kept for credit.

Evidence: built Gateway, CLI and real Chromium, main twice and candidate twice, stepping only the process wall clock (`Date.now`); no system clock change. On main, a Discord deployment timeout aborted or overran after a 60-second step, the Chromium context popover retried after about 100 ms despite server backoff, and the `sessions.usage`, Pi session catalog and GitHub project caches refreshed too early or too late. With this change, each followed real elapsed time. Ordinary controls passed, and epoch timestamps were unchanged. Details: #190894 (comment).

Thanks @Alix-007, @chengzhichao-xydt, @huwei-xydt.

Co-authored-by: Alix-007 <[email protected]>
Co-authored-by: chengzhichao-xydt <[email protected]>
Co-authored-by: Claude Code <[email protected]>
Co-authored-by: 胡伟0668000622 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Thank you! Your fix is included in #190894, landed in fca1c6e with your commit kept for credit.

@obviyus obviyus closed this Nov 2, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
…ions (openclaw#190894)

fix: measure durations, timeouts and cache ages with the monotonic clock

Several timeouts, cache TTLs and retry backoffs measured elapsed time with the wall clock. When the system clock jumped (NTP correction, sleep and resume, manual change), they fired too early, never fired, or ignored server backoff. These callers now use the monotonic clock (`src/shared/monotonic-time.ts` in core, `performance.now()` in extensions). Stored and displayed timestamps stay on the wall clock, and SDK signatures and public epochs are unchanged.

This sweep includes openclaw#190846, openclaw#190852, openclaw#190853, openclaw#187703, openclaw#187689, openclaw#187782, openclaw#187765, openclaw#189161, openclaw#189160 and openclaw#190098, with the contributors' commits kept for credit.

Evidence: built Gateway, CLI and real Chromium, main twice and candidate twice, stepping only the process wall clock (`Date.now`); no system clock change. On main, a Discord deployment timeout aborted or overran after a 60-second step, the Chromium context popover retried after about 100 ms despite server backoff, and the `sessions.usage`, Pi session catalog and GitHub project caches refreshed too early or too late. With this change, each followed real elapsed time. Ordinary controls passed, and epoch timestamps were unchanged. Details: openclaw#190894 (comment).

Thanks @Alix-007, @chengzhichao-xydt, @huwei-xydt.

Co-authored-by: Alix-007 <[email protected]>
Co-authored-by: chengzhichao-xydt <[email protected]>
Co-authored-by: Claude Code <[email protected]>
Co-authored-by: 胡伟0668000622 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants