graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Fall back to the Anthropic Console sign-in when the Claude plan is spent
justrach5b1492dfba93
diff --git a/src/agent_request_quota.zig b/src/agent_request_quota.zigindex 718b31ee..2ae7090c 100644--- a/src/agent_request_quota.zig+++ b/src/agent_request_quota.zig@@ -31,6 +31,9 @@ pub fn isQuotaExceeded(body: []const u8) bool {"credits_exhausted", "credit_limit_exceeded", "insufficient_funds","http 402", "exhausted_credit", "credit_balance_too_low","subscription_sharing_v2_usage_limit_exceeded",+ // A Claude subscription past its extra usage answers 400+ // invalid_request_error with only this phrase to go on.+ "out of extra usage",};for (needles) |needle| if (util.indexOfIgnoreCase(body, needle) != null) return true;return false;@@ -173,6 +176,7 @@ test "isQuotaExceeded (#opencode-parity): billing cap detected, transient throtttry std.testing.expect(isQuotaExceeded("{\"error\":{\"code\":\"insufficient_quota\",\"message\":\"You exceeded your current quota\"}}"));try std.testing.expect(isQuotaExceeded("Quota Exceeded for this key"));try std.testing.expect(isQuotaExceeded("{\"error\":{\"code\":\"subscription_sharing_usage_limit_exceeded\"}}"));+ try std.testing.expectEqual(Fault.quota, classify("invalid_request_error", null, "You're out of extra usage. Add more at claude.ai/settings/usage and keep going.").?);// transient rate-limit -> NOT a quota cap; must still retrytry std.testing.expect(!isQuotaExceeded("Rate limit reached. Please try again in 20s."));try std.testing.expect(!isQuotaExceeded("429 too many requests"));diff --git a/src/credential_failover.zig b/src/credential_failover.zigindex d97badf8..606f43c5 100644--- a/src/credential_failover.zig+++ b/src/credential_failover.zig@@ -43,6 +43,14 @@ pub fn park(provider_id: []const u8, value: []const u8, source: Keys.CredentialSg_promoted[i] = false;}+/// A metered credential read only after a plan took the slot (Anthropic's+/// Console profile loads after preferPlan): park it so the plan can still hand+/// over. Never displaces a credential already parked or a non-plan seat.+pub fn parkBehindPlan(provider_id: []const u8, seated: Keys.CredentialSource, value: []const u8, source: Keys.CredentialSource) void {+ if (seated != .login or standingBy(provider_id) or promoted(provider_id)) return;+ park(provider_id, value, source);+}+/// Is a metered credential standing by for this provider, unused so far?pub fn standingBy(provider_id: []const u8) bool {const i = indexOf(provider_id) orelse return false;@@ -155,3 +163,20 @@ test "#471 a parked metered key is handed over once, and only once" {try std.testing.expect(promote("no-such-provider") == null);try std.testing.expect(!standingBy("no-such-provider"));}++test "a Console profile read after the Claude plan seated is parked behind it" {+ resetForTest();+ defer resetForTest();++ // Only a plan seat gets a reserve.+ parkBehindPlan("anthropic", .stored, "sk-ant-oat01-console", .profile);+ try std.testing.expect(!standingBy("anthropic"));++ parkBehindPlan("anthropic", .login, "sk-ant-oat01-console", .profile);+ try std.testing.expect(standingBy("anthropic"));+ // An earlier reserve (an env key parked by preferPlan) is kept.+ parkBehindPlan("anthropic", .login, "other", .stored);+ const p = promote("anthropic").?;+ try std.testing.expectEqualStrings("sk-ant-oat01-console", p.key);+ try std.testing.expectEqual(Keys.CredentialSource.profile, p.source);+}diff --git a/src/startup_keys.zig b/src/startup_keys.zigindex 00172f49..f1e756be 100644--- a/src/startup_keys.zig+++ b/src/startup_keys.zig@@ -339,9 +339,13 @@ pub fn resolveKeysOptional(io: Io, gpa: Allocator, arena: Allocator, environ_map} else keys_cli.loadMissingStoredKeys(io, gpa, arena, home, &keys, .all);}const home = keys_cli.homeEnv(environ_map) orelse "";- if (keys.get("anthropic") == null) if (ap.load(io, arena, environ_map, home, false)) |t| {- _ = keys.set("anthropic", t, .profile);- };+ if (keys.get("anthropic") == null) {+ if (ap.load(io, arena, environ_map, home, false)) |t| _ = keys.set("anthropic", t, .profile);+ } else if (keys.source("anthropic") == .login and !credential_failover.standingBy("anthropic")) {+ // The Claude plan took the slot first; keep the Console sign-in in+ // reserve so a spent plan hands over instead of failing every turn.+ if (ap.load(io, arena, environ_map, home, false)) |t| credential_failover.parkBehindPlan("anthropic", .login, t, .profile);+ }var model_catalog: models_cache.LazyCodexCatalog = .{ .codex_home = oauth.codexHomeDir(arena, home) orelse "" };const saved_model: ?serde.SavedModel = if (model_flag == null) serde.loadModel(io, arena, home) else null;// Dynamic Codex discovery is observable only when startup may select