[PR #1073] [MERGED] fix(evidence): name the failed constraint when a bundle is rejected #2622

Closed
opened 2026-10-17 21:08:19 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/1073
Author: @kaoru0822-kitauji
Created: 10/8/2026
Status: ✅ Merged
Merged: 10/8/2026
Merged by: @kaoru0822-kitauji

Base: main ← Head: fix/evidence-bundle-diagnostics


📝 Commits (2)

  • cf96ceb fix(evidence): name the failed constraint when a bundle is rejected
  • 38bbb65 fix(evidence): require a complete record before the single-record hint

📊 Changes

6 files changed (+147 additions, -8 deletions)

View changed files

📝 src/application/EvidenceBundleFiles.ts (+19 -6)
📝 src/application/investigation/EvidenceLedger.ts (+2 -0)
📝 src/domain/evidenceBundle.ts (+28 -0)
📝 src/domain/evidenceErrors.ts (+13 -1)
📝 tests/boundary/filesystem/evidenceBundleFiles.test.ts (+49 -1)
📝 tests/boundary/mcp/bundleComparisonMcp.test.ts (+36 -0)

📄 Description

Problem

rea evidence-import, evidence-export, compare, and the MCP import_evidence_bundle and compare_bundles tools give every rejected bundle the same message, with no details:

{"code":"evidence_integrity_mismatch","category":"integrity_mismatch","message":"Evidence is invalid or has changed. Recreate or re-import it, then try again."}

This includes the most common case: a single Evidence record. That is exactly what every CLI command prints. Running rea compare a.json b.json on two command results, or rea evidence-import result.json, looks like tampering even though the record is canonical and intact. (I checked: its semantic ID verifies, and wrapped in a bundle it parses.) A caller can't tell a wrong document shape from a schema problem or a real identity mismatch.

Change

  • Add describeEvidenceBundleFailure to the domain. It returns one of three messages:
    • Single record: "Expected an Evidence bundle with records and manifest arrays, but this JSON is one Evidence record (ev_…). Export a session bundle with the MCP export_evidence_bundle tool and supply that file."
    • Schema mismatch: the location and message of the first Zod issue, plus how many more issues there are.
    • Other failures: the thrown constraint message, such as "Evidence semantic identifier does not match its record", with recovery advice.
  • A process-capture record that fails parseProcessCapture is now reported with its evidence_id. Before, a schema path inside normalized_result was reported as if it were a bundle path.
  • EvidenceIntegrityError accepts the userMessage option, like AnalysisCapabilityUnavailableError. EvidenceBundleFiles.readEvidenceBundle and EvidenceLedger.import use it.
  • The error code, category and retryable stay the same, and EvidenceReferenceError messages are unchanged. Only the message text becomes specific.

No schemas change.

Verification

  • npm run test:focused -- tests/boundary/filesystem/evidenceBundleFiles.test.ts tests/boundary/mcp/bundleComparisonMcp.test.ts: the new assertions cover a single record, a schema mismatch and a tampered record, through both the filesystem reader and MCP compare_bundles. All 3 fail with the source change reverted.
  • All 32 test files that reference Evidence bundles, the ledger or EvidenceIntegrityError: 270 passed.
  • npm run check:fast
  • rea evidence-import and rea compare on a real inspect-asset-catalog result now return the single-record message.

No real Hopper or Ghidra verification was run, because this change does not touch those providers.

🤖 Generated with Claude Code


🔄 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/1073 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/8/2026 **Status:** ✅ Merged **Merged:** 10/8/2026 **Merged by:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Base:** `main` ← **Head:** `fix/evidence-bundle-diagnostics` --- ### 📝 Commits (2) - [`cf96ceb`](https://github.com/morluto/rea/commit/cf96ceb2119f52f61a621d2a790b7c8804c65595) fix(evidence): name the failed constraint when a bundle is rejected - [`38bbb65`](https://github.com/morluto/rea/commit/38bbb656da2659088e30a1ca3e4434b2f65bab32) fix(evidence): require a complete record before the single-record hint ### 📊 Changes **6 files changed** (+147 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `src/application/EvidenceBundleFiles.ts` (+19 -6) 📝 `src/application/investigation/EvidenceLedger.ts` (+2 -0) 📝 `src/domain/evidenceBundle.ts` (+28 -0) 📝 `src/domain/evidenceErrors.ts` (+13 -1) 📝 `tests/boundary/filesystem/evidenceBundleFiles.test.ts` (+49 -1) 📝 `tests/boundary/mcp/bundleComparisonMcp.test.ts` (+36 -0) </details> ### 📄 Description ## Problem `rea evidence-import`, `evidence-export`, `compare`, and the MCP `import_evidence_bundle` and `compare_bundles` tools give every rejected bundle the same message, with no details: ```json {"code":"evidence_integrity_mismatch","category":"integrity_mismatch","message":"Evidence is invalid or has changed. Recreate or re-import it, then try again."} ``` This includes the most common case: a single Evidence record. That is exactly what every CLI command prints. Running `rea compare a.json b.json` on two command results, or `rea evidence-import result.json`, looks like tampering even though the record is canonical and intact. (I checked: its semantic ID verifies, and wrapped in a bundle it parses.) A caller can't tell a wrong document shape from a schema problem or a real identity mismatch. ## Change - Add `describeEvidenceBundleFailure` to the domain. It returns one of three messages: - **Single record:** "Expected an Evidence bundle with records and manifest arrays, but this JSON is one Evidence record (`ev_…`). Export a session bundle with the MCP export_evidence_bundle tool and supply that file." - **Schema mismatch:** the location and message of the first Zod issue, plus how many more issues there are. - **Other failures:** the thrown constraint message, such as "Evidence semantic identifier does not match its record", with recovery advice. - A process-capture record that fails `parseProcessCapture` is now reported with its `evidence_id`. Before, a schema path inside `normalized_result` was reported as if it were a bundle path. - `EvidenceIntegrityError` accepts the `userMessage` option, like `AnalysisCapabilityUnavailableError`. `EvidenceBundleFiles.readEvidenceBundle` and `EvidenceLedger.import` use it. - The error code, category and `retryable` stay the same, and `EvidenceReferenceError` messages are unchanged. Only the `message` text becomes specific. No schemas change. ## Verification - `npm run test:focused -- tests/boundary/filesystem/evidenceBundleFiles.test.ts tests/boundary/mcp/bundleComparisonMcp.test.ts`: the new assertions cover a single record, a schema mismatch and a tampered record, through both the filesystem reader and MCP `compare_bundles`. All 3 fail with the source change reverted. - All 32 test files that reference Evidence bundles, the ledger or `EvidenceIntegrityError`: 270 passed. - `npm run check:fast` - `rea evidence-import` and `rea compare` on a real `inspect-asset-catalog` result now return the single-record message. No real Hopper or Ghidra verification was run, because this change does not touch those providers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-17 21:08:19 +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#2622
No description provided.