diff --git a/changelog.d/fixed-15435-fanout-grounding-budget.md b/changelog.d/fixed-15435-fanout-grounding-budget.md new file mode 100644 index 0000000000..e20c193655 --- /dev/null +++ b/changelog.d/fixed-15435-fanout-grounding-budget.md @@ -0,0 +1 @@ +- A combined review head's fan-out now splits the shared grounding tool-call budget across its per-perspective sub-agents instead of leaving each to read the whole-review cap as its own. diff --git a/src/pkg/review/prompts.go b/src/pkg/review/prompts.go index 927bd718d4..2857cf2405 100644 --- a/src/pkg/review/prompts.go +++ b/src/pkg/review/prompts.go @@ -743,12 +743,23 @@ func buildHeadFanOutInstruction(pr PullRequest, perspectives []Perspective, back fmt.Fprintf(&b, "1. Fetch the PR metadata, the full diff of %s#%d and any linked issue or contract ONCE, yourself, as the read instructions above describe.\n", pr.Repo, pr.Number) fmt.Fprintf(&b, "2. Start one sub-agent per perspective, all %d at once, IN PARALLEL, not one after another (Claude Code: the Task tool; Codex and other backends: their sub-agent facility). Give each sub-agent the diff, the PR metadata, the linked issue or contract text, the shared instructions above (scope contract, grounding, finding schema) and ONLY its own section from PERSPECTIVE SECTIONS below. Each sub-agent returns exactly one verdict object for its perspective.\n", len(perspectives)) writeFanOutModelPin(&b, backend, model) + fmt.Fprintf(&b, " Grounding budget: the shared %d tool calls cover this whole review, not each sub-agent. Tell each sub-agent it may make at most %d investigation tool calls for its own perspective, so the total across all %d stays within the cap.\n", combinedGroundingBudget(len(perspectives)), fanOutSubAgentBudget(len(perspectives)), len(perspectives)) b.WriteString("3. Sub-agents must NOT post anything on the PR, must NOT call hive-review, must NOT read other hive reviews of this head SHA, and must NOT fetch the PR or its diff again: they work from what you passed them. They may read the surrounding code in the checkout to ground a finding.\n") b.WriteString("4. Collect every result, check each object names its own perspective and carries this PR's repo, number, head_sha and body_digest, write them as ONE JSON array to the verdict file, and record it ONCE with the --record-verdict command above. Only you call hive-review.\n") b.WriteString("If sub-agents are unavailable, or one fails or returns no usable verdict, review those perspectives yourself one by one in this session. The array contract is unchanged either way.\n") return b.String() } +// fanOutSubAgentBudget splits the combined grounding budget evenly across the +// per-perspective sub-agents of a fan-out (hivecommons/hive#15435), so the +// shared "whole review" cap is not read as each sub-agent's own. +func fanOutSubAgentBudget(n int) int { + if n < 1 { + n = 1 + } + return max(1, combinedGroundingBudget(n)/n) +} + // writeFanOutModelPin keeps the head's model guarantee across the fan-out. // A head IS its model (review_heads: each head's report is stamped with the // model that head ran), and its kick already carries the independent-review diff --git a/src/pkg/review/review_heads_test.go b/src/pkg/review/review_heads_test.go index 430dd3fafd..8465470a0f 100644 --- a/src/pkg/review/review_heads_test.go +++ b/src/pkg/review/review_heads_test.go @@ -395,6 +395,7 @@ func TestCombinedHeadPromptFansOutPerPerspective(t *testing.T) { "must NOT fetch the PR or its diff again", "record it ONCE with the --record-verdict command above. Only you call hive-review.", "If sub-agents are unavailable", + "cover this whole review, not each sub-agent", } for _, tc := range []struct { name string