graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix: stop looping the same unresolved compact_cut (#706)
Cursor Agent289147cb9dbb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3099c031..5a0e3c2d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,6 +22,9 @@ current is part of cutting a release.so one wedged PTY child cannot hang pre-push (#704).`peer_message` resolves a live session by its visible title orsaved-session base (#700). Presence is still device-local.+ In-turn compaction stops after the same unresolved pin fails to+ shrink twice (#706). Credential files fsync their directory after+ rename (#405 / #705).No tag until asked.## v0.0.282 (2026-08-31)diff --git a/docs/adr/0058-compact-cut-stalls-on-no-progress.md b/docs/adr/0058-compact-cut-stalls-on-no-progress.mdnew file mode 100644index 00000000..396da144--- /dev/null+++ b/docs/adr/0058-compact-cut-stalls-on-no-progress.md@@ -0,0 +1,25 @@+# 0058. compact_cut stalls when the same pin does not shrink++Status: accepted 2026-08-31++## Context++A long Codex tool turn (#706) retried `compact_cut` at one unresolved+boundary 41 times. Compaction reclaimed some prefix, then the live+suffix grew past 285k tokens and the turn failed. Prior fixes (#163,+#193, #201, #440, #581) still allow a single current turn to outgrow+the safe retained suffix.++## Decision++Record each in-turn cut's boundary and suffix-token estimate. If the+same boundary fails to shrink by 2k tokens twice in a row, stop+further summarization spends for that unresolved turn, announce once,+and take the existing recover/trim path. A material shrink or a new+boundary resets the counter. A resolved turn clears it.++## Consequences++The harness will not resend an ever-larger pinned current turn. It+does not invent a mid-turn tool-pair checkpoint; that remains a+follow-up if stall-then-trim is still too coarse.diff --git a/docs/adr/README.md b/docs/adr/README.mdindex e1890014..a01644aa 100644--- a/docs/adr/README.md+++ b/docs/adr/README.md@@ -68,6 +68,7 @@ record only when you need the evidence or the edge cases.| [0055](0055-lean-oneshot-bash-15s.md) | Lean `-p` bash auto-backgrounds at 15s; interactive / `--no-lean` stay 120s (ADR 0026). || [0056](0056-composer-image-chips-sync-on-delete.md) | Composer image chips sync on delete and reuse `#N`; `clipboard_paste` MIME/bytes wait until send. || [0057](0057-peer-title-is-an-address.md) | `peer_message` resolves exact title / saved-session base before opaque id or goal. |+| [0058](0058-compact-cut-stalls-on-no-progress.md) | Same unresolved `compact_cut` pin that does not shrink stops after two tries. |## When to write onediff --git a/docs/releases/v0.0.283.md b/docs/releases/v0.0.283.mdindex d5b964a9..c355eba3 100644--- a/docs/releases/v0.0.283.md+++ b/docs/releases/v0.0.283.md@@ -33,3 +33,10 @@ whoever is still running.`peer_message` (#700) lists the visible title and saved-session baseand resolves those before opaque id / goal fragments. Duplicate titlesare ambiguous. Older presence files without the new fields still parse.++A long current tool turn that pins `compact_cut` at one boundary no+longer retries that cut while context grows (#706). Two no-progress+attempts escalate once.++#405 / #705: POSIX credential replace fsyncs the destination directory+after rename. Windows stays atomic-file + home ACL.diff --git a/src/agent.zig b/src/agent.zigindex 5dfe4917..3e9a26c6 100644--- a/src/agent.zig+++ b/src/agent.zig@@ -207,6 +207,7 @@ pub const Agent = struct {compact_transport_failures: u8 = 0, // bounded escape for repeated opaque over-cap WriteFailed/network failurescompact_summary_failures: u8 = 0, // #379: consecutive complete-but-unusable (empty/truncated) summariescompact_pin_degraded: bool = false, // #581: pinned suffix over budget — skip+say once per unresolved turn+ compact_stall: @import("compact_cut.zig").Stall = .{}, // #706: same-boundary no-progress cutsempty_completion_retries: u8 = 0, // degenerate empty completions re-asked this turn (agent_empty_completion.zig)named_work_nudges: u8 = 0, // named-file / zero-tool nudge this turn (named_work.zig)precompact_note_gen: ?u32 = null, // #391: history_rewrites at the last pre-compaction note-to-self, so one history generation buys at most one note however often compaction is retried (compact_note.decideCalls)diff --git a/src/agent_compact.zig b/src/agent_compact.zigindex df5e4c71..1a4d1770 100644--- a/src/agent_compact.zig+++ b/src/agent_compact.zig@@ -137,6 +137,17 @@ pub fn compact(self: *Agent) anyerror!usize {const live_context_local_tokens = self.context_local_tokens;const live_effective_context = self.effectiveContextTokens();const plan = compact_cut.pinDegrade(live_messages.items, recent_context_tokens, self.compact_pin_degraded);+ const suffix = compact_cut.suffixTokens(live_messages.items, plan.start);+ // #706: same unresolved pin that is not shrinking — do not resend an+ // ever-larger current turn. Escalate once, then stay quiet.+ if (compact_cut.noteStall(&self.compact_stall, plan.start, suffix)) {+ compact_cut.noteCut(self.tracer, live_messages.items, plan.start);+ if (!self.compact_pin_degraded) {+ if (!main_mod.json_mode) try self.say("[compaction stalled: the current turn is not shrinking — stopping further cuts]\n", .{});+ self.compact_pin_degraded = true;+ }+ return error.ActivePromptPinned;+ }compact_cut.noteCut(self.tracer, live_messages.items, plan.start);// #581 residual: a pin that already exceeds the keep budget cannot be// summarized. Announce once per unresolved turn, then stay quiet.@@ -517,7 +528,10 @@ pub fn repeatedEmptySummaryFailure(self: *Agent, err: anyerror) bool {}pub fn compactOrRecover(self: *Agent, trim_on_fail: bool) void {- if (compact_cut.lastIsResolved(self.messages.items)) self.compact_pin_degraded = false;+ if (compact_cut.lastIsResolved(self.messages.items)) {+ self.compact_pin_degraded = false;+ compact_cut.resetStall(&self.compact_stall);+ }if (self.compact_pin_degraded and !trim_on_fail) return;if (self.compact()) |_| {self.compact_transport_failures = 0;diff --git a/src/cli.zig b/src/cli.zigindex f002d69e..a986cd27 100644--- a/src/cli.zig+++ b/src/cli.zig@@ -25,6 +25,8 @@ pub const changelog_text =\\ • deleted composer image chips reuse #N; paste traces omit MIME/bytes until send (#702)\\ • peer_message addresses a live session by its visible title or saved-session base (#700)\\ • tuiguard fails a wedged PTY probe instead of hanging pre-push (#704)+ \\ • same-boundary compact_cut with no shrink stops after two tries (#706)+ \\ • credential replace fsyncs the POSIX directory after rename (#405)\\\\0.0.282\\ • pasted-text chips are atomic spans — a typed lookalike stays literal (#674)diff --git a/src/compact_cut.zig b/src/compact_cut.zigindex ddd37bc6..31aadd18 100644--- a/src/compact_cut.zig+++ b/src/compact_cut.zig@@ -118,6 +118,36 @@ pub fn pinDegrade(items: []const Value, token_budget: u64, already: bool) CutPla};}+/// #706: same unresolved pin, suffix did not shrink — another summarization+/// spend will not get the live turn under the line.+pub const Stall = struct {+ boundary: usize = std.math.maxInt(usize),+ suffix_tokens: u64 = 0,+ no_progress: u8 = 0,+};++pub const stall_shrink_tokens: u64 = 2_048;+pub const stall_repeats: u8 = 2;++pub fn resetStall(s: *Stall) void {+ s.* = .{};+}++/// Record this attempted cut. True once the same boundary has failed to+/// shrink the live suffix `stall_repeats` times in a row.+pub fn noteStall(s: *Stall, start: usize, suffix: u64) bool {+ const same = s.boundary == start;+ const no_shrink = suffix + stall_shrink_tokens >= s.suffix_tokens;+ if (same and no_shrink) {+ s.no_progress +|= 1;+ } else {+ s.no_progress = 0;+ }+ s.boundary = start;+ s.suffix_tokens = suffix;+ return s.no_progress >= stall_repeats;+}+/// Pick the earliest clean user-turn boundary whose suffix fits in the recent/// context budget. Returning items.len means "summarize everything". We never/// split at a tool output, so retained call/result history stays valid.@@ -395,3 +425,15 @@ test "pinDegrade: prefix still compactable once; already-degraded skips the spentry std.testing.expectEqual(@as(usize, 2), again.start);try std.testing.expectEqual(DegradeAction.silent, again.action);}++test "noteStall: same boundary with no shrink escalates; a real shrink resets" {+ var s: Stall = .{};+ try std.testing.expect(!noteStall(&s, 10, 50_000));+ try std.testing.expect(!noteStall(&s, 10, 49_500));+ try std.testing.expect(noteStall(&s, 10, 49_000));+ resetStall(&s);+ try std.testing.expect(!noteStall(&s, 10, 50_000));+ try std.testing.expect(!noteStall(&s, 10, 40_000));+ try std.testing.expect(!noteStall(&s, 10, 39_000));+ try std.testing.expect(!noteStall(&s, 20, 80_000));+}