Skip to content

fix(serve): cap and reclaim offscreen browser tabs (port of upstream #19628) - #369

Merged
fabolivark merged 1 commit into
mainfrom
feat/upstream-serve-tab-cap
Sep 9, 2026
Merged

fabolivark merged 1 commit into
mainfrom
feat/upstream-serve-tab-cap

Conversation

@fabolivark

@fabolivark fabolivark commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 +217 0 +217
Prod 3 +186 −2 +184

Port of stablyai/orca#19628. Second slice of the upstream batch — #368 carries the six that applied cleanly; this one needed real adaptation, so it ships on its own rather than risking that batch.

Why it matters here

Every offscreen browser tab is a BrowserWindow with its own renderer process, and on a headless orca serve nothing reclaims one an agent forgot to close — there is no window in which the growth is visible either. Upstream measured a single working day reaching 9 open tabs backed by 6 renderers of 220-480 MB each on a 4 vCPU / 8 GB host: load average 6.85, 2.5 GB of swap in use, and a paired client that reported only "Reconnecting to remote runtime".

That is our deployment: orca-contabo runs two instances on 11 GiB.

What entered as-is

offscreen-browser-tab-capacity.ts and offscreen-renderer-process-reclaim.ts are self-contained and taken verbatim, including the reasoning for the default of 4 and the ORCA_MAX_OFFSCREEN_BROWSER_TABS override (1-64).

What was adapted, and why

Our offscreen-browser-backend.ts predates upstream's:

  • No options bag. Ours was constructor(private readonly browserManager: BrowserManager) {}. Added one carrying only maxTabs and rendererProcessControl; upstream's getAgentBrowserBridge does not exist here.
  • No retirePageOwner. So settleOwnerRetirement and its 5 s timeout have nothing to wrap. The renderer reclaim — the half that actually frees the slot — is kept.
  • No browser error taxonomy. Rather than invent one to carry a single code, the refusal declares its own class with the same code upstream throws (browser_tab_capacity), so a caller that already handles that keeps working.

One upstream test left out

does not spend a slot on a page the registry refused asserts a path that does not exist here: our registerOffscreenGuest returns void and cannot refuse, while upstream's returns a boolean. Making it refusable changes browser-manager's contract, which is a different change from the cap — so it is named here rather than quietly adapted.

Tests

7 of upstream's 8 cases, plus the whole browser suite: 654 tests green. check:test-case-deletion OK (none lost), max-lines ratchet OK.

…tream #19628)

Port de stablyai/orca#19628. Cada tab offscreen es un BrowserWindow con su
propio proceso renderer, y en un `orca serve` headless nada reclama el que un
agente se olvido de cerrar — tampoco hay ventana donde se vea crecer. Upstream
midio un dia de trabajo llegando a 9 tabs con 6 renderers de 220-480 MB en un
host de 4 vCPU / 8 GB: load 6.85, 2.5 GB de swap, y un cliente que solo decia
"Reconnecting to remote runtime". Nos aplica directo: contabo corre dos
instancias en 11 GiB.

Los dos modulos nuevos entran tal cual. El backend se adapta porque el nuestro
es anterior al de upstream:

- Nuestro constructor no tenia options bag; se agrega uno con `maxTabs` y
  `rendererProcessControl` solamente. El `getAgentBrowserBridge` de upstream no
  existe aca.
- No tenemos `retirePageOwner`, asi que la parte de `settleOwnerRetirement` no
  aplica; queda el reclamo del renderer, que es lo que libera el puesto.
- No tenemos taxonomia de errores de browser. En vez de inventarla para cargar
  un codigo, la refusal declara su propia clase con el MISMO codigo que usa
  upstream (`browser_tab_capacity`), asi un caller que ya lo maneja sigue
  andando.

Queda fuera un caso de test de upstream: "does not spend a slot on a page the
registry refused" afirma un camino que aca no existe — nuestro
`registerOffscreenGuest` devuelve `void` y no puede rechazar. Hacerlo
rechazable es cambiar el contrato de browser-manager, que es otra cosa.

654 tests de browser en verde.
@fabolivark
fabolivark merged commit 3c83cc0 into main Sep 9, 2026
33 checks passed
@fabolivark
fabolivark deleted the feat/upstream-serve-tab-cap branch September 9, 2026 15:37
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