Skip to content

fix(native): retain value trace source evidence - #8384

Merged
morluto merged 6 commits into
mainfrom
codex/value-trace-source-evidence
Nov 4, 2026
Merged

morluto merged 6 commits into
mainfrom
codex/value-trace-source-evidence

Conversation

@morluto

@morluto morluto commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Summary

trace_native_values can cite function Evidence that is missing from the session bundle. Fixes #8282.

Problem and expected behavior

A Ghidra snapshot replay adds a replay caveat to the returned observation; reconstructing Evidence from that observation creates a different ID from the retained original. Kuna's live observations can have no session-issued ID at all. Consequently the IDs in trace procedures, nodes and edges can fail lookup even though the trace is otherwise usable.

Change and scope

  • A composed workflow can request retention for an observation it will cite. Reuse a session-issued ID; otherwise commit the observation and its producer sources to the bounded workflow Evidence ledger before returning its ID. This does not make live observations snapshot-cacheable.
  • The value trace requests that ownership and refuses an unowned ID. An adapter with no Evidence recorder receives a capability error rather than a completed trace with unresolved links.
  • Revise the value-trace workflow profile so older cached traces are not replayed as corrected results. Their historical Evidence remains available.
  • Add source-closure controls to the real Kuna and Ghidra verifier lanes; preserve existing trace and provider contracts.

Contract and boundary impact

  • Semantic owner: the workflow Evidence collector retains newly observed sources; the session retains its already-issued IDs. The trace consumes those IDs rather than deriving another identity.
  • Scope decision: ordinary Evidence and workflow correction; no new provider capability or target authority.
  • CLI/MCP: source IDs and Evidence links are now resolvable for the session-backed workflow. Fixed adapters without an Evidence recorder receive a typed refusal. No tool schema changes.
  • Snapshot: trace_native_values workflow revision 2 refuses replay of revision 1 results; existing source observations and historical records remain usable. Other workflow revisions do not change.
  • Process and target: no changes to target selection, provider execution, mutation authority, or cleanup. Tests run caller-provided Kuna/Ghidra on temporary source-owned fixtures.
  • Generated metadata and installation: none.

Expected effects when running the real verifier:

  • 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

On a source-owned unexecuted Mach-O, real Ghidra 12.1.4 MCP produced two missing warm source IDs on main; this branch resolved both. Real Kuna 1.986 produced one missing source ID per trace on main; this branch retained it, while preserving the explicit unavailable def-use unknown. In both cases, the corrected IDs also resolved after bundle export/import into a fresh target-free server. The target hash was unchanged.

The real-provider lanes now check that cited sources exist in the bundle. The MCP boundary tests exercise both advertised schema profiles and an adapter without a recorder; the workflow and snapshot tests cover live source ownership, replay identity, cancellation after source observation, and the older workflow revision. The full Ghidra host-native lane passed against the final runtime and edit/source-identity regression in an isolated checkout with separate verifier corrections for #8172 and #8380. It recorded 437 successful and 52 rejected boundary calls, and verified complete cleanup with no remaining descendants. The added verifier has formatting-only differences from the committed file. This was not a clean-tree lane. No Windows, Hopper, other Ghidra/Kuna versions or general corpus claim.

A further real-provider control used an owned, unexecuted arm64 Mach-O with an imported GOT slot and computed call (SHA-256 62da83d290c7b276d8708937930ef12f469f41782710fed439001c01c2747c76). On current main, the warm two-node Ghidra page cited one source ID absent from the imported bundle; this branch resolved it. Both unpaged and repeated Kuna traces cited one missing source ID on main and a resolvable source on this branch. Ghidra retained its static computed-call observation and max_depth limitation; Kuna retained its unavailable def-use unknown. Within each provider, normalized traces matched across revisions after excluding source Evidence IDs. Bundle imports preserved the original trace results and limitations; the target hash was unchanged. This is one static import-slot case, not evidence of runtime reachability or general paging completeness.

Kuna 1.988 and profile integration control

On head a20c186e, real Kuna 1.988 stdio MCP on a source-owned, unexecuted x86-64 ELF: cold and repeated trace_native_values calls in compact and full profiles retained each cited source, linked it at the top level, and resolved its summary; the unavailable def-use unknown remained. On separate #8651 head c103de06, the same cold and repeated Kuna calls returned a source ID absent from the session bundle and an empty top-level link list; following the ID returned evidence_integrity_mismatch. The target digest was unchanged (d3baa5cf385b68e3a8de02ed0884d9c9e781bd2c6b63201250635e4dc37655e8). Both versions were real-provider runs, but #8384's older release policy reported 1.988 as unverified. No offline-bundle control was run for this particular fixture.

Both branches independently assigned value traces revision 2 for different semantics. #8651's later head febd4ee70 instead adds value_flow_limitations: provider-attributed-v1 as a separate profile commitment. In an isolated cherry-pick combination, the intermediate commits removed this PR's revision 2; manually retaining revision 2 alongside the new commitment produced distinct combined identity. Real Ghidra carried the value-flow caveat, and real Kuna retained resolvable source IDs and its no-def-use unknown in both profiles. Preserve both fields when combining; this was an explicitly adjusted experimental checkout, not either PR's clean head.

Validation performed

  • Hosted CI on prior head 1e77ce796 failed one fixed-adapter registration test that still expected a value trace without a source Evidence owner. Updated that test to assert the intentional capability_unavailable result; focused MCP registration, value-trace failure, and schema/paging suites passed (12 tests). A later review narrowed the assertion to stable error code and operation; the registration and no-owner suites passed again (10 tests). The latest head is awaiting hosted CI.

  • npm run check:ci:fast and npm run docs:check — passed.

  • Focused source tests (workflow, value trace, native reader, snapshot cache) — 105 passed.

  • npm run test:focused -- tests/boundary/mcp/nativeValueTraceCompleteness.test.ts tests/boundary/mcp/nativeValueTraceFailures.test.ts — 5 passed.

  • npm run verify:kuna — passed with verified Kuna 1.986 on macOS arm64; both symbolized and stripped fixture lanes and cleanup completed.

  • Real Ghidra 12.1.4 and Kuna 1.986 stdio MCP cold/warm and fresh-server bundle controls — passed on macOS arm64; pre-change controls reproduced missing IDs.

  • Additional real Ghidra selected-project x86-64 Mach-O control: full traces, eight five-node pages, and depth/function/edge budget controls produced 13 records that survived export/import with unchanged normalized results. Across those traces, all 23 per-trace distinct source references resolved on this branch; 19 did not on main. The unmatched-argument finding itself remains [Bug] Native value trace does not locate recovered call arguments without bindings #8358. Target and selected-project hashes were unchanged.

  • Real Ghidra saved-snapshot controls, including an ambiguous historical binding — source IDs resolved live and after fresh-server import. These controls precede the final unowned-ID guard, which does not affect session-issued IDs.

  • Real Kuna 1.986 lifecycle control on the final head: an explicitly injected per-function watchdog stall produced a partial trace and retained unavailable pseudocode; after saving and reopening the snapshot with a separate clean cache, a fresh trace retained a distinct successful source. The snapshot had no replay entries for these live observations. Both historical and new pseudocode views resolved after export/import into a target-free server. Target and snapshot hashes were unchanged. This does not claim a natural failure rate or automatic cache repair.

  • Integration control: applied PR fix(cli): export source Evidence for native value traces #8297 head acdddaf on this branch in an isolated checkout, resolving its documentation conflict. Real Ghidra selected/fresh and Kuna CLI exports contained every cited source; fresh target-free MCP servers imported the bundles and resolved each source. Kuna summary also retained its source and no-def-use unknown. This is a combined-branch result, not a claim that fix(cli): export source Evidence for native value traces #8297 alone fixes source ownership. That historical combination omitted page_truncated and traversal from the summary. Current fix(cli): export source Evidence for native value traces #8297 head 095e8f394 includes both fields; a later standalone Ghidra CLI control is described below.

Review follow-up measurement

The success path now reuses the retained ID without rebuilding and hashing the full function Evidence; error branches still construct the partial observation. One before/after real Kuna run traced the same Brotli function and retrieved its source summary through stdio MCP. Cold (new provider caches) elapsed 2.185 / 2.188 s, sampled process-family CPU 2.14 / 2.13 s and peak RSS 462 / 464 MiB; warm (fresh server, reused respective cache) elapsed 1.301 / 1.305 s, CPU 1.45 / 1.45 s and peak RSS 391 / 390 MiB. Trace and source-view results matched excluding Evidence identifiers. These single runs do not establish a speedup; OS caches and scheduling were not controlled, and sampling can miss short-lived children.

Estimated o200k_base tokens for JSON-serialized SDK catalog, tool requests and replies were 130,950 / 130,928 cold and 130,933 / 130,887 warm; approximately 125,362 tokens were the full compact catalog in each. Evidence IDs and temporary paths varied. This is not measured model usage and excludes transport negotiation and host-specific tool filtering. The full Ghidra lane, including the added edit/source-identity regression, passed with the two separately described verifier corrections.

Combined-branch limitation

In an isolated combination with #8444, a real Kuna value trace completed before a test-injected zero-capacity ledger refused its function source. The current combined branches returned the refused source but omitted the completed trace. An uncommitted shared-recovery experiment returned both, but lacks a verified pre-construction allocation admission and is not part of this PR. A separate Ghidra zero-capacity control refused its source before trace completion. These are injected capacity controls, not observed production exhaustion. See #8425.

Compatibility, safety, and release

  • No compatibility shim. Older cached value traces are not reused under the new profile; exact historical records remain accessible.
  • Fixed in-memory adapters without a recorder no longer return a successful trace that cannot retain its cited sources. Session-backed CLI/MCP workflows retain the sources.
  • The CLI's separate source-bundle handoff is tracked in [Bug] trace-native-values CLI cannot save the source Evidence it cites #8285 and is not added here.

Current #8297 summary control

On #8297 head 095e8f394, real Ghidra 12.1.4 one-shot CLI on an unexecuted, source-built arm64 Mach-O distinguished two cases with --detail summary --evidence_output: a two-node page of a completed 12-node traversal reported page_truncated: true and traversal.status: complete; a five-node traversal capped by max_nodes reported page_truncated: false, traversal.status: truncated, and reason max_nodes. The exported capped trace retained the same fields. The uncapped and capped bundles respectively contained two and one linked analyze_function records, and every top-level trace link resolved within its bundle. This corrects the stale observation in the earlier combined-branch control; this standalone control does not establish source identity for a combination of the two PRs. Target SHA-256 b814f3cc4226f9fe3788dedf8a14f869ca45339c5f49fc2a7709eddd2df0bd6b remained unchanged.

Current combined CLI and offline handoff control

In an isolated, uncommitted combination of #8297 095e8f394 and this PR a20c186eb (one documentation conflict resolved by retaining both descriptions), real Kuna 1.989 and Ghidra 12.1.4 one-shot trace-native-values --detail summary --evidence_output succeeded on the unexecuted fixture described above. The Kuna trace retained its no-def-use unknown and one function source; the paged Ghidra trace retained two function sources, two procedures, two nodes and four edges. Every source ID cited by the page's procedures, nodes and edges was in its exported bundle; fresh target-free MCP servers opened each cited source via inspect_analysis_view in both compact and full input/output profiles. The focused CLI export tests passed in this combined checkout. The SHA-256 stayed unchanged. This covers one fresh-import CLI path, not snapshot replay, finalization cancellation, larger graphs, or either PR independently.

Current combined snapshot control

On the same isolated #8297 095e8f394 + this PR a20c186eb combination, an MCP session analyzed _evaluate and saved a snapshot before a fresh session reopened it and ran trace_native_values. Real Ghidra 12.1.4 reused the original function Evidence ID and reported snapshot replay; every source ID cited by the returned trace page was present in its exported bundle in both schema profiles. With real Kuna 1.989, the trace instead used a new resolvable function Evidence ID, kept its no-def-use unknown and reported no replay limitation; this control does not establish Kuna snapshot reuse. The same fixture digest was unchanged.

The one-shot CLI does not expose --snapshot: the equivalent command reports Unknown flag, including on a checkout based on current main. The MCP test therefore does not establish a CLI snapshot handoff. #8781 tracks that separate UX question.

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.

@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

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

Summary

The PR keeps the function Evidence cited by trace_native_values, reuses retained source IDs, and prevents older cached traces from replaying as corrected results.

  • Value traces use function source IDs that their session can retain.
  • Older cached value traces stay in history but no longer replay.
  • Import and stream setup edits leave behavior unchanged.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Observation[Function observation] --> Owned{Retained ID present?}
  Owned -->|Yes| Reuse[Reuse original ID]
  Owned -->|No| Collector[Keep function and producer Evidence]
  Collector --> ID[Return kept ID]
  Reuse --> Trace[Build trace with source IDs]
  ID --> Trace
  Trace --> Retain[Retain collected sources before success]
  Retain --> Accepted{Recorder accepts?}
  Accepted -->|Yes| Result[Publish linked trace]
  Accepted -->|No| Refusal[Return typed failure]
Loading

Reviews (5) · Last reviewed commit: "test(native): keep value-trace stop cove..." · Reviewed by Greptile

@morluto
morluto marked this pull request as ready for review November 1, 2026 03:55
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 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 ⚠️ Failed 2026-11-04T16:12:56.968312Z
We couldn’t complete this review. Comment @codex review to try again.
cc3f170 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.

@morluto

morluto commented Nov 1, 2026

Copy link
Copy Markdown
Owner Author

A real-Kuna, injected-zero-capacity integration control found an interaction with #8444: after the combined branches complete trace_native_values, failure to publish its source returns the unretained function dossier but loses the completed trace. With #8444 alone, the corresponding capacity failure returns the completed trace. Both full and compact MCP schema profiles reproduced this through production registration; the target was not executed. Details, normal-capacity control, and limitations: #8425 (comment).

This is a source-publication ownership and resource-boundary follow-up; it does not invalidate the normal-capacity source-closure fix. A fix needs to keep the failed source and completed workflow distinct and report actual retention/closure, while honoring headroom and transport bounds.

…rce-evidence

# Conflicts:
#	docs/native-investigation.md
Main's stop and continuation cases now meet the trace's evidence-owner
precondition: direct calls supply a source id, and a completed MCP trace
runs in a session that can retain it.
@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 merged commit 52bca6d into main Nov 4, 2026
48 checks passed
@morluto
morluto deleted the codex/value-trace-source-evidence branch November 4, 2026 16:19
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working labels 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Cached native value traces cite source Evidence absent from exported bundles

2 participants