A self-organizing Obsidian vault that gives AI coding agents persistent memory.
TypeScript ai-agentsclaude-codecodex-cligemini-cliknowledge-managementobsidianobsidian-vaultpersistent-memorysecond-braintemplate
fix: the markup refusal's recovery is a different shape, not the one that folded (#245)
Brenno Ferrari1d367af3c78f
diff --git a/.claude/scripts/lib/mcp-capture.ts b/.claude/scripts/lib/mcp-capture.tsindex 2a7e520..acc3737 100644--- a/.claude/scripts/lib/mcp-capture.ts+++ b/.claude/scripts/lib/mcp-capture.ts@@ -331,7 +331,32 @@ export function toolMarkupRefusal(site: ToolMarkupSite, args?: Record<string, un"CHECK THE FIELD LIST ABOVE FIRST. If a field you sent is missing from it,","its text was folded into this one and the data is gone rather than merely","mispunctuated; the offset then tracks your whole payload rather than a",- "position inside your own prose. Re-send every field in that case.",+ "position inside your own prose.",+ "",+ // The old text ended "Re-send every field in that case", which is the+ // shape that folded. A caller that complied reproduced the failure and+ // had no second move, so the tool got abandoned rather than retried.+ //+ // What the retry must be smaller in is NOT settled, and this wording is+ // deliberately careful about that. A reproduction on `remember` folded+ // with FEWER fields and a longer body while a wider, shorter call+ // succeeded, which rules out field count as the driver; a separate+ // `record_work` sequence folded at a field of only 832 characters,+ // which cuts against a clean size threshold. Total serialized request+ // size has never been measured directly. Until it is, say "smaller"+ // and name both axes rather than picking one and being wrong.+ "In that case do NOT re-send the same shape — it folds again. Retry",+ "SMALLER IN TOTAL SIZE, not merely with fewer fields: a call with fewer",+ "fields but a longer body has been refused where a wider, shorter one",+ "succeeded. Send the required fields with the prose trimmed, let that",+ "write land, then add the rest in a follow-up call. Two records that",+ "arrive beat one that never does.",+ "",+ // Priced, because the narrow retry is a trade and a caller taking it+ // blind loses the structured half without noticing.+ "The cost, so you take it knowingly: a field you drop survives only as",+ "prose if you move it into the body. As a FIELD it is gone, so anything",+ "that queries on it will not see this record.","","If every field you sent is listed, then only the closing tags are wrong:","re-send the same text with exactly one closing tag per parameter, and",diff --git a/.claude/scripts/tests/capture-markup-guard.test.ts b/.claude/scripts/tests/capture-markup-guard.test.tsindex d2d41c1..ddfa94c 100644--- a/.claude/scripts/tests/capture-markup-guard.test.ts+++ b/.claude/scripts/tests/capture-markup-guard.test.ts@@ -167,6 +167,60 @@ describe("the refusal names the fields the server received", () => {assert.match(msg, /CHECK THE FIELD LIST ABOVE FIRST/);});+ // #244. The trailing branch used to end "Re-send every field in that case",+ // which is the shape that folded: a caller that complied reproduced the+ // failure and had no second move, so the write tools got abandoned rather+ // than retried. The recovery has to name a DIFFERENT shape than the one that+ // just failed, or the message is a loop.+ test("the trailing branch names a different shape to retry, not the one that folded", () => {+ const args = { summary: `${PROSE}</invoke></function_calls>`, folder: "brain" };+ const site = describeToolMarkup(args);+ const msg = toolMarkupRefusal(site!, args);+ assert.ok(!/Re-send every field/.test(msg), "must not send the caller back into the folding shape");+ assert.match(msg, /do NOT re-send the same shape/);+ });++ // The axis matters as much as the direction. A reproduction folded with+ // FEWER fields and a longer body while a wider, shorter call succeeded, so a+ // caller told only to "drop fields" keeps the long body and keeps failing.+ test("the retry is smaller in total size, not merely in field count", () => {+ const args = { summary: `${PROSE}</invoke>`, folder: "brain" };+ const msg = toolMarkupRefusal(describeToolMarkup(args)!, args);+ assert.match(msg, /SMALLER IN TOTAL SIZE/);+ assert.match(msg, /not merely with fewer fields/);+ });++ // Dropping a field is a trade, not a free retry: the prose can be moved into+ // the body but the FIELD is gone, and a caller taking that blind loses the+ // queryable half without noticing.+ test("the trailing branch prices the field it asks the caller to drop", () => {+ const args = { summary: `${PROSE}</invoke>`, folder: "brain" };+ const msg = toolMarkupRefusal(describeToolMarkup(args)!, args);+ assert.match(msg, /queries on it will not see this record/);+ });++ // The mechanism is not settled, so the message must not promise the retry+ // works — it has been refused at least once. This is the property most+ // likely to be "helpfully" strengthened by a later edit, so it is pinned.+ test("the recovery is offered, never promised", () => {+ const args = { summary: `${PROSE}</invoke>`, folder: "brain" };+ const msg = toolMarkupRefusal(describeToolMarkup(args)!, args);+ assert.ok(+ !/will (succeed|work|fix)|guaranteed|always works/i.test(msg),+ "the narrow retry is a mitigation, not a cure, and must not be stated as one",+ );+ });++ // The other half of the split must not drift while this one changes.+ test("the embedded branch keeps its own repair", () => {+ const args = { summary: `before <parameter name="x">after`, folder: "brain" };+ const site = describeToolMarkup(args);+ assert.equal(site?.trailing, false);+ const msg = toolMarkupRefusal(site!, args);+ assert.match(msg, /swallowed the field after it/);+ assert.ok(!/SMALLER IN TOTAL SIZE/.test(msg), "the narrow retry belongs to the trailing branch only");+ });+// The optional contract: existing callers pass one argument and still get a// usable message, it simply omits the list.test("called without args the message is still produced, minus the list", () => {