Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(reconstruction): merge repeated observations into one generated obligation (#3524)

Kaoru08220f966e2b44ca
diff --git a/src/application/ReconstructionObligationCandidates.ts b/src/application/ReconstructionObligationCandidates.ts
index a269829dc..5cc9436b1 100644
--- a/src/application/ReconstructionObligationCandidates.ts
+++ b/src/application/ReconstructionObligationCandidates.ts
@@ -413,7 +413,22 @@ const addCandidate = (
...current.authority_references,
...candidate.authority_references,
]),
- definitionCount: current.definitionCount + candidate.definitionCount,
+ // Each observation keeps its own unresolved authority and next steps.
+ unavailable_authority: uniqueBy(
+ [...current.unavailable_authority, ...candidate.unavailable_authority],
+ (item) => item,
+ ),
+ required_next_evidence: uniqueBy(
+ [...current.required_next_evidence, ...candidate.required_next_evidence],
+ (item) => item,
+ ),
+ // A generated ID digests its derivation key, so two generated candidates
+ // with one ID are the same claim seen by several records. Only another
+ // reviewed definition can introduce a competing definition.
+ definitionCount:
+ current.origin === "generated" && candidate.origin === "generated"
+ ? current.definitionCount
+ : current.definitionCount + candidate.definitionCount,
});
};
diff --git a/src/application/ReconstructionObligationLedger.closure.test.ts b/src/application/ReconstructionObligationLedger.closure.test.ts
index 86dc84474..34249ac1a 100644
--- a/src/application/ReconstructionObligationLedger.closure.test.ts
+++ b/src/application/ReconstructionObligationLedger.closure.test.ts
@@ -31,6 +31,49 @@ describe("reconstruction obligation ledger", () => {
expect(first.status).toBe("open");
});
+ it("merges repeated captures of one process scenario into one definition", () => {
+ const first = processEvidence();
+ const second = processEvidence({
+ residual_unknowns: [{ scope: "network", reason: "Second run only." }],
+ });
+ expect(second.evidence_id).not.toBe(first.evidence_id);
+ const single = build(request([first]));
+ const repeated = build(request([first, second]));
+
+ const obligation = repeated.obligations[0];
+ expect(repeated.obligations).toHaveLength(1);
+ expect(obligation?.obligation_id).toBe(
+ single.obligations[0]?.obligation_id,
+ );
+ expect(obligation?.diagnostics.map(({ code }) => code)).not.toContain(
+ "duplicate-definition",
+ );
+ expect(
+ obligation?.authority_references.map(({ evidence_id: id }) => id).sort(),
+ ).toEqual([first.evidence_id, second.evidence_id].sort());
+ // The second capture's own uncertainty stays visible after the merge.
+ expect(obligation?.unavailable_authority).toContain(
+ "network: Second run only.",
+ );
+ });
+
+ it("still reports a reviewed definition that reuses a generated ID", () => {
+ const capture = processEvidence();
+ const generated = build(request([capture])).obligations[0];
+ if (generated === undefined) throw new Error("Expected process obligation");
+ const ledger = build(
+ request([capture], {
+ reviewed_obligations: [
+ reviewedObligation(generated.obligation_id, capture.evidence_id),
+ ],
+ }),
+ );
+
+ expect(
+ ledger.obligations[0]?.diagnostics.map(({ code }) => code),
+ ).toContain("duplicate-definition");
+ });
+
it("does not let green unit evidence close a packaged-process obligation", () => {
const capture = processEvidence();
const proof = proofEvidence("green-unit");
diff --git a/src/application/ReconstructionObligationLedger.fixture.ts b/src/application/ReconstructionObligationLedger.fixture.ts
index 19a319779..ba1578281 100644
--- a/src/application/ReconstructionObligationLedger.fixture.ts
+++ b/src/application/ReconstructionObligationLedger.fixture.ts
@@ -14,7 +14,10 @@ import {
type ReviewedReconstructionObligation,
} from "../domain/reconstructionObligationLedgerSchemas.js";
-import { processCaptureSchema } from "../domain/process/processCapture.js";
+import {
+ processCaptureSchema,
+ type UnverifiedProcessCapture,
+} from "../domain/process/processCapture.js";
/** Build controlled fixture Evidence used by reconstruction-ledger scenarios. */
export const proofEvidence = (id: string) =>
createEvidence(
@@ -31,13 +34,18 @@ export const proofEvidence = (id: string) =>
);
/** Use the canonical empty process capture as a controlled Evidence example. */
-export const processEvidence = () =>
+export const processEvidence = (
+ overrides: Partial<UnverifiedProcessCapture> = {},
+) =>
createEvidence(undefined, PROCESS_PROVIDER, {
predicateType: "rea.process-capture",
operation: "capture_process_scenario",
parameters: {},
result: jsonValueSchema.parse(
- processCaptureSchema.parse(EMPTY_PROCESS_CAPTURE_EXAMPLE),
+ processCaptureSchema.parse({
+ ...EMPTY_PROCESS_CAPTURE_EXAMPLE,
+ ...overrides,
+ }),
),
confidence: "observed",
authority: "controlled-replay",