[PR #4995] fix(browser): reclaim scenario profiles whose owner is gone #6717

Open
opened 2026-11-01 21:42:31 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4995
Author: @skyzhao1223
Created: 10/18/2026
Status: 🔄 Open

Base: main ← Head: fix/scenario-profile-reclamation


📝 Commits (1)

  • f725549 fix(browser): reclaim scenario profiles whose owner is gone

📊 Changes

5 files changed (+455 additions, -3 deletions)

View changed files

📝 docs/browser-scenario-contract.md (+6 -1)
📝 src/browser/PlaywrightScenarioBrowser.test.ts (+72 -2)
📝 src/browser/PlaywrightScenarioBrowser.ts (+10 -0)
➕ src/browser/ScenarioProfileReclamation.test.ts (+176 -0)
➕ src/browser/ScenarioProfileReclamation.ts (+191 -0)

📄 Description

Summary

Addresses #4659.

A terminated capture-browser-scenario launch leaves its temporary Chrome
profile behind, and nothing reclaimed it later. The profile retains cookies,
history, cache and origin storage of the visited origin; the issue measured 14
such profiles on one host. The published documentation clarification stated that
later REA runs do not reclaim these paths, and that reclamation was still
missing.

Problem and expected behavior

Smallest trigger: kill an REA process during a launch-mode scenario. The
rea-browser-scenario-* profile survives in the temp root. Expected: a later
REA run can reclaim what a terminated run left behind, without ever removing a
profile another process still holds.

Change and scope

  • Each launch writes .rea-scenario-owner.json (schema, owning pid, creation
    time, mode 0600) into the profile it creates.
  • Before creating its own profile, a later launch calls
    reclaimStaleScenarioProfiles(). A prefixed directory is removed only when
    it is a real directory (never a symlink), carries this marker, its recorded
    owner is gone, and its Chromium singleton entries do not establish a live
    browser. Every unproven answer keeps the directory: a missing or malformed
    marker, an unreadable or non-symlink SingletonLock/SingletonCookie/
    SingletonSocket, or a singleton target without a trailing process id.
  • docs/browser-scenario-contract.md now describes the reclamation and what
    remains.

Intentionally not included: Playwright playwright-artifacts-* directories.
The issue is explicit that ownership must not be inferred from that name, and
those directories are not REA-owned. They remain documented as a gap. The
wrapper-cancellation channel in the issue is also not implemented.

Open question for review: is launch-time reclamation the direction you want, or
would you prefer an explicit command/flag so deletion never happens as a side
effect of another scenario? I can move or drop this in favor of that.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the launch boundary in PlaywrightScenarioBrowser; reclamation runs before mkdtemp and writes the marker before launchPersistentContext.
  • Contribution scope fit and linked maintainer decision: ordinary fix inside an existing capability boundary; no new provider, authority, or target execution. Deletion is limited to REA-owned temporary profiles and is fail-closed.
  • CLI and MCP/tool-catalog contract: no tool, CLI flag, or result-schema change. Reclamation is best-effort and never fails the caller's scenario.
  • Provider, bridge, target-format, or platform compatibility: POSIX singleton links are parsed for a trailing process id; any other form (including the Windows file form) is treated as held and left in place, so Windows reclamation happens only when the singleton entries are absent.
  • Evidence, artifact, provenance, or reconstruction contract: none; no Evidence record is produced or altered.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): removal is scoped to directories matching REA's own prefix inside the OS temp root that also carry REA's own owner marker.
  • Generated metadata, package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: src/browser/ScenarioProfileReclamation.test.ts (9 tests) covers reclamation of a stale owner, keeping a live owner, keeping a directory without the marker, a live singleton owner, a dead singleton owner, an unprovable singleton entry, foreign prefixes/plain files/symlinked directories, a real exited process, and this process's own profile. PlaywrightScenarioBrowser.test.ts adds a launch-path test that proves a stale profile is reclaimed and the new profile carries the marker before the browser starts.
  • Base reproduction or other evidence: source-derived from the launch path (mkdtemp plus process-local cleanup only) and the issue's measured Windows/Linux runs.
  • User-visible CLI/MCP output (if applicable): none changes; no new output is added.
  • Remaining proof gaps: no real killed-run harness (Chrome plus forced termination) was executed on this host, and no Windows run was executed. playwright-artifacts-* directories are still not reclaimed. A profile whose Chrome was also terminated on Windows keeps its singleton file, so it is not reclaimed there.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:local -- src/browser/ScenarioProfileReclamation.test.ts src/browser/PlaywrightScenarioBrowser.test.ts src/browser/PlaywrightScenarioSession.test.ts — 52 passed (9 + 18 + 25).
  • npm run check:fast — typecheck and lint, 2 tasks successful.
  • npm run docs:check — exit 0, including the onboarding/readme consistency suite (5 passed).
  • npx oxfmt --check on the four changed source files — all correctly formatted.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. A later launch may now remove a stale REA scenario profile that previously stayed behind.
  • Real Hopper/Ghidra, browser, or OS coverage: no real browser was launched or killed; the earlier docs clarification remains the reference for the abrupt-termination behavior.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: this removes leftover Chrome profile data (cookies, history, storage) that previously persisted. It never removes a directory without REA's marker and never removes a profile with a live or unprovable lock.

Author readiness

Human owner: @skyzhao1223

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/4995 **Author:** [@skyzhao1223](https://github.com/skyzhao1223) **Created:** 10/18/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/scenario-profile-reclamation` --- ### 📝 Commits (1) - [`f725549`](https://github.com/morluto/rea/commit/f72554996d4d665bcb1a5906fdfb624e26373d99) fix(browser): reclaim scenario profiles whose owner is gone ### 📊 Changes **5 files changed** (+455 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `docs/browser-scenario-contract.md` (+6 -1) 📝 `src/browser/PlaywrightScenarioBrowser.test.ts` (+72 -2) 📝 `src/browser/PlaywrightScenarioBrowser.ts` (+10 -0) ➕ `src/browser/ScenarioProfileReclamation.test.ts` (+176 -0) ➕ `src/browser/ScenarioProfileReclamation.ts` (+191 -0) </details> ### 📄 Description ## Summary Addresses #4659. A terminated `capture-browser-scenario` launch leaves its temporary Chrome profile behind, and nothing reclaimed it later. The profile retains cookies, history, cache and origin storage of the visited origin; the issue measured 14 such profiles on one host. The published documentation clarification stated that later REA runs do not reclaim these paths, and that reclamation was still missing. ## Problem and expected behavior Smallest trigger: kill an REA process during a launch-mode scenario. The `rea-browser-scenario-*` profile survives in the temp root. Expected: a later REA run can reclaim what a terminated run left behind, without ever removing a profile another process still holds. ## Change and scope - Each launch writes `.rea-scenario-owner.json` (schema, owning pid, creation time, mode 0600) into the profile it creates. - Before creating its own profile, a later launch calls `reclaimStaleScenarioProfiles()`. A prefixed directory is removed only when it is a real directory (never a symlink), carries this marker, its recorded owner is gone, and its Chromium singleton entries do not establish a live browser. Every unproven answer keeps the directory: a missing or malformed marker, an unreadable or non-symlink `SingletonLock`/`SingletonCookie`/ `SingletonSocket`, or a singleton target without a trailing process id. - `docs/browser-scenario-contract.md` now describes the reclamation and what remains. Intentionally not included: Playwright `playwright-artifacts-*` directories. The issue is explicit that ownership must not be inferred from that name, and those directories are not REA-owned. They remain documented as a gap. The wrapper-cancellation channel in the issue is also not implemented. Open question for review: is launch-time reclamation the direction you want, or would you prefer an explicit command/flag so deletion never happens as a side effect of another scenario? I can move or drop this in favor of that. ## Contract and boundary impact - Semantic owner and earliest changed stage: the launch boundary in `PlaywrightScenarioBrowser`; reclamation runs before `mkdtemp` and writes the marker before `launchPersistentContext`. - Contribution scope fit and linked maintainer decision: ordinary fix inside an existing capability boundary; no new provider, authority, or target execution. Deletion is limited to REA-owned temporary profiles and is fail-closed. - CLI and MCP/tool-catalog contract: no tool, CLI flag, or result-schema change. Reclamation is best-effort and never fails the caller's scenario. - Provider, bridge, target-format, or platform compatibility: POSIX singleton links are parsed for a trailing process id; any other form (including the Windows file form) is treated as held and left in place, so Windows reclamation happens only when the singleton entries are absent. - Evidence, artifact, provenance, or reconstruction contract: none; no Evidence record is produced or altered. - Target selection, authority, upstream behavior, and cleanup details (if applicable): removal is scoped to directories matching REA's own prefix inside the OS temp root that also carry REA's own owner marker. - Generated metadata, package, or installation impact: none. Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible. - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [x] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: `src/browser/ScenarioProfileReclamation.test.ts` (9 tests) covers reclamation of a stale owner, keeping a live owner, keeping a directory without the marker, a live singleton owner, a dead singleton owner, an unprovable singleton entry, foreign prefixes/plain files/symlinked directories, a real exited process, and this process's own profile. `PlaywrightScenarioBrowser.test.ts` adds a launch-path test that proves a stale profile is reclaimed and the new profile carries the marker before the browser starts. - Base reproduction or other evidence: source-derived from the launch path (`mkdtemp` plus process-local cleanup only) and the issue's measured Windows/Linux runs. - User-visible CLI/MCP output (if applicable): none changes; no new output is added. - Remaining proof gaps: no real killed-run harness (Chrome plus forced termination) was executed on this host, and no Windows run was executed. `playwright-artifacts-*` directories are still not reclaimed. A profile whose Chrome was also terminated on Windows keeps its singleton file, so it is not reclaimed there. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:local -- src/browser/ScenarioProfileReclamation.test.ts src/browser/PlaywrightScenarioBrowser.test.ts src/browser/PlaywrightScenarioSession.test.ts` — 52 passed (9 + 18 + 25). - `npm run check:fast` — typecheck and lint, 2 tasks successful. - `npm run docs:check` — exit 0, including the onboarding/readme consistency suite (5 passed). - `npx oxfmt --check` on the four changed source files — all correctly formatted. ## Compatibility, safety, and release - Breaking changes or migration steps: none. A later launch may now remove a stale REA scenario profile that previously stayed behind. - Real Hopper/Ghidra, browser, or OS coverage: no real browser was launched or killed; the earlier docs clarification remains the reference for the abrupt-termination behavior. - Package or release metadata impact: none. - Security, privacy, process, or containment review: this removes leftover Chrome profile data (cookies, history, storage) that previously persisted. It never removes a directory without REA's marker and never removes a profile with a live or unprovable lock. ## Author readiness <!-- The human owner completes these declarations before requesting review. AI agents must leave these declarations to a human. Draft PRs may leave them unchecked. --> Human owner: @skyzhao1223 - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [ ] This PR addresses a concrete problem or an agreed enhancement. - [ ] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [ ] The PR has one focused outcome and the title follows `type(scope): outcome`. - [ ] Related issue is linked, or the reason for not linking one is stated above. - [ ] Tests cover changed observable behavior and meaningful failure paths. - [ ] Owning docs, contracts, and generated metadata are updated where needed. - [ ] User-visible CLI/MCP changes include representative output. - [ ] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6717
No description provided.