Skip to content

The prefix budget measures a quantity that changes with what is installed on the machine: grep's description is 134 bytes longer without ripgrep #981

Closed

Description

@santoshkumarradha

Symptom

TestTheLeanPrefixStaysUnderItsBudget reads a different number on every machine at the same commit. Measured at d84120b30's parent shape, one sha, three boxes:

where lean prefix tool block
GitHub runner (touched packages) 31,555 14,390
this laptop 31,484 14,319
the Spark 31,453 —

The gate failed on CI while passing on both machines the lane could run it on, which is the worst shape a budget can have: the lane cutting bytes cannot see the number the gate will read.

Cause

internal/exec/bare/grepfindls.go. ripgrepPath probes exec.LookPath("rg") once per process and grepToolDescription picks the description from it — grepDescription where ripgrep is installed, grepFallbackDescription where it is not, and the fallback carries two extra sentences ("Walks the tree itself (ripgrep is not on this machine), so it does NOT read .gitignore — it skips .git, node_modules, vendor and files that look binary"). The GitHub runner has no rg; this laptop has one at /opt/homebrew/bin/rg.

That is 134 bytes of difference in one tool, and it lands in the tool block the budget weighs.

The behaviour itself is right and was deliberate (#: "A CAPABILITY THAT CANNOT WORK IS ABSENT, AND THIS ONE CAN ALWAYS WORK" — the tool keeps its name and only its engine and one sentence change). What is wrong is that a LEDGER measures it.

Replication — a stranger can run this

git checkout <any commit on dev>
go test -run TestTheLeanPrefixStaysUnderItsBudget -v ./internal/session   # with rg on PATH
env PATH=/usr/bin:/bin:$(dirname $(which go)) \
  go test -run TestTheLeanPrefixStaysUnderItsBudget -v ./internal/session # with rg hidden

On dev at 84016ad09 those two read 31,341 and 31,448: a 107-byte spread with nothing changed but PATH. The second figure is the one CI reads.

Acceptance

The budget test measures a figure that does not move with the machine, and says which shape it measured. Either:

  • it weighs the belt with the probe pinned to a stated answer (both arms, or the worst arm), and the failure message names the arm; or
  • the environment-dependent sentence leaves the description and becomes a fact the tool answers with, so the description is one string everywhere.

Either way, internal/session/prefixbudget_test.go fails identically on the laptop, the Spark and the GitHub runner at one sha, and a lane that measures 40 bytes of headroom has 40 bytes of headroom.

Found while cutting #923's prefix cost: that PR read 18 bytes under the budget on the laptop and 55 over on CI, and the difference was entirely this.

🤖 Generated with Claude Code


Drafted with CodeAF · reviewed and owned by the author

Activity

  1. AbirAbbas commented on Sep 16, 2026

    @AbirAbbas
    Collaborator

    Fixed by #996, using the first of the two options this issue allowed: the gate weighs the belt with the probe pinned to the worst arm.

    bare.WidestGrepDescription (internal/exec/bare/grepfindls.go) returns the longer of the two grep sentences by measurement rather than by assumption, and widestBelt in internal/session/prefixbudget_test.go substitutes it before either budget test weighs the belt, so one commit reads one number on a laptop with ripgrep, on the Spark and on the GitHub runner. TestTheFixedPrefixStaysUnderItsBudget and TestTheLeanPrefixStaysUnderItsBudget both pass on dev at 77293538c. The failure message itself does not spell which arm it weighed; the helper's own comment does. Deleting the variance at its source, the issue's second option, is section 3 of #1010.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething the code does that it should not

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions