Skip to content

fix(browser): keep the node-host proxy deadline on the monotonic clock - #185753

Merged
obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/invoke-browser-proxy-deadline-monotonic-141
Oct 27, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/invoke-browser-proxy-deadline-monotonic-141

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A browser node running openclaw node run fences a healthy browser.proxy request with browser proxy timed out right after the node clock steps forward, and lets an already-expired request keep running for the length of a backward step. Each request gets a 20-second budget that runBrowserProxyCommand measured on the wall clock while setTimeout consumed it on the monotonic clock.

  • Problem: deadlineAt is seeded with Date.now() and the dispatch budget is deadlineAt - Date.now(), then handed to withTimeout, which arms a monotonic setTimeout. Any step between the seed and the read resizes the budget.
  • Solution: measure both reads on the clock that consumes them (performance.now()).
  • What changed: two reads in extensions/browser/src/node-host/invoke-browser.ts; two existing clock-sensitive tests repointed at the clock that now owns the budget; two regression tests (forward jump, rollback) during upload staging.
  • What did NOT change: the withTimeout relative-duration contract, the 20-second default, resolveBrowserProxyTimeoutMs, the timeout message and diagnostics, staging/discard behavior, and the constant-duration status-probe and staging budgets.
-  const deadlineAt = Date.now() + timeoutMs;
+  const deadlineAt = performance.now() + timeoutMs;
...
-  const remainingTimeoutMs = deadlineAt - Date.now();
+  const remainingTimeoutMs = deadlineAt - performance.now();

Why This Change Was Made

deadlineAt is process-local - created and read inside one call, never serialized or compared with another process's epoch - so monotonic time is the only correct source and no dual-clock bridge is needed. The module already seeds and reads performance.now() for its ARIA capture deadline, so this follows the local pattern.

withTimeout stays a relative-duration consumer: it is shared by every timeout in the extension. Deliberately left alone: browser-proxy-upload.ts still uses Date.now() for temp-file mtime staleness (file times are wall-clock), and withTimeout's pause/resume accounting still uses Date.now(); a dispatch that pauses in waitForBrowserStartup can reach the latter, but that is pre-existing, shared by all extension timeouts, and a named follow-up.

Risk is one behavior change: an in-flight request keeps the budget it was created with. No config, API, message, or persistence surface changes; production lines are +2/-2.

User Impact

Browser nodes no longer fail healthy proxy requests right after a clock correction, and no longer let an exhausted request keep running after a rollback. The default stays 20 seconds, the timeout still names method, path, profile and value, and a staged upload is still discarded when the deadline wins.

Evidence

Before/after on the same shipped entry point: a real Gateway plus a real browser node (openclaw node run), invoked through openclaw nodes invoke. Every request stages a real 64 KiB upload and dispatches POST /hooks/file-chooser to a live Chrome input[type=file]; the only injected part is the clock step - a proof-only preload that offsets Date.now once, right after the staged file write, never performance.now, and logs the delays withTimeout arms.

Case Pre-fix (3be098d + regressions) Post-fix (c8ea4b5)
A: +3600000 ms at the post-staging read, 5000 ms budget browser proxy timed out for POST /hooks/file-chooser after 5000ms; the step lands on the remaining-budget read (invoke-browser.ts:413) {"result":{"ok":true}}; staging arm 5000 then dispatch arm 4984 (budget intact)
B: -3600000 ms at the same read, 2000 ms budget, page change handler blocks ~3 s {"result":{"ok":true}} after the 3 s handler; dispatch arm 3601970 (about a 1 h budget) browser proxy timed out ... after 2000ms; arm delay=1982, timer-fired delay=1982
# case A, post-fix
$ openclaw nodes invoke --node <id> --command browser.proxy.upload.v1 --params @upload.json --invoke-timeout 60000
{"ok":true,"nodeId":"<id>","command":"browser.proxy.upload.v1","payloadJSON":"{\"result\":{\"ok\":true}}"}
[proof] staged-write upload-<id>/0/upload-64k.bin          browser-proxy-upload.ts:440
[proof] STEP 3600000ms after staged write                 withTimeout sdk-node-runtime.ts:36
[proof] arm delay=5000 (staging) -> arm delay=4984 (dispatch)

# case A, pre-fix
{"ok":false,"error":{"message":"INVALID_REQUEST: Error: browser proxy timed out for POST /hooks/file-chooser after 5000ms; browser action; profile=openclaw"}}
[proof] STEP 3600000ms after staged write                 runBrowserProxyCommand invoke-browser.ts:413

# case B, pre-fix
{"payloadJSON":"{\"result\":{\"ok\":true}}"}
[proof] arm delay=3601970

# case B, post-fix
{"ok":false,"error":{"message":"INVALID_REQUEST: Error: browser proxy timed out for POST /hooks/file-chooser after 2000ms; ..."}}
[proof] arm delay=1982; timer-fired delay=1982

Unit runs, base tree with the regression tests applied, then this head:

$ npx vitest run extensions/browser/src/node-host/invoke-browser.test.ts
# base + regressions
 × keeps the proxy budget when the wall clock jumps during upload staging
 × keeps the proxy budget when the wall clock rolls back during upload staging
 Tests  3 failed | 28 passed (31)
