Skip to content

refactor(providers): finalize apktool and shared artifact resources through runOwned - #10653

Merged
morluto merged 5 commits into
mainfrom
refactor/run-owned-partial-hook
Nov 15, 2026
Merged

morluto merged 5 commits into
mainfrom
refactor/run-owned-partial-hook

Conversation

@morluto

@morluto morluto commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

runOwned (from #10645) required the completed value to be a partial observation and could not bind a close failure to its exact cleanup lease, so provider finalizers kept their own result.ok && signal.aborted reclassification and lease-group composition. This adds both hooks, moves runOwned to the provider layer, and migrates the first sites: the shared ArtifactAnalysisResources.finish (TShark and sigrok) and Apktool's decode finalizer. A counted architecture guard stops new hand-written reclassifications.

Stacked on #10645 (base branch refactor/finalized-outcome). Refs #4227 #4330

Problem and expected behavior

  • ArtifactAnalysisResources.finish and ApktoolProvider each re-derived the finalization precedence: release, then signal.aborted reclassification, then a hand-built cleanup composite. Neither kept a cancellation that arrived during final cleanup on an already-recorded failure, which the documented precedence (tool-design.md, "Own the lifecycle") requires.
  • Expected: one owner applies the precedence. A recorded failure stays primary and keeps a later cancellation as a secondary failure. A pre-commit cancellation keeps the completed value's partial observation. A completed value with unconfirmed cleanup is cleanup_incomplete and keeps it (D1). A close failure stays bound to the exact lease whose confirmed release resolves it.

Change and scope

  • src/providers/runOwned.ts (moved from src/application/):
    • Moved because provider and foundation code cannot depend on application workflows (layer order in docs/architecture/architecture.mermaid; ratchet proposed in test(architecture): ratchet top-level layer direction and mutual imports #10584). It depends only on domain and artifact types.
    • partial: (value) => AnalysisPartialObservation is required. It projects a completed value into what a pre-commit cancellation or retained cleanup keeps. finishAnalysisCommand passes the identity.
    • cleanupLeases binds a close failure to the exact leases (AnalysisCleanupLeaseGroup) whose confirmed release resolves it and attributes its resources.
    • signal is optional.
  • src/process/ArtifactAnalysisResources.ts: finish is removed. TsharkCaptureProvider and SigrokRecordingProvider call runOwned with close: () => resources.release().
  • src/apktool/ApktoolProvider.ts: the release, reclassification and lease-group block is replaced by runOwned with cleanupLeases: [lease]. The cleanup error is still ProviderCleanupError("apktool", [root]).
  • scripts/verify/architecture-guards.mjs: new counted guard completed-abort-reclassification (.ok && isAborted( / .ok && …signal.aborted) outside runOwned. The baseline has 22 files; it can only shrink. The pattern is syntactic, so some baselined matches may be pre-admission or deadline checks that are legitimate; each migration slice re-examines its file.
  • Not included (separate slices, each its own PR): EvidenceBundleCommands, LldbCallTracer, SignatureTargetBinding, Ghidra, ADB, ReferenceSourceReaderEntries, and the MCP-side projection. The work bodies of Tshark, sigrok and Apktool still run before runOwned; only finalization moved.
  • Contribution scope: not applicable (internal refactor within existing boundaries).

Contract and boundary impact

  • Semantic owner and earliest changed stage: runOwned owns finalization precedence for these three providers. The superseded ArtifactAnalysisResources.finish and Apktool's local composition are removed.
  • Contribution scope fit and linked maintainer decision: D1 (keep the documented cleanup_incomplete contract), relayed by the coordinator.
  • CLI and MCP/tool-catalog contract: unchanged schemas. One additive diagnostic: when TShark, sigrok or Apktool work has already failed and the caller cancels during final cleanup, the failure now lists that cancellation in secondary_failures.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none. Completed values are still kept as the same createAnalysisExecutionEvidence partial observation.
  • Target selection, authority, upstream behavior, and cleanup details: cleanup ownership is unchanged. The same leases are bound and retried.
  • Generated metadata, package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

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

None checked: result composition only.

Evidence and regression coverage

  • Tests added or updated:
    • src/providers/runOwned.test.ts: three new cases. A non-partial value keeps its projected partial when cancellation arrives during final cleanup. A close failure bound by cleanupLeases reports the lease's resources and resolves when the lease later releases. A producer-typed close failure is bound to the leases while the failed work stays primary.
    • src/process/ArtifactAnalysisResources.test.ts: the existing finish cases now run through runOwned via a local helper. "keeps an existing physical primary across cleanup-time cancellation" now also asserts the late cancellation is kept as a secondary failure.
  • Base reproduction: with the cancellation attachment disabled in runOwned, so it behaves like the removed finish, both parameterizations of that test fail (2 failed | 27 passed). With it enabled they pass.
  • Lifecycle regressions covered: cancellation during final cleanup (failed and released close); cleanup retry through the bound lease. Not covered here: late handshake and mixed child outcomes, which the planned lifecycle harness covers.
  • Remaining proof gaps: no real tshark, sigrok-cli or Apktool run. The boundary suites below use their existing fixtures.

Validation performed

  • 2026-11-15, after merging current origin/main (conflicts: guard list kept both completed-abort-reclassification and gdb-mi-record-regex; ArtifactAnalysisResources.finish stays removed, main had only re-spelled its cancellation; baselines merged per file and shrunk): npm run check:fast — passed; node scripts/verify/architecture-guards.mjs — passed; npm run test:local -- src/providers/runOwned.test.ts src/process/ArtifactAnalysisResources.test.ts — 38 passed.
  • npm run typecheck: passed.
  • npm run check:fast: passed (typecheck and lint).
  • node scripts/verify/architecture-guards.mjs: passed across 2791 source files. Before the baseline shrink, it reported the removed AnalysisCancelledError constructions in Apktool and ArtifactAnalysisResources as stale.
  • npm run test:local -- src/providers/runOwned.test.ts src/process/ArtifactAnalysisResources.test.ts src/apktool/ApktoolProvider.test.ts src/apktool/ApktoolDecodeTimeout.test.ts src/apktool/ApktoolCommandRecovery.test.ts src/apktool/ApktoolWorkspace.lifecycle.test.ts: 6 files, 148 tests passed.
  • npm run test:focused -- tests/boundary/captures/captureDescriptorCleanup.test.ts tests/boundary/captures/captureProvider.test.ts tests/boundary/signals/recordingDescriptorCleanup.test.ts tests/boundary/signals/recordingProvider.test.ts tests/boundary/process/artifactProducerCancellation.test.ts: 146 passed, 14 skipped (both descriptor-cleanup files skip on this host).
  • npm run test:focused -- tests/boundary/cli/finishAnalysisCommand.test.ts tests/boundary/cli/wasmLateCancellationCli.test.ts: 14 passed.
  • npx oxfmt --check on changed files: clean.
  • Pre-push hook ran on git push.
  • After rebasing onto main (dd7597a; the counted cleanup-dependency-binding baseline from refactor(errors): read cleanup completion from dependencies instead of pushing it to dependents #10744 conflicted with this PR's completed-abort-reclassification section): kept both sections, moved the runOwned.ts entry to src/providers/, shrank stale counts; node scripts/verify/architecture-guards.mjs passed; npm run check:fast passed; npm run test:focused -- src/providers/runOwned.test.ts src/providers/runOwned.lifecycle.test.ts src/process/ArtifactAnalysisResources.test.ts src/native/SignatureTargetBinding.test.ts tests/boundary/providers/adb/adbInputSnapshotOwnership.test.ts tests/boundary/providers/adb/adbScreenPublicationCancellation.test.ts tests/process-global/bundleComparisonFailures.test.ts: 7 files, 176 passed.
  • After rebasing onto main (conflicts: architecture-guards.mjs, both guards kept; provider-failure-classifier-baseline.json, main's new {owners, counts} shape kept with the runOwned.ts entry moved to src/providers/): node scripts/verify/architecture-guards.mjs --shrink-baselines passed with no change; npm run check:fast passed; npm run test:focused -- src/providers/runOwned.test.ts src/process/ArtifactAnalysisResources.test.ts tests/boundary/providers/apktoolDecodeDeadline.test.ts: 39 passed; npm run test:focused -- src/providers/runOwned.lifecycle.test.ts: 34 passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. runOwned is unreleased (refactor(application): own the finalization precedence in runOwned #10645) and its import path moves with it.
  • Real Hopper/Ghidra, browser, or OS coverage: macOS only, fixtures only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none. No process, path or authority change.

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 14, 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-15T09:34:37.175411Z b6ecdd2 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 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[High impact] The reviewed changes appear safe to merge; no actionable failure was established.

Summary

Moves runOwned into the provider layer and centralizes final cleanup across provider and bundle workflows.

  • One finalizer now decides how completed work, cancellation, and cleanup fit together.
  • TShark and sigrok finish their resource-backed results through the shared finalizer.
  • Apktool finalizes decode results through the shared owner.
  • ADB analysis and screen-capture results now use shared finalization.
  • Evidence-bundle reads and exports now finish through the shared finalizer.
  • LLDB tracing now uses the shared finalizer for completed traces and cleanup.
  • Signature inspection and snapshot binding now use shared finalization.
  • Ghidra profile results now pass through the shared finalizer.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Run work"] --> B["Record result and any commit"]
  B --> C["Close owned resources"]
  C --> D["Keep recorded failure or apply cancellation cutoff"]
  D --> E{"Cleanup confirmed?"}
  E -- Yes --> F["Return completed, cancelled, or failed outcome"]
  E -- No --> G["Return cleanup_incomplete with retained facts"]
  G -. Retry .-> H["Exact retained owners release"]
  H --> I["Clear their bound cleanup state"]
Loading

Reviews (6) · Last reviewed commit: "Merge origin/main into refactor/run-owne..." · Reviewed by Greptile

…hrough runOwned

runOwned moves to the provider layer so provider sites can use it without depending on application workflows. It gains a completed-value projection (partial) for values that are not themselves partial observations, an optional signal, and cleanupLeases that bind a close failure to the exact leases whose confirmed release resolves it.

ArtifactAnalysisResources.finish is removed; TShark and sigrok finalize through runOwned with the shared release as close. Apktool's hand-written release, cancellation and lease-group composition is replaced by runOwned. A failed primary now keeps a cancellation observed during final cleanup as a secondary failure, as the documented precedence requires.

A counted architecture guard refuses new hand-written completed-result abort reclassification outside runOwned.
* refactor(adb): finalize runtime-root work through runOwned

The ADB runtime-root finalizer re-derived the precedence by hand and kept its own cancellation-with-cleanup combiner. It now runs through runOwned: the work body maps snapshot failures, close releases the root lease and binds its own cleanup error, and partial projects the completed execution. A cancellation whose cleanup fails is now the shared cleanup composite with the cancellation as its primary, as runOwned produces for every other owner.

* refactor(providers): keep completed values as diagnostics in runOwned and migrate four finalizers (#10691)

* refactor(providers): keep completed values as diagnostics in runOwned and migrate signature, Ghidra, bundle and LLDB finalization

* test(providers): run the lifecycle scenarios over every runOwned adopter shape (#10707)

One table of testing.md lifecycle rows runs over partial, diagnostics, publishing and lease adopters, replacing the hand-written precedence cases it covers.
@morluto
morluto force-pushed the refactor/run-owned-partial-hook branch from 667d69b to 77dbbf7 Compare November 15, 2026 08:40
@morluto
morluto merged commit 26520bd into main Nov 15, 2026
7 checks passed
@morluto
morluto deleted the refactor/run-owned-partial-hook branch November 15, 2026 09:44
@morluto morluto added area: providers Provider and capability discovery, including provider proposal triage provider: apktool Analysis provider / engine: apktool labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: providers Provider and capability discovery, including provider proposal triage provider: apktool Analysis provider / engine: apktool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant