Skip to content

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

Python

feat(cache): default stable catalog; xAI children share role-lane conv-id

Cursor Agent92ec3b277ed9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d9c4e3df..eaeccd8f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,14 @@ current is part of cutting a release.
clobber `--old` / `--rlm`.
- The spec stays folded behind `load_tool_schemas`. `--schema` / the
64-cell tool-catalog kernel do not grow a new tool.
+- Prompt-cache max: `GRAFF_STABLE_CATALOG` is on by default so
+ `load_tool_schemas` (including `rlm`) does not rewrite tools JSON.
+ Spawned subagents inherit it. Children share four role-lane
+ `x-grok-conv-id` / `prompt_cache_key` values (official xAI sticky
+ routing — same id, same server). rlm's `subagent("task")` uses
+ label `subagent`, so siblings hit one lane. They do not reuse the
+ root id. Opt out of stable catalog with `GRAFF_STABLE_CATALOG=0`
+ or `GRAFF_NO_STABLE_CATALOG=1`.
- Measured default-RLM vs `--old` on grok-4.6 SuperGrok (one `rlm`
suite rep): both 5/5, $0.0000 / $0.0000 (flat-rate). Persist
`bind-reuse` 99.6s / 135k in → 39.2s / 25.3k in. Suite totals
diff --git a/docs/adr/0009-gpt-5-6-explicit-prompt-cache-boundary.md b/docs/adr/0009-gpt-5-6-explicit-prompt-cache-boundary.md
index 3a7dd330..3edc884e 100644
--- a/docs/adr/0009-gpt-5-6-explicit-prompt-cache-boundary.md
+++ b/docs/adr/0009-gpt-5-6-explicit-prompt-cache-boundary.md
@@ -35,9 +35,11 @@ unsupported parameter, so its supported automatic/keyed path must remain.
documented approximately 15 requests/minute per-key guidance while preserving
reuse across repeated workflow roles. Codex uses this supported keyed,
automatic path without explicit options.
-- xAI keeps automatic caching and distinct child conversation ids; its header
- and body continue to carry the same affinity value. It never receives OpenAI
- Platform breakpoint/options fields.
+- xAI keeps automatic prefix caching. Header `x-grok-conv-id` and body
+ `prompt_cache_key` are the same sticky-routing id (official maximize-hits
+ guidance). Root uses the project id; children share role lanes, not the
+ root id and not a per-agent suffix. It never receives OpenAI Platform
+ breakpoint/options fields.
- Cache writes are parsed separately from reads and ordinary input, shown in the
cost summary, and billed at the documented 1.25× rate for GPT-5.6 and
Anthropic ephemeral cache creation.
diff --git a/docs/adr/0011-prompt-cache-max-is-visible.md b/docs/adr/0011-prompt-cache-max-is-visible.md
index ad54b1b4..5b7dce90 100644
--- a/docs/adr/0011-prompt-cache-max-is-visible.md
+++ b/docs/adr/0011-prompt-cache-max-is-visible.md
@@ -26,22 +26,29 @@ intentional. `/debug` counted tokens; it did not say why a miss happened.
- Named busts (`goal`, `playbook`, `compact`, `persona`, `tools`, `mcp`) are
recorded at the mutation site and counted only when the next request's
system+tools hash actually changes. Startup compose is not a bust.
-- Do not default `GRAFF_STABLE_CATALOG`. Do not move playbook / compact notes
- / standing goal off the prefix — those ride the system prompt on purpose
- (ADR 0005, #381, #391) and already share the compaction boundary.
+- `GRAFF_STABLE_CATALOG` is the default (2026-08-25). RLM default makes
+ `load_tool_schemas("rlm")` a guaranteed first-turn load; rewriting tools
+ JSON there was a 0% cache-read on the next call. The loaded schema still
+ rides the load result; the catalog head stays byte-identical. Opt out
+ with `GRAFF_STABLE_CATALOG=0` or `GRAFF_NO_STABLE_CATALOG=1`. Do not move
+ playbook / compact notes / standing goal off the prefix — those ride the
+ system prompt on purpose (ADR 0005, #381, #391) and already share the
+ compaction boundary.
- `/btw` is a grok-build side-call: same system prompt, same tools JSON, same
`prompt_cache_key` as the parent. The side-question note is appended as a
user message. Tools are advertised for the prefix and not executed.
## Consequences
-A `/cache` after a miss names the lever. Revisit defaulting stable-catalog
-only if a new live measurement shows load-after-load cache-read returning
-from 0% without discovery or compaction regressions.
+A `/cache` after a miss names the lever. Stable-catalog is now the default
+so an `rlm` (or MCP) load does not rewrite the tools prefix. Children
+inherit the process-global catalog mode.
-Subagents (2026-08-21): non-xAI children share four role-lane prefix keys so
-repeated scouts reuse system+tools. xAI children stay per-agent — mixing them
-into the root conv-id would break append-only prefix matching (ADR 0009).
+Subagents (2026-08-25): children share four role-lane `x-grok-conv-id` /
+`prompt_cache_key` values so sibling scouts with the same system+tools
+land on the same xAI server (official sticky routing). They do not reuse
+the root id — the child prefix is a different messages array. A
+per-agent pointer suffix was a forced miss.
Live Grok 4.6 (Responses, SuperGrok OAuth, 2026-08-19): same-process
append-only turn 2 cached 3,712 of turn 1's 3,721 input tokens. `/btw` after
diff --git a/docs/adr/README.md b/docs/adr/README.md
index 5f135d56..6e2aeb6e 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -21,7 +21,7 @@ record only when you need the evidence or the edge cases.
| [0008](0008-synthetic-evals-use-external-verifiers.md) | Synthetic coding evals promote only external-verifier passes; model judges may tiebreak correctness, never decide it. |
| [0009](0009-gpt-5-6-explicit-prompt-cache-boundary.md) | GPT-5.6 OpenAI Platform marks the stable prefix explicitly; Codex and xAI stay on their supported keyed automatic-cache paths. |
| [0010](0010-background-jobs-wait-for-exit.md) | `bash_output`/`agent_output` `wait_ms>0` blocks until exit (10h cap); do not poll every 30s. |
-| [0011](0011-prompt-cache-max-is-visible.md) | Prompt-cache max is `/cache` posture, not a new default; `/btw` rides the parent prefix. |
+| [0011](0011-prompt-cache-max-is-visible.md) | Prompt-cache max is on: stable catalog by default; `/cache` is the HUD; `/btw` rides the parent prefix; children share role-lane `x-grok-conv-id` / `prompt_cache_key` (not the root id). |
| [0012](0012-overflow-handles-named-limits-extra-roots.md) | Fat tool results become `tr_N` handles; named `--context-limit` caps prefix bytes; `--add-dir` extra roots are PathConfine allow-lists, not cwd/skill/session sources. |
| [0013](0013-list-dir-lives-in-codedb.md) | Directory listing is `codedb list_dir` (in-process BFS, gitignore, 10k cap), not a new always-on catalog tool. |
| [0014](0014-session-resume-carries-the-room-cursor.md) | `/resume` restores the peer-channel byte cursor and inbox; it does not replay the room into history. |
diff --git a/docs/releases/v0.0.276.md b/docs/releases/v0.0.276.md
index be91dd2b..1f699be2 100644
--- a/docs/releases/v0.0.276.md
+++ b/docs/releases/v0.0.276.md
@@ -14,6 +14,13 @@ are the only Prime-shaped pieces, still in Zig.
`--schema` and the 64-cell tool-catalog kernel do not list `rlm` as a
new always-on tool — it still folds behind `load_tool_schemas`.
+Prompt-cache max is on: the catalog stays byte-identical after a load
+(`GRAFF_STABLE_CATALOG` default). Children inherit that. Sibling
+`subagent()` calls share one `x-grok-conv-id` / `prompt_cache_key` lane
+(official xAI sticky routing) so they land on the server that already
+has the child prefix. They do not reuse the root id. Opt out of stable
+catalog with `GRAFF_STABLE_CATALOG=0`.
+
Measured 2026-08-25 on grok-4.6 SuperGrok (`graff-dev-old` vs default
`graff-dev`, one `rlm` suite rep, ADR 0022): both **5/5**, **$0.0000**
both ways (subscription, not in $). Persist `bind-reuse` **99.6s /
diff --git a/src/agent_request_body.zig b/src/agent_request_body.zig
index 8a7beea4..6e4f8801 100644
--- a/src/agent_request_body.zig
+++ b/src/agent_request_body.zig
@@ -169,8 +169,9 @@ pub fn buildBody(self: *Agent, tools: ?[]const u8, force_tool: bool, stream: boo
}
try s.endObject();
}
- // Sticky cache partition. xAI stays per-agent; everyone else uses
- // a prefix lane so repeated subagent roles reuse system+tools.
+ // Sticky cache partition. Same value as x-grok-conv-id (xAI
+ // official maximize-hits). Root is the project id; children
+ // share a role lane so sibling scouts reuse system+tools.
var ckbuf: [96]u8 = undefined;
try s.objectField("prompt_cache_key");
try s.write(http_headers.requestCacheKey(self.io, self.label, self, self.provider.id, &ckbuf));
diff --git a/src/cli.zig b/src/cli.zig
index 2e6f0973..c0cccd8d 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -23,6 +23,7 @@ pub const changelog_text =
\\──────────
\\0.0.276
\\ • rlm (RLM + mid-stream spec-ptc) is the default loop; --old / --no-rlm restores structured-only
+ \\ • prompt-cache max: stable catalog is the default (loads no longer rewrite tools JSON); children share prefix lanes
\\
\\0.0.275
\\ • OpenRouter requests carry app attribution (categories: cli-agent, programming-app)
diff --git a/src/grok_spec_conformance.zig b/src/grok_spec_conformance.zig
index 299bb0dd..02d7f531 100644
--- a/src/grok_spec_conformance.zig
+++ b/src/grok_spec_conformance.zig
@@ -40,7 +40,7 @@ fn cacheKeyIn(body: []const u8) ?[]const u8 {
return body[from..end];
}
-test "grok spec: Chat Completions x-grok-conv-id is stable for root and isolated for a child" {
+test "grok spec: Chat Completions x-grok-conv-id is stable for root; child is a role lane not the root id" {
const io = std.testing.io;
var root_slot: usize = 1;
var child_slot: usize = 2;
@@ -53,6 +53,9 @@ test "grok spec: Chat Completions x-grok-conv-id is stable for root and isolated
try std.testing.expect(!std.mem.eql(u8, root_id, http_headers.sessionId(io)));
const child_id = http_headers.promptCacheKey(io, "sub", @ptrCast(&child_slot), &cbuf);
try std.testing.expect(!std.mem.eql(u8, root_id, child_id));
+ var sib_slot: usize = 3;
+ var sbuf: [96]u8 = undefined;
+ try std.testing.expectEqualStrings(child_id, http_headers.promptCacheKey(io, "sub", @ptrCast(&sib_slot), &sbuf));
const xai: @import("provider.zig").Provider = .{ .id = "xai", .kind = .openai, .auth = .bearer, .url = "", .api_key = "k", .model = "grok-4.6", .context = 500_000 };
var h1: [12]std.http.Header = undefined;
diff --git a/src/http_headers.zig b/src/http_headers.zig
index 3866b3a4..0a960fcc 100644
--- a/src/http_headers.zig
+++ b/src/http_headers.zig
@@ -39,12 +39,17 @@ pub fn sessionId(io: Io) []const u8 {
return session_id_buf[0..session_id_len];
}
-/// Conversation affinity for one agent. xAI routes `x-grok-conv-id` (Chat
-/// Completions) and `prompt_cache_key` (Responses) to the same server — that
-/// is how an append-only conversation can keep finding its cached prefix.
-/// Root is the durable project id; each concurrent child gets its own suffix.
+/// Conversation affinity for one request. xAI routes `x-grok-conv-id` (Chat
+/// Completions) and `prompt_cache_key` (Responses) to the same server — cache
+/// entries are per-server, so a sticky id is how prefix hits stay reliable
+/// (docs.x.ai prompt-caching / maximizing-cache-hits). Root is the durable
+/// project id. Children share four role lanes so sibling scouts with the
+/// same system+tools land together; they do **not** reuse the root id
+/// (different prefix). `agent` is unused: a pointer suffix would split
+/// siblings onto different servers and miss on purpose.
pub fn promptCacheKey(io: Io, label: []const u8, agent: *const anyopaque, buf: []u8) []const u8 {
- return projectCacheKey(io, label, agent, buf);
+ _ = agent;
+ return promptPrefixCacheKey(io, label, buf);
}
/// OpenAI/Codex cache affinity for requests sharing a stable prompt prefix.
@@ -58,13 +63,12 @@ pub fn promptPrefixCacheKey(io: Io, label: []const u8, buf: []u8) []const u8 {
return std.fmt.bufPrint(buf, "{s}-child-{d}", .{ base, lane }) catch base;
}
-/// Partition for one request. xAI conversation affinity is per-agent (append-only
-/// conv-id). Everyone else uses a prefix lane so repeated subagent roles hit
-/// the warm system+tools cache instead of writing a unique suffix (ADR 0011).
+/// Partition for one request. Header (`x-grok-conv-id`) and body
+/// (`prompt_cache_key`) must be the same value — xAI treats them as the
+/// same sticky-routing id. Role lanes for every provider, including xAI.
pub fn requestCacheKey(io: Io, label: []const u8, agent: *const anyopaque, provider_id: []const u8, buf: []u8) []const u8 {
- if (std.mem.eql(u8, provider_id, "xai"))
- return promptCacheKey(io, label, agent, buf);
- return promptPrefixCacheKey(io, label, buf);
+ _ = provider_id;
+ return promptCacheKey(io, label, agent, buf);
}
var project_id_buf: [36]u8 = undefined;
@@ -115,8 +119,8 @@ pub fn projectRootId(io: Io) []const u8 {
}
/// Side-calls that replay the parent history (`/btw`) share the root
-/// partition. Concurrent workers stay isolated. grok-build's recap does the
-/// same: same `prompt_cache_key` as the parent so the prefix stays warm.
+/// partition. Workers use a role lane, not the root id. grok-build's recap
+/// does the same as `/btw`: same `prompt_cache_key` as the parent.
pub fn sharesParentCache(label: []const u8) bool {
return std.mem.eql(u8, label, "btw");
}
@@ -351,12 +355,14 @@ test "project and prefix cache keys preserve conversation and sharing boundaries
try std.testing.expectEqualStrings(a, projectRootId(std.testing.io));
try std.testing.expect(!std.mem.eql(u8, a, sessionId(std.testing.io)));
- // xAI conversation affinity stays distinct for concurrent children.
+ // Live keys (promptCacheKey) share a role lane — xAI cache is per-server
+ // and prefix-matched; a unique suffix per sibling is a forced miss.
var buf3: [96]u8 = undefined;
var buf4: [96]u8 = undefined;
- const sub = projectCacheKey(std.testing.io, "sub", agent, &buf3);
- const sibling_sub = projectCacheKey(std.testing.io, "sub", sibling, &buf4);
- try std.testing.expect(!std.mem.eql(u8, sub, sibling_sub));
+ const sub = promptCacheKey(std.testing.io, "sub", agent, &buf3);
+ const sibling_sub = promptCacheKey(std.testing.io, "sub", sibling, &buf4);
+ try std.testing.expectEqualStrings(sub, sibling_sub);
+ try std.testing.expect(!std.mem.eql(u8, sub, a));
var btw_buf: [96]u8 = undefined;
try std.testing.expectEqualStrings(a, projectCacheKey(std.testing.io, "btw", sibling, &btw_buf));
@@ -371,16 +377,24 @@ test "project and prefix cache keys preserve conversation and sharing boundaries
try std.testing.expect(std.mem.startsWith(u8, prefix1, a));
try std.testing.expect(!std.mem.eql(u8, prefix1, a));
- // Chat-wire OpenAI scouts share a role lane; xAI scouts stay isolated.
+ // OpenAI and xAI scouts share a role lane (header and body use this).
var oai1: [96]u8 = undefined;
var oai2: [96]u8 = undefined;
- try std.testing.expectEqualStrings(
- requestCacheKey(std.testing.io, "implement", agent, "openai", &oai1),
- requestCacheKey(std.testing.io, "implement", sibling, "openai", &oai2),
- );
- var x1: [96]u8 = undefined;
- var x2: [96]u8 = undefined;
- try std.testing.expect(!std.mem.eql(u8, requestCacheKey(std.testing.io, "implement", agent, "xai", &x1), requestCacheKey(std.testing.io, "implement", sibling, "xai", &x2)));
+ const oai_lane = requestCacheKey(std.testing.io, "implement", agent, "openai", &oai1);
+ try std.testing.expectEqualStrings(oai_lane, requestCacheKey(std.testing.io, "implement", sibling, "openai", &oai2));
+ var xai1: [96]u8 = undefined;
+ var xai2: [96]u8 = undefined;
+ const xai_lane = requestCacheKey(std.testing.io, "implement", agent, "xai", &xai1);
+ try std.testing.expectEqualStrings(xai_lane, requestCacheKey(std.testing.io, "implement", sibling, "xai", &xai2));
+ try std.testing.expectEqualStrings(oai_lane, xai_lane);
+
+ // rlm's subagent("task") defaults description to "subagent" — siblings
+ // share one prefix lane on every provider, including xAI.
+ var rlm1: [96]u8 = undefined;
+ var rlm2: [96]u8 = undefined;
+ const rlm_lane = requestCacheKey(std.testing.io, "subagent", agent, "xai", &rlm1);
+ try std.testing.expectEqualStrings(rlm_lane, requestCacheKey(std.testing.io, "subagent", sibling, "xai", &rlm2));
+ try std.testing.expect(std.mem.indexOf(u8, rlm_lane, "-child-") != null);
}
test "x-grok-conv-id with no explicit conv still uses the project root id" {
diff --git a/src/mcp_schema_gate.zig b/src/mcp_schema_gate.zig
index 74acc838..ac080557 100644
--- a/src/mcp_schema_gate.zig
+++ b/src/mcp_schema_gate.zig
@@ -99,13 +99,14 @@ pub const Policy = struct {
pub var g_policy: Policy = .{};
-/// GRAFF_STABLE_CATALOG=1 experiment (#476): a loaded tool's schema rides the
-/// load_tool_schemas RESULT in the conversation, so the catalog does not need
-/// to re-render it — skipping policy-deferred tools even after load keeps the
-/// request prefix byte-identical all session, which is what provider prefix
-/// caching charges against. Every load otherwise busts the cache (measured:
-/// 0% cache on the calls right after each load).
-pub var g_stable_catalog = false;
+/// Default on (ADR 0011, 2026-08-25): a loaded tool's schema rides the
+/// load_tool_schemas RESULT, so the catalog does not re-render it. Skipping
+/// policy-deferred tools even after load keeps the request prefix
+/// byte-identical all session — what provider prefix caching charges
+/// against. A load otherwise busts the cache (measured: 0% cache on the
+/// calls right after each load). `GRAFF_STABLE_CATALOG=0` /
+/// `GRAFF_NO_STABLE_CATALOG=1` restore the mutating catalog.
+pub var g_stable_catalog = true;
/// Deferred by POLICY, ignoring load state — the stable-catalog render rule
/// and (in stable mode) the listing, which must not change as tools load.
diff --git a/src/mcp_schema_gate_tests.zig b/src/mcp_schema_gate_tests.zig
index c39ede6d..4e7f5d30 100644
--- a/src/mcp_schema_gate_tests.zig
+++ b/src/mcp_schema_gate_tests.zig
@@ -286,8 +286,9 @@ test "stable catalog: a load only appends tail bytes, and the tool stays visible
const meta_spec = [_]@import("schema.zig").ToolSpec{.{ .name = gate.tool_name, .desc = gate.tool_desc, .schema = gate.tool_schema }};
const schema_mod = @import("schema.zig");
+ const saved_stable = gate.g_stable_catalog;
gate.g_stable_catalog = true;
- defer gate.g_stable_catalog = false;
+ defer gate.g_stable_catalog = saved_stable;
const before = try schema_mod.renderRootTools(arena, .anthropic, &meta_spec, fat);
const req = try std.json.parseFromSliceLeaky(Value, arena, "{\"tools\":[\"mcp__fat__t0\"]}", .{ .allocate = .alloc_always });
const loaded = try gate.loadInto(arena, fat, req);
diff --git a/src/prompt_cache_hud.zig b/src/prompt_cache_hud.zig
index a6214c13..13f70330 100644
--- a/src/prompt_cache_hud.zig
+++ b/src/prompt_cache_hud.zig
@@ -211,7 +211,7 @@ pub fn render(w: *Io.Writer) !void {
}
try w.writeAll(
\\ remaining max
- \\ GRAFF_STABLE_CATALOG=1 opt-in: keep tools JSON byte-identical after load
+ \\ GRAFF_STABLE_CATALOG=0 opt out: loads rewrite tools JSON (stable is the default)
\\ /goal /never /strict each prefix rewrite is one miss; compaction already pays one
\\ leave skill bodies and file: paths out of the prefix (already the default)
\\ append-only messages official xAI prefix; edit/remove/reorder is a miss
@@ -219,7 +219,7 @@ pub fn render(w: *Io.Writer) !void {
\\ Z.AI implicit prefix (cached_tokens); thinking.clear_thinking=false
\\ Vercel gateway implicit cache (cached_tokens); coding-agent /v1
\\ /btw parent tools + system + cache key; note is the user message
- \\ subagents prefix lanes (OpenAI/chat); xAI conv stays isolated
+ \\ subagents role-lane x-grok-conv-id / prompt_cache_key (not the root id)
\\
);
}
diff --git a/src/session_settings.zig b/src/session_settings.zig
index fdb77903..9efa7fb7 100644
--- a/src/session_settings.zig
+++ b/src/session_settings.zig
@@ -145,11 +145,24 @@ pub fn applyEnvKnobs(arena: Allocator, environ_map: anytype) !void {
// GRAFF_NO_NATIVE_FOLD: presence-based — restore full power-tool schemas
// in every request (the pre-fold interactive surface).
if (environ_map.get("GRAFF_NO_NATIVE_FOLD") != null) native_fold.enabled = false;
- // GRAFF_STABLE_CATALOG: presence-based experiment (#476) — policy-deferred
- // tools stay out of the catalog even after load_tool_schemas enables them,
- // keeping the request prefix byte-identical all session for the provider's
- // prefix cache. The loaded schema rides the load result in-conversation.
- if (environ_map.get("GRAFF_STABLE_CATALOG") != null) mcp_schema_gate.g_stable_catalog = true;
+ // GRAFF_STABLE_CATALOG is on by default (ADR 0011). Always query so a
+ // dropped parse is visible. GRAFF_NO_STABLE_CATALOG=1 or
+ // GRAFF_STABLE_CATALOG=0|off|false|no restores the mutating catalog;
+ // GRAFF_STABLE_CATALOG=1 wins if both are set.
+ {
+ const no_sc = environ_map.get("GRAFF_NO_STABLE_CATALOG");
+ const sc = environ_map.get("GRAFF_STABLE_CATALOG");
+ if (no_sc) |v| {
+ if (std.mem.eql(u8, v, "1") or std.ascii.eqlIgnoreCase(v, "true") or std.ascii.eqlIgnoreCase(v, "on") or std.ascii.eqlIgnoreCase(v, "yes"))
+ mcp_schema_gate.g_stable_catalog = false;
+ }
+ if (sc) |v| {
+ const off = std.mem.eql(u8, v, "0") or std.ascii.eqlIgnoreCase(v, "false") or std.ascii.eqlIgnoreCase(v, "off") or std.ascii.eqlIgnoreCase(v, "no");
+ const on = std.mem.eql(u8, v, "1") or std.ascii.eqlIgnoreCase(v, "true") or std.ascii.eqlIgnoreCase(v, "on") or std.ascii.eqlIgnoreCase(v, "yes");
+ if (off) mcp_schema_gate.g_stable_catalog = false;
+ if (on) mcp_schema_gate.g_stable_catalog = true;
+ }
+ }
// (#codex-ws) GRAFF_CODEX_WS_IDLE_SECS raises/lowers the held-WS idle limit
// (default 4 min — the backend killed ours within 8.5 min idle; opencode
// pools at 5). Mirrors GRAFF_STREAM_STALL_SECS above: seconds, ignored if
diff --git a/src/session_settings_tests.zig b/src/session_settings_tests.zig
index 9683a601..2185fe18 100644
--- a/src/session_settings_tests.zig
+++ b/src/session_settings_tests.zig
@@ -24,6 +24,7 @@ const http = @import("http.zig");
const ws = @import("ws.zig");
const agent_ws = @import("agent_ws.zig");
const plugins = @import("plugins.zig");
+const mcp_schema_gate = @import("mcp_schema_gate.zig");
const Knob = struct { name: []const u8, value: []const u8 };
@@ -52,6 +53,8 @@ const knobs = [_]Knob{
.{ .name = "GRAFF_WS_FORCE_FAIL_ONCE", .value = "1" },
.{ .name = "GRAFF_WS_FORCE_FAIL_COUNT", .value = "3" },
.{ .name = "GRAFF_NO_PLUGINS", .value = "1" },
+ .{ .name = "GRAFF_STABLE_CATALOG", .value = "1" },
+ .{ .name = "GRAFF_NO_STABLE_CATALOG", .value = "1" },
.{ .name = "GRAFF_VERCEL_URL", .value = "https://ai-gateway.vercel.sh/v1/chat/completions" },
};
@@ -97,6 +100,7 @@ const Saved = struct {
ws_fail_once: bool,
ws_fail_count: u8,
plugins_off: bool,
+ stable_catalog: bool,
fn capture() Saved {
return .{
@@ -120,6 +124,7 @@ const Saved = struct {
.ws_fail_once = ws.g_force_connect_failure_once,
.ws_fail_count = ws.g_force_connect_failure_count,
.plugins_off = plugins.disabled,
+ .stable_catalog = mcp_schema_gate.g_stable_catalog,
};
}
@@ -145,6 +150,7 @@ const Saved = struct {
ws.g_force_connect_failure_once = s.ws_fail_once;
ws.g_force_connect_failure_count = s.ws_fail_count;
plugins.disabled = s.plugins_off;
+ mcp_schema_gate.g_stable_catalog = s.stable_catalog;
}
};
@@ -188,6 +194,7 @@ test "applyEnvKnobs actually applies the values it reads" {
provider_mod.g_compact_pct_override = null;
tool_handle.threshold_bytes = tool_handle.default_threshold_bytes;
plugins.disabled = false;
+ mcp_schema_gate.g_stable_catalog = false;
var asked: [knobs.len]bool = @splat(false);
try session_settings.applyEnvKnobs(arena_state.allocator(), RecordingEnv{ .asked = &asked });
@@ -208,6 +215,7 @@ test "applyEnvKnobs actually applies the values it reads" {
try std.testing.expect(ws.g_force_connect_failure_once);
try std.testing.expectEqual(@as(u8, 3), ws.g_force_connect_failure_count);
try std.testing.expect(plugins.disabled);
+ try std.testing.expect(mcp_schema_gate.g_stable_catalog); // GRAFF_STABLE_CATALOG=1 wins over GRAFF_NO_STABLE_CATALOG=1
}
const PairEnv = struct {
@@ -244,3 +252,18 @@ test "GRAFF_OLD / GRAFF_RLM=0 turn default rlm off; --old is not clobbered by en
try std.testing.expect(!rlm.available);
try std.testing.expect(rlm.cli_set);
}
+
+test "GRAFF_STABLE_CATALOG=0 / GRAFF_NO_STABLE_CATALOG turn default-on catalog off" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const saved = Saved.capture();
+ defer saved.restore();
+
+ mcp_schema_gate.g_stable_catalog = true;
+ try session_settings.applyEnvKnobs(arena_state.allocator(), PairEnv{ .pairs = &.{.{ .name = "GRAFF_STABLE_CATALOG", .value = "0" }} });
+ try std.testing.expect(!mcp_schema_gate.g_stable_catalog);
+
+ mcp_schema_gate.g_stable_catalog = true;
+ try session_settings.applyEnvKnobs(arena_state.allocator(), PairEnv{ .pairs = &.{.{ .name = "GRAFF_NO_STABLE_CATALOG", .value = "1" }} });
+ try std.testing.expect(!mcp_schema_gate.g_stable_catalog);
+}