Skip to content

refactor(errors): read cleanup completion from dependencies instead of pushing it to dependents - #10744

Merged
morluto merged 4 commits into
mainfrom
refactor/cleanup-ownership-model
Nov 15, 2026
Merged

morluto merged 4 commits into
mainfrom
refactor/cleanup-ownership-model

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

This is the first slice of moving resource-ownership state out of AnalysisError (W4c). cleanupIncomplete is no longer a public mutable field that resolveCleanup() pushes through a WeakRef graph of dependents. It is now a getter: the error's own unresolved state, decided by its bound dependencies when it has any. Behavior is unchanged for every existing composition. The target model for the remaining slices is below.

Workstream W4, decision (5): target model first, then a first slice. No linked issue. Refs the audit's "lost ownership" class (#8559 stays deferred).

Problem and expected behavior

An AnalysisError is both a diagnostic value and the mutable handle that tracks resource ownership. On main:

  • cleanupIncomplete is a public writable field. ProviderCleanupError, WebScriptExportError and BrowserObservationError redeclare it as their own field, and ProcessCaptureError writes it with ||=.
  • bindCleanupDependencies registers the composite in each dependency's #cleanupDependents (WeakRefs). resolveCleanup() then walks that graph to flip every composite's flag. If a composite stops being reachable through that graph, its status goes stale. Any writer can also flip the flag without the owner releasing anything.

Expected: only the owning resource's release changes cleanup state. Composites read it when asked.

Target model (remaining W4c slices)

  1. Owner of state. AnalysisCleanupLease (one resource) and AnalysisCleanupLeaseGroup / ArtifactResourceScope (sets) are the only places that record "released" and "which resources remain". Errors never store a completion flag of their own.
  2. Errors hold claims, not flags. An error carries an immutable list of the claims (leases) it reports: cleanupIncomplete = claims.some(c => !c.released) and cleanupResources = ∪ unreleased claims' resources, read at projection time. cleanup (the observation) stays as history.
  3. Composition copies claims. Composing errors (today bindCleanupDependencies, 210 sites) takes the union of the parts' claims. There is no dependents graph and no resolveCleanup() (53 sites): the owner releases its lease, and every error that holds the claim reads the change. A re-wrapped or re-typed error keeps ownership because the claims travel with it (cleanupPrimary chains already do this for diagnostics).
  4. Producers without a lease today (new ProviderCleanupError(provider, resources, …) with a later resolveCleanup() by the retrying owner) get a lease at the producing boundary, for example the debugger registry from refactor(process): own gdb and rizin debugger sessions in one registry #10735 or the owned MCP transport. resolveCleanup() becomes lease.release() at that owner.
  5. cleanupRetry / resource owners (bindCleanupRetry, bindCleanupResourceOwner, bindCleanupCompletionOwner) fold into the lease. A lease can expose retry and live cleanupResources, as AnalysisCleanupLease.forCloseOwner already does.
  6. Sequence. (a) This slice: completion is read, not pushed, and is not writable. (b) Replace resolveCleanup() at lease-backed owners with lease.release(), one owner family per PR, starting with AnalysisCleanupLeaseGroup.ownerReleased. (c) Make bindCleanupDependencies copy claims, then delete it once the runOwned adopters (W4b) cover the composition sites. (d) Add a guard: no resolveCleanup / bindCleanupDependencies outside src/domain and the lease owners, as a counted baseline that can only shrink.

Change and scope (this slice)

  • src/domain/analysisErrorBase.ts:
    • cleanupIncomplete is a getter over a private #cleanupIncomplete flag and the bound dependencies, read when asked. Completion stays monotonic, as before: once complete, a later binding cannot reopen it.
    • #cleanupDependents and the push propagation in resolveCleanup() are removed.
    • New protected markCleanupIncomplete() for subclasses that start with unreleased resources.
  • ProviderCleanupError, WebScriptExportError, BrowserObservationError and ProcessCaptureError set their initial state through markCleanupIncomplete instead of a public field.
  • Not included: claims and leases on errors, removal of resolveCleanup / bindCleanupDependencies, and the guard. Those are slices (b) to (d) above.

Contribution scope: internal refactor; not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: AnalysisError still owns the flag in this slice. Composites now derive their state from their dependencies, and no other code can write it.
  • Contribution scope fit and linked maintainer decision: W4 decision (5).
  • CLI and MCP/tool-catalog contract: none. Projection reads the same cleanupIncomplete and cleanupResources values.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details: retention and retry semantics are unchanged.
  • Generated metadata, package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: src/domain/analysisErrorCleanup.test.ts, "reads completion through nested compositions from the releasing owner only". It covers a two-level composition resolved by the root owner, the monotonic completion, and that Reflect.set(error, "cleanupIncomplete", false) is refused.
  • Base reproduction: on main, cleanupIncomplete is a writable data property, so the Reflect.set assertion fails there.
  • Remaining proof gaps: only the suites listed below ran locally. CI covers the rest.

