[PR #6302] [MERGED] fix(evidence): report contradictory unknown input as invalid input #7268

Closed
opened 2026-11-01 21:46:36 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/6302
Author: @Sriram-PR
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @morluto

Base: main ← Head: fix/unknown-invalid-input-classification


📝 Commits (1)

  • 3f3ce75 fix(evidence): report contradictory unknown input as invalid input

📊 Changes

2 files changed (+117 additions, -4 deletions)

View changed files

📝 src/application/investigation/EvidenceLedger.ts (+22 -4)
📝 tests/boundary/mcp/serverUnknownsMcp.test.ts (+95 -0)

📄 Description

Summary

record_unknown and update_unknown reject internally inconsistent input (a resolved status with resolution: null, or one Evidence ID in both the supporting and contradicting lists), but the rejection came back as execution_failure with "Evidence state changed before the update completed. Refresh the current state and try again." Nothing changed concurrently, and retrying the same call can never succeed. docs/mcp-contracts.md ("Error recovery and deadline ownership") says invalid input should be corrected, not retried unchanged.

Fixes #6106

Problem and expected behavior

Smallest trigger: record an unknown, then call update_unknown with its current expected_revision, status: "resolved" and resolution: null. On main the response is code: "execution_failure", the "Evidence state changed" message, and details: { reason: "invalid-transition" }, without the issue the schema already raises at resolution. Expected: invalid_request / invalid_input naming the rejected field and telling the caller to fix the request, while real revision conflicts stay revision_conflict.

Change and scope

  • EvidenceLedger.recordUnknown and updateUnknown wrapped every createResidualUnknown / updateResidualUnknown failure as UnknownRegistryError("invalid-transition"). Those functions fail by throwing the revision schema's ZodError, so a ZodError now goes through the existing requestInputError(operation, cause, input), the same helper the other workflows use for request validation. Its issues keep their paths, so resolution is named. Any other failure keeps the old invalid-transition error.
  • The fix is at the ledger, where the failure is first classified, so the error projection and presentation code don't change.
  • Not included: recordWithUnknown (automatic unknowns built by workflows, not caller input) still reports invalid-transition, and the "Evidence state changed" message for the remaining UnknownRegistryError reasons is unchanged.

Contribution scope: ordinary fix within existing boundaries; no scope decision needed.

Contract and boundary impact

  • Semantic owner and earliest changed stage: EvidenceLedger.recordUnknown / updateUnknown in src/application/investigation/EvidenceLedger.ts, where the residual-unknown revision is validated.
  • Contribution scope fit and linked maintainer decision: not applicable (bug fix, #6106).
  • CLI and MCP/tool-catalog contract: no schema change. record_unknown / update_unknown report schema-invalid unknowns as invalid_request with details.issues instead of execution_failure. Revision conflicts, missing unknowns and integrity failures are unchanged.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none; rejected writes still leave the ledger unchanged.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • 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.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/mcp/serverUnknownsMcp.test.ts adds reports contradictory unknown input as a correctable request, which goes through the MCP server: an overlapping supporting/contradicting record_unknown and a resolved-with-null-resolution update_unknown must be invalid_request / invalid_input with the schema issue (path: ["resolution"] for the update), the ledger must stay at revision 1, and a stale expected_revision must still be revision_conflict.
  • Base reproduction: the issue's test passes on main 002e1b68 against the built server (showing the wrong execution_failure). The new test fails on main's source with expected { code: 'execution_failure', ... } to match object { code: 'invalid_request', ... }; the 3 other tests in the file pass on both.
  • User-visible MCP output for the update case:
    main:   {"code":"execution_failure","category":"execution_failure","message":"Evidence state changed before the update completed. Refresh the current state and try again.","retryable":false,"details":{"reason":"invalid-transition"}}
    branch: {"code":"invalid_request","category":"invalid_input","message":"Analysis input is invalid. Check the arguments and try again.","retryable":false,"recovery":{"kind":"inspect_input_contract","operation":"update_unknown"},"details":{"operation":"update_unknown","issues":[{"path":["resolution"],"reason":"invalid_value","message":"Only resolved unknowns carry a resolution"}]}}
    
    (remediation omitted). The overlap case reports "path":[],"message":"Evidence cannot simultaneously support and contradict", since that check is on the whole revision rather than one field.
  • Remaining proof gaps: a schema failure on a field the ledger derives itself (identity, revision chain) would also be reported as invalid input; I couldn't find a caller input that reaches one.

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

  • npx vitest run tests/boundary/mcp/serverUnknownsMcp.test.ts: 4 passed (the new test fails on main's source)
  • npx vitest run over the 30 test files that reference unknowns, EvidenceLedger or UnknownRegistryError, plus tests/conformance/contracts/analysisErrorProjection.test.ts: 448 passed
  • npm run test:focused -- tests/boundary/mcp/toolSchemaValidity.test.ts tests/boundary/mcp/serverUnknownsMcp.test.ts: 19 passed
  • npm run check:fast: typecheck and lint passed
  • npm run verify:architecture-guards: passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Callers that matched execution_failure / invalid-transition for these inputs now get invalid_request with issues.
  • Real Hopper/Ghidra, browser, or OS coverage: Linux x64, Node 24.18.0; no provider involved.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none.

Author readiness

Human owner: @Sriram-PR

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/6302 **Author:** [@Sriram-PR](https://github.com/Sriram-PR) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/unknown-invalid-input-classification` --- ### 📝 Commits (1) - [`3f3ce75`](https://github.com/morluto/rea/commit/3f3ce75ac09a3e00406e4fae3f33702b7b50d62b) fix(evidence): report contradictory unknown input as invalid input ### 📊 Changes **2 files changed** (+117 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/application/investigation/EvidenceLedger.ts` (+22 -4) 📝 `tests/boundary/mcp/serverUnknownsMcp.test.ts` (+95 -0) </details> ### 📄 Description ## Summary `record_unknown` and `update_unknown` reject internally inconsistent input (a resolved status with `resolution: null`, or one Evidence ID in both the supporting and contradicting lists), but the rejection came back as `execution_failure` with "Evidence state changed before the update completed. Refresh the current state and try again." Nothing changed concurrently, and retrying the same call can never succeed. docs/mcp-contracts.md ("Error recovery and deadline ownership") says invalid input should be corrected, not retried unchanged. Fixes #6106 ## Problem and expected behavior Smallest trigger: record an unknown, then call `update_unknown` with its current `expected_revision`, `status: "resolved"` and `resolution: null`. On main the response is `code: "execution_failure"`, the "Evidence state changed" message, and `details: { reason: "invalid-transition" }`, without the issue the schema already raises at `resolution`. Expected: `invalid_request` / `invalid_input` naming the rejected field and telling the caller to fix the request, while real revision conflicts stay `revision_conflict`. ## Change and scope - `EvidenceLedger.recordUnknown` and `updateUnknown` wrapped every `createResidualUnknown` / `updateResidualUnknown` failure as `UnknownRegistryError("invalid-transition")`. Those functions fail by throwing the revision schema's `ZodError`, so a `ZodError` now goes through the existing `requestInputError(operation, cause, input)`, the same helper the other workflows use for request validation. Its issues keep their paths, so `resolution` is named. Any other failure keeps the old `invalid-transition` error. - The fix is at the ledger, where the failure is first classified, so the error projection and presentation code don't change. - Not included: `recordWithUnknown` (automatic unknowns built by workflows, not caller input) still reports `invalid-transition`, and the "Evidence state changed" message for the remaining `UnknownRegistryError` reasons is unchanged. Contribution scope: ordinary fix within existing boundaries; no scope decision needed. ## Contract and boundary impact - Semantic owner and earliest changed stage: `EvidenceLedger.recordUnknown` / `updateUnknown` in `src/application/investigation/EvidenceLedger.ts`, where the residual-unknown revision is validated. - Contribution scope fit and linked maintainer decision: not applicable (bug fix, #6106). - CLI and MCP/tool-catalog contract: no schema change. `record_unknown` / `update_unknown` report schema-invalid unknowns as `invalid_request` with `details.issues` instead of `execution_failure`. Revision conflicts, missing unknowns and integrity failures are unchanged. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: none; rejected writes still leave the ledger unchanged. - Target selection, authority, upstream behavior, and cleanup details: not applicable. - 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. - [x] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: `tests/boundary/mcp/serverUnknownsMcp.test.ts` adds `reports contradictory unknown input as a correctable request`, which goes through the MCP server: an overlapping supporting/contradicting `record_unknown` and a resolved-with-null-resolution `update_unknown` must be `invalid_request` / `invalid_input` with the schema issue (`path: ["resolution"]` for the update), the ledger must stay at revision 1, and a stale `expected_revision` must still be `revision_conflict`. - Base reproduction: the issue's test passes on main 002e1b68 against the built server (showing the wrong `execution_failure`). The new test fails on main's source with `expected { code: 'execution_failure', ... } to match object { code: 'invalid_request', ... }`; the 3 other tests in the file pass on both. - User-visible MCP output for the update case: ``` main: {"code":"execution_failure","category":"execution_failure","message":"Evidence state changed before the update completed. Refresh the current state and try again.","retryable":false,"details":{"reason":"invalid-transition"}} branch: {"code":"invalid_request","category":"invalid_input","message":"Analysis input is invalid. Check the arguments and try again.","retryable":false,"recovery":{"kind":"inspect_input_contract","operation":"update_unknown"},"details":{"operation":"update_unknown","issues":[{"path":["resolution"],"reason":"invalid_value","message":"Only resolved unknowns carry a resolution"}]}} ``` (remediation omitted). The overlap case reports `"path":[],"message":"Evidence cannot simultaneously support and contradict"`, since that check is on the whole revision rather than one field. - Remaining proof gaps: a schema failure on a field the ledger derives itself (identity, revision chain) would also be reported as invalid input; I couldn't find a caller input that reaches one. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npx vitest run tests/boundary/mcp/serverUnknownsMcp.test.ts`: 4 passed (the new test fails on main's source) - `npx vitest run` over the 30 test files that reference unknowns, `EvidenceLedger` or `UnknownRegistryError`, plus `tests/conformance/contracts/analysisErrorProjection.test.ts`: 448 passed - `npm run test:focused -- tests/boundary/mcp/toolSchemaValidity.test.ts tests/boundary/mcp/serverUnknownsMcp.test.ts`: 19 passed - `npm run check:fast`: typecheck and lint passed - `npm run verify:architecture-guards`: passed ## Compatibility, safety, and release - Breaking changes or migration steps: none. Callers that matched `execution_failure` / `invalid-transition` for these inputs now get `invalid_request` with issues. - Real Hopper/Ghidra, browser, or OS coverage: Linux x64, Node 24.18.0; no provider involved. - Package or release metadata impact: none. - Security, privacy, process, or containment review: none. ## Author readiness Human owner: @Sriram-PR - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:46:36 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#7268
No description provided.