Skip to content

fix(browser): open the browser in a project its server has only just started - #65720

Merged
Hona merged 2 commits into
devfrom
browser-cold-attach
Nov 23, 2026
Merged

Hona merged 2 commits into
devfrom
browser-cold-attach

Conversation

@Hona

@Hona Hona commented Nov 23, 2026

Copy link
Copy Markdown
Member

The browser pane now attaches to a project that its server has only just started. The first attach to such a project is refused, because its plugins are still loading, and the pane took that answer for a server with no browser: "The browser couldn't open".

sequenceDiagram
    participant P as Pane
    participant S as Server
    P->>S: attach
    Note over S: starts the project, plugins still loading
    S-->>P: 400 rpc.unavailable
    Note over P: before: browser.pane.unsupported
    loop until the project lists its plugins, 10 s at most
        P->>S: plugin.list
        S-->>P: none yet
    end
    P->>S: attach
    S-->>P: attached
Loading
  • When a project is cold: the app updated and restarted its server, or the server had evicted the idle project and started it again for this attach. One week of my desktop logs has 17 of these, 5 within 4 s of an app start and 12 mid-run: each browser.pane.unsupported pairs with an attach 400 at most 513 ms after location services booted.
  • What it cost: the pane stayed unsupported until a plugin.updated or server.connected woke it. In the logs its next attach came 0.8 to 2.6 s later, and once not within 3 minutes. Meanwhile the pane said the browser could not open and available(session) was false.
  • The fix: on rpc.unavailable before the handshake, the pane waits until the project lists its plugins, then attaches once more. This is the client-side wait AGENTS.md asks for under Plugin Loading, the same poll as waitForPlugins in the CLI.
const loaded = client.plugin.list({ location: { directory: session.location.directory } }).pipe(
  Effect.repeat({
    until: (plugins) => plugins.data.length > 0,
    schedule: Schedule.spaced("100 millis").pipe(Schedule.upTo({ duration: "10 seconds" })),
  }),
  Effect.ignore,
)

Deferred.await(connected).pipe(
  Effect.andThen(attach),
  Effect.catchIf(
    (error) => attachmentFailure(error) === "unavailable" && selectBinding(machine.state, binding)?.status === "connecting",
    () => loaded.pipe(Effect.andThen(attach)),
  ),
)
  • A server with no browser: it lists its plugins at once, so it is unsupported one round trip later, as before.
  • A slow project: one that takes more than 10 s to load its plugins ends unsupported, and plugin.updated wakes it as today. A server that started every open project at once took up to 6 s in the logs.
  • Idle eviction: an attachment the server accepted and then dropped still suspends. Attaching again would start the project the server just evicted.
  • Tests: the stand-in server of electron-open.test.ts now starts cold. It refuses attach and lists no plugin until its third answer to the plugin list, and the test checks that the pane was refused once and listed three times.
  • Flag: none, this is a fix.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks sound to me, but I couldn't verify it by running it. Electron won't start in the review sandbox (libnspr4.so is missing), so electron-open.test.ts couldn't run, and the pane can't be reached from the TUI. tsc -b in packages/gui-plugins passes, and so do the pane-machine.test.ts tests (53).

From reading the code: the retry only applies to rpc.unavailable while the binding is still connecting. An attachment that was accepted and then dropped still suspends. If the second attach also fails, the pane ends unsupported as before. Built-in plugins, the browser's among them, are turned on in the supervisor's first batch, so waiting for any plugin to be listed is enough. The 10 s wait fits inside the 15 s register timeout. The fixture's counters depend on the request count, not on timers, so the check shouldn't be flaky.

Public API: unchanged (client-side desktop pane only).

If you haven't already, could you confirm the cold-start case once in the desktop app, since it couldn't be exercised here?

@Hona
Hona merged commit 45aca07 into dev Nov 23, 2026
10 checks passed
@Hona
Hona deleted the browser-cold-attach branch November 23, 2026 05:54
@amrkmn amrkmn mentioned this pull request Nov 23, 2026
1 task
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.

1 participant