Repository navigation
refactor(errors): read cleanup completion from dependencies instead of pushing it to dependents - #10744
Merged
Conversation
11 tasks
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Contributor
[Medium impact] The reviewed changes appear safe to merge; no blocking issue was found. SummaryCleanup errors now read completion from dependencies and lease-backed claims instead of receiving pushed updates.
DiagramsequenceDiagram
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
Reviews (3) · Last reviewed commit: "chore(verify): count resolveCleanup and ..." · Reviewed by Greptile |
morluto
force-pushed
the
refactor/cleanup-ownership-model
branch
from
November 15, 2026 02:28
d4247aa to
a43b5a4
Compare
This was referenced Nov 15, 2026
Merged
…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
force-pushed
the
refactor/cleanup-ownership-model
branch
from
November 15, 2026 06:02
2e29d66 to
f1ab7a5
Compare
This was referenced Nov 15, 2026
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is the first slice of moving resource-ownership state out of
AnalysisError(W4c).cleanupIncompleteis no longer a public mutable field thatresolveCleanup()pushes through aWeakRefgraph 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
AnalysisErroris both a diagnostic value and the mutable handle that tracks resource ownership. Onmain:cleanupIncompleteis a public writable field.ProviderCleanupError,WebScriptExportErrorandBrowserObservationErrorredeclare it as their own field, andProcessCaptureErrorwrites it with||=.bindCleanupDependenciesregisters 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)
AnalysisCleanupLease(one resource) andAnalysisCleanupLeaseGroup/ArtifactResourceScope(sets) are the only places that record "released" and "which resources remain". Errors never store a completion flag of their own.cleanupIncomplete = claims.some(c => !c.released)andcleanupResources = ∪ unreleased claims' resources, read at projection time.cleanup(the observation) stays as history.bindCleanupDependencies, 210 sites) takes the union of the parts' claims. There is no dependents graph and noresolveCleanup()(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 (cleanupPrimarychains already do this for diagnostics).new ProviderCleanupError(provider, resources, …)with a laterresolveCleanup()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()becomeslease.release()at that owner.cleanupRetry/ resource owners (bindCleanupRetry,bindCleanupResourceOwner,bindCleanupCompletionOwner) fold into the lease. A lease can exposeretryand livecleanupResources, asAnalysisCleanupLease.forCloseOwneralready does.resolveCleanup()at lease-backed owners withlease.release(), one owner family per PR, starting withAnalysisCleanupLeaseGroup.ownerReleased. (c) MakebindCleanupDependenciescopy claims, then delete it once therunOwnedadopters (W4b) cover the composition sites. (d) Add a guard: noresolveCleanup/bindCleanupDependenciesoutsidesrc/domainand the lease owners, as a counted baseline that can only shrink.Change and scope (this slice)
src/domain/analysisErrorBase.ts:cleanupIncompleteis a getter over a private#cleanupIncompleteflag and the bound dependencies, read when asked. Completion stays monotonic, as before: once complete, a later binding cannot reopen it.#cleanupDependentsand the push propagation inresolveCleanup()are removed.protected markCleanupIncomplete()for subclasses that start with unreleased resources.ProviderCleanupError,WebScriptExportError,BrowserObservationErrorandProcessCaptureErrorset their initial state throughmarkCleanupIncompleteinstead of a public field.resolveCleanup/bindCleanupDependencies, and the guard. Those are slices (b) to (d) above.Contribution scope: internal refactor; not applicable.
Contract and boundary impact
AnalysisErrorstill owns the flag in this slice. Composites now derive their state from their dependencies, and no other code can write it.cleanupIncompleteandcleanupResourcesvalues.Evidence and regression coverage
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 thatReflect.set(error, "cleanupIncomplete", false)is refused.main,cleanupIncompleteis a writable data property, so theReflect.setassertion fails there.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-pushcheck:fasthook passed.main):bindCleanupDependenciessettles 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-pushcheck:fastpassed.Compatibility, safety, and release
cleanupIncompletewas not part of a public package API.Author readiness
Human owner:
Before merge
type(scope): outcome.