[PR #6381] fix(browser): return completed scenario capture when cleanup is unconfirmed #7323

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

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/6381
Author: @sx4im
Created: 10/22/2026
Status: 🔄 Open

Base: main ← Head: fix/6166-completed-capture-cleanup


📝 Commits (2)

  • b8e45c3 fix(browser): return completed scenario capture when cleanup is unconfirmed
  • e53eaf8 Merge main into fix/6166-completed-capture-cleanup

📊 Changes

5 files changed (+148 additions, -48 deletions)

View changed files

📝 src/application/BrowserScenarioCaptureService.test.ts (+23 -0)
📝 src/browser/BrowserScenarioPartialObservation.ts (+52 -6)
📝 src/browser/PlaywrightBrowserScenarioProvider.test.ts (+54 -18)
📝 src/browser/PlaywrightBrowserScenarioProvider.ts (+13 -18)
📝 src/domain/browserScenarioCapture.ts (+6 -6)

📄 Description

Summary

Fixes #6166. When every action in a capture_browser_scenario run completed but browser cleanup timed out or could not be confirmed, the tool reported a hard cleanup_incomplete failure (retryable: false) and retained the finished observation only as a raw partial with no evidence_id. The caller lost a capture that had actually succeeded.

Problem and expected behavior

Smallest trigger: a scenario whose steps all complete, followed by a session close that fails or times out (the report shows a 30s cleanup confirmation timeout after the final wait_for_timeout). Violated invariant: a completed observation should stay a completed result; cleanup is a separate outcome. Expected: return the Evidence with its evidence_id, report cleanup status on the capture, and keep the unconfirmed resources visible.

Change and scope

Capture success and cleanup success are now modeled separately:

  • browserScenarioCaptureSchema admits cleanup: "incomplete" on a completed capture (the value already existed on retained partial observations; the redundant widened type on BrowserScenarioCaptureData is gone).
  • In the Playwright provider, when the operation outcome is ok and every step completed, a cleanup failure returns the completed capture with browser.cleanup: "incomplete" and one limitation naming the cleanup reason and the resources that may remain. The shared completeness classification moved into BrowserScenarioPartialObservation.ts so both return paths use it.
  • Nothing changes when the operation itself failed or a step did not complete: the existing cleanup error, partial observation, and live cleanup resolution behave as before. The cleanup lease stays retained in every cleanup failure case, so provider close and the next capture still retry it and surface it if it never settles.

Scope decision: not applicable. This is an ordinary fix inside the existing browser capture workflow; it adds no capability, authority, or target interaction.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the capture contract in src/domain/browserScenarioCapture.ts; behavior changes at the provider cleanup stage in src/browser/PlaywrightBrowserScenarioProvider.ts.
  • Contribution scope fit and linked maintainer decision: fits the existing browser scenario workflow; no maintainer scope decision required for a bug fix within existing boundaries.
  • CLI and MCP/tool-catalog contract: the capture_browser_scenario result schema gains the cleanup value "incomplete". In the case above, CLI and MCP now return a successful Evidence result instead of an error result.
  • Provider, bridge, target-format, or platform compatibility: Playwright browser scenario provider only. No bridge, format, or platform change.
  • Evidence, artifact, provenance, or reconstruction contract: completed captures in the cleanup-unconfirmed case are now issued as Evidence with an evidence_id, so they can be referenced, exported, and compared like any other result. Provenance fields are unchanged.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): no new authority and no change to target selection. Cleanup ownership is retained exactly as before; unconfirmed resources are named in the capture limitations and retried on provider close.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none committed. CI generates the catalogs; the generated tool schema will show the added enum value.

Expected effects (check known effects; use documentation-only on its own).

  • 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:
    • PlaywrightBrowserScenarioProvider.test.ts: new regression test (close fails after every action completed returns the capture with cleanup: "incomplete" and the resource limitation); the cleanup tests that encoded the old hard-failure outcome for completed captures now assert the returned capture plus retained-lease resolution through provider close. Operation-failure and cancellation variants are unchanged.
    • BrowserScenarioCaptureService.test.ts: new test that a completed capture reporting incomplete cleanup is returned as Evidence with an evidence_id.
  • Base reproduction or other evidence: executed. On the base revision the new provider test failed with the reported behavior (a cleanup_incomplete BrowserObservationError; the completed steps sat in partial_observation as a raw capture with no evidence_id), and the new service test failed because the degraded capture was rejected. Both pass with this change.
  • User-visible CLI/MCP output (if applicable): no real-browser run was available in the build environment, so no CLI transcript is attached; the unit and contract tests above cover the returned shapes.
  • Remaining proof gaps: real Playwright verification (npm run verify:browser) not run; see Validation performed for the unrelated main build break that also blocks built boundary tests.

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/PlaywrightBrowserScenarioProvider.test.ts src/application/BrowserScenarioCaptureService.test.ts: 42 passed. The 2 new regression tests fail on the base revision and pass here.
  • npm run test:local on 13 related files (capture schema, scenario diff inputs, analysis-view scenario records, environment scenario/source/state, scenario browser, execution boundary, provider operation execution, error projection, tool effects) : 247 passed.
  • npm run test:local -- src/browser/PlaywrightScenarioSession.test.ts src/browser/PlaywrightScenarioStorage.test.ts src/browser/history/CaptureFailures.test.ts src/browser/assets/ScriptCaptureAdapters.test.ts: 69 passed.
  • npm run verify:module-boundaries: passed (2,728 source files).
  • npx tsc -p tsconfig.build.json --noEmit: no errors from this change. Two errors in src/application/ReconstructionObligationCandidates.ts (uniqueBy is not defined) are present on clean main as well and are unrelated; they also block test:focused built boundary tests in this environment.
  • src/domain/browserScenarioDiff.test.ts has 4 storage canonicalization failures that are identical on clean main; unrelated to this change.
  • oxlint and oxfmt on the touched files: no errors, format clean.
  • CI on this PR: Source tests, Static checks, Docs Generation, Build package, and browser / real-browser passed. Test shard (7/8) and Portable tests failed; the other shards were cancelled by fail-fast. Check annotations do not name the failing test. Locally, the only failure I can reproduce is ReconstructionObligationCandidates.semantic.test.ts (1 test), which fails identically on clean main in the same area as the uniqueBy break above, and a peer PR on the same base failed Portable tests and a different shard the same evening. Every test covering this change passes locally and in the Source tests job.

Compatibility, safety, and release

  • Breaking changes or migration steps: one behavior change. A capture whose actions all completed but whose cleanup is unconfirmed previously returned a cleanup_incomplete error; it now returns a successful Evidence result with browser.cleanup: "incomplete". Callers that keyed on the error code for this case should read browser.cleanup instead. No input, configuration, or stored-data migration.
  • Real Hopper/Ghidra, browser, or OS coverage: none; fake-session provider tests and contract tests only. npm run verify:browser was not available in this environment.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new process, network, or file authority. Cleanup ownership of a possibly running browser and its profile stays with the provider lease until a retry confirms it, as before.

Author readiness

Human owner: @sx4im

  • 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/6381 **Author:** [@sx4im](https://github.com/sx4im) **Created:** 10/22/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/6166-completed-capture-cleanup` --- ### 📝 Commits (2) - [`b8e45c3`](https://github.com/morluto/rea/commit/b8e45c3c65bf173e9bb57ac0fd58c8710f215880) fix(browser): return completed scenario capture when cleanup is unconfirmed - [`e53eaf8`](https://github.com/morluto/rea/commit/e53eaf85061a4e6560947c17d27a3bf81dd83c53) Merge main into fix/6166-completed-capture-cleanup ### 📊 Changes **5 files changed** (+148 additions, -48 deletions) <details> <summary>View changed files</summary> 📝 `src/application/BrowserScenarioCaptureService.test.ts` (+23 -0) 📝 `src/browser/BrowserScenarioPartialObservation.ts` (+52 -6) 📝 `src/browser/PlaywrightBrowserScenarioProvider.test.ts` (+54 -18) 📝 `src/browser/PlaywrightBrowserScenarioProvider.ts` (+13 -18) 📝 `src/domain/browserScenarioCapture.ts` (+6 -6) </details> ### 📄 Description ## Summary Fixes #6166. When every action in a `capture_browser_scenario` run completed but browser cleanup timed out or could not be confirmed, the tool reported a hard `cleanup_incomplete` failure (`retryable: false`) and retained the finished observation only as a raw partial with no `evidence_id`. The caller lost a capture that had actually succeeded. ## Problem and expected behavior Smallest trigger: a scenario whose steps all complete, followed by a session close that fails or times out (the report shows a 30s cleanup confirmation timeout after the final `wait_for_timeout`). Violated invariant: a completed observation should stay a completed result; cleanup is a separate outcome. Expected: return the Evidence with its `evidence_id`, report cleanup status on the capture, and keep the unconfirmed resources visible. ## Change and scope Capture success and cleanup success are now modeled separately: - `browserScenarioCaptureSchema` admits `cleanup: "incomplete"` on a completed capture (the value already existed on retained partial observations; the redundant widened type on `BrowserScenarioCaptureData` is gone). - In the Playwright provider, when the operation outcome is ok and every step completed, a cleanup failure returns the completed capture with `browser.cleanup: "incomplete"` and one limitation naming the cleanup reason and the resources that may remain. The shared completeness classification moved into `BrowserScenarioPartialObservation.ts` so both return paths use it. - Nothing changes when the operation itself failed or a step did not complete: the existing cleanup error, partial observation, and live cleanup resolution behave as before. The cleanup lease stays retained in every cleanup failure case, so provider close and the next capture still retry it and surface it if it never settles. Scope decision: not applicable. This is an ordinary fix inside the existing browser capture workflow; it adds no capability, authority, or target interaction. ## Contract and boundary impact - Semantic owner and earliest changed stage: the capture contract in `src/domain/browserScenarioCapture.ts`; behavior changes at the provider cleanup stage in `src/browser/PlaywrightBrowserScenarioProvider.ts`. - Contribution scope fit and linked maintainer decision: fits the existing browser scenario workflow; no maintainer scope decision required for a bug fix within existing boundaries. - CLI and MCP/tool-catalog contract: the `capture_browser_scenario` result schema gains the `cleanup` value `"incomplete"`. In the case above, CLI and MCP now return a successful Evidence result instead of an error result. - Provider, bridge, target-format, or platform compatibility: Playwright browser scenario provider only. No bridge, format, or platform change. - Evidence, artifact, provenance, or reconstruction contract: completed captures in the cleanup-unconfirmed case are now issued as Evidence with an `evidence_id`, so they can be referenced, exported, and compared like any other result. Provenance fields are unchanged. - Target selection, authority, upstream behavior, and cleanup details (if applicable): no new authority and no change to target selection. Cleanup ownership is retained exactly as before; unconfirmed resources are named in the capture limitations and retried on provider close. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact: none committed. CI generates the catalogs; the generated tool schema will show the added enum value. Expected effects (check known effects; use documentation-only on its own). - [ ] Read existing files or captured data. - [x] 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: - `PlaywrightBrowserScenarioProvider.test.ts`: new regression test (close fails after every action completed returns the capture with `cleanup: "incomplete"` and the resource limitation); the cleanup tests that encoded the old hard-failure outcome for completed captures now assert the returned capture plus retained-lease resolution through provider close. Operation-failure and cancellation variants are unchanged. - `BrowserScenarioCaptureService.test.ts`: new test that a completed capture reporting incomplete cleanup is returned as Evidence with an `evidence_id`. - Base reproduction or other evidence: executed. On the base revision the new provider test failed with the reported behavior (a `cleanup_incomplete` `BrowserObservationError`; the completed steps sat in `partial_observation` as a raw capture with no `evidence_id`), and the new service test failed because the degraded capture was rejected. Both pass with this change. - User-visible CLI/MCP output (if applicable): no real-browser run was available in the build environment, so no CLI transcript is attached; the unit and contract tests above cover the returned shapes. - Remaining proof gaps: real Playwright verification (`npm run verify:browser`) not run; see Validation performed for the unrelated `main` build break that also blocks built boundary tests. 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/PlaywrightBrowserScenarioProvider.test.ts src/application/BrowserScenarioCaptureService.test.ts`: 42 passed. The 2 new regression tests fail on the base revision and pass here. - `npm run test:local` on 13 related files (capture schema, scenario diff inputs, analysis-view scenario records, environment scenario/source/state, scenario browser, execution boundary, provider operation execution, error projection, tool effects) : 247 passed. - `npm run test:local -- src/browser/PlaywrightScenarioSession.test.ts src/browser/PlaywrightScenarioStorage.test.ts src/browser/history/CaptureFailures.test.ts src/browser/assets/ScriptCaptureAdapters.test.ts`: 69 passed. - `npm run verify:module-boundaries`: passed (2,728 source files). - `npx tsc -p tsconfig.build.json --noEmit`: no errors from this change. Two errors in `src/application/ReconstructionObligationCandidates.ts` (`uniqueBy` is not defined) are present on clean `main` as well and are unrelated; they also block `test:focused` built boundary tests in this environment. - `src/domain/browserScenarioDiff.test.ts` has 4 storage canonicalization failures that are identical on clean `main`; unrelated to this change. - oxlint and oxfmt on the touched files: no errors, format clean. - CI on this PR: Source tests, Static checks, Docs Generation, Build package, and browser / real-browser passed. Test shard (7/8) and Portable tests failed; the other shards were cancelled by fail-fast. Check annotations do not name the failing test. Locally, the only failure I can reproduce is `ReconstructionObligationCandidates.semantic.test.ts` (1 test), which fails identically on clean `main` in the same area as the `uniqueBy` break above, and a peer PR on the same base failed Portable tests and a different shard the same evening. Every test covering this change passes locally and in the Source tests job. ## Compatibility, safety, and release - Breaking changes or migration steps: one behavior change. A capture whose actions all completed but whose cleanup is unconfirmed previously returned a `cleanup_incomplete` error; it now returns a successful Evidence result with `browser.cleanup: "incomplete"`. Callers that keyed on the error code for this case should read `browser.cleanup` instead. No input, configuration, or stored-data migration. - Real Hopper/Ghidra, browser, or OS coverage: none; fake-session provider tests and contract tests only. `npm run verify:browser` was not available in this environment. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no new process, network, or file authority. Cleanup ownership of a possibly running browser and its profile stays with the provider lease until a retry confirms it, as before. ## Author readiness Human owner: @sx4im - [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 - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [ ] User-visible CLI/MCP changes include representative output. - [x] 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#7323
No description provided.