Skip to content

fix: expose authenticated records refused by the evidence ledger - #8426

Merged
morluto merged 4 commits into
codex/context-capacity-recoveryfrom
codex/evidence-retention-recovery
Nov 1, 2026
Merged

morluto merged 4 commits into
codex/context-capacity-recoveryfrom
codex/evidence-retention-recovery

Conversation

@morluto

@morluto morluto commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

A provider can complete a direct operation, then REA's Evidence ledger can refuse the record because its retained-representation allowance is full. Today the caller receives only the capacity error and loses the completed observation. Return an authenticated record inline as details.partial_observation: {kind: "unretained-evidence", evidence: ...} when retention admission fails. The error remains a failure, and the ID is not a session reference.

Partially addresses #8425; a source-record admission failure can still discard the completed primary observation, as described below. This draft is stacked on #8424, which is stacked on #8419 and #8417; integrate those parents first. It does not implement the composed Evidence handoff in #8364.

The ledger attaches a record only after authentication succeeds and before failed admission could mutate the ledger. This also covers a capacity refusal of an atomic derived-Evidence and Unknown write: if the Evidence already exists, the error returns its retained reference; otherwise it returns the authenticated record inline. The refused write commits neither new Evidence nor an Unknown revision. Authentication or headroom failures do not claim an authenticated record. If the inline observation cannot fit within MCP delivery limits, the original retention error instead reports partial_observation_omitted and its response constraint when the remaining error fits. The oversized-error fallback excludes a second unretained partial from its nested retention error so it cannot recursively overflow. For an oversized context reply, REA omits unretained facet observations in estimated size order until the reply fits, marks each omission, and keeps successful facets and smaller partials. If the remaining context still cannot fit, recovery directs the caller to discover and export retained Evidence through session tools, while stating that some facets may not have been retained. No uncommitted retained-evidence reference is offered.

Validation

  • At 050362143, a controlled SDK MCP handoff with synthetic function dossiers exported the retained bundle after atomic refusal, closed the session, and imported it into a fresh target-free session. An already-retained comparison worked by reference with find_changed_behavior. An unretained comparison was rejected by reference, then worked inline with its retained sources; both the default input-element allowance and an explicit REA_MCP_MAX_INPUT_ELEMENTS=65536 worked for this fixture. Two cases passed under each setting; larger inline records may still exceed the limit. No provider was launched.
  • Follow-up at 050362143: 13 focused MCP tests passed, including four comparison/atomic-capacity cases across compact and full output profiles, with and without the same comparison preexisting; the earlier unretained-result regression failed on the prior head in both profiles. The error projection validates, retained source records remain available, and no Unknown revision is committed. 100 source tests, check:fast, docs:check and git diff --check passed.
  • Real Ghidra 12.1.4/JDK 21: captured two function dossiers from an owned static Mach-O, then used retained references in a fresh target-free MCP session with a deliberately limited investigation. The atomic write returned the complete authenticated but unretained comparison and left zero Unknown revisions. The target hash stayed unchanged and it was not executed. The limit was injected; this does not establish default-capacity exhaustion.
  • Real Kuna 1.986 on macOS arm64: with a zero-byte injected Evidence allowance, an instrumented admitted execution for direct MCP address_name returned _main; the caller received the same provider/profile/limitations as inline unretained Evidence and the ledger remained empty. A normal-allowance control returned and retained the direct Evidence.
  • Real Ghidra 12.1.4/JDK 21: with a 20,000-byte injected allowance, the context name and its record remained available while the procedure capacity error included the authenticated but unretained procedure observation. The direct and facet errors matched. A normal-allowance control succeeded. The MCP server and SDK used in-memory transport; the source-owned arm64 Mach-O was not executed and its digest stayed unchanged. The allowances are test injection, not reproduction of production-default exhaustion.
  • Follow-up at 458674fba: 13 focused MCP tests and check:fast passed. The session-only catalog advertises neither direct address_name nor other direct calls; the recovery test follows the advertised summary and export tools, checks the complete oversized record when retained, and verifies the empty result when no profile permitted retention. The prior guidance fails this test.
  • 35 focused MCP tests passed on the preceding head, covering inline unretained Evidence under compact/full profiles, the public bundle's empty record list, one and two simulated 6 MiB unretained context facets with smaller siblings, oversized omission and bounded fallback, and existing partial/oversized error handling. The original context overflow reproduced on the prior draft under both profiles; three direct-retention cases failed on its parent. Removing the fallback projection separately reproduced an empty MCP error.
  • 115 source tests across context composition, retention, error projection and server passed, including invalid Evidence and authentication-headroom refusals without an authenticated partial.
  • npm run check:fast, npm run docs:check, formatting and git diff --check passed. Ajv 2020 accepted the real Ghidra context result against both parent-advertised output profiles; the error details schema permits the additional observation.

