Skip to content

fix(browser): treat no-op BROWSER values as unset so headless sessions can fall back - #756

Merged
backnotprop merged 1 commit into
backnotprop:mainfrom
yonihorn:fix/browser-sentinel-handling
May 19, 2026
Merged

backnotprop merged 1 commit into
backnotprop:mainfrom
yonihorn:fix/browser-sentinel-handling

Conversation

@yonihorn

@yonihorn yonihorn commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When $BROWSER (or $PLANNOTATOR_BROWSER) is set to a no-op sentinel like true, false, none, :, 0, or 1 — as Claude Code's agent view does (BROWSER=true) — openBrowser() shells out via Bun.$ and runs something equivalent to true http://localhost:NNNN. true(1) exits 0 without doing anything, the function returns success, and the server then sits in waitForDecision() forever. No browser appears, the URL isn't recoverable, and the session looks hung.

This is the BROWSER-sentinel branch of the same family as #163 (which fixed BROWSER=open / VS Code devcontainer scripts). The remaining sentinel case still affects every headless / background runner that conventionally sets BROWSER=true to disable browser launching.

Fix

packages/server/browser.ts:

  • Add isNoOpBrowserSentinel() recognising the documented no-op values (case- and whitespace-insensitive).
  • In openBrowser(), treat a sentinel-valued PLANNOTATOR_BROWSER / BROWSER as if the variable were unset, so we fall through to the platform default (open / xdg-open / cmd.exe /c start) instead of shelling out to the sentinel.
  • In shouldTryRemoteBrowserFallback(), treat the same sentinels as "no real handler configured" so the VS Code IPC fallback still fires in remote sessions where it would otherwise be skipped.

Net behaviour:

Env Before After
BROWSER=true (agent view) runs true http://... → no-op IPC fallback → platform default
BROWSER=/usr/bin/firefox spawns firefox spawns firefox (unchanged)
PLANNOTATOR_BROWSER='Google Chrome' (macOS) open -a chrome open -a chrome (unchanged)
unset platform default platform default (unchanged)

No protocol or stdout changes, no new dependencies, no surface-area additions.

Tests

Adds packages/server/browser.test.ts coverage:

  • shouldTryRemoteBrowserFallback now returns true when BROWSER / PLANNOTATOR_BROWSER are sentinels.
  • isNoOpBrowserSentinel recognises the documented values (incl. TRUE, none ) and rejects real handlers (/usr/bin/firefox, Google Chrome, open).

bun test is green (1167 pass / 0 fail). bun run typecheck is clean.

Refs #154 (BROWSER-sentinel cause; other code paths in that issue may still apply).

Fixes #724

…s can fall back

Claude Code's agent view (and similar background/headless environments) sets
$BROWSER=true to mean "do not launch a browser." The previous logic took that
literally and ran `true http://localhost:NNNN` via `Bun.$`, which exits 0 without
opening anything. The server then sits forever in waitForDecision() with no
visible UI and no way for the user to recover the URL.

Detect the documented no-op sentinels (`true`, `false`, `none`, `:`, `0`, `1`)
on both PLANNOTATOR_BROWSER and BROWSER and treat them as if the variable were
unset. This lets shouldTryRemoteBrowserFallback() reach the VS Code IPC
fallback in remote sessions and lets openBrowser() fall through to the
platform default when nothing else is configured.

Refs backnotprop#154.
@backnotprop

Copy link
Copy Markdown
Owner

Is this the fix for Claude Code's agent view ? Trying it now

@backnotprop

Copy link
Copy Markdown
Owner

great work

@backnotprop
backnotprop merged commit 42c85f0 into backnotprop:main May 19, 2026
10 checks passed
backnotprop added a commit that referenced this pull request Oct 14, 2026
…1923)

browser.ts reads none/true/false/0/1/: as unset (#756) and falls through
to the system default, so every test that set PLANNOTATOR_BROWSER=none
opened real tabs on the developer's screen whenever it reached
openBrowser (a foreground plannotator inbox, a session without
--background).

- tests/helpers/no-browser.ts: NO_BROWSER, an absolute path to a program
  that exits at once (/usr/bin/true, /bin/true, true on PATH; whoami.exe
  on Windows).
- Every 'none' in tests/e2e, tests/helpers/inbox-world.ts and the CLI
  tests now uses it.
- The bun test preload sets PLANNOTATOR_BROWSER=NO_BROWSER for every test.
- tests/no-browser-sentinel.test.ts scans tests, scripts, package.json
  files and the workflows for a sentinel value.

No product change.
backnotprop added a commit that referenced this pull request Oct 15, 2026
* Every session prints its URL (re-applies #1184)

Every Bun session now writes one stable stderr line on start, before it
launches a browser:

  Plannotator session ready: <url>

Remote forwarding advice and a failed browser launch become follow-up lines
under it, so the URL appears exactly once. A local session whose browser
opened fine used to print nothing (#1134), and a launcher that never exits
hid the URL until it did.

- shared-handlers: SESSION_READY_LINE_PREFIX, an `announce` option, the line
  printed before the launch; isCodexDesktopHost removed (its case is covered).
- --tailscale: announceTailscaleSession prints the ready line once, then the
  tailnet line and QR.
- OpenCode embedded runtime: announce: false (its toast or transcript notice
  carries the URL); an OpenCode 2 host without session.synthetic logs the URL
  instead. The CLI bridge's stderr filter also forwards the remote follow-up
  and the "Could not open a browser" line.
- Pi: the in-turn "opened" message always carries the URL; the after-turn
  notify runs only for the archive and the event API, or after a failed
  launch (remote no longer shows the URL twice).

Re-applies the design of #1184 by @technicalpickles on current main.

Co-authored-by: Josh Nichols <[email protected]>

* PLANNOTATOR_BROWSER=none opens nothing

A "none" value on PLANNOTATOR_BROWSER (or --browser): none, false, 0, off,
no, true, 1 or :, trimmed and any case, now opens nothing at all, local or
remote: no VS Code IPC, no Glimpse, no BROWSER, no system opener. Since #756
these values were read as "unset" and opened the system default (or ran
BROWSER, or Glimpse), so there was no way to say "never open".

The rule lives in one module, packages/shared/browser-intent.ts
(resolveBrowserIntent: none | default | explicit), vendored to Pi. Bun's
openBrowser and shouldTryRemoteBrowserFallback and Pi's openBrowser use it,
so every caller follows it (sessions, the Inbox, sessions --open, t3 login).
The Bun CLI prints "  Not opening a browser (PLANNOTATOR_BROWSER=none)."
under the ready line; Pi says it in its opened message. BROWSER keeps #756:
its no-op values are still ignored and the default chain runs, because hosts
set it (Claude Code's agent view sets BROWSER=true).

Tests: a pure table for the intent; one process test per runtime whose PATH
holds only stand-in open, xdg-open and glimpseui scripts (and a recording
VS Code IPC server on Bun), proving nothing launches for none (BROWSER set,
local and remote) and that BROWSER=true still runs the default opener.

* Review fixes: neutral mod starting text, --browser none in help, drop unused quiet option, comment fixes

* Fix the merge: drop the blank line main's handleServerReady kept twice

---------

Co-authored-by: Josh Nichols <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web UI does not open after ExitPlanMode on Windows + Claude Code (0.19.15) — server runs, plan captured

2 participants