Skip to content

feat(grouping): skip the grouping LLM call for small change sets - #1103

Merged
lizhengfeng101 merged 4 commits into
mainfrom
feat/skip-grouping-for-small-change-sets
Aug 31, 2026
Merged

lizhengfeng101 merged 4 commits into
mainfrom
feat/skip-grouping-for-small-change-sets

Conversation

@lizhengfeng101

Copy link
Copy Markdown
Contributor

What

Skip the GROUPING_TASK LLM 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 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.
Files Combined churn Strategy
≥ GROUPING_MIN_FILES not consulted GROUPING_TASK LLM call
< GROUPING_MIN_FILES < GROUPING_BUNDLE_LINE_THRESHOLD one group holding every file, no LLM call
< GROUPING_MIN_FILES ≥ GROUPING_BUNDLE_LINE_THRESHOLD one group per file, no LLM call

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: GROUPING_MIN_FILES keeps grouping unconditional, GROUPING_BUNDLE_LINE_THRESHOLD never 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 / 200 defaults come from measuring grouping behaviour across a 194-PR corpus; 5 and 6 for the file threshold both scored worse.

Behaviour details

  • A bundled group still passes through enforceMaxFilesPerGroup and enforceGroupTokenBudget, so a bundle that outgrows the prompt limit degrades to per-file groups — the same shape a failed grouping call already falls back to.
  • The stdout line reports the partition that was actually produced, not the one the plan asked for, so a bundle degraded by a size valve is not announced as one group.
  • A skip emits a grouping.skipped telemetry event carrying strategy, group.file_count, lines.changed, threshold.files and threshold.lines. GroupingStrategy.String() returns unknown for 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.
  • No session record is written for a skip, 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.

Tests

  • GroupingPlan table tests cover both thresholds, the >= boundary at the file threshold, high churn not overriding it, and 0 / negative values disabling each step.
  • groupDiffs tests cover the bundle path, the per-file path, the bundle disabled by a 0 churn threshold, the bundle split by the token valve, and that the stdout line names the shape that came out.
  • 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.

make check and make test both pass.

Docs

telemetry.md in all five locales gains the new event in the span tree, the span-attribute table and the event table.

@github-actions

Copy link
Copy Markdown
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
lizhengfeng101 force-pushed the feat/skip-grouping-for-small-change-sets branch from 0420a67 to 409d6a4 Compare August 31, 2026 08:22
… 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.
@lizhengfeng101
lizhengfeng101 merged commit da102ec into main Aug 31, 2026
14 checks passed
@lizhengfeng101
lizhengfeng101 deleted the feat/skip-grouping-for-small-change-sets branch August 31, 2026 09:11
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants