Skip to content

refactor(errors): compose multi-part provider cleanup failures through one owner - #12002

Merged
morluto merged 4 commits into
morluto:mainfrom
anant8140:claude/cleanup-aggregate-owner
Nov 19, 2026
Merged

morluto merged 4 commits into
morluto:mainfrom
anant8140:claude/cleanup-aggregate-owner

Conversation

@anant8140

@anant8140 anant8140 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Next batch for #11859 (Refs #11859; the issue stays open for the remaining sites). Four providers built the same multi-part cleanup composite by hand. This adds one shared owner for it and moves those four sites onto it. Independent of #12000 (no file overlap; the two branches merge cleanly).

Problem and expected behavior

CdpBrowserProvider, CdpElectronProvider, FridaInstrumentationManager and PlaywrightBrowserScenarioProvider each wrote:

new ProviderCleanupError(id, failures.flatMap((f) => f.cleanupResources), { reason }, {
  operation,
  cause: new AggregateError(causes, message?),
}).bindCleanupDependencies(failures)

Expected contract: the composite lists the parts' resources, keeps every failure in its aggregate cause, and completes only after every typed part reports release.

Change and scope

  • Add providerCleanupErrorFromFailures(providerId, failures, reason, { operation, causes?, message? }) to src/domain/analysisErrorCleanup.ts (an existing owner exempt from the guard).
    • causes keeps non-AnalysisError failures in the aggregate cause without making them own completion, as both CDP providers did (AggregateError(failures) while binding only typed).
    • message keeps the aggregate messages Frida and Playwright used. When omitted, new AggregateError(x, undefined) has the same empty message as new AggregateError(x).
    • The helper always calls bindCleanupDependencies, even with an empty list, as the old code did.
  • Move the four sites onto it. No other behavior change.
  • cleanup-dependency-binding baseline: 46 files / 77 sites → 43 files / 73 sites.

Not included: sites that bind a resource owner, bind different errors than the ones they compose (PcapProvider.ts:1007, NativeMacOSProvider.ts:1897), or build custom diagnostics (Kuna, SQLite, Firmware, ArtifactAnalysisResources, ScreenJudge). Those need their own decisions.

Contribution scope: not applicable (internal refactor within existing boundaries).

Contract and boundary impact

  • Semantic owner and earliest changed stage: providerCleanupErrorFromFailures now owns multi-part provider cleanup composition; close/shutdown paths of the four providers.

  • Contribution scope fit and linked maintainer decision: not applicable.

  • CLI and MCP/tool-catalog contract: none.

  • Provider, bridge, target-format, or platform compatibility: none.

  • Evidence, artifact, provenance, or reconstruction contract: none.

  • Target selection, authority, upstream behavior, and cleanup details: same composite error, resources, cause and completion dependencies.

  • Generated metadata, package, or installation impact: none.

  • 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

Before the change, I checked which of these sites existing tests protect: removing bindCleanupDependencies from each site on base only failed Frida's tests. The CDP browser, Electron and Playwright multi-failure paths had no test that noticed.

  • Tests added or updated:

    • src/domain/analysisErrorCleanup.test.ts: helper resources, provider/operation/reason, aggregate cause with an untyped failure, message, default cause, and completion only after both parts release.
    • tests/boundary/browser/cdpProviderCloseComposition.test.ts: for both CDP providers, close() with both close steps failing returns the composite (provider, operation, resources, aggregate causes) that completes only after both parts release; with one untyped failure, the cause keeps it but completion follows the typed part only. Uses vi.spyOn on prototypes, no module mocks.
    • src/browser/PlaywrightBrowserScenarioProvider.test.ts: two retained cleanups whose retries fail compose into one failure that stays incomplete after one releases and completes after both.
  • Base reproduction or other evidence (executed), on the 6 related test files (234 tests):

    Code Result
    This change passed
    Base site code (6752875) with the new tests passed
    Harmless wording change to every reason and aggregate message passed (tests assert facts, not prose, per docs/development/testing.md)
    Helper without bindCleanupDependencies 8 failed
    Helper ignores causes 3 failed
    Helper ignores message 2 failed (helper and caller-data checks)
    Electron site without causes 1 failed
    Playwright site with a different operation 1 failed

    Dropping a part from the composite's constructor resource list is not detected, and cannot be: while dependencies are bound, AnalysisError.cleanupResources reports the pending dependencies' resources, not the constructor list (src/domain/analysisErrorBase.ts).

  • User-visible CLI/MCP output: none.

  • Remaining proof gaps: Frida's aggregate message is covered only through the helper test; existing Frida tests cover its dependency binding. The full test suite was not run locally.

Validation performed

  • npx vitest run src/domain/analysisErrorCleanup.test.ts tests/boundary/browser/cdpProviderCloseComposition.test.ts src/browser/PlaywrightBrowserScenarioProvider.test.ts src/frida/FridaInstrumentationManager.test.ts tests/boundary/browser/cdpProviderCleanupOwnership.test.ts tests/boundary/browser/cdpElectronProvider.test.ts — 234 passed (plus the matrix above).
  • npx vitest run tests/boundary/filesystem/ciTestProjects.test.ts — 23 passed.
  • node scripts/verify/architecture-guards.mjs — passed across 2871 source files.
  • npm run typecheck — exit 0.
  • npm run verify:module-boundaries — passed.
  • npm run check — exit 0 (typecheck, lint, oxfmt format check, knip, metadata, guards, typed lint).
  • npm run check:fast — exit 0.
  • npx oxfmt --check on changed files — clean.
  • npx oxlint on changed files — no errors; 22 warnings before and after (pre-existing).

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; no real browser or Frida process is needed for these close paths.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none.

Author readiness

Human owner: @anant8140

  • 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.

🤖 Generated with Claude Code

…h one owner

CdpBrowserProvider, CdpElectronProvider, FridaInstrumentationManager and
PlaywrightBrowserScenarioProvider each built the same composite by hand: a
ProviderCleanupError listing the parts' resources, an AggregateError cause,
and bindCleanupDependencies over the parts. providerCleanupErrorFromFailures
in src/domain/analysisErrorCleanup.ts now owns that composition. `causes`
keeps non-AnalysisError failures in the aggregate cause without making them
own completion, as the CDP providers did; `message` keeps the aggregate
messages Frida and Playwright used.

Tests: helper unit tests, new close-composition tests for both CDP providers,
and a Playwright test with two failed cleanup retries. They pass on the base
revision and on this change, and fail when the helper drops the dependency
binding, the extra causes or the message.

Lowers the cleanup-dependency-binding baseline to 43 files / 73 sites.

Refs morluto#11859

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

This refactor moves repeated cleanup-error composition into one shared helper without changing the four providers’ behavior.

  • Four provider cleanup paths now use one shared owner for combined failures.

No actionable correctness or security issues found. Tests were not rerun during this review.

Reviews (4) · Last reviewed commit: "Merge main into contributor cleanup aggr..." · Reviewed by Greptile

@anant8140
anant8140 marked this pull request as ready for review November 18, 2026 06:45
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T12:37:28.919777Z 2200c97 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Anant Mandanka and others added 2 commits November 18, 2026 12:20
Follows docs/development/testing.md: the close-composition tests now check
provider, operation, resources, aggregate causes and completion, not the
explanatory reason or aggregate message. A harmless wording change passes;
a lost binding, lost cause or wrong operation still fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@morluto

morluto commented Nov 19, 2026

Copy link
Copy Markdown
Owner

I merged main into this branch at 2200c97031 after #12077 landed. The reconciliation preserves both cleanup helpers, their tests, and the remaining per-provider baseline counts. The effective PR still changes the original nine files. All 220 focused tests passed, along with npm run check:fast and the PR whitespace check. The updated head is awaiting fresh CI and automated review.

@morluto
morluto enabled auto-merge (squash) November 19, 2026 12:37
@morluto
morluto merged commit b6363ef into morluto:main Nov 19, 2026
42 checks passed
@morluto morluto added the area: domain Domain logic, errors, and pure functions label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants