Skip to content

fix(cli): retain linked sources in function bundles - #8873

Merged
morluto merged 15 commits into
mainfrom
codex/function-source-bundle
Nov 7, 2026
Merged

morluto merged 15 commits into
mainfrom
codex/function-source-bundle

Conversation

@morluto

@morluto morluto commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Problem and outcome

rea function --evidence_output could report success while saving a parent that cited a missing Ghidra historical-analysis source. Capture the exact transitive source records while the one-shot session owns them, and include them in the requested bundle. A missing source fails before publication; missing transitive sources and finalization failures can report already captured records through the existing bounded recovery contract. Related: #8872.

The snapshot replay path captures from the authenticated snapshot bundle before returning. This PR builds on merged #8870 and incorporates the source-delivery changes already merged in #8585. Default output without an Evidence bundle remains outside this change (#8590).

Integration and review follow-up

Merged main through c928bb8d. The import conflict arose because main uses the shared closure resolver while this path needs the collector for partial sources; the merged file imports the collector and checker it actually uses, preserving the shared resolver for its other consumers. On Node 24.22.1, build:cached, check:fast, format:check, and five focused closure, replay, delivery, cleanup and limitations suites passed (84 tests, 2 skipped). Real-provider checks were not rerun for this merge.

Merged main through 2e2f981c. The merge combined two versions of the closure traversal; the merged owner retains one traversal that can either stop on failure or collect reachable partial sources. Removed the duplicate source-list merge in CLI delivery so each supplied source is processed once. The Ghidra verifier now emits PASS only after its owned cleanup succeeds; failed cleanup retains its resources and cannot be reported as success.

Node 24.22.1 focused source tests passed: closure, direct snapshot replay and CLI evidence delivery: 44 passed, 2 skipped; direct-analysis cleanup and limitations: 35 passed. build:cached (3 tasks, 1 cached), uncached check:fast and verifier syntax checks passed; full format:check passed after integrating upstream #9280. After building, the process-ownership test passed (1 test). Real Ghidra and a real cleanup failure were not rerun. Earlier real-provider observations below are historical and do not qualify the merged head.

