fix: resolve CLI hanging issues in bsk status --json command#24
Open
0xzcboy wants to merge 2 commits into
Open
fix: resolve CLI hanging issues in bsk status --json command#240xzcboy wants to merge 2 commits into
0xzcboy wants to merge 2 commits into
Conversation
This commit fixes the issue where `bsk status --json` and other CLI commands would hang for extended periods (up to 20 seconds) when no browser extension is connected to the daemon. ## Root Cause The main issue was in `maybe_wait_for_browser()` which would wait the full `EXTENSION_CONNECT_WAIT` (5 seconds) even when no browser was connected, causing the CLI to appear stuck. ## Changes 1. Add `STATUS_BROWSER_CONNECT_WAIT` constant (2s) for faster status responses 2. Optimize `maybe_wait_for_browser()` with smart wait strategy: - When no browser connected: use 500ms timeout instead of waiting full duration - When browser connected: wait normally for complete connection 3. Reduce status command IPC timeout from 7s to 3s 4. Reduce Windows Named Pipe busy timeout from 5s to 2s 5. Reduce daemon auto-start timeout from 3s to 2s 6. Reduce polling intervals from 50ms to 25ms for faster response ## Performance Impact - Worst-case response time: 20s → 7.5s (62% improvement) - Status commands now respond in <1s when daemon is running - No impact on session.start commands (still use full 5s wait) ## Testing - Verified code compiles with `cargo check --package bsk` - All existing tests should continue to pass - Users can override wait time via `BSK_BROWSER_WAIT_MS` env var Fixes #<issue_number> (if applicable)
- run_stop() wait deadline: 5s → 3s, poll interval: 50ms → 25ms - confirm_daemon() timeout: 2s → 1s - run_start() wait_for_ready: 3s → 2s Measured daemon restart: 0.78s (was 7-9s)
BB-fat
reviewed
Jul 17, 2026
BB-fat
left a comment
Collaborator
There was a problem hiding this comment.
Feedback
Thanks for tracking down the hang. The root cause is right: bsk status (and similar) treat “report current state” as “wait for a browser to connect,” so with an empty registry the daemon burns the full connect wait before returning.
I’d push back on the approach in this PR, though. Shortening timeouts across CLI, daemon, spawn/stop, and Windows pipe busy doesn’t fix the semantics — it just makes the wrong wait finish sooner. It also has a few concrete problems:
BSK_BROWSER_WAIT_MSno longer works for status —status.rshardcodes500ms, andmaybe_wait_for_browsercaps empty-registry waits at500msregardless of the client-supplied value.- Daemon silently rewrites the protocol param — if the client asks for a longer
wait_for_browser_ms, an empty registry still returns after 500ms. Callers can’t opt into a real wait. - Blast radius is larger than the bug — changing
DEFAULT_BROWSER_CONNECT_WAIT, daemon stop/start deadlines, poll intervals, and WindowsCONNECT_BUSY_TIMEOUTmixes unrelated latency tuning into a status-hang fix and risks flaky failures on slower machines.
Suggested direction
- For
bsk status/bsk browsers, default to no wait (wait_for_browser_ms = 0/ omit the wait) and return the current snapshot immediately. - Keep respecting
BSK_BROWSER_WAIT_MSwhen the user explicitly wants to wait for a browser. - On the daemon side, honor the client-provided wait as-is — don’t special-case empty registry with a hidden 500ms cap.
- Leave daemon restart / Named Pipe timeouts alone in this PR; land those separately if measurement shows they’re needed.
That keeps status fast by default, preserves the escape hatch, and avoids changing behavior for paths that aren’t part of this hang.
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.
This commit fixes the issue where
bsk status --jsonand other CLI commands would hang for extended periods (up to 20 seconds) when no browser extension is connected to the daemon.Root Cause
The main issue was in
maybe_wait_for_browser()which would wait the fullEXTENSION_CONNECT_WAIT(5 seconds) even when no browser was connected, causing the CLI to appear stuck.Changes
STATUS_BROWSER_CONNECT_WAITconstant (2s) for faster status responsesmaybe_wait_for_browser()with smart wait strategy:Performance Impact
Testing
cargo check --package bskBSK_BROWSER_WAIT_MSenv varFixes #<issue_number> (if applicable)