fix(rectification): stop unwritten-evidence claims and same-cluster dasha false conflicts (BUG-635–640)
Independent Staging Quality Gate / validate (push) Has been cancelled
Independent Staging Quality Gate / publish (push) Has been cancelled

Host only says 记下了 after a real write; Mastra schema rejections fail closed. Ledger year keys no longer drop quality probes, dual-dasha agreement is per cluster, width uses cluster span, and public house tables follow the inference minute.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jesse_Chen
2026-09-10 17:38:37 +08:00
co-authored by Cursor
parent 301827ad59
commit a998b6ec53
38 changed files with 1437 additions and 124 deletions
@@ -3,8 +3,14 @@ import { readFileSync } from "node:fs";
import test from "node:test";
import {
batchResultFromToolChunk,
composeHostFallbackNarration,
DEFAULT_RETRY_CONSTRAINT,
isToolInputRejection,
publicWriteToolCompleted,
retryConstraintForAttempt,
turnExpectsEvidenceWrite,
UNWRITTEN_EVIDENCE_RETRY_CONSTRAINT,
} from "../src/lib/rectification-agentic/v9/host-fallback.ts";
test("host fallback recap uses only batch return lines", () => {
@@ -45,6 +51,32 @@ test("write-tool completion is limited to batch, set-focus and compare", () => {
assert.equal(publicWriteToolCompleted(failedBatch), false);
});
test("schema rejection envelopes are not treated as batch recaps or write completion", () => {
const envelope = {
error: true,
message: "Tool input validation failed",
validationErrors: { errors: [], fields: { kind: "debt" } },
};
assert.equal(isToolInputRejection(envelope), true);
assert.equal(composeHostFallbackNarration(envelope), null);
assert.equal(batchResultFromToolChunk({
type: "tool-result",
payload: { toolName: "rectification-record-evidence-batch", result: envelope },
}), null);
assert.equal(isToolInputRejection({ error: true, message: "no fields" }), false);
});
test("year fallback is gone; only explicit evidence expectedWrite triggers the guard", () => {
assert.equal(turnExpectsEvidenceWrite("opening", "evidence"), false);
assert.equal(turnExpectsEvidenceWrite("read_only", "none"), false);
assert.equal(turnExpectsEvidenceWrite("evidence", "evidence"), true);
assert.equal(turnExpectsEvidenceWrite("evidence", "none"), false);
assert.equal(turnExpectsEvidenceWrite("evidence", "unknown"), false);
assert.equal(turnExpectsEvidenceWrite("evidence", undefined), false);
assert.equal(retryConstraintForAttempt("evidence_not_written"), UNWRITTEN_EVIDENCE_RETRY_CONSTRAINT);
assert.equal(retryConstraintForAttempt("empty_stream"), DEFAULT_RETRY_CONSTRAINT);
});
test("case snapshot receipts expose host_fallback origin from the durable phase", () => {
const route = readFileSync(
new URL("../src/app/api/rectification/cases/[caseId]/route.ts", import.meta.url),