Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

feat(compact): server-side compaction is the default on the Responses route

Rach Pradhan0237cecf8f2b
diff --git a/src/agent_server_compact.zig b/src/agent_server_compact.zig
index 7e1894bd..11d48a6e 100644
--- a/src/agent_server_compact.zig
+++ b/src/agent_server_compact.zig
@@ -28,37 +28,18 @@ const Agent = @import("agent.zig").Agent;
const Provider = @import("provider.zig").Provider;
const http = @import("http.zig");
const telemetry = @import("telemetry.zig");
-const keys_cli = @import("keys_cli.zig");
const goal_flow = @import("goal_flow.zig");
-/// GRAFF_SERVER_COMPACT=0/false/off forces the client arm, =1 forces the
-/// server arm (session_settings.applyEnvKnobs). Default: A/B assignment.
+/// GRAFF_SERVER_COMPACT=0/false/off forces the client arm, =1 the server arm
+/// (session_settings.applyEnvKnobs). Default: server. The #compact-ab
+/// experiment concluded — the server blob is recall-safe — so every eligible
+/// provider takes the server path unless this knob opts out.
pub var g_server_compact_override: ?bool = null;
-/// A/B assignment (#compact-ab): 50/50, bucketed by the anonymous install id
-/// so a person's arm is stable across sessions and machines stay whole-user
-/// consistent. Set once per process by assignArm (startup); null means
-/// unassigned, which behaves as the client arm (the pre-feature default).
-var g_ab_arm: ?bool = null;
-
-/// Pure bucketing: true = server arm. Deterministic on the install id.
-pub fn armForId(id: *const [32]u8) bool {
- return (std.hash.Wyhash.hash(0, id) & 1) == 0;
-}
-
-/// Startup hook (session_settings.setupSkillsAndTheme): bucket this install.
-/// The env override wins outright, so no assignment is made when it is set.
-pub fn assignArm(io: Io, arena: std.mem.Allocator, home: []const u8) void {
- if (g_server_compact_override != null or g_ab_arm != null) return;
- const id = keys_cli.loadOrCreateId(io, arena, home, ".simple-harness-install-id");
- g_ab_arm = armForId(&id);
-}
-
/// Is the server-compaction path active for this provider?
pub fn enabled(p: Provider) bool {
if (manualRoute(p) == .local) return false;
- if (g_server_compact_override) |o| return o;
- return g_ab_arm orelse false;
+ return g_server_compact_override orelse true;
}
/// One OTLP log record: body="experiment", kind="compact_ab", detail carries
diff --git a/src/agent_server_compact_tests.zig b/src/agent_server_compact_tests.zig
index 5e91f987..8429fdb5 100644
--- a/src/agent_server_compact_tests.zig
+++ b/src/agent_server_compact_tests.zig
@@ -27,7 +27,6 @@ const autocompact = asc.autocompact;
const autocompactIf = asc.autocompactIf;
const explicitCompact = asc.explicitCompact;
const installCompactionItem = asc.installCompactionItem;
-const armForId = asc.armForId;
const ManualRoute = asc.ManualRoute;
const test_support = @import("agent_compact_test_support.zig");
@@ -123,28 +122,26 @@ test "installCompactedOutput transactionally replaces history and resets meters"
try std.testing.expectEqual(@as(u64, 2), agent.history_rewrites);
}
-test "enabled: responses-only; unassigned defaults to client; override wins" {
+test "enabled: responses-only; server is the default; override wins" {
var p: Provider = .{ .id = "codex", .kind = .responses, .auth = .bearer, .url = "", .api_key = "k", .model = "m", .context = 272_000 };
- try std.testing.expect(!enabled(p)); // no assignment in tests → client arm
+ try std.testing.expect(enabled(p)); // server arm by default
p.kind = .anthropic;
try std.testing.expect(!enabled(p));
p.kind = .openai;
try std.testing.expect(!enabled(p));
p.kind = .responses;
- asc.g_server_compact_override = true;
+ p.id = "openai";
try std.testing.expect(enabled(p));
+ p.id = "kilo"; // third-party Responses hosts keep the local summary
+ try std.testing.expect(!enabled(p));
+ p.id = "codex";
asc.g_server_compact_override = false;
try std.testing.expect(!enabled(p));
+ asc.g_server_compact_override = true;
+ try std.testing.expect(enabled(p));
asc.g_server_compact_override = null;
}
-test "armForId: deterministic bucketing of the install id" {
- const id: [32]u8 = "0123456789abcdef0123456789abcdef".*;
- try std.testing.expectEqual(armForId(&id), armForId(&id));
- const other: [32]u8 = "ffffffffffffffffffffffffffffffff".*;
- _ = armForId(&other); // both buckets are reachable outcomes; no crash, pure
-}
-
test "writeContextManagement: automatic threshold and forced Codex pass stay OpenAI-only" {
var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena_state.deinit();
diff --git a/src/session_settings.zig b/src/session_settings.zig
index 81efef11..3fe8a086 100644
--- a/src/session_settings.zig
+++ b/src/session_settings.zig
@@ -186,9 +186,6 @@ pub fn applyEnvKnobs(arena: Allocator, environ_map: anytype) !void {
pub fn setupSkillsAndTheme(io: Io, arena: Allocator, environ_map: anytype, out: *Io.Writer, flags: args.Flags, use_color: bool, json_mode: bool, cwd_display: []const u8) !ThemeSetup {
try applyEnvKnobs(arena, environ_map);
- // #compact-ab: bucket this install into a compaction arm once per process.
- // After applyEnvKnobs so GRAFF_SERVER_COMPACT wins and skips assignment.
- server_compact.assignArm(io, arena, @import("keys_cli.zig").homeEnv(environ_map) orelse "");
skills.loadSkillSettings(io, arena); // per-skill opt-outs, also gates the auto-connect
anim.loadAnimationSetting(io, arena); // {"animation": "..."} → thinking spinner choice
anim.loadThemeSetting(io, arena); // {"theme": "<name>"} → opt-in terminal color theme
diff --git a/src/task_outcome.zig b/src/task_outcome.zig
index c2b483e2..279b3f47 100644
--- a/src/task_outcome.zig
+++ b/src/task_outcome.zig
@@ -109,7 +109,7 @@ pub fn noteSessionEnd(root: *Agent) void {
test "armLabel: responses follows the arm, others are out of the experiment" {
var p: Provider = .{ .id = "codex", .kind = .responses, .auth = .bearer, .url = "", .api_key = "k", .model = "m", .context = 272_000 };
- try std.testing.expectEqualStrings("client", armLabel(p)); // unassigned in tests → client
+ try std.testing.expectEqualStrings("server", armLabel(p)); // server is the default arm
p.kind = .anthropic;
try std.testing.expectEqualStrings("other", armLabel(p));
p.kind = .openai;