Back to Engineering Blog
AI Development 7 min read

Reviews, Not Chat History, Were the Token Bill

We first trimmed how much GitHub and Mattermost context each agent read, then measured and found the real cost driver was something else. Here is what we changed.

Jason NevillBy , Houston, TX
#AI-Logos#Tokens#CostControl#GitHub#Mattermost

Key Architectural Takeaways

  • Agents no longer re-read the repository's accumulated chat and GitHub context on every review; the diff is built by a script.
  • The largest cost was every new commit triggering a full review by every reviewer, including commits replaced minutes later.
  • A settle window, a circuit breaker and incremental re-reviews cut that cost without changing who must approve.

Compression costs time and tokens

Each coding agent can only hold so much context. When it fills up, the tool compresses it, which costs time and tokens and risks losing detail. As the number of agents and pull requests grew, we started designing for that limit instead of fighting it.

Step one: stop re-reading the world

Early reviews made every agent re-digest the repository's accumulated context, its digest files, rules and the chat and GitHub history they summarize, before looking at the change. We replaced that with a shared lean review brief. The diff is computed by a script, not by the model, and pasted into the prompt, so the reviewer reads only the change under review. The rules-of-engagement text is attached only when the diff is security-related. If a diff is too big to review whole, the tool fails closed instead of silently truncating it.

Step two: measure

We then measured where tokens actually went. The chat history was not the main driver, because the review path never injected it. The driver was every new commit on a pull request triggering a full review by every reviewer, including commits superseded minutes later, plus repeated retries against a fallback reviewer that was failing.

Three changes

  1. Settle window. A pull request is not reviewed until its newest commit is at least 15 minutes old and its checks have finished. A label can bypass it.
  2. Circuit breaker. A reviewer with three failed jobs and no success in three hours is skipped until it recovers.
  3. Incremental re-review. A second review by the same reviewer sees only the changes since its last reviewed commit, its own previous findings, and the replies since. It must mark each earlier finding fixed or not fixed.

None of these change who has to approve. They change when a review is attempted and what it has to read.

A review digest that uses no model

For humans, a small script lists the unseen review comments and verdicts across open pull requests using only the GitHub CLI. No model call, no tokens.

Takeaway

Measure before you optimize. Our first guess about where the tokens went was reasonable and only partly right.

Some of what's described here is a design that hasn't been fully tested yet; those parts say so in the text.

Follow the build on LinkedIn or by RSS.

All Articles

Follow the build

Questions about the build, or spotted something we got wrong? Find us on LinkedIn and GitHub.