Skip to content

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

Python

fix(worker): /model re-derives the ladder worker default; startup and switches share the bench ladder (#371)

justrach04bc71d694b6
diff --git a/src/agent.zig b/src/agent.zig
index 80c4aeea..127a6ad2 100644
--- a/src/agent.zig
+++ b/src/agent.zig
@@ -72,6 +72,7 @@ pub const Agent = struct {
client: *std.http.Client,
provider: Provider,
subagent_provider: ?Provider = null, // optional model pin for every direct child/workflow/judge
+ subagent_provider_explicit: bool = false, // #371: --subagent-*/GRAFF_SUBAGENT_*/--no-subagent-tier freeze it; a DERIVED default re-follows /model (providers.applyProviderInner)
subagent_cross_provider: bool = false, // user explicitly allowed the pin to cross a provider/data boundary
messages: std.json.Array,
// Codex Responses WS delta transport: one WS held ACROSS user turns (codex_chain.zig), sending previous_response_id + only new items. Reset by closeCodexWs.
diff --git a/src/bench_priors.zig b/src/bench_priors.zig
index b4dade22..c4e0c2d4 100644
--- a/src/bench_priors.zig
+++ b/src/bench_priors.zig
@@ -140,6 +140,18 @@ pub fn noteKeys(keys: *provider_mod.Keys) *provider_mod.Keys {
return keys;
}
+/// Startup composition, riding resolveKeys' return: snapshot availability,
+/// then load/derive the sheet — so the #291 worker default (resolved moments
+/// later in main) sees the SAME bench ladders as every later /model
+/// re-derivation (#371). Without this, startup derived workers from the
+/// compiled table while a switch re-derived from the bench one, and the two
+/// disagreed (terra vs the data-blessed gpt-5.5 on codex).
+pub fn noteKeysAtStartup(keys: provider_mod.Keys, io: Io, arena: Allocator, home: ?[]const u8) provider_mod.Keys {
+ const kept = noteAvailability(keys);
+ loadInto(io, arena, home);
+ return kept;
+}
+
/// Best sheet score for `model` as served by `provider_id`; null when the
/// sheet has no opinion.
pub fn scoreFor(provider_id: []const u8, model: []const u8) ?f64 {
diff --git a/src/providers.zig b/src/providers.zig
index 58d07f37..a25097ed 100644
--- a/src/providers.zig
+++ b/src/providers.zig
@@ -94,6 +94,14 @@ fn applyProviderInner(root: *Agent, arena: Allocator, p: Provider, persist: bool
}
}
root.provider = p;
+ // #371: the #291 worker default resolved once at startup; without this a
+ // /model switch left children on the OLD provider's rung (root on codex,
+ // workers silently still on kimi — a cost and consent surprise) or with
+ // no ladder descent at all. Only the DERIVED default follows the root;
+ // explicit --subagent-* choices stay exactly as the user stated them.
+ if (!root.subagent_provider_explicit) if (@import("bench_priors.zig").g_keys) |k| {
+ root.subagent_provider = @import("subagent_selection.zig").resolveSubagentProvider(k.*, p, null, null, false, false);
+ };
// Keep the context estimate and first request exact without eagerly
// materializing formats this session has never used.
try root.ensureRootTools(p.kind);
@@ -471,6 +479,8 @@ test "applyProviderInner preserves the server meter on an exact model re-selecti
var root: Agent = undefined;
root.provider = p;
+ root.subagent_provider = null;
+ root.subagent_provider_explicit = true; // this test is about the meter, not #371 re-derivation
root.arena = a;
root.registry = null;
root.messages = std.json.Array.init(a);
diff --git a/src/session_run.zig b/src/session_run.zig
index a6a84ec8..983a025e 100644
--- a/src/session_run.zig
+++ b/src/session_run.zig
@@ -187,8 +187,7 @@ pub fn runOneshotPrompt(gpa: Allocator, io: Io, arena: Allocator, root: *agent_m
/// `approvals` is an out-param: main() declares it (`var approvals: Approvals
/// = undefined;`) and this fills it in place, so main() can still register
/// its own `defer` for `approvals.prefixes` right after the call (a `defer`
-/// registered inside this helper would fire at the WRONG time — when this
-/// function returns, not when main() does).
+/// registered here would fire when THIS returns, not when main() does).
pub fn initApprovalsHooksFleet(io: Io, gpa: Allocator, arena: Allocator, environ_map: anytype, approvals: *approvals_mod.Approvals, flags: args.Flags, out: *Io.Writer, json_mode: bool) !void {
approvals.* = .{ .yolo = flags.yolo_flag };
const persisted_approvals = approvals.loadPersisted(io, gpa, arena);
@@ -246,6 +245,7 @@ pub fn buildRootAgent(
.client = client,
.provider = default_provider,
.subagent_provider = subagent_provider,
+ .subagent_provider_explicit = flags.subagent_provider_flag != null or flags.subagent_model_flag != null or flags.no_subagent_tier_flag or environ_map.get("GRAFF_SUBAGENT_PROVIDER") != null or environ_map.get("GRAFF_SUBAGENT_MODEL") != null, // #371: only a USER-stated worker choice survives /model
.subagent_cross_provider = flags.allow_cross_provider_subagents_flag,
.home = keys_cli.homeEnv(environ_map) orelse "",
.messages = std.json.Array.init(arena),
diff --git a/src/startup.zig b/src/startup.zig
index ad2bf950..0da58655 100644
--- a/src/startup.zig
+++ b/src/startup.zig
@@ -306,7 +306,7 @@ pub fn resolveKeys(io: Io, gpa: Allocator, arena: Allocator, environ_map: anytyp
}
}
}
- return .{ .keys = @import("bench_priors.zig").noteAvailability(keys), .default_provider = default_provider, .stale_saved_model = stale_saved_model, .preferred_provider = preferred_provider, .codex_account = codex_account, .model_catalog = model_catalog, .stored_keys_loaded = stored_keys_loaded };
+ return .{ .keys = @import("bench_priors.zig").noteKeysAtStartup(keys, io, arena, keys_cli.homeEnv(environ_map)), .default_provider = default_provider, .stale_saved_model = stale_saved_model, .preferred_provider = preferred_provider, .codex_account = codex_account, .model_catalog = model_catalog, .stored_keys_loaded = stored_keys_loaded };
}
/// Root system-prompt layering, frozen at startup so it stays