Validation

  • After merging the updated fix: preserve source closure during snapshot replay #8870 base and main, check:fast passed and six source-closure, snapshot, CLI and MCP suites passed (123 tests, 2 skipped). The real Ghidra 12.1.4/JDK 21 verifier passed complete, summary and no-overwrite checks; target and project contents remained unchanged (target SHA-256 f2e37d3446e978b41a3111918a386065591eafa921a1e964626825acfb9e1d3f). Real provider cleanup failure was not exercised.

  • Review follow-up: the Ghidra verifier now uses the shared process owner and retains its temporary directory if process cleanup fails; nonzero-exit output is read from the owner snapshot. nativeVerifierCommandOwnership.test.ts passed (1 test), and node --check passed. The updated verifier passed with real Ghidra 12.1.4 and JDK 21 on macOS arm64: complete, summary, and no-overwrite checks passed, and target and project contents remained unchanged (target SHA-256 a1609877a6e080f31e04b7884bad21956299526e1774fea152d09a43bc168a12). Real provider cleanup failure was not exercised.

  • Disposable integration with capacity-recovery fix!: preserve results when source publication fails #8444 head 6fd318a99: the merge was clean, the combined build succeeded, and five focused one-shot, MCP, snapshot, CLI and failure-recovery suites passed (84 tests, 2 skipped). The real Ghidra function-bundle verifier passed on the combined build. These are combined-checkout controls, not standalone verification or a merged change.

  • Review follow-up: collection visits all reachable authenticated records even when one ancestor is missing; completed partial observations collect their sources before cleanup, and source capture precedes parent admission. Four focused suites passed (66 tests, 2 skipped). Cancellation-at-result and failed-parent-admission regressions failed against the previous PR head and pass now. The synthetic missing-ancestor/sibling control exercises the shared closure owner. The real Ghidra CLI verifier and check:fast passed after the change.

  • scripts/verify-real-ghidra-function-bundle.mjs builds a source fixture and saved project with a synthetic history report, then exercises the public CLI for complete, summary and no-overwrite delivery. It hashes every original project file and the target. On macOS arm64 with Ghidra 12.1.4/JDK 21 it failed on the pre-fix build for a missing linked record and passed on this prototype. The target was not executed. docs:check passed.

  • Real Ghidra no-overwrite control: function --detail summary --evidence_output against a pre-existing caller file exited 1 with invalid_request, left its contents unchanged, and returned a complete failure source closure containing the linked historical health record. This exercises one publication failure, not real provider cleanup failure.

  • Combined prototype source-free control: real Kuna 1.990 produced successful summary bundles for both function and trace on the same fixture, with no unresolved links. Neither result had a linked source, so this does not verify Kuna transitive-source capture. The target SHA-256 remained 510a23fc3c152175b9977130b3b1711d580e47d22a085cdee6a4e0c9dea2c51a.

  • Offline handoff on the combined prototype: after the real Ghidra CLI runs, a fresh target-free MCP server configured with unavailable Ghidra and Java imported both bundles in each schema profile. Exact-ID retrieval reproduced each linked source record; a trace-reference page matched the two retained rows and a function pseudocode view matched the retained text. Bundle hashes stayed unchanged. This tests offline consumption, not provider rediscovery or the standalone PRs in isolation.

  • Combined feat(native): page retained feature traces #8585 head 1fc86c45a with this PR in the integration prototype: five focused suites passed (64 tests, 2 skipped). Real Ghidra on the synthetic-history fixture saved both function and trace results with their linked health source; every link in the trace bundle resolved. This combined checkout is not standalone coverage for either PR.

  • Real Ghidra 12.1.4/JDK 21 on macOS arm64, using a disposable existing project with a synthetic historical report: both complete and summary rea function --evidence_output calls saved the parent and its linked health record. The same fixture reproduced the missing source before this change. A snapshot was selected, but the documentless function calls did not replay; this is a live-provider control, not a real replay test. Target and selected project descriptor hashes were unchanged; project contents were not independently hashed as a whole.

  • Three focused CLI, one-shot filesystem and failure-recovery suites passed (58 tests, 2 skipped), including cancellation, injected cleanup failure, and a missing transitive source. The missing-source regression failed before the partial-capture fix; afterward it preserved the available source, identified the missing ancestor, and wrote no bundle. A simulated-provider snapshot replay exported the parent and exact linked source without restarting the provider.

  • check:fast and git diff --check passed. Real provider cleanup failure, other platforms, and other commands/providers were not exercised. The existing no-output behavior is unchanged.

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.

@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

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

Summary

The PR keeps linked source records available until a requested function bundle is delivered.

  • Function bundles now keep the source records they link to.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Run analysis or replay snapshot"] --> B["Capture linked source records"]
  B --> C{"Every source available?"}
  C -->|Yes| D["Admit parent and finish cleanup"]
  C -->|No| E["Keep failure and available sources"]
  D --> F{"Analysis and cleanup succeeded?"}
  F -->|Yes| G["Publish requested bundle"]
  F -->|No| E
  E --> H["Return bounded recovery details"]
Loading

Reviews (7) · Last reviewed commit: "fix(cli): reconcile evidence closure wit..." · Reviewed by Greptile

Comment thread src/application/DirectAnalysis.ts Resolved
Comment thread src/application/DirectAnalysis.ts Resolved
@morluto
morluto marked this pull request as ready for review November 4, 2026 16:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 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-07T16:51:53.878217Z 73e7be5 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.

# Conflicts:
#	src/application/DirectAnalysis.ts
#	src/application/binary/AnalysisSnapshotCache.ts
#	src/application/binary/AnalysisSnapshotReplayBinding.ts
#	src/application/investigation/InvestigationEvidence.ts
#	tests/boundary/filesystem/directAnalysisSnapshotReplay.test.ts
#	tests/boundary/mcp/workflowSnapshotReplayMcp.test.ts
# Conflicts:
#	src/application/DirectAnalysis.ts
#	src/cli/analysisEvidenceDelivery.ts
#	tests/boundary/filesystem/directAnalysisSnapshotReplay.test.ts
Comment thread src/cli/analysisEvidenceDelivery.ts Resolved
Base automatically changed from codex/snapshot-source-closure to main November 7, 2026 08:22
@morluto
morluto enabled auto-merge (squash) November 7, 2026 18:17
@morluto
morluto merged commit 56fb521 into main Nov 7, 2026
51 of 53 checks passed
@morluto
morluto deleted the codex/function-source-bundle branch November 7, 2026 20:12
@morluto morluto added area: cli CLI adapter and one-shot commands bug Something isn't working labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant