From d03657a9810aea9c2ac3c26a80b72f3bdfe42b6a Mon Sep 17 00:00:00 2001 From: Douglas Baggett Date: Mon, 9 Nov 2026 07:01:38 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20[v6]=20proxy=20cap:=20a=20per-ag?= =?UTF-8?q?ent=20GitHub=20API=20hourly=20cap=20applies=20without=20the=20f?= =?UTF-8?q?leet=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AgentGitHubAPIHourlyCap returned the default 300 whenever agents.github_api_hourly_cap was unset, before it looked at the agent's own override, so agents.reviewer.github_api_hourly_cap: 600 alone was ignored. The override is read first now, then the base agent's (for a replica or review head written before a reload re-copies the base), then the fleet key, then the default. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Douglas Baggett --- .../fixed-agent-github-cap-override-alone.md | 1 + .../operator-reference/runtime-and-quota.md | 5 +++ src/pkg/config/github_api_budget.go | 20 +++++++-- src/pkg/config/github_api_budget_test.go | 43 +++++++++++++++++++ 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 changelog.d/fixed-agent-github-cap-override-alone.md diff --git a/changelog.d/fixed-agent-github-cap-override-alone.md b/changelog.d/fixed-agent-github-cap-override-alone.md new file mode 100644 index 0000000000..8e829454fb --- /dev/null +++ b/changelog.d/fixed-agent-github-cap-override-alone.md @@ -0,0 +1 @@ +- **A per-agent GitHub API hourly cap now applies without the fleet key.** `agents..github_api_hourly_cap` was read only when `agents.github_api_hourly_cap` was also set, so `agents.reviewer.github_api_hourly_cap: 600` on its own left the reviewer at the default 300. The override now applies on its own, and a replica or review head that has none of its own takes its base agent's. `0` still means no cap at either level. See [Runtime and quota](src/docs/operator-reference/runtime-and-quota.md). diff --git a/src/docs/operator-reference/runtime-and-quota.md b/src/docs/operator-reference/runtime-and-quota.md index 0587cf4e56..14d32a4eb1 100644 --- a/src/docs/operator-reference/runtime-and-quota.md +++ b/src/docs/operator-reference/runtime-and-quota.md @@ -163,6 +163,11 @@ loops, so the proxy enforces two safeguards: minting is not agent-attributed and is not counted. Set the value to `0` to disable the fleet default, or set `agents..github_api_hourly_cap` to override one agent (`0` disables that agent's cap). + The override applies on its own, whether or not the fleet key is set. A + replica (`reviewer-2`, …) or review head takes its base agent's override + unless it has one of its own. The order is the agent's own value, then the + base agent's, then `agents.github_api_hourly_cap`, then the default of 300. + A config reload reaches the proxy without a restart. - `github.agent_reserve_floor` (default `400`) protects the shared core bucket. When the latest rate-limit reading shows `core.remaining` below the floor, agent read requests receive the same proxy `429` even if the agent has not diff --git a/src/pkg/config/github_api_budget.go b/src/pkg/config/github_api_budget.go index 48551cb149..cdcb654e2f 100644 --- a/src/pkg/config/github_api_budget.go +++ b/src/pkg/config/github_api_budget.go @@ -147,16 +147,30 @@ func mappingNode(node *yaml.Node) *yaml.Node { return node } +// AgentGitHubAPIHourlyCap is the per-agent proxy cap on charged GitHub API +// responses per sliding hour; 0 means no cap. An agent's own +// agents..github_api_hourly_cap wins, then its base agent's (a replica +// or review head is built as a copy of the base, so it normally carries the +// base's value already; the lookup also covers a base override set after the +// copy was made), then agents.github_api_hourly_cap, then the default of 300. +// The override used to be read only when the fleet key was set as well, so +// agents.reviewer.github_api_hourly_cap: 600 on its own left the reviewer at +// 300. func (c *Config) AgentGitHubAPIHourlyCap(agentName string) int { if c == nil { return DefaultAgentsGitHubAPIHourlyCap } - if c.AgentsGitHubAPIHourlyCap == 0 && !c.AgentsGitHubAPIHourlyCapSet { - return DefaultAgentsGitHubAPIHourlyCap - } if a, ok := c.Agents[agentName]; ok && a.GitHubAPIHourlyCap != nil { return *a.GitHubAPIHourlyCap } + if base := c.BaseAgentName(agentName); base != agentName { + if a, ok := c.Agents[base]; ok && a.GitHubAPIHourlyCap != nil { + return *a.GitHubAPIHourlyCap + } + } + if c.AgentsGitHubAPIHourlyCap == 0 && !c.AgentsGitHubAPIHourlyCapSet { + return DefaultAgentsGitHubAPIHourlyCap + } return c.AgentsGitHubAPIHourlyCap } diff --git a/src/pkg/config/github_api_budget_test.go b/src/pkg/config/github_api_budget_test.go index 7767133e8e..273d23fb58 100644 --- a/src/pkg/config/github_api_budget_test.go +++ b/src/pkg/config/github_api_budget_test.go @@ -61,3 +61,46 @@ agents: t.Fatalf("cap = %d, want explicit zero", got) } } + +// A per-agent override applies on its own: the fleet key used to be required +// too, so this left the reviewer at 300 (projectbluefin hive, 2026-11-09). +func TestGitHubAPIBudgetOverrideWithoutFleetKey(t *testing.T) { + raw := ` +agents: + reviewer: + github_api_hourly_cap: 600 + scanner: + enabled: true + quality: + github_api_hourly_cap: 0 +` + var cfg Config + if err := yaml.NewDecoder(strings.NewReader(raw)).Decode(&cfg); err != nil { + t.Fatalf("Decode: %v", err) + } + cfg.applyDefaults() + for agent, want := range map[string]int{"reviewer": 600, "scanner": DefaultAgentsGitHubAPIHourlyCap, "quality": 0} { + if got := cfg.AgentGitHubAPIHourlyCap(agent); got != want { + t.Errorf("%s cap = %d, want %d", agent, got, want) + } + } +} + +// A replica takes its base agent's override, including one set on the base +// after the replica entry was built, and its own override still wins. +func TestGitHubAPIBudgetReplicaUsesBaseOverride(t *testing.T) { + six, nine := 600, 900 + cfg := &Config{AgentRuntimeConfig: AgentRuntimeConfig{Agents: map[string]AgentConfig{ + "reviewer": {}, + "reviewer-2": {ReplicaOf: "reviewer"}, + "reviewer-3": {ReplicaOf: "reviewer", GitHubAPIHourlyCap: &nine}, + }}} + reviewer := cfg.Agents["reviewer"] + reviewer.GitHubAPIHourlyCap = &six + cfg.Agents["reviewer"] = reviewer + for agent, want := range map[string]int{"reviewer": 600, "reviewer-2": 600, "reviewer-3": 900, "scanner": DefaultAgentsGitHubAPIHourlyCap} { + if got := cfg.AgentGitHubAPIHourlyCap(agent); got != want { + t.Errorf("%s cap = %d, want %d", agent, got, want) + } + } +}