Limits and tradeoffs

When admission fails for a provider source before the primary Evidence is recorded, the inline partial is the source and the completed primary result can still be lost. In a real selected-project Ghidra test with synthetic project-history metadata and an injected zero-byte allowance, the provider resolved audit_checkpoint_evaluate while the response contained only the unretained health source. A normal-allowance control retained both; REA did not modify the test project or execute the target. A synthetic-provider test also showed that a source and primary may have the same operation and parameters, so those fields cannot establish the partial's role. In a separate synthetic three-source MCP test, the first source was retained, the second refused, and the third unattempted; a retry failed again at the second without duplicating the first. This source-stage gap remains in #8425 and has implications for #8364.

A controlled context test on this head also combined a source-retention refusal with a separate facet cleanup failure: the aggregate preserved the cleanup owner but lost the refused source partial. The unpublished completed-primary prototype still lost both the source and primary in that sequence. This used a simulated provider and injected zero-byte allowance; it is not a real-provider cleanup reproduction. See the issue comment.

A public compare_functions MCP control also reproduced completed-result loss at a separate composed-workflow boundary: with a zero-byte injected allowance and two synthetic inline dossiers, the producer computed the comparison, but source recording returned the refused input dossier and discarded the comparison. At normal capacity the same input returned the identical computed comparison and retained both sources. This is not a real-provider or default-capacity reproduction. See the issue comment. A fix limited to BinarySession would not cover this path. Before the atomic follow-up, another controlled case retained both sources but lost the comparison when the comparison-and-Unknown write was refused. The current change preserves that authenticated result, without claiming that an uncommitted Unknown was saved.

The fix applies to single-record and atomic Evidence/Unknown capacity admission after authentication. It does not cover bundle import, failures before authentication or capacity admission, another recorder's failures, SDK-suppressed cancellation replies, or aggregate handoff. A complete inline unretained record has no dedicated public record-import workflow; #8427 discusses fresh-session handoff without manually assembling a canonical bundle. An observation too large for MCP remains unretained and is explicitly reported as omitted. Context omission uses estimated representation size for ordering, so unusual escaping can cause more records to be omitted than an optimal wire-size ordering; at most five facet alternatives are tried. If the remaining context or reduced error is still too large, the applicable delivery recovery applies. Windows, real cleanup failures, default-heap exhaustion, autonomous agents and process-family CPU/memory impact are unverified.

For the single real fixtures, minified o200k_base payloads grew from 130 to 730 tokens for the Kuna direct error and 334 to 1,309 for the Ghidra context result. These are JSON counts, not latency, CPU, memory, or agent-task measurements; full Evidence is carried inline when it fits.

A warm test-suite measurement of the same four controlled overflow cases sampled 7.65 seconds, at least 9.83 CPU seconds and 1,867,664 KiB summed process-family RSS with the full catalog; limiting that focused test to the session catalog sampled 3.90 seconds, at least 5.09 CPU seconds and 1,263,776 KiB. One run each included npm, Turbo, Vitest startup and all four cases; sampled RSS includes shared pages and CPU may miss short-lived processes. A marker field name changed between runs, and cold runs and provider costs were not measured. The two-large structured response was 1,121 o200k_base tokens, excluding the tool catalog. These are test-harness observations, not production or agent-task benchmarks.

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 Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The reviewed changes appear safe to merge within the stated scope.

Summary

