]> git.hungrycats.org Git - bees/commit
scan_next: gate each Plan B dst on its own debt, not the aggregate
authorZygo Blaxell <bees@furryterror.org>
Thu, 9 Jul 2026 04:53:10 +0000 (00:53 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sat, 5 Sep 2026 04:04:13 +0000 (00:04 -0400)
commitd0ac631273dba9e674dadfc5d0d1cb8a934fa4da
tree9fc7a9d1f7f5447dedcd86e856319a6de804a487
parent4e740586021a35d5c6f23032aef666a628390350
scan_next: gate each Plan B dst on its own debt, not the aggregate

Plan B executes each destination independently — each is a reversed Plan A
against the single start src — but its cost was evaluated only in aggregate: the
per-candidate debts were summed and the plan admitted if the sum beat
do-nothing.  That let a batch of profitable singleton dedupes subsidize an
individually-catastrophic drain.  The instrumentation showed it directly: one
Plan B emitted 130 dst lines sharing one aggregate debt, 129 of them 1-ref
extents (each a real space win) and one a 9912-ref extent whose own debt is
~+521k (redirecting 9912 references onto a fresh src, priced by ref-op-cost).
The group summed to -7197, so the fat drain rode along — re-canonicalizing a
near-canonical extent instead of leaving it to accumulate and retire.

Gate each candidate on its own signed space-debt at accept time: drop it unless
its per-entry debt beats the do-nothing floor (< 0).  The profitable singletons
are unaffected; the high-ref drain is declined, so the fat extent stays the
canonical src, keeps absorbing, and retires at refs-max as intended.  A
force-marked candidate bypasses the gate, mirroring the FullRewrite floor's
benefit-gate bypass, since force means "rewrite regardless of benefit".

This is the last of the reference-cluster cost-model defects: retirement
(refs_fetch) settles clusters, refs_created makes ref-op-cost price ref moves,
and this gate stops Plan B from subsidizing a drain past that price.

Assisted-by: Claude-Code:claude-opus-4-8
src/bees-scan-next.cc