Skip to content

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

Python

fix(models): /models pings the router catalogs live instead of showing the boot snapshot

Rach Pradhanb91ede0c6875
diff --git a/src/commands_misc.zig b/src/commands_misc.zig
index b7001af7..35595ec9 100644
--- a/src/commands_misc.zig
+++ b/src/commands_misc.zig
@@ -368,6 +368,11 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,
if (std.mem.eql(u8, line, "/models")) {
root.ensureStoredKeys(keys);
providers.ensureModelQueryCatalogs(root, keys.*, "");
+ // The explicit listing is the freshness moment: live-refresh the
+ // router-catalog providers, bypassing the per-process latch and 6h
+ // TTL that made /models show a boot-time snapshot until restart.
+ const pinged = providers.refreshModelListing(root, keys.*);
+ if (pinged > 0) try out.print("{s}(pinged {d} provider catalog(s) live){s}\n", .{ style.dim, pinged, style.reset });
try out.writeAll("model ctx compact@ provider key vision\n");
for (pricing.models()) |m| {
const has_key = keys.get(m.provider) != null;
diff --git a/src/providers.zig b/src/providers.zig
index 901cc113..f6e89c15 100644
--- a/src/providers.zig
+++ b/src/providers.zig
@@ -327,6 +327,15 @@ pub fn ensureModelQueryCatalogs(root: *Agent, keys: Keys, query: []const u8) voi
router_catalog.ensureForQuery(root.io, root.gpa, root.arena, root.home, keys, query);
}
+/// The /models listing's live refresh: the explicit ping is the freshness
+/// moment, so the router-catalog providers (codegraff/anthropic/fireworks/
+/// workspace router) are re-fetched NOW — concurrently, cache as offline
+/// fallback — instead of showing the boot-time snapshot until restart.
+/// Codex and Kimi keep their bespoke caches; /models prints their sources.
+pub fn refreshModelListing(root: *Agent, keys: Keys) usize {
+ return router_catalog.refreshForListing(root.io, root.gpa, root.arena, root.home, keys);
+}
+
/// Structured set_model has separate provider/model fields. An explicit
/// provider fully determines routing; a model-only request remains fuzzy.
pub fn controlRequestMayUseCodex(provider_query: []const u8, model_query: []const u8, legacy_name: []const u8) bool {
diff --git a/src/router_catalog.zig b/src/router_catalog.zig
index 756c374d..ba2d4db6 100644
--- a/src/router_catalog.zig
+++ b/src/router_catalog.zig
@@ -478,6 +478,37 @@ pub fn ensureForStartup(io: Io, gpa: Allocator, arena: Allocator, home: []const
}
}
+/// An explicit /models listing is the freshness moment: hit every keyed
+/// dynamic provider live, concurrently (startup's own fan-out), bypassing
+/// BOTH the once-per-process attempt latch and the 6h TTL — the pair that
+/// made /models show a boot-time snapshot until restart. The disk cache
+/// remains the offline fallback, and each live list is re-cached for the
+/// next boot. Returns how many providers were pinged.
+pub fn refreshForListing(io: Io, gpa: Allocator, arena: Allocator, home: []const u8, keys: provider.Keys) usize {
+ var futures: [provider.provider_specs.len + 1]?Io.Future(FetchOutcome) = @splat(null);
+ var pinged: usize = 0;
+ for (provider.provider_specs, 0..) |spec, index| {
+ if (!dynamic(spec)) continue;
+ const key = keys.get(spec.id) orelse continue;
+ if (key.len == 0) continue;
+ attempted[index] = true;
+ futures[index] = spawnFetch(io, gpa, home, spec, key, keys.source(spec.id));
+ pinged += 1;
+ }
+ if (provider.additional_router) |spec| {
+ if (keys.get(spec.id)) |key| if (key.len != 0) {
+ additional_attempted = true;
+ futures[provider.provider_specs.len] = spawnFetch(io, gpa, home, spec, key, keys.source(spec.id));
+ pinged += 1;
+ };
+ }
+ for (&futures) |*maybe| {
+ const outcome = if (maybe.*) |*fut| fut.await(io) else continue;
+ finishFetch(io, arena, home, outcome);
+ }
+ return pinged;
+}
+
pub fn ensureForQuery(io: Io, gpa: Allocator, arena: Allocator, home: []const u8, keys: provider.Keys, query: []const u8) void {
for (provider.provider_specs, 0..) |spec, index| {
if (!dynamic(spec) or !catalog_selection.queryMayUse(spec.id, query)) continue;