Returns authenticated Evidence inline when retention fails. The latest change extends this recovery to atomic Evidence-and-Unknown writes and returns a saved ID when the Evidence already exists.

  • Capacity errors can carry authenticated records that the ledger refused to keep.
  • MCP replies keep useful context when unretained records exceed delivery limits.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Completed Evidence and proposed unknown"] --> B["Authenticate records and check links"]
  B -->|Invalid| C["Return error without a partial"]
  B -->|Valid| D{"Retention fits?"}
  D -->|Yes| E["Commit the complete write"]
  D -->|No| F{"Evidence already saved?"}
  F -->|Yes| G["Return capacity error with saved ID"]
  F -->|No| H{"Inline record fits MCP?"}
  H -->|Yes| I["Return capacity error with Evidence"]
  H -->|No| J["Return omission details or delivery recovery"]
Loading

Reviews (4) · Last reviewed commit: "fix(evidence): preserve completed atomic..." · Reviewed by Greptile

Comment thread src/server/ToolResultDelivery.ts Resolved
@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 ✅ Completed 2026-11-01T04:48:46.045257Z 0503621 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 changed the title fix: preserve completed evidence on retention refusal fix: expose authenticated records refused by the evidence ledger Nov 1, 2026
@morluto
morluto merged commit 2f59bc0 into codex/context-capacity-recovery Nov 1, 2026
1 check passed
@morluto
morluto deleted the codex/evidence-retention-recovery branch November 1, 2026 09:23
morluto added a commit that referenced this pull request Nov 7, 2026
* fix: retain address context cleanup failures

* fix!: preserve address context input errors

BREAKING CHANGE: Strict clients that cached the previous full inspect_address_context output schema must refresh tools/list and accept the typed error field on unavailable facets.

* test: use session contract for address context

* fix!: preserve address context resource recovery

BREAKING CHANGE: Clients validating unavailable context facets against a cached strict full output schema must refresh tools/list to accept resource_constraint errors.

* fix: expose authenticated records refused by the evidence ledger (#8426)

* fix: preserve completed evidence on retention refusal

* fix: preserve context when unretained evidence exceeds delivery limits

* fix(mcp): recover oversized context from session evidence

* fix(evidence): preserve completed atomic write results

* fix(cli): preserve caller path in unretained evidence

* style(test): format CLI help default annotations (#9280)

---------

Co-authored-by: Cursor Agent <[email protected]>
morluto added a commit that referenced this pull request Nov 8, 2026
* fix: retain address context cleanup failures

* fix!: preserve address context input errors

BREAKING CHANGE: Strict clients that cached the previous full inspect_address_context output schema must refresh tools/list and accept the typed error field on unavailable facets.

* test: use session contract for address context

* fix!: preserve address context resource recovery

BREAKING CHANGE: Clients validating unavailable context facets against a cached strict full output schema must refresh tools/list to accept resource_constraint errors.

* fix: expose authenticated records refused by the evidence ledger (#8426)

* fix: preserve completed evidence on retention refusal

* fix: preserve context when unretained evidence exceeds delivery limits

* fix(mcp): recover oversized context from session evidence

* fix(evidence): preserve completed atomic write results

* fix: retain completed results when source publication fails

* test: cover bounded recovery with unknown retention

* fix(evidence): preserve recovery identity and finalization facts

* fix(evidence): clarify retention of omitted observations

* test(evidence): compare omission guidance with its owner

* fix(evidence): preserve completed composed workflows

* fix(evidence): clarify unretained recovery export

* test(evidence): cover mixed recovery guidance

* fix(evidence): preserve caller scope in secondary failures

* refactor(evidence): remove superseded cleanup projection

* test(evidence): align recovery checks with owners

* fix: preserve cleanup on partial recovery limits

* test: use owners for diagnostic wording

* fix: admit completed analysis before evidence construction

* fix: preserve selected paths when reusing evidence

* fix(cli): preserve caller path in unretained evidence

* fix(evidence): preserve recovery metadata and admission bounds

* refactor: consolidate evidence closure imports

* style(test): format CLI help default annotations (#9280)

* test(mcp): keep recovery checks focused on contract facts

* fix(evidence): preserve feature trace replay revision

* test: align evidence recovery checks with ownership

* test: align partial recovery and cleanup diagnostics

* fix(evidence): preserve nested partials during cleanup

* fix(evidence): respect outer recovery ownership

* fix(capture): discard rejected nested observations

* test(frida): assert inline evidence recovery

---------

Co-authored-by: Cursor Agent <[email protected]>
@morluto morluto added area: evidence Evidence, artifacts, and reconstruction 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: evidence Evidence, artifacts, and reconstruction bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant