Skip to content

refactor(errors): compose desktop state-reader close failures with analysisErrorWithCleanupDependencies - #12000

Closed
anant8140 wants to merge 4 commits into
morluto:mainfrom
anant8140:claude/changes
Closed

anant8140 wants to merge 4 commits into
morluto:mainfrom
anant8140:claude/changes

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 custom-error / multi-dependency sites). The first step of the issue's plan (HistoricalCaptureDecoder.ts, HopperFileOffset.ts, the direct PcapProvider.ts site) already landed on main; the baseline was 46 files / 77 sites at 6752875.

Problem and expected behavior

src/cli/desktopCaptureCommands.ts composed the state-reader close failures with analysisErrorWithCleanupFailure(typed[0], typed[1], operation) and then called combined.bindCleanupDependencies(typed) by hand. That is the composition analysisErrorWithCleanupDependencies in src/domain/analysisErrorCleanup.ts owns.

Change and scope

  • Use analysisErrorWithCleanupDependencies(typed[0]!, typed[1]!, operation).
  • The close callback pushes at most two failures (SQLite close, then OwnedWorkerRuntime.retryPending() for exports) and only takes this branch when failures.length > 1, so typed is exactly [primary, cleanup] and the bound dependencies are unchanged.
  • Remove the file from scripts/verify/baselines/cleanup-dependency-binding.json (now 45 files / 76 sites).

Not included: the other analysisErrorWithCleanupFailure(...).bindCleanupDependencies(...) sites are not equivalent to the helper. PcapProvider.ts:1007 binds [commandFailure, snapshotFailure] rather than its composed parts, NativeMacOSProvider.ts:1897 also binds producer when a descriptor cleanup is present, and SourceMapCommand.ts passes a resource owner. Those need their own small batches.

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

Contract and boundary impact

  • Semantic owner and earliest changed stage: analysisErrorWithCleanupDependencies now owns this composition; desktop capture CLI close path.

  • 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, same cleanup 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

  • Tests added or updated: tests/boundary/application/desktopStateReaderCleanup.test.ts drives export-desktop-application in process with both the SQLite close and the export-worker retry failing. It checks that both cleanup failures and their resources reach the projected cleanup_incomplete error, and that the thrown composite stays incomplete until each part's release claim reports release, then completes. It lives in the isolated boundary project because it uses module mocks.
  • Base reproduction or other evidence (executed): the test passes on base 6752875 and on this change, so behavior is unchanged. Mutation checks: replacing the helper with analysisErrorWithCleanupFailure (no dependency binding) fails the test, and throwing only the first failure fails the test. The architecture guard enforces the lower baseline.
  • User-visible CLI/MCP output: none.
  • Remaining proof gaps: the full test suite was not run locally (targeted tests only).

Validation performed

  • node scripts/verify/architecture-guards.mjs — Architecture guards passed across 2871 source files.
  • node scripts/run-typescript.mjs --noEmit — exit 0.
  • npx vitest run tests/boundary/mcp/cleanupPrimaryProjection.test.ts tests/boundary/cli/projectCliAnalysisResult.test.ts tests/boundary/providers/desktopExportSeedPolicy.test.ts — 3 files, 10 tests passed.
  • npx vitest run tests/boundary/application/desktopStateReaderCleanup.test.ts — 1 passed; on base 6752875 — 1 passed; with the binding removed — 1 failed; with the second failure dropped — 1 failed.
  • npx vitest run tests/boundary/filesystem/ciTestProjects.test.ts tests/evaluation/noSharedModuleMockRule.test.ts — 35 passed.
  • npm run typecheck — exit 0.
  • 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 src/cli/desktopCaptureCommands.ts tests/boundary/application/desktopStateReaderCleanup.test.ts — no errors; only the existing max-lines warnings in the CLI file.
  • npm run verify:module-boundaries — passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • 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

…alysisErrorWithCleanupDependencies

The desktop capture CLI built a cleanup composite with
analysisErrorWithCleanupFailure and then bound both parts as dependencies by
hand. The close path collects at most two failures (SQLite close and the
export worker retry), so binding `typed` is exactly binding the primary and
cleanup parts, which is what analysisErrorWithCleanupDependencies owns.

Removes src/cli/desktopCaptureCommands.ts from the
cleanup-dependency-binding baseline (45 files / 76 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: 4/5 Tier: plus

[Medium impact] The change is limited to cleanup composition in desktop CLI operations.

Keep this PR unmerged until the export close path preserves all collected cleanup owners.

Findings

  1. P1 Third cleanup failure gets dropped ▶
Fix with agent prompt
### Issue 1
src/cli/desktopCaptureCommands.ts:259-263
The export close callback can collect three failures: `resources.close()`, `sqlite.close()`, and `OwnedWorkerRuntime.retryPending()`. If staged-state cleanup and SQLite close fail while a previously retained worker also fails its retry, this call binds only the first two errors. The old `bindCleanupDependencies(typed)` kept all three.

Once the first two owners release, the combined error can report `cleanupIncomplete === false` while the worker remains unreleased. This violates the requirement to retain every unresolved cleanup owner. Compose all collected errors and add a three-failure regression.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Replaces manual cleanup-error binding with analysisErrorWithCleanupDependencies, removes the matching baseline entry, and adds a CLI regression test.

  • Desktop close errors use one helper to track both cleanup failures.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Export closes readers] --> B[Close staged resources]
  B --> C[Close SQLite]
  C --> D[Retry retained workers]
  D --> E{Three failures?}
  E -->|Yes| F[Helper binds first two errors]
  F --> G[First two owners release]
  G --> H[Combined error reports cleanup complete]
  H --> I[Worker may still need cleanup]
Loading

Reviews (5) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

@anant8140
anant8140 marked this pull request as ready for review November 18, 2026 06:18
@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-20T14:09:59.776197Z ba630e8 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.

Drives export-desktop-application in process with both the SQLite close and
the export worker retry failing. Checks that both cleanup failures and their
resources reach the projected error, and that the thrown composite stays
incomplete until each part's owner confirms release, then completes.

Passes on the base revision and on this change. Fails if the second failure
is dropped or if the composite is not bound to its parts.

Refs morluto#11859

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	scripts/verify/baselines/cleanup-dependency-binding.json
@anant8140

Copy link
Copy Markdown
Contributor Author

I merged current main into this branch at ba630e837.

The only conflict was in scripts/verify/baselines/cleanup-dependency-binding.json: main had removed the src/cutter/CutterBridgeClient.ts entry and this PR removes the src/cli/desktopCaptureCommands.ts entry, so the merge keeps both removals. The effective PR is unchanged: the same three files, +146 −5, and analysisErrorWithCleanupDependencies has the same signature on main.

Checked on the merged head:

  • npm run test:focused -- tests/boundary/application/desktopStateReaderCleanup.test.ts: passes
  • the same test against main's version of desktopCaptureCommands.ts: passes (behavior unchanged), while verify:architecture-guards fails there with src/cli/desktopCaptureCommands.ts: 1 (baseline 0)
  • composing with analysisErrorWithCleanupFailure and no dependency binding: the test fails
  • npm run check:fast and npm run check: pass
  • npx oxfmt --check on the changed files: pass

CI is waiting for approval to run on the fork.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ba630e837c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +259 to 261
throw analysisErrorWithCleanupDependencies(
typed[0]!,
typed[1]!,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bind every collected close failure

When export_desktop_application gets failures from all three cleanup stages above (resources.close(), sqlite.close(), and OwnedWorkerRuntime.retryPending()), this helper binds only typed[0] and typed[1]. The removed bindCleanupDependencies(typed) also tracked the worker failure, whereas the new composite can report completion after the first two owners release while that third owner remains unreleased; compose or bind every collected failure.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

Comment on lines +259 to 263
throw analysisErrorWithCleanupDependencies(
typed[0]!,
typed[1]!,
operation,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Third cleanup failure gets dropped

The export close callback can collect three failures: resources.close(), sqlite.close(), and OwnedWorkerRuntime.retryPending(). If staged-state cleanup and SQLite close fail while a previously retained worker also fails its retry, this call binds only the first two errors. The old bindCleanupDependencies(typed) kept all three.

Once the first two owners release, the combined error can report cleanupIncomplete === false while the worker remains unreleased. This violates the requirement to retain every unresolved cleanup owner. Compose all collected errors and add a three-failure regression.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/desktopCaptureCommands.ts
Line: 259-263

Comment:
**Third cleanup failure gets dropped**

The export close callback can collect three failures: `resources.close()`, `sqlite.close()`, and `OwnedWorkerRuntime.retryPending()`. If staged-state cleanup and SQLite close fail while a previously retained worker also fails its retry, this call binds only the first two errors. The old `bindCleanupDependencies(typed)` kept all three.

Once the first two owners release, the combined error can report `cleanupIncomplete === false` while the worker remains unreleased. This violates the requirement to retain every unresolved cleanup owner. Compose all collected errors and add a three-failure regression.

**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Thank you for this, and for the CLI-level test approach, which #13168 reuses. Since this PR was written, main added the artifact-scope close, so the state-reader close can now collect three failures. A two-argument analysisErrorWithCleanupDependencies(typed[0], typed[1]) would drop the third from the composite's dependencies. #13168 folds every failure through the helper and covers the three-failure case, so I'm closing this PR as superseded.

@N0zoM1z0 N0zoM1z0 closed this Nov 21, 2026
@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.

3 participants