graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Compaction: publish the note before a summary that does not fork
justrach988787a3aecb
diff --git a/docs/adr/0220-claude-prompt-cache-forks-and-pricing.md b/docs/adr/0220-claude-prompt-cache-forks-and-pricing.mdindex 51c85c7b..edbf14bb 100644--- a/docs/adr/0220-claude-prompt-cache-forks-and-pricing.md+++ b/docs/adr/0220-claude-prompt-cache-forks-and-pricing.md@@ -49,7 +49,8 @@ these gaps:system prompt, thinking, effort and speed. Every message goes verbatim, withthe instruction appended as the last user message. The note's persona leadsits instruction. The summary sees the whole history, and nothing is trimmed.- The note's system-prompt refresh runs after the summary.+ The note's system-prompt refresh runs after the summary, which keeps the+ cached prompt. Without a fork it runs before, as it did.- **Otherwise the old shape runs without breakpoints.** A compaction requestthat shares no prefix gets no `cache_control`. This covers Anthropic andAnthropic models through OpenRouter. It is sent uncached (1x) instead ofdiff --git a/src/agent_compact.zig b/src/agent_compact.zigindex 3cf4bea3..b14c2de3 100644--- a/src/agent_compact.zig+++ b/src/agent_compact.zig@@ -130,7 +130,7 @@ pub fn compact(self: *Agent) anyerror!usize {// history it describes. Gated, budgeted, best-effort: every refusal is a// named skip, so everything below runs unconditionally.const note = compact_note_glue.maybeWrite(self);- defer if (note == .fire) compact_note_glue.publish(self); // after the summary, which forks the old system prompt+ defer if (note == .fire and fork) compact_note_glue.publish(self); // a fork's summary keeps the cached prompt// #163: reclaim room BEFORE the summarization request so it fits under the// model's input cap. On codex/gpt-5.x an over-cap request fails to WRITE// (WriteFailed) rather than returning a clean overflow, so compaction coulddiff --git a/src/compact_note_glue.zig b/src/compact_note_glue.zigindex 5968a43c..d3e0b44d 100644--- a/src/compact_note_glue.zig+++ b/src/compact_note_glue.zig@@ -92,16 +92,18 @@ pub fn maybeWrite(self: *Agent) Decision {const reply = askModel(self) orelse return .skip_failed;if (!compact_note.record(self.io, self.arena, self.session_name, self.history_rewrites, reply))return .skip_failed;+ // The very next request is compaction's summary, which carries the note.+ // A fork keeps the prompt the conversation was cached under instead, and+ // compact() publishes once its summary is done (ADR 0220).+ if (!cache_fork.shares()) publish(self);if (!main_mod.json_mode) self.say(" 📝 wrote a pre-compaction note to self ({d} chars)\n", .{reply.len}) catch {};if (self.tracer) |tr| tr.note("compact", "wrote a pre-compaction note to self (#391)");return .fire;}-/// After a `.fire`: the note is in the SYSTEM prompt, beside HARD-/// CONSTRAINTS, so it has to be re-composed to reach the next request — the-/// same refresh a mid-session `/never` performs, and for the same reason.-/// compact() calls this once its summary request is done: that request forks-/// the prompt the conversation was cached under (ADR 0220).+/// The note is in the SYSTEM prompt, beside HARD CONSTRAINTS, so it has to+/// be re-composed to reach the next request — the same refresh a mid-session+/// `/never` performs, and for the same reason.pub fn publish(self: *Agent) void {prompts.armCompactNotes(self.session_name);@import("prompt_cache_hud.zig").noteBust(.compact);