Skip to content

fix(ghidra): declare observed function facets and call coverage - #3025

Closed
RishTheFish21 wants to merge 2 commits into
morluto:mainfrom
RishTheFish21:fix/ghidra-function-facet-coverage
Closed

RishTheFish21 wants to merge 2 commits into
morluto:mainfrom
RishTheFish21:fix/ghidra-function-facet-coverage

Conversation

@RishTheFish21

Copy link
Copy Markdown
Contributor

Summary

Fixes #2980. Since #2450 (b17487f4), compare_functions treats an empty facet without a coverage declaration as unknown, and the calls dimension also needs Evidence relationship coverage. The Ghidra bridge declared neither, so comparing a Ghidra analyze_function result with itself returned unknown instead of unchanged. That stopped every real-Ghidra lane at the native-value check (scripts/lib/native-value-e2e.mjs:238), before it reached the lane's own fixtures.

Problem and expected behavior

Before, on main: a Ghidra dossier compared with itself → status: "unknown", with comments ("Provider did not declare coverage for this empty facet") and calls ("Provider did not report relationship coverage") unresolved.

After: the same comparison is unchanged, because Ghidra declares the facets it actually observed and reports call coverage for analyze_function.

Change and scope

  • ReaGhidraBridge.java: function dossiers include facet_availability. Every facet is read from the complete function body (all instructions and comment types, reference-manager edges, call references, basic blocks), so each is declared available. pseudocode is declared unavailable when there's no decompiled body (external or bodyless procedures).
  • GhidraProviderCapabilities.ts: relationshipCoverageFor("analyze_function") returns the same complete coverage and diagnostic as procedure_callers/procedure_callees. The dossier's callers and callees come from the same getCallingFunctions/getCalledFunctions calls.
  • GhidraAnalysisProfile.ts: call_relationship_coverage bumped to -v2 and function_facet_availability: "declared-observed-facets-v1" added, so cached representations from before this change can't replay under the new contract (same approach as 5dfb9d05).
  • docs/mcp-contracts.md: documents Ghidra's declarations next to the existing IDA note.

Not changed: the comparison rules from #2450.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Ghidra bridge function dossier and Ghidra provider Evidence.
  • CLI and MCP/tool-catalog contract: no schema change. Ghidra now fills the existing optional facet_availability field, and analyze_function Evidence carries relationship_coverage.
  • Provider, bridge, target-format, or platform compatibility: Ghidra only, all platforms.
  • Evidence, artifact, provenance, or reconstruction contract: Ghidra analyze_function call relationships are now reported complete with the existing resolved-call-reference diagnostic, matching procedure_callers/procedure_callees. The profile version changes so older cached Evidence doesn't replay.
  • Process execution, authorization, cleanup, or containment impact: none.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: GhidraProvider.behavior.test.ts. A new test checks that analyze_function Evidence carries the complete call coverage with its diagnostic and keeps the declared facets; the profile assertion is updated for the new versions.
  • Base reproduction or other evidence: on main, npm run verify:ghidra:aarch64-jump-table fails at native-value-e2e.mjs:238 with the two unknown dimensions above (details in #ISSUE).
  • User-visible CLI/MCP output: compare_functions on two identical Ghidra dossiers returns unchanged.
  • Remaining proof gaps: real Ghidra on macOS arm64 only; Hopper not checked.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:focused -- src/ghidra/GhidraProvider.behavior.test.ts: passed
  • npm run check:fast: passed
  • npm run knip: passed
  • npm run docs:check: passed
  • npm run verify:ghidra:aarch64-jump-table on an Apple Silicon Mac (Ghidra 12.1.4, JDK 21), with no local skips: passed. On main it fails at the native-value self-comparison.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Cached Ghidra Evidence from the old profile is not replayed and is recomputed.
  • Real Hopper/Ghidra, browser, or OS coverage: real Ghidra on macOS arm64.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none; declares facts the bridge already collected.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • 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 Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T22:27:36.542051Z 8e3a097 PR opened
ℹ️ 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.

@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: 8e3a0975e8

ℹ️ 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 +60 to 63
operation === "analyze_function"
? {
status: "complete",
diagnostics: [resolvedCallReferenceLimitation],

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 Do not mark incomplete analyzed call sets complete

When the analyzed function contains a targetless indirect/computed call, this new branch emits status: "complete" even though analyzeFunctionObservation only serializes the resolved getCallingFunctions/getCalledFunctions sets and never fills unresolved_calls. Because functionCallCoverageLimitations ignores diagnostics on complete coverage, compare_functions can label that incomplete call set unchanged (and call-path consumers can treat it as exhaustive); emit the unresolved sites or downgrade this coverage instead.

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

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Adds function facet declarations to analysis output.

The PR should not merge until unresolved indirect calls remain unknown during function comparison.

Findings

  1. P1 Unresolved calls look unchanged ▶
  2. P2 Bridge changes escape the test ▶
Fix with agent prompt
### Issue 1
src/ghidra/GhidraProviderCapabilities.ts:undefined-60
With complete coverage for `analyze_function`, functions with unresolved indirect calls compare as `unchanged` in the `calls` dimension when their resolved callers and callees match. `analyzeFunctionObservation` never adds `unresolved_calls`, and `functionCallCoverageLimitations` ignores diagnostics for complete coverage.

Share the unresolved-call collector from `procedureReferences` with `analyze_function` and include those sites in the dossier. This keeps unresolved calls `unknown` while allowing fully observed functions to compare normally.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 2
src/ghidra/GhidraProvider.behavior.test.ts:698-704
The mock supplies `facet_availability`, so this test only checks that the provider preserves it. Removing the Java declaration would leave the test passing.

Add bridge-level coverage for an ordinary function and an external or bodyless function, including the unavailable `pseudocode` branch. That would catch regressions in the producer this PR changes.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

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

Summary

Ghidra function dossiers now declare which facets were observed. analyze_function also reports call relationship coverage.

  • Ghidra function comparisons can now recognize identical dossiers as unchanged.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Ghidra function observations] --> B[Dossier with facet_availability]
  B --> C[Provider adds relationship coverage]
  C --> D[Evidence]
  D --> E[Function comparison]
  P[Versioned analysis profile] --> K[Profile-specific cache key]
  K --> D
Loading

Reviews (2) · Last reviewed commit: "Merge upstream main" · Reviewed by Greptile

operation === "procedure_callers" || operation === "procedure_callees"
operation === "procedure_callers" ||
operation === "procedure_callees" ||
operation === "analyze_function"

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 Unresolved calls look unchanged

With complete coverage for analyze_function, functions with unresolved indirect calls compare as unchanged in the calls dimension when their resolved callers and callees match. analyzeFunctionObservation never adds unresolved_calls, and functionCallCoverageLimitations ignores diagnostics for complete coverage.

Share the unresolved-call collector from procedureReferences with analyze_function and include those sites in the dossier. This keeps unresolved calls unknown while allowing fully observed functions to compare normally.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/ghidra/GhidraProviderCapabilities.ts
Line: 60

Comment:
**Unresolved calls look unchanged**

With complete coverage for `analyze_function`, functions with unresolved indirect calls compare as `unchanged` in the `calls` dimension when their resolved callers and callees match. `analyzeFunctionObservation` never adds `unresolved_calls`, and `functionCallCoverageLimitations` ignores diagnostics for complete coverage.

Share the unresolved-call collector from `procedureReferences` with `analyze_function` and include those sites in the dossier. This keeps unresolved calls `unknown` while allowing fully observed functions to compare normally.

---

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

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +698 to +704
Promise.resolve(
ok({
value: { ...dossier, comments: [], facet_availability: facets },
limitations: [],
}),
),
close: () => Promise.resolve(ok(null)),

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.

P2 Bridge changes escape the test

The mock supplies facet_availability, so this test only checks that the provider preserves it. Removing the Java declaration would leave the test passing.

Add bridge-level coverage for an ordinary function and an external or bodyless function, including the unavailable pseudocode branch. That would catch regressions in the producer this PR changes.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/ghidra/GhidraProvider.behavior.test.ts
Line: 698-704

Comment:
**Bridge changes escape the test**

The mock supplies `facet_availability`, so this test only checks that the provider preserves it. Removing the Java declaration would leave the test passing.

Add bridge-level coverage for an ordinary function and an external or bodyless function, including the unavailable `pseudocode` branch. That would catch regressions in the producer this PR changes.

---

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

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working labels Oct 13, 2026
@kaoru0822-kitauji kaoru0822-kitauji added the ci-fix-wip Claimed by the CI-fix track label Oct 14, 2026
@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

CI-fix track: main already has a different implementation of this, so I didn't push a merge. #3002 (242e2b0, "preserve function facet and call coverage", closes #2951) makes the Ghidra bridge emit facet_availability through a facetAvailability helper, including an explicit unavailable-pseudocode reason. It carries observed call-set coverage through the parsed provider result and Evidence, uses a function_dossier_coverage: observed-facets-and-call-relationships-v1 profile commitment, and reads comments through Ghidra's indexed comment addresses. Merging this branch conflicts in all five files: functionFacetAvailability, relationshipCoverageFor for analyze_function, the function_facet_availability commitment, and comments(List<Instruction>), each against main's version. Resolving that means choosing between the two designs, and main already chose #3002's. If any behavior here is missing from main (for example analyze_function relationship coverage), please rebase and propose just that delta. The failing Source tests and shard jobs reflected main's state at the time.

@kaoru0822-kitauji kaoru0822-kitauji removed the ci-fix-wip Claimed by the CI-fix track label Oct 14, 2026
@RishTheFish21

Copy link
Copy Markdown
Contributor Author

Thanks @kaoru0822-kitauji. #3002 already covers this, and more completely, since it also keeps unresolved indirect calls out of "complete" coverage, which addresses the P1 both reviewers raised here. There's no remaining delta worth a rebase, so I'm closing this in favour of #3002.

@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks @RishTheFish21 for spotting that undeclared Ghidra facets made even a self-comparison look unknown. Main now carries explicit facet and call-coverage declarations through the provider result (main).

@morluto morluto added the provider: ghidra Analysis provider / engine: ghidra label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Real-Ghidra lanes fail: compare_functions of a Ghidra dossier with itself is unknown after #2450

3 participants