fix(agent): keep the turn's real answer when a correction ends in a call note

Agent check on 51ac8c7: the tax answer (a table with the deadline) was
flagged for narrating a call; two corrections later the last reply was
only '(called add_task)', so the person saw 'could not finish' although
the deadline was recorded. The turn now keeps its best real answer,
narration removed, and stores that when the last reply has nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Lem7GyhyyjKhmwjG8G7Ud
This commit is contained in:
Claude committed 2026-10-22 16:42:25 +00:00
1 parent 51ac8c7d44
commit 2a4221ed0a
2 files changed
+21 -1

No files matched your search

+15
View File
@@ -330,3 +330,18 @@ describe("a runaway reply", () => {
expect(model.seen[1]).toContain("the same call was already made in this reply");
});
});
describe("an answer lost to its correction", () => {
it("keeps the turn's real answer when the last reply is only a call note", async () => {
const id = await matter();
const model = scriptedModel([
{ text: "Your objection is due 4 November 2026. update_matter(title)" },
{ text: "(called add_task)" },
{ text: "(called add_task)" },
]);
await runTurn({ db, master: MASTER, matterId: id, sub: OWNER, env: ENV, fetchImpl: model.impl, text: "When?" });
const view = (await loadMatter(db, MASTER, id, OWNER))!;
const answer = view.events.filter((e) => e.kind === "message" && e.role === "assistant").at(-1);
expect(answer && answer.kind === "message" ? answer.text : "").toContain("Your objection is due 4 November 2026");
});
});
+6 -1
View File
@@ -637,6 +637,7 @@ async function runTurnLocked(input: {
const readLaw = input.readLaw ?? readLawDefault;
let servedBy = "";
let finalText = "";
let bestAnswer = "";
let corrections = 0;
let unverified = false;
let recorded = 0;
@@ -695,6 +696,10 @@ async function runTurnLocked(input: {
deadlines: recorded + view.items.filter((i) => i.kind === "deadline").length,
});
trace(problems);
// The best real answer of the turn so far, without any narration: what
// the person gets if a later correction ends in nothing but a call note.
const substance = withoutNarration(turn.text, TOOL_NAMES);
if (substance.length > bestAnswer.length) bestAnswer = substance;
// Asking for a source is pointless once neither search nor Fedlex can
// be reached; the answer is then stored marked unverified instead.
const correctable = problems.filter((p) => canSearch || canReadLaw || p !== "unsourced");
@@ -720,7 +725,7 @@ async function runTurnLocked(input: {
continue;
}
unverified = problems.includes("unsourced") || problems.includes("narrated");
finalText = problems.includes("narrated") ? withoutNarration(turn.text, TOOL_NAMES) : turn.text;
finalText = problems.includes("narrated") ? substance || bestAnswer : turn.text;
break;
}