Validation performed

  • npm run test:focused -- src/domain/analysisErrorCleanup.test.ts src/domain/analysisErrorProjection.test.ts src/domain/providerCleanupError.test.ts src/artifacts/AnalysisCleanupLease.test.ts src/artifacts/ArtifactProviderCleanup.test.ts tests/boundary/mcp/cleanupPrimaryProjection.test.ts tests/boundary/filesystem/binaryTargetCleanup.test.ts tests/boundary/mcp/batchSourcePublicationCleanup.test.ts tests/boundary/cli/finishAnalysisCommand.test.ts tests/composition/analysis-sessions/binarySession.test.ts tests/boundary/providers/ownedCommandCleanup.test.ts tests/boundary/providers/native/lldbPrelaunchCleanup.test.ts tests/boundary/providers/kuna/kunaWorkspaceRollback.test.ts tests/boundary/providers/hopper/hopperFileOffsetClose.test.ts src/providers/AnalysisClientFailure.test.ts tests/boundary/providers/GdbSessionManagerCoverage.test.ts tests/boundary/providers/RizinDebugSessionReviewRegressions.test.ts tests/boundary/mcp/gdbRetirementCancellation.test.ts tests/boundary/providers/ghidra/ghidraLaunchOutcome.test.ts: 19 files, 501 passed, 2 skipped (before the new test was added).
  • npm run test:focused -- src/domain/analysisErrorCleanup.test.ts: 23 passed (with the new test).
  • npm run typecheck: passed. The pre-push check:fast hook passed.
  • Review follow-up (a43b5a4, rebased onto main): bindCleanupDependencies settles the dependencies already bound before adding more. New test "keeps completion when a dependency is bound after release without an intermediate read" failed before the fix. npm run test:focused -- src/domain/analysisErrorCleanup.test.ts src/domain/analysisErrorProjection.test.ts src/domain/providerCleanupError.test.ts src/artifacts/AnalysisCleanupLease.test.ts src/artifacts/ArtifactProviderCleanup.test.ts tests/boundary/mcp/cleanupPrimaryProjection.test.ts tests/boundary/cli/finishAnalysisCommand.test.ts tests/boundary/providers/ownedCommandCleanup.test.ts: 8 files, 154 passed. Pre-push check:fast passed.
  • macOS only.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. cleanupIncomplete was not part of a public package API.
  • Real Hopper/Ghidra, browser, or OS coverage: none.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no process or resource behavior changes.

Author readiness

Human owner:

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 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-15T06:05:02.227411Z f1ab7a5 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.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge; no blocking issue was found.

Summary

Cleanup errors now read completion from dependencies and lease-backed claims instead of receiving pushed updates.

  • Errors read cleanup completion from their dependencies and lease claims.

Diagram

sequenceDiagram
  participant Owner
  participant Lease as AnalysisCleanupLease
  participant Group as AnalysisCleanupLeaseGroup
  participant Error as AnalysisError
  participant Caller
  Owner->>Lease: release()
  Lease->>Group: ownerReleased(lease)
  Group->>Group: Remove released owner
  Caller->>Error: Read cleanupIncomplete
  Error->>Error: Read bound dependencies, if present
  Error->>Group: Otherwise read cleanupReleased
  Error-->>Caller: Current cleanup status
Loading

Reviews (3) · Last reviewed commit: "chore(verify): count resolveCleanup and ..." · Reviewed by Greptile

Comment thread src/domain/analysisErrorBase.ts Resolved
…f pushing it to dependents

AnalysisError.cleanupIncomplete becomes a getter over the error's own unresolved state and its bound dependencies. The WeakRef dependents graph and resolveCleanup's push propagation are removed, and subclasses mark their initial state through markCleanupIncomplete instead of overriding a public mutable field.
A composite whose dependencies had released but whose status was never read
stayed incomplete when a later dependency was bound.
…resolving them (#10759)

AnalysisCleanupLeaseGroup no longer calls resolveCleanup() on its error.
The error holds the group as a release claim and reads cleanupReleased when
asked, so completion follows the lease owner without a push.
… so they only shrink (#10763)

* refactor(errors): let errors read a lease group's release instead of resolving them

AnalysisCleanupLeaseGroup no longer calls resolveCleanup() on its error.
The error holds the group as a release claim and reads cleanupReleased when
asked, so completion follows the lease owner without a push.

* chore(verify): count resolveCleanup and bindCleanupDependencies calls so they only shrink
@morluto
morluto force-pushed the refactor/cleanup-ownership-model branch from 2e29d66 to f1ab7a5 Compare November 15, 2026 06:02
@morluto
morluto merged commit dd7597a into main Nov 15, 2026
55 checks passed
@morluto
morluto deleted the refactor/cleanup-ownership-model branch November 15, 2026 07:22
@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.

1 participant