Repository navigation
fix(agents): keep sandbox CDP probe deadline on the monotonic clock - #185574
SunnyShu0925 wants to merge 1 commit into
Conversation
|
🦞👀 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: stale review; fresh review needed. Summary Next step Review history (2 earlier review cycles)
|
4b8b9b3 to
e2a4c35
Compare
|
@clawsweeper re-review. |
|
🦞👀 Re-review progress:
|
e2a4c35 to
5ab1678
Compare
waitForSandboxCdp seeded its startup deadline and remaining-time checks with Date.now() (wall clock) while the abort and poll timers consumed those values through libuv monotonic timers. A wall-clock step-back made the while loop's Date.now() < deadline guard unreachable, so the probe spinned until the container teardown path; a step-forward prematurely aborted healthy requests. Seed and read the deadline with performance.now() so every consumer shares one monotonic domain.
5ab1678 to
902938f
Compare
|
Closing this PR as superseded by #186556. Main merged #186556 (2026-10-28), which rewrote Confirmed on current main ( |
What Problem This Solves
Starting a sandbox browser can hang past its configured startup deadline, or fail early on a healthy browser.
waitForSandboxCdpseeded itsdeadlineand read its remaining-time checks fromDate.now()(wall clock), while the fetch-abort timer and the pollsleepconsumed those values through libuv monotonic timers. When the wall clock steps back (NTP correction, manual time change), thewhile (Date.now() < deadline)guard can never become true, so the probe spins until the hung container is force-removed; when the wall clock steps forward, a healthy request is aborted early and the browser startup is reported as timed out.performance.now(), so the guard, the abort timer, and the poll sleep share one monotonic domain.src/agents/sandbox/browser.ts—waitForSandboxCdpnow usesperformance.now()for the deadline, the loop guard, and the two remaining-time reads. The helper stays private; the regression drives it through the real browser-startup path (onEnsureAttachTarget) against a realnode:httppeer. The existing "stalled CDP request" test's fake-timer config also fakesperformance, soadvanceTimersByTimeAsyncmoves the deadline on the same clock.createdAtMs/lastUsedAtMstimestamps stay wall-clock on purpose;ensureSandboxBrowserand the container lifecycle are untouched.Why This Change Was Made
The deadline is a purely process-local budget: it is not serialized, persisted, or compared across processes by any
Date.now()consumer, so switching to the monotonic clock is the correct, minimal fix (the same pattern already merged for the wall-clock family, e.g. #169908, #155863). Keeping the helper private avoids a test-only production seam: the existing lifecycle fixture already invokes the probe throughonEnsureAttachTarget, so the regression extends that path instead of importing the helper.performance.now()exists on Node 16+, andsetTimeout/sleepaccept the float it returns.User Impact
Sandbox browser startup now honors its configured timeout regardless of wall-clock adjustments: a step-back no longer makes the CDP probe spin past the deadline, and a step-forward no longer aborts a healthy probe early. Users see either a timely "browser not reachable" failure or a successful attach, instead of a hung startup or a false timeout.
Evidence
Shipped entry point, real Docker sandbox, real clock step.
openclaw gateway(this checkout, isolatedOPENCLAW_STATE_DIR) plus the shippedopenclaw agent --agent main -m "hi"turn, withsandbox.mode: "all",backend: "docker", and browserautoStartTimeoutMs: 8000. The scripted model requests thebrowsertool (open about:blank); the browser plugin attaches to the sandbox bridge, and the bridge'sonEnsureAttachTargetcallswaitForSandboxCdpagainst the container's mapped CDP port. The image is the contract-labelled sandbox-browser image (org.openclaw.sandbox-browser.contract=2026-05-12-cdp-relay-auth).The container's CDP peer answers
500and logs every request with aCLOCK_MONOTONICtimestamp — that is the peer the probe really polls (each probe request carries the sandboxAuthorizationheader; the plugin's reachability check does not). While the probe waits, the hostCLOCK_REALTIMEis stepped withsudo date -sby ±60 s, a real NTP-style jump;CLOCK_MONOTONIC/performance.now()is untouched. The step is applied on the first authenticated probe request, i.e. after the budget was seeded on the pre-step clock. The peer is a stub rather than Chromium because this environment has no outbound network to build a real browser image; the probe transport, container lifecycle, and clock are real.Raw container log (first authenticated probe request → last), base −60 s vs this PR −60 s:
Every run ends in the same production failure —
Sandbox browser CDP did not become reachable on 127.0.0.1:<port> within 8000ms. The hung container has been forcefully removed.— the difference is only when it appears. In the base −60 s run the client surfaced a bridge-level error first while the container log shows the probe still waiting 68.6 s: the probe outlived the request.Regression tests (RED on the base commit, GREEN with the fix).
The negative row asserts the deadline still expires after a step-back (no budget stretch); the positive row asserts attach still happens when the browser turns healthy inside the monotonic budget (no premature abort). The sign of the delta is preserved, so the two rows no longer exercise the same rewind.
oxfmt --checkandoxlintare clean; the diff has no config, persistence, or new public surface.