]> 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, 10 Oct 2026 19:00:03 +0000 (15:00 -0400)
commit7ddccbbdb8b38b8bcd20fd99486b2c7dc1d0452e
treee242c29f78b51709adf5a2ed86319ea326a1bbbd
parentc53acdf0af94b7d09fd2de2ea4f8b1817b3df810
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
Assisted-by: Claude-Code:claude-opus-5-5
src/bees-scan-next.cc