From 7a5b125405929df12dd239a62498d101dcd99500 Mon Sep 17 00:00:00 2001 From: Mikael Hugo Date: Sat, 2 May 2026 23:46:07 +0200 Subject: [PATCH] feat(sf): persist continueWithDefault escalations as memories too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When an agent escalates with continueWithDefault=true, it has already proceeded with the recommendation — the artifact JSON captures the audit trail but no other surface carries the rationale forward. Downstream tasks running after this one would query memories and find nothing about the choice. resolveEscalation already writes a memory on the continueWithDefault= false path (after operator resolves). This is the symmetric write for the continueWithDefault=true path: same category="architecture", same "[escalation:T##]" prefix, with the rationale prefixed "auto-applied default: ..." so a journal scan can tell apart continueWithDefault entries from operator-resolved ones. Now a slice's full decision history (operator-resolved + auto-accepted + default-applied escalations) lives uniformly in the memory store and flows into the cosine ranking for downstream prompts. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/resources/extensions/sf/escalation.ts | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/resources/extensions/sf/escalation.ts b/src/resources/extensions/sf/escalation.ts index 63ddd03fc..9e198343e 100644 --- a/src/resources/extensions/sf/escalation.ts +++ b/src/resources/extensions/sf/escalation.ts @@ -142,6 +142,38 @@ export function writeEscalationArtifact( }), ); + // continueWithDefault=true: the agent already proceeded with its + // recommendation. The artifact is the audit trail, but the choice + + // rationale should ALSO land in the memory store so future tasks see + // it via getRelevantMemoriesRanked — otherwise the rationale lives + // only in the JSON artifact and never reaches downstream prompts. + // resolveEscalation handles this for the continueWithDefault=false + // path; we do the symmetric write here. Best-effort. + if (artifact.continueWithDefault) { + try { + const recommendedOption = artifact.options.find( + (o) => o.id === artifact.recommendation, + ); + const memoryContent = formatEscalationMemoryContent( + artifact, + recommendedOption, + `auto-applied default: ${artifact.recommendationRationale}`, + ); + createMemory({ + category: "architecture", + content: memoryContent, + confidence: 0.85, + source_unit_type: "execute-task", + source_unit_id: artifact.taskId, + }); + } catch (memoryErr) { + logWarning( + "tool", + `escalation: continueWithDefault memory write failed: ${(memoryErr as Error).message}`, + ); + } + } + return path; }