Skip to content

Factory 0.4.2

Choose a tag to compare

@lpbaril lpbaril released this 09 Nov 21:18
· 25 commits to master since this release

Factory 0.4.2 shows where a factory's tokens go and keeps the Lead's context small. On the BusinessOS factory, the Lead went from 732K tokens of context to 112K, and every later Lead turn re-reads that much less.

Where tokens go

Health now has a token profile, read from the run ledger, for the turns that started in its date window:

  • By role: tokens excluding cached, cached tokens, each one's share, failed and interrupted turns, and the median cached tokens per turn.
  • By what became of the task: merged, closed without merging, PR still open, no PR, and turns not tied to a task (mostly the Lead's).
  • Failed or interrupted turns, and their share.
  • The Lead's cached tokens per turn, in the first and last quarter of each Lead thread's turns.

It's in bb factory health APP [--since …] [--before …] and below the PR numbers in the Health dialog. Tokens per merged task now use the same definition, so the two agree.

On BusinessOS since Nov 5, merged tasks took 94% of tokens excluding cached, and failed turns 2%. The Lead held 28% of cached tokens, and its context kept growing.

A smaller Lead context

  • Early compaction. When a Lead goes idle and its context holds more than the new setting, "Compact the Lead's context above this many tokens" (300,000 by default; 0 is off), the factory asks bb to compact it.
    • What it waits for: it waits while a merge card or a question waits for you, and checks the Lead is still idle just before compacting.
    • How often: at most once every 30 minutes. After a failed attempt it waits 30 minutes, doubling with each failure in a row, up to a day.
    • What stays: the Lead's standing rules come from the plugin, so they survive compaction.
  • bb factory lead-context APP shows how full the Lead's context is, the threshold, and the last compaction or failure.
  • The Lead reads evidence, not code. It's told not to read source files or diffs itself. It checks a claim against QA's verdict, CI, a task comment or git diff --stat, and sends a specialist when code needs a look.
  • Short final messages. The Planner, Explorer, Builder, QA and Designer post their full report as a task comment, then end with three lines or fewer, since their final message goes into the Lead's context. PR reviewers, design reviewers and the shadow reviewer are unchanged.

When you upgrade

  • Compaction is on for every factory at 300,000 tokens. Each Lead above that is compacted after its next turn, not while it's idle, so a Lead nobody is using costs nothing. Set it to 0 to turn it off.
  • Running agents pick up the new rules through their standing instructions on their next turn.

Limits

  • What compaction keeps: older conversation becomes the provider's summary, so details of older discussions with the Lead may be summarized.
  • Cached tokens per turn grow with both the context and the number of steps in a turn. They're a sign of growth, not a measure of context size. Providers count cached input differently, so compare roles on the same provider.
  • Tool overhead: the run ledger records totals per turn, so it can't show how much of a request is tool definitions.
  • Tried on real work: the BusinessOS Lead was compacted from 732K to 112K, and then answered a status question correctly, at about 113K. Not yet: a compaction that fails and backs off, and compaction on a provider other than Claude Code.

Full Changelog: v0.4.1...v0.4.2