graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
feat(fleet): slot axis via allowlist, not a composite niche (#290)
Rach Pradhan9e10ef698736
diff --git a/src/main.zig b/src/main.zigindex 98596165..f6f4082e 100644--- a/src/main.zig+++ b/src/main.zig@@ -591,4 +591,7 @@ const exec = @import("exec.zig");test { // pull in tests from imported modules (mcp.zig)_ = mcp;_ = @import("main_test.zig");+ // A module referenced only from a test file is NOT analyzed otherwise, so+ // its tests silently compile to nothing and the suite still reports green.+ _ = @import("scoring_slot_test.zig");}diff --git a/src/scoring.zig b/src/scoring.zigindex ad5c28ee..98539d0f 100644--- a/src/scoring.zig+++ b/src/scoring.zig@@ -12,6 +12,9 @@ const Allocator = std.mem.Allocator;const pricing = @import("pricing.zig");const priceFor = pricing.priceFor;const util = @import("util.zig");+// The closed slot vocabulary telemetrySlot allowlists against (#293). shapes.zig+// is a std-only leaf, so this cannot cycle back through scoring.+const shapes = @import("shapes.zig");/// Short stable fingerprint of a system prompt (first 8 bytes of SHA-256,/// hex): equal hashes along a trajectory edge mean the prompt didn't change.@@ -188,6 +191,25 @@ pub fn telemetryProviderClass(value: []const u8) ?[]const u8 {return null;}+/// Project a workflow slot onto the wire — the third MAP-Elites coordinate+/// (#290), after the niche and the provider class.+///+/// A slot originates from a free-form workflow phase title, so it gets the+/// ALLOWLIST treatment (like telemetryProviderClass) rather than the+/// hash-everything-else treatment (telemetryNiche/telemetryHash). That is+/// only sound because the vocabulary in shapes.zig is CLOSED: a canonical+/// slot is one of ten structural words carrying no user content, so it can+/// ship as plaintext without widening the egress contract documented above.+///+/// Anything off-vocabulary returns "" (uncelled) rather than a fingerprint —+/// hashing would mint a private per-title cell that no other run can ever+/// join against, which is worse than not celling the round at all.+pub fn telemetrySlot(value: []const u8) []const u8 {+ for (shapes.canonical_slots) |slot|+ if (std.ascii.eqlIgnoreCase(value, slot)) return slot;+ return "";+}+/// Read the signing key from GRAFF_SCORE_KEY_FILE, or the conventional/// ~/.simple-harness/score.key when no path is configured. The key stays/// outside cwd so learning adapters and confined subagents cannot read it.diff --git a/src/scoring_slot_test.zig b/src/scoring_slot_test.zignew file mode 100644index 00000000..f46dbbff--- /dev/null+++ b/src/scoring_slot_test.zig@@ -0,0 +1,86 @@+//! Tests for the MAP-Elites slot axis (#290) — the third cell coordinate.+//!+//! Split into its own file because scoring.zig and subagent.zig are both at or+//! near the 600-line cap. Pulled into the test root via src/main.zig's `test {}`+//! hook: without that reference these tests compile to nothing and the suite+//! still reports green (the exact trap that made #291's 9 new tests dead).++const std = @import("std");+const scoring = @import("scoring.zig");+const shapes = @import("shapes.zig");++test "telemetrySlot: canonical vocabulary passes through, case-insensitively" {+ for (shapes.canonical_slots) |slot|+ try std.testing.expectEqualStrings(slot, scoring.telemetrySlot(slot));+ try std.testing.expectEqualStrings("verify", scoring.telemetrySlot("VERIFY"));+ try std.testing.expectEqualStrings("synthesize", scoring.telemetrySlot("Synthesize"));+}++test "telemetrySlot: anything off-vocabulary is uncelled, never hashed, never echoed" {+ // This is the privacy property the whole slot design rests on. telemetryNiche+ // hashes free-form input to custom-<hex>; a slot must do NEITHER that nor echo+ // the input, because a per-title hash mints a private cell nothing can join+ // against, and echoing would put user task labels on the wire in cleartext.+ const leaky = [_][]const u8{+ "Migrate Acme billing schema",+ "/Users/someone/secret-project",+ "find", // NB: canonical only as a bare word; see the compound cases below+ "code review",+ "",+ "custom-deadbeefdeadbeef",+ };+ for (leaky) |v| {+ const got = scoring.telemetrySlot(v);+ if (got.len == 0) continue; // uncelled: the safe outcome+ // Whatever came back must be a member of the closed vocabulary — never a+ // fingerprint, never a substring of the caller's text.+ var member = false;+ for (shapes.canonical_slots) |slot| if (std.mem.eql(u8, slot, got)) {+ member = true;+ };+ try std.testing.expect(member);+ try std.testing.expect(!std.mem.startsWith(u8, got, "custom-"));+ }+ // Free-form titles specifically must be dropped, not projected.+ try std.testing.expectEqualStrings("", scoring.telemetrySlot("Migrate Acme billing schema"));+ try std.testing.expectEqualStrings("", scoring.telemetrySlot("/Users/someone/secret-project"));+}++test "canonicalSlot + telemetrySlot compose: a real phase title reaches a cell or nothing" {+ // The production path is telemetrySlot(canonicalSlot(title)).+ const compose = struct {+ fn f(title: []const u8) []const u8 {+ return scoring.telemetrySlot(shapes.canonicalSlot(title));+ }+ }.f;+ // Titles the shape catalog tells the model to use land in their cell.+ try std.testing.expectEqualStrings("find", compose("find security bugs"));+ try std.testing.expectEqualStrings("verify", compose("verify each finding"));+ try std.testing.expectEqualStrings("synthesize", compose("Synthesize the results"));+ try std.testing.expectEqualStrings("transform", compose("transform each file"));+ // A customer name in a phase title reaches no cell and leaves no plaintext.+ try std.testing.expectEqualStrings("", compose("Migrate Acme billing schema"));+ // And the composed result is always vocabulary-or-empty, never caller text.+ for ([_][]const u8{ "Migrate Acme billing", "ponder deeply", "", "x" }) |t| {+ const got = compose(t);+ if (got.len > 0) {+ var member = false;+ for (shapes.canonical_slots) |slot| if (std.mem.eql(u8, slot, got)) {+ member = true;+ };+ try std.testing.expect(member);+ }+ }+}++test "slot never widens the niche: the signed niche stays exactly the agent name" {+ // Regression guard for the design error that sank the first #290 attempt:+ // the composite "agent/tier/slot" string was fed to signScore AND to the+ // fleet niche, where telemetryNiche hashed it to custom-<hex> — so the score+ // record and the fleet record named two different cells and stopped joining.+ // The slot must therefore never be concatenated into a niche.+ var buf: [23]u8 = undefined;+ try std.testing.expectEqualStrings("reviewer", scoring.telemetryNiche(&buf, "reviewer"));+ // If anyone reintroduces a composite, this is what it would do:+ try std.testing.expect(std.mem.startsWith(u8, scoring.telemetryNiche(&buf, "reviewer/frontier/verify"), "custom-"));+}diff --git a/src/subagent.zig b/src/subagent.zigindex 4dcc21ef..38d68a64 100644--- a/src/subagent.zig+++ b/src/subagent.zig@@ -69,7 +69,8 @@ const subagent_run = @import("subagent_run.zig");pub const AgentUsage = subagent_run.AgentUsage;pub const SubRun = subagent_run.SubRun;pub const runSub = subagent_run.runSub;-const childProvider = subagent_run.childProvider;+const variantProviderClass = subagent_run.variantProviderClass;+const shapes = @import("shapes.zig");const FailKind = subagent_run.FailKind;const classifyFailure = subagent_run.classifyFailure;@@ -477,6 +478,17 @@ pub fn scoreVariants(}if (vn < 2) return;+ // A tournament must vary exactly ONE axis: if the variants did not all run on+ // the same capability tier, the ranking reflects the model as much as the+ // prompt, and filing it under the prompt fingerprint writes model effects into+ // the genome archive (#290). Bail before spawning a judge — unscoreable round.+ for (1..vn) |k| {+ if (!std.mem.eql(u8, variantProviderClass(ctx, vidx[0]), variantProviderClass(ctx, vidx[k]))) {+ if (ctx.tracer) |tr| tr.note("fleet", "tournament skipped: variants span provider classes");+ return;+ }+ }+// All fallible work (prompt builds) before any future spawns, so an early// return can never abandon a running judge.const jprompts = arena.alloc([]const u8, vn) catch return;@@ -487,8 +499,9 @@ pub fn scoreVariants(const jfuts = arena.alloc(Io.Future(ToolOutput), vn) catch return;for (jfuts, jprompts) |*jf, jp| jf.* = ctx.io.async(judgeTask, .{ ctx, jp });- const pclass = providerClass(childProvider(ctx.provider, ctx.subagent_provider, ctx.subagent_cross_provider).model);const run_id: []const u8 = &scoring.g_run_id;+ // This phase's MAP-Elites slot (#290/#293); "" off-vocabulary. See telemetrySlot.+ const slot = scoring.telemetrySlot(shapes.canonicalSlot(title));for (jfuts, 0..) |*jf, k| {const i = vidx[k];const jout = jf.await(ctx.io);@@ -509,6 +522,7 @@ pub fn scoreVariants(// above; every score that leaves the client is [0,1], so divide at// the emission boundary — s01 is what gets signed and sent.const s01 = s / 100.0;+ const pclass = variantProviderClass(ctx, i);const genome_fp = promptFingerprint(overrides[i].?);const esh_fp = promptFingerprint(raws[i]);const genome: []const u8 = &genome_fp;@@ -521,7 +535,10 @@ pub fn scoreVariants(const sig = signScore(genome, "", s01, run_id, "", "", esh, niche, pclass);const sig_s: []const u8 = if (scoring.g_score_key != null) &sig else "";var provbuf: [512]u8 = undefined;- const prov = std.fmt.bufPrint(&provbuf, "{s}\t{s}\t{s}\t{s}\t{s}", .{ "", "", esh, pclass, niche }) catch "";+ // Slot is APPENDED as a 6th component, so a collector indexing 0..4 is+ // unaffected. Advisory like the rest of `prov` (signScore holds the+ // authoritative copies); signing it would need a collector-first deploy.+ const prov = std.fmt.bufPrint(&provbuf, "{s}\t{s}\t{s}\t{s}\t{s}\t{s}", .{ "", "", esh, pclass, niche, slot }) catch "";// Genome-send (issue #168 Gap 5), mirroring runEval: ride the variant's// text over on a propose (deduped by fingerprint server-side) so the// scored cell has a servable genome even when runSub never proposed it.diff --git a/src/subagent_run.zig b/src/subagent_run.zigindex 2c7197c7..01f90c5d 100644--- a/src/subagent_run.zig+++ b/src/subagent_run.zig@@ -101,6 +101,27 @@ pub fn childProvider(root: Provider, pinned: ?Provider, allow_cross_provider: boreturn if (std.mem.eql(u8, child.id, root.id) or allow_cross_provider) child else root;}+/// Capability tier ("frontier" | "mid" | "small") of the model that ran variant+/// `i` of a workflow phase — the provider-class axis of the MAP-Elites cell.+///+/// Today every child in a phase resolves through the same session-level+/// subagent provider, so this returns the same value for every `i`. It is+/// written per-variant regardless, because this is exactly the seam that+/// per-persona / per-spawn model pins (#292) extend: with the class hoisted to+/// a phase-level constant, the first heterogeneous fan-out would keep reporting+/// the ROOT's class for every variant and quietly file model effects under the+/// prompt genome. Keeping the lookup per-variant means #292 changes this one+/// function instead of having to notice a stale constant.+///+/// NOTE (#291): providerClass cannot currently distinguish gpt-5.6-sol from+/// gpt-5.6-terra/-luna — all three classify as "frontier". Until that is+/// resolved this axis cannot separate ladder rungs, and the matched-tournament+/// guard in scoreVariants is correspondingly blind to a rung-only difference.+pub fn variantProviderClass(ctx: tools.ToolCtx, i: usize) []const u8 {+ _ = i; // per-variant model pins land in #292+ return scoring.providerClass(childProvider(ctx.provider, ctx.subagent_provider, ctx.subagent_cross_provider).model);+}+pub const AgentUsage = struct {duration_ms: u64 = 0,tool_calls: u32 = 0,