# head
 Tests  31 passed (31)

Supporting checks on this head: oxlint on both changed files reports 0 warnings and 0 errors, oxfmt --check and git diff --check are clean, and CI openclaw/ci-gate passed. Collision check: no open PR changes extensions/browser/src/node-host/ - open PRs matching browser proxy, invoke-browser and node-host were compared by changed files.

Not covered: a local tsgo typecheck (this checkout's shared node_modules guard rejects declaration inputs), which the CI check-prod-types and check-test-types jobs cover, and the Codex autoreview engine, whose provider returned HTTP 403 in this environment.

Independent runtime verification

#185753 (comment) — real built Gateway, paired node host and native Chromium: +1h staging jumps fail on main twice but upload successfully on the candidate twice; rollback cases retain the 400ms candidate budget, and no-step controls succeed. Process-local Date.now simulation and external staging-write trigger are disclosed; no system clock changes.

@clawsweeper

clawsweeper Bot commented Oct 27, 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. labels Oct 27, 2026
`runBrowserProxyCommand` seeded the request deadline with `Date.now()` and
derived the dispatch budget from the same wall-clock epoch
(`deadlineAt - Date.now()`), while `withTimeout` consumes that budget on a
monotonic `setTimeout`. A forward clock step shrank the budget to zero and
fenced a healthy proxy request as `browser proxy timed out`; a rollback
inflated it and let an expired request outlive the configured timeout.

The deadline is process-local — never serialized, persisted, or compared to a
wall-clock epoch by another process — so the monotonic clock is the only
correct source. Two reads now use `performance.now()`; no signature, config,
or timeout-text change.
@SunnyShu0925
SunnyShu0925 force-pushed the fix/invoke-browser-proxy-deadline-monotonic-141 branch from 9b98f90 to c8ea4b5 Compare October 27, 2026 10:03
@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. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR measures the browser node’s proxy deadline with performance.now() so wall-clock changes cannot resize its remaining budget.

Example: The node’s wall clock advances one hour while staging an upload with a 3000 ms proxy budget.

  • Before: The request times out prematurely and the browser file input remains empty.
  • After: The request succeeds and the browser selects proof185753.txt.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Minimal, correct repair with distinct regressions, shipped-entry-point A/B proof, and green exact-head quality gates.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Exact candidate c8ea4b5 was exercised through shipped nodes invoke, a real Gateway, a paired node-host, and native Chromium in separate secretless containers; obviyus’s linked A/B results show corrected forward-jump uploads, bounded rollback timeouts, and successful no-step controls with DOM readback. The disclosed injection changes only process-local Date.now after a real staging write.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A clock correction can fail a healthy remote browser upload immediately or allow its proxy deadline to overrun.
Reason: The patch restores the existing request-budget contract without adding options, changing defaults, or expanding public APIs.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current browser-node timeout defect with a minimal change, relevant regressions, and sufficient exact-head runtime proof; no blocking findings remain.

Priority: P2
Reviewed head: c8ea4b561c2d0afcd43d00b5addd3afbbff77b53

Before merge

None.

Findings

None.

Agent review details

How this fits together

The browser plugin receives node commands from the Gateway, stages upload bytes, dispatches browser routes with the remaining request budget, and returns a serialized result or timeout.

flowchart LR
  A[Nodes invoke CLI] --> B[Gateway]
  B --> C[Paired browser node]
  C --> D[Upload staging]
  D --> E[Monotonic remaining budget]
  E --> F[Browser route dispatcher]
  F --> G[Chromium file input]
Loading

Technical review

Best possible solution:

Merge the focused monotonic-clock repair while retaining the existing timeout owner, defaults, cancellation, and upload lifecycle.

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

Current-main source establishes the clock-domain mismatch, and supplied built-runtime A/B evidence reproduces both directions through the shipped CLI and node path; this read-only review ran no target code.

Is this the best way to solve the issue?

Replacing both process-local deadline reads is the smallest complete repair: elapsed request time must remain independent of wall-clock adjustments, and no new state or abstraction is needed.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 94d8f428691a.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source 0, Tests +48. Total +48 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 2 0
Tests 1 50 2 +48
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 52 4 +48

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Clock corrections can prematurely fail browser-node requests or inflate their timeout, with a limited browser-proxy blast radius.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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-10-27T10:22:06.872Z sha c8ea4b5 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-27T12:57:12.671Z sha c8ea4b5 :: needs maintainer review before merge. :: none

Reviewed October 27, 2026, 10:55 AM ET / 14:55 UTC (Revision 3).

@clawsweeper

clawsweeper Bot commented Oct 27, 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. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 27, 2026
@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Independent built Gateway + node-host + Chromium proof

Exact candidate c8ea4b561c2d0afcd43d00b5addd3afbbff77b53; pinned main 5e0fb6733a29ab6f20239166618a141e8f7a73ea. Both refs built successfully in separate secretless node:24.22.1 containers. Each run used the shipped Gateway, a real separately configured/paired openclaw node run process, and native headless Chromium 156.0.8078.47 serving a real file input. No product edits, pushes or helper-level proxy invocation.

The operator used shipped openclaw nodes invoke --command browser.proxy.upload.v1 through the Gateway to request POST /hooks/file-chooser, with a native upload envelope. The node performed its real upload staging, browser route dispatch and Playwright/CDP file-input operation. Independent CDP DOM readback checked the browser's actual selected file, not just the RPC response.

Clock simulation: only the task-owned node-host process has a preload wrapping Date.now(). An external filesystem-edge wrapper calls the original fs.promises.writeFile unchanged, then changes that process's Date.now offset immediately after the actual staged upload file has been written, while staging is still active. It records the triggering write and offset once per request. No staging/dispatcher/deadline function is mocked or replaced; performance.now, native timers, Gateway/Chromium clocks and the system clock remain unchanged. Offset resets after each request. This is the authorized in-process clock-step method, not a system time change or natural NTP claim.

Case Main observed result Candidate observed result
+1 hour during staging, run 1 Premature 3000 ms proxy-timeout error; input remains empty RPC success; actual input selects proof185753.txt (39 bytes)
+1 hour during staging, run 2 Same premature timeout; input remains empty Same successful native upload (39 bytes)
-1 hour during staging, run 1 Proxy budget no longer wins: missing-element action runs to its 2000 ms route failure Proxy reports its intended 400 ms timeout
-1 hour during staging, run 2 Same missing-element route failure Same 400 ms proxy timeout
No-step control RPC success; actual input selects fixture (37 bytes) Same success and actual selection

Whole-CLI elapsed times (include CLI startup, Gateway transport and status diagnostics; these are not pure proxy execution timings): forward main 973/659 ms, candidate 1432/957 ms; rollback main 3198/3080 ms, candidate 1210/1052 ms; no-step main 936 ms, candidate 926 ms. Each case has exactly one recorded staging-edge trigger; the no-step trigger applies offset zero. Native requests, error text and browser file-selection readback support the deadline distinction independently of these startup-inclusive timings.

The initial setup used an unsupported browser-profile color field, which config validation rejected before runtime. Removing that harness-only field fixed setup; neither product schema nor safety checks were changed. Browser access is limited to task-owned loopback CDP and a synthetic upload page. This proof does not claim rendered UI behavior, remote network faults or real clock synchronization events.

Current exact-head openclaw/ci-gate, dependency review and security-sensitive review are success. Failed jobs 0, cancelled 0. No new local unit-test/lint result is claimed; the independent proof is the built shipped node path above.

@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

Independent exact-head built Gateway/paired-node/native-Chromium clock-step A/B evidence is linked in the body: two forward jumps per ref, two rollback cases per ref and no-step controls. Product source head unchanged.

@clawsweeper

clawsweeper Bot commented Oct 27, 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. labels Oct 27, 2026
@obviyus
obviyus merged commit 67ad5ac into openclaw:main Oct 27, 2026
160 of 161 checks passed
@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Landed in 67ad5ac. Thanks @SunnyShu0925. Browser proxy uploads no longer fail after a clock jump.

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@obviyus Thanks!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
openclaw#185753)

fix(browser): keep the node-host proxy deadline on the monotonic clock

The browser node-host proxy deadline was measured with the wall clock, so a forward clock jump during a proxied browser upload made it fail early. The deadline now uses monotonic time.

Evidence: a built Gateway with a paired node host and native Chromium, with Date.now jumped forward one hour in the node process only during staging. On main the upload failed early (twice); with this change it succeeded, confirmed by reading the file selection back from the DOM (twice). Backward steps keep the 400 ms timeout, and runs without a step succeed on both refs. Production 4 lines.

Thanks @SunnyShu0925.

Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 28, 2026
#185753)

fix(browser): keep the node-host proxy deadline on the monotonic clock

The browser node-host proxy deadline was measured with the wall clock, so a forward clock jump during a proxied browser upload made it fail early. The deadline now uses monotonic time.

Evidence: a built Gateway with a paired node host and native Chromium, with Date.now jumped forward one hour in the node process only during staging. On main the upload failed early (twice); with this change it succeeded, confirmed by reading the file selection back from the DOM (twice). Backward steps keep the 400 ms timeout, and runs without a step succeed on both refs. Production 4 lines.

Thanks @SunnyShu0925.

Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 67ad5ac)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 8c4e2126269950ccd21cad66f8ebe3d049d6bea9)
RomneyDa added a commit that referenced this pull request Oct 28, 2026
#185753)

fix(browser): keep the node-host proxy deadline on the monotonic clock

The browser node-host proxy deadline was measured with the wall clock, so a forward clock jump during a proxied browser upload made it fail early. The deadline now uses monotonic time.

Evidence: a built Gateway with a paired node host and native Chromium, with Date.now jumped forward one hour in the node process only during staging. On main the upload failed early (twice); with this change it succeeded, confirmed by reading the file selection back from the DOM (twice). Backward steps keep the 400 ms timeout, and runs without a step succeed on both refs. Production 4 lines.

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 67ad5ac)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit a88e3d7ea90072dff2d975dfead1778c97ecfeea)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. extensions: browser P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants