Skip to content

Commit f8c7738

Browse files
shrey150claude
andauthored
fix: browse env inconsistently updates internal state (browserbase#1806)
## Summary - `browse env` showed stale "local" mode after `browse env remote` - Root cause: `.mode` file was only written during lazy browser init (`ensureBrowserInitialized`), not at daemon startup. Between daemon start and first command, `readCurrentMode()` returned `null` and fell back to hardcoded `"local"` - Write `.mode` eagerly in `runDaemon()` at startup so it's immediately available - Fall back to `desiredMode` instead of `"local"` in the `env` display handler as a safety net ## Test plan - [x] Reproduced bug: `browse env remote` → `browse env` showed `"mode":"local"` - [x] Verified fix: `browse env remote` → `browse env` now shows `"mode":"remote"` - [x] `mode.test.ts` passes (3/3) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes `browse env` showing stale "local" after `browse env remote` (STG-1547). The daemon now writes `.mode` at startup, the display falls back to `desiredMode` until mode is written, and a patch changeset is added for `@browserbasehq/browse-cli`. <sup>Written for commit 9661d92. Summary will update on new commits. <a href="https://cubic.dev/pr/browserbase/stagehand/pull/1806">Review in cubic</a></sup> <!-- End of auto-generated description by cubic. --> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2abf5b9 commit f8c7738

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

.changeset/fix-cli-env-mode.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/browse-cli": patch
3+
---
4+
5+
Fix `browse env` showing stale mode after `browse env remote`

packages/cli/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,9 @@ const DEFAULT_VIEWPORT = { width: 1288, height: 711 };
260260
async function runDaemon(session: string, headless: boolean): Promise<void> {
261261
await cleanupStaleFiles(session);
262262

263-
// Write daemon PID file
263+
// Write daemon PID file and initial mode so status is immediately available
264264
await fs.writeFile(getPidPath(session), String(process.pid));
265+
await fs.writeFile(getModePath(session), await getDesiredMode(session));
265266

266267
// Browser state (initialized lazily on first command)
267268
let stagehand: Stagehand | null = null;
@@ -1537,7 +1538,7 @@ program
15371538
let mode: string | null = null;
15381539
const desiredMode = await getDesiredMode(session);
15391540
if (await isDaemonRunning(session)) {
1540-
mode = toModeTarget((await readCurrentMode(session)) ?? "local");
1541+
mode = toModeTarget((await readCurrentMode(session)) ?? desiredMode);
15411542
}
15421543
console.log(JSON.stringify({
15431544
mode: mode ?? "not running",

0 commit comments

Comments
 (0)