fix(rectification): read credible_range as the still-valid union

Write and read used different range definitions at the same lead of 8, so a real separation always fail-closed the candidate projection.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jesse_Chen
2026-08-28 23:12:16 +08:00
parent 7de36e11d6
commit 53eb815c95
5 changed files with 278 additions and 68 deletions
@@ -12,7 +12,7 @@ import { probeFromEngine } from "../core/probes-from-engine.ts";
import { selectHighestGainProbe } from "../core/select-probe.ts";
import { askedEventProbeKeysFromLedgerEvidence } from "../core/candidate-contrast-packet.ts";
import { rankActive } from "../core/convergence-evaluator.ts";
import { rangeFromTimes } from "../core/credible-range.ts";
import { rangeFromTimes, unionStillValidRange } from "../core/credible-range.ts";
import { previousInferenceFromReceipt } from "../core/compose-receipt.ts";
import type { AnswerClass, ConflictProbe, InferenceState } from "../core/types.ts";
import {
@@ -135,22 +135,23 @@ export function authoritativeCandidateProjection<T extends CandidateSnapshotRow>
});
const representativeTime = active[0]?.time ?? null;
const activePoints = active.flatMap((item) => [item.cluster_range[0], item.time, item.cluster_range[1]]);
const authoritativeRange = rangeFromTimes(activePoints);
const activeSpan = rangeFromTimes(activePoints);
const stillValidRange = unionStillValidRange(inference.candidates);
const receiptRange = inference.credible_range;
const activeRangesValid = Boolean(authoritativeRange) && active.every((item) => {
const activeRangesValid = Boolean(activeSpan) && active.every((item) => {
const clusterRange = rangeFromTimes(item.cluster_range);
return clusterRange?.[0] === item.cluster_range[0]
&& clusterRange[1] === item.cluster_range[1]
&& rangeFromTimes([item.time])?.[0] === item.time
&& item.time >= clusterRange[0]
&& item.time <= clusterRange[1]
&& item.cluster_range[0] >= authoritativeRange![0]
&& item.cluster_range[1] <= authoritativeRange![1];
&& item.cluster_range[0] >= activeSpan![0]
&& item.cluster_range[1] <= activeSpan![1];
});
const receiptRangeMatches = Boolean(authoritativeRange && receiptRange)
const receiptRangeMatches = Boolean(stillValidRange && receiptRange)
&& receiptRange![0] <= receiptRange![1]
&& receiptRange![0] === authoritativeRange![0]
&& receiptRange![1] === authoritativeRange![1];
&& receiptRange![0] === stillValidRange![0]
&& receiptRange![1] === stillValidRange![1];
const consistent = active.length > 0
&& completeCandidateSet
&& candidates.length === active.length
@@ -165,7 +166,7 @@ export function authoritativeCandidateProjection<T extends CandidateSnapshotRow>
? active.map((item) => ({ id: item.id, time: item.time, score: item.posterior_score }))
: [],
representativeTime: consistent ? representativeTime : null,
credibleRange: consistent ? authoritativeRange : null,
credibleRange: consistent ? stillValidRange : null,
};
}