Repository navigation
feat(grouping): skip the grouping LLM call for small change sets - #1103
Merged
Merged
Conversation
Contributor
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 4 selected item(s). |
A change set with only a few files spent a metadata-only LLM round trip deciding a partition that was never in doubt. Below GROUPING_MIN_FILES the space of sensible partitions is tiny, so the call buys no information and is now decided locally instead. Two thresholds cooperate and answer different questions. GROUPING_MIN_FILES (4) asks whether the partition is worth computing at all. Only then does GROUPING_BUNDLE_LINE_THRESHOLD (200) ask whether those files can share one review: a bundled group spreads MAX_REVIEW_ROUNDS across every file in it, so past a churn ceiling each file is better off with its own subtask and its own rounds. File count is deliberately not re-examined at the second step, and churn is not consulted at the first. Either threshold set to 0 disables its own step. A bundled group still passes through enforceMaxFilesPerGroup and enforceGroupTokenBudget, so a bundle that outgrows the prompt limit degrades to per-file groups - the shape a failed grouping call already falls back to. The skip logs the partition it actually produced rather than the one the plan asked for, and emits a grouping.skipped telemetry event carrying the strategy, the file count, the churn and both thresholds. No session record is written, so no grouping_task entry appears in the viewer. groupChurn becomes diffsChurn: grouping runs before any FileGroup exists, so the churn helper now takes the diffs directly. The retry e2e fixture grows to four files. Those tests are about per-request retry accounting, which needs each file to be its own request; below GROUPING_MIN_FILES they would have been bundled into a single group and the accounting under test would collapse. The fake LLM answers the grouping call with one group per file, served before the failure-injection switch so the marker-less grouping request can never absorb a file's 429 or 402. Tests meaning "the whole review failed" now call failAll() instead of naming files, so they keep meaning that when the fixture changes.
The fake identifies GROUPING_TASK by a fragment of its system prompt, which nothing links to the prompt file at compile time. A reword there degraded these tests silently: the fake missed the grouping call, fell through to the plan response, failed to parse as a grouping reply, and left groupDiffs falling back to per-file dispatch — the very shape the grouping branch constructs on purpose, so every assertion still passed with the coverage gone. That state was the status quo before the fixture grew a grouping answer, and it went unnoticed. Count recognized grouping requests and assert the count in the test that attributes a 429 and a 402 to named files, since that attribution only holds while each file is its own request. One call site is enough: a prompt reword is a global event. Deliberately not in startFakeLLM's cleanup, where a test whose change set never reaches the grouping call would fail for the wrong reason.
A single-file change set skips the grouping call too, but emitted nothing, so anyone counting skipped groupings from telemetry had to know about a hidden path to get the total right. The event now fires there as well, routed through a shared emitGroupingSkipped so the two skip paths cannot drift apart in what they report. The single-file short-circuit stays ahead of GroupingPlan rather than folding into it. It has to: GroupingPlan returns GroupingViaLLM once GROUPING_MIN_FILES is 0, which would send a grouping call for one file, and its bundle branch would relabel the group smallChangeSetLabel instead of the file path. Tests now pin both, so the ordering cannot be undone silently. Telemetry only for that path — no terminal line. The two audiences differ: an aggregate has to be complete, while a reader of the terminal gains nothing from being told that one file needs no partition. The count also moves from group.file_count to file.count. The event fires before any FileGroup exists, so it describes the change set the way review.started does, not the group-scoped spans that pair group.file_count with a group.label there is none of here. Renaming now costs nothing, since the attribute has not shipped. Also covers the log's remaining shape, "reviewing as N groups", which needs GROUPING_MIN_FILES raised past maxFilesPerGroup — the case the bundle's enforceMaxFilesPerGroup call exists to guard, previously asserted nowhere.
lizhengfeng101
force-pushed
the
feat/skip-grouping-for-small-change-sets
branch
from
August 31, 2026 08:22
0420a67 to
409d6a4
Compare
… cost GroupingPlan's comment said a bundled group "spreads MAX_REVIEW_ROUNDS across every file in it", which reads as if the round budget were divided among the files. It is not: the main loop re-runs over the whole group, so every file is seen in every round. What a bigger bundle dilutes is one round's attention, not the number of rounds — say that instead, since this is the sole rationale for the GROUPING_BUNDLE_LINE_THRESHOLD default. Also record a known cost of bundling next to the size valves: the --max-tokens-budget look-ahead in dispatchSubtasks is per group, so a bundle makes it all-or-nothing over the whole change set, and its estimate sums estimateDiffFileTokens, charging the fixed prompt overhead once per file even though a bundle's files share one conversation. Comments only, no behaviour change.
stay-foolish-forever
approved these changes
Aug 31, 2026
Githab-capibara
added a commit
to Githab-capibara/open-code-review
that referenced
this pull request
Sep 17, 2026
…baba#1103) * feat(grouping): skip the grouping LLM call for small change sets A change set with only a few files spent a metadata-only LLM round trip deciding a partition that was never in doubt. Below GROUPING_MIN_FILES the space of sensible partitions is tiny, so the call buys no information and is now decided locally instead. Two thresholds cooperate and answer different questions. GROUPING_MIN_FILES (4) asks whether the partition is worth computing at all. Only then does GROUPING_BUNDLE_LINE_THRESHOLD (200) ask whether those files can share one review: a bundled group spreads MAX_REVIEW_ROUNDS across every file in it, so past a churn ceiling each file is better off with its own subtask and its own rounds. File count is deliberately not re-examined at the second step, and churn is not consulted at the first. Either threshold set to 0 disables its own step. A bundled group still passes through enforceMaxFilesPerGroup and enforceGroupTokenBudget, so a bundle that outgrows the prompt limit degrades to per-file groups - the shape a failed grouping call already falls back to. The skip logs the partition it actually produced rather than the one the plan asked for, and emits a grouping.skipped telemetry event carrying the strategy, the file count, the churn and both thresholds. No session record is written, so no grouping_task entry appears in the viewer. groupChurn becomes diffsChurn: grouping runs before any FileGroup exists, so the churn helper now takes the diffs directly. The retry e2e fixture grows to four files. Those tests are about per-request retry accounting, which needs each file to be its own request; below GROUPING_MIN_FILES they would have been bundled into a single group and the accounting under test would collapse. The fake LLM answers the grouping call with one group per file, served before the failure-injection switch so the marker-less grouping request can never absorb a file's 429 or 402. Tests meaning "the whole review failed" now call failAll() instead of naming files, so they keep meaning that when the fixture changes. * test(retry): assert the fake recognizes the grouping call The fake identifies GROUPING_TASK by a fragment of its system prompt, which nothing links to the prompt file at compile time. A reword there degraded these tests silently: the fake missed the grouping call, fell through to the plan response, failed to parse as a grouping reply, and left groupDiffs falling back to per-file dispatch — the very shape the grouping branch constructs on purpose, so every assertion still passed with the coverage gone. That state was the status quo before the fixture grew a grouping answer, and it went unnoticed. Count recognized grouping requests and assert the count in the test that attributes a 429 and a 402 to named files, since that attribution only holds while each file is its own request. One call site is enough: a prompt reword is a global event. Deliberately not in startFakeLLM's cleanup, where a test whose change set never reaches the grouping call would fail for the wrong reason. * fix(grouping): report the skip for single-file change sets A single-file change set skips the grouping call too, but emitted nothing, so anyone counting skipped groupings from telemetry had to know about a hidden path to get the total right. The event now fires there as well, routed through a shared emitGroupingSkipped so the two skip paths cannot drift apart in what they report. The single-file short-circuit stays ahead of GroupingPlan rather than folding into it. It has to: GroupingPlan returns GroupingViaLLM once GROUPING_MIN_FILES is 0, which would send a grouping call for one file, and its bundle branch would relabel the group smallChangeSetLabel instead of the file path. Tests now pin both, so the ordering cannot be undone silently. Telemetry only for that path — no terminal line. The two audiences differ: an aggregate has to be complete, while a reader of the terminal gains nothing from being told that one file needs no partition. The count also moves from group.file_count to file.count. The event fires before any FileGroup exists, so it describes the change set the way review.started does, not the group-scoped spans that pair group.file_count with a group.label there is none of here. Renaming now costs nothing, since the attribute has not shipped. Also covers the log's remaining shape, "reviewing as N groups", which needs GROUPING_MIN_FILES raised past maxFilesPerGroup — the case the bundle's enforceMaxFilesPerGroup call exists to guard, previously asserted nowhere. * docs(grouping): correct the round-count rationale and note the budget cost GroupingPlan's comment said a bundled group "spreads MAX_REVIEW_ROUNDS across every file in it", which reads as if the round budget were divided among the files. It is not: the main loop re-runs over the whole group, so every file is seen in every round. What a bigger bundle dilutes is one round's attention, not the number of rounds — say that instead, since this is the sole rationale for the GROUPING_BUNDLE_LINE_THRESHOLD default. Also record a known cost of bundling next to the size valves: the --max-tokens-budget look-ahead in dispatchSubtasks is per group, so a bundle makes it all-or-nothing over the whole change set, and its estimate sums estimateDiffFileTokens, charging the fixed prompt overhead once per file even though a bundle's files share one conversation. Comments only, no behaviour change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Skip the
GROUPING_TASKLLM call when the change set is small enough that the partition was never in doubt, and decide the partition locally instead.Two new template fields drive it, and they answer different questions:
GROUPING_MIN_FILES(4) — is the partition worth computing at all? Below it the space of sensible partitions is tiny, so a metadata-only round trip buys no information.GROUPING_BUNDLE_LINE_THRESHOLD(200) — only asked once the file count is already low: can those files share one review? A bundled group spreadsMAX_REVIEW_ROUNDSacross every file in it, so past a churn ceiling each file is better off with its own subtask and its own rounds.GROUPING_MIN_FILESGROUPING_TASKLLM callGROUPING_MIN_FILESGROUPING_BUNDLE_LINE_THRESHOLDGROUPING_MIN_FILESGROUPING_BUNDLE_LINE_THRESHOLDFile count is deliberately not re-examined at the second step, and churn is not consulted at the first. Either threshold set to
0disables its own step:GROUPING_MIN_FILESkeeps grouping unconditional,GROUPING_BUNDLE_LINE_THRESHOLDnever bundles.Why
For a two- or three-file change there is almost nothing to partition, so the grouping call was pure latency and cost on the most common review shape. Bundling those files into one review is also the better outcome on its own merits — one conversation sees all of them, which catches cross-file problems that per-file dispatch cannot.
The
4/200defaults come from measuring grouping behaviour across a 194-PR corpus;5and6for the file threshold both scored worse.Behaviour details
enforceMaxFilesPerGroupandenforceGroupTokenBudget, so a bundle that outgrows the prompt limit degrades to per-file groups — the same shape a failed grouping call already falls back to.grouping.skippedtelemetry event carryingstrategy,group.file_count,lines.changed,threshold.filesandthreshold.lines.GroupingStrategy.String()returnsunknownfor an unhandled value rather than falling through to a real strategy name, so a future addition that forgets its case surfaces as an anomaly instead of inflating an existing bucket.grouping_taskentry appears in the viewer.groupChurnbecomesdiffsChurn: grouping runs before anyFileGroupexists, so the churn helper now takes the diffs directly.Tests
GroupingPlantable tests cover both thresholds, the>=boundary at the file threshold, high churn not overriding it, and0/ negative values disabling each step.groupDiffstests cover the bundle path, the per-file path, the bundle disabled by a0churn threshold, the bundle split by the token valve, and that the stdout line names the shape that came out.GROUPING_MIN_FILESthey would have been bundled into a single group and the accounting under test would collapse. The fake LLM answers the grouping call with one group per file, served before the failure-injection switch so the marker-less grouping request can never absorb a file's 429 or 402. Tests meaning "the whole review failed" now callfailAll()instead of naming files, so they keep meaning that when the fixture changes.make checkandmake testboth pass.Docs
telemetry.mdin all five locales gains the new event in the span tree, the span-attribute table and the event table.