Repository navigation
fix(cli): leave CPU wait out of the viewer bridge readiness budget - #309
Merged
Merged
Conversation
Under 16 busy loops on 2 pinned CPUs, the viewer bridge reported ready after up to 8.0 s, so the fixed 8 s bound sometimes expired. Timing probes showed that about 93% of the wait is the bridge loading the CLI before its own code runs: about 0.4 s of CPU on an idle host. /proc/<pid>/schedstat showed that 85% to 87% of the loaded wall time was run-queue wait; the bridge's own time stayed under 1 s. The bridge already reports readiness through bridge.json, so the parent keeps that signal. The 8 s budget now counts only time the bridge was not waiting for a CPU. A hung bridge still fails within 8 s on an idle host, and a bridge that exits still fails at once. A wall cap of 8 times the budget ends a bridge that never gets a CPU. The timeout error now says how long it waited, how much of that was CPU wait, and where the bridge log is. With the budget cut to 2 s as an experiment, the viewer mode test passed 3 of 3 runs under the same load, while the wall waits were 3 s to 8 s. The viewer mode test runs seven CLI calls and two bridge starts, so its timeout now counts nine spawns (90 s). Under load it took 32 s to 49 s. Closes #301
…orts The CLI lifecycle test starts an emulator without --port and expected emulator-5556. The read-only shared start in emulator.test.ts also had no port range, so it probed 5556 too. When both probes ran at once, or a real emulator held 5556, the allocator moved to 5558 and the CLI test failed. The shared start now uses the emulator test's private port window. The CLI lifecycle tests hold a host-wide "auto-floor" test port lock, so a concurrent run of the same file cannot probe the floor at the same time. The CLI test still proves allocation from the 5556 floor: it expects the first free console port pair from the floor, which is 5556 unless a real emulator holds it. With 5556 held by another process, the old test failed with emulator-5558 and the new test passed. Two CLI lifecycle runs and an emulator.test.ts run, started together 8 times, passed 24 of 24. Closes #306
…ge startup Viewer bridge startup holds the session VNC lock until the bridge reports ready. Since #301 that can take up to 64 s on a busy host, but other callers of the lock gave up after 10 s. A concurrent viewer start, session destroy or takeover could fail while a permitted startup was still running. The lock wait for a live holder is now 90 s. A dead holder is still detected by its pid and replaced at once, so stale-lock recovery is unchanged. The bridge wall cap is now also bounded by the lock wait minus a 20 s margin for the probe, the old bridge stop and the cleanup, so the two bounds cannot drift apart. At the defaults the cap stays 64 s. Releasing the lock during the readiness wait is not safe. The bridge is not recorded yet, so a concurrent start would launch a second bridge and rotate its token, and a destroy would not see the bridge to stop it. A new test holds a startup for 11 s and checks that a concurrent lock caller waits for it and sees the recorded bridge. Before this change it failed at 10.1 s with "Timed out waiting to ensure VNC".
The CLI desktop+android failure test, the MCP android_start tests and the security session_create android test start an emulator without a port, so they probe from the 5556 floor. They did not hold the "auto-floor" test port lock, so they could still take the floor while the CLI lifecycle tests expected it. Each of them now holds the lock in its describe. The CLI test gets its own nested describe so the rest of the desktop tests do not wait. With the lock held by another process for 20 s, the three tests finished at 4 s to 8 s before this change. After it they waited and finished at 23 s to 25 s. Without a holder they take 1 s to 4 s. Closes #308
The 90 s wait for a live session VNC lock holder outlasts the MCP client's 60 s request deadline. A cancelled session_destroy kept waiting and tore the session down after the lock was released. withSessionVncLock now takes an optional AbortSignal. It stops waiting when aborted and checks the signal again after it gets the lock, before the operation runs. Desktop and browser teardown pass it through, and MCP session_destroy passes the request signal. CLI callers are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The viewer bridge readiness bound no longer fails on a busy host, and the tests that auto-allocate emulator ports stop taking each other's ports.
#301: the bridge already reports readiness by writing
bridge.json. Under load, 85 to 87% of its startup time was spent waiting for a CPU, mostly while node loaded the CLI bundle. Its own CPU time stayed under 1 s. The 8 s readiness budget now counts elapsed time minus the bridge's CPU wait, read from/proc/<pid>/schedstat, with a wall-time cap of 64 s. A hung bridge still fails within 8 s on an idle host, and a bridge that exits still fails at once. The error now says how long the bridge waited, how much of it was CPU wait, and where its log is. Whereschedstatis missing, the budget falls back to wall time as before. The viewer mode test timeout went from 70 s to 90 s, because it starts nine processes. Bridge startup holds the session VNC lock, so a live holder is now waited on for up to 90 s instead of 10 s, and the bridge cap is tied to that bound. MCPsession_destroypasses the request's cancellation signal into the lock wait and into each session's teardown, so a cancelled request destroys nothing that had not started.#306: the read-only shared start in
emulator.test.tsnow passes the test port range. The CLI Android lifecycle tests hold a host-wideauto-floortest port lock, and still prove allocation from the 5556 floor. Every other test that allocates from 5556 holds the same lock: the CLI desktop-plus-Android failure test, the MCPandroid_starttest (#308), and the security no-sudo test.Closes #301
Closes #306
Closes #308
schedstat~/Artifacts/pickforge-batch4-2026-10-08/worker-Y-report.mdviewer-bridge.test.ts, worker reportemulator-5558); fixed passedemulator.test.tsrun at once, 8 roundsviewer-bridge.test.tssession-destroy-cancel.test.ts,viewer-state.test.ts~/Artifacts/pickforge-batch4-2026-10-08/Y-cov-r4.logQA device pass: skipped. The user-facing change is a timeout and an error message that only appear under heavy load. Driving the real viewer would open a browser on the live desktop, and the commands test already runs the real bridge with a fake browser.