Skip to content

fix: reap managed web browser orphans#1112

Merged
thymikee merged 3 commits into
mainfrom
codex/web-agent-browser-lifecycle-1109
Jul 6, 2026
Merged

fix: reap managed web browser orphans#1112
thymikee merged 3 commits into
mainfrom
codex/web-agent-browser-lifecycle-1109

Conversation

@thymikee

@thymikee thymikee commented Jul 5, 2026

Copy link
Copy Markdown
Member

Summary

Adds managed web browser lifecycle protection for agent-device-owned agent-browser Chrome fleets.

  • Sets a five-minute managed agent-browser idle timeout by default, with AGENT_BROWSER_IDLE_TIMEOUT_MS and AGENT_DEVICE_WEB_IDLE_TIMEOUT_MS overrides.
  • Tags managed Chrome launches and reaps only Chrome-like processes that carry the tag or run from the managed agent-device browser home during daemon startup.
  • Adds a doctor check that reports the live agent-device-owned Chrome process count and PIDs.

Closes #1109

Residual risk: orphan detection intentionally stays conservative. It will not touch ordinary user Chrome, but it may leave behind a process if its command line no longer contains the launch marker or managed browser-home path.

Touched files: 8; scope stayed within web lifecycle/doctor handling.

Validation

  • pnpm check:quick
  • pnpm format
  • ./node_modules/.bin/vitest run src/platforms/web/agent-browser-lifecycle.test.ts src/platforms/web/agent-browser-tool.test.ts src/platforms/web/agent-browser-provider.test.ts src/daemon/handlers/tests/session-doctor-web.test.ts

@thymikee thymikee force-pushed the codex/web-agent-browser-lifecycle-1109 branch from 740b94a to 36ebd9e Compare July 5, 2026 09:55
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

Size Report

Metric Base Current Diff
JS raw 1.5 MB 1.5 MB +5.5 kB
JS gzip 491.8 kB 493.7 kB +1.9 kB
npm tarball 597.4 kB 599.1 kB +1.7 kB
npm unpacked 2.1 MB 2.1 MB +5.5 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 28.0 ms 28.6 ms +0.6 ms
CLI --help 52.7 ms 55.3 ms +2.6 ms

Top changed chunks:

Chunk Raw diff Gzip diff
dist/src/session.js +1.0 kB +305 B
dist/src/internal/daemon.js +855 B +178 B
dist/src/runner-client.js 0 B -1 B

@thymikee

thymikee commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

Follow-up issue #1123 is an actionable blocker for this PR as currently scoped: the daemon startup reaper should avoid killing managed browsers still owned by active/recent sessions, and provider-startup/process-tree cleanup gaps need addressing or explicit deferral before this is merge-ready.

@thymikee

thymikee commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

Addressed #1123 blockers in commit 0826306:

  • Reaper now skips cleanup when daemon/session ownership reports open web sessions and when managed browser socket activity is still recent.
  • Matching is narrowed to the managed .agent-browser/browsers subtree or the explicit launch marker.
  • Cleanup expands matched browser roots to their process tree before TERM/KILL so renderer/GPU descendants are covered.
  • provider-startup cleanup is wired through the daemon default web provider with debounce; daemon-startup passes current web session ownership.
  • Added behavior tests for skip decisions, process-tree signaling, provider-startup wiring, and daemon-startup session-store integration.

Validation:

  • pnpm exec vitest run src/platforms/web/agent-browser-lifecycle.test.ts src/platforms/web/agent-browser-provider.test.ts src/daemon/server/daemon-runtime-web-cleanup.test.ts
  • pnpm format
  • pnpm check:quick
  • pnpm build
  • pnpm test:smoke
  • pnpm check:unit

@thymikee

thymikee commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

Review pass after 0826306: no remaining actionable blockers found.

Checked against #1123 and the prior PR blocker. The reaper now skips when session ownership reports open web sessions or recent managed browser activity, narrows process matching to the managed browser subtree or explicit launch marker, expands cleanup to the matched browser process tree, and wires provider-startup cleanup with debounce. The new tests cover skip decisions, process-tree signaling, provider-startup wiring, and daemon-startup session-store integration.

CI is green, and the worker validation included focused lifecycle/provider/runtime tests, format, quick checks, build, smoke, and unit. Marking this ready for human maintainer judgment.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Jul 6, 2026
@thymikee thymikee merged commit 126d85a into main Jul 6, 2026
21 checks passed
@thymikee thymikee deleted the codex/web-agent-browser-lifecycle-1109 branch July 6, 2026 13:51
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-06 13:51 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

web: agent-browser Chrome fleets leak and can spin at 100% CPU for days — add idle lifecycle/reaper

1 participant