fix: resolve active blocks via their rendered summary after prune (billion-context-pi#195) - #119
Merged
Merged
Conversation
…llion-context-pi#195) An active block whose raw messages were replaced by the synthetic acp_summary_bN message became unresolvable: resolveAnchorIndex only looked up effectiveMessageIds by raw id, so compress(bN..bN) failed with a misleading 'already compressed / 0 chars < min' error and the block could never be promoted. - add summaryMessageId/isSummaryMessageId helpers (prune.ts) - add visibleBlockAnchor(block, indexByMessageId): summary index ?? earliest raw id; use at every block-anchor site (active boundary resolution, nested discovery, adjusted-range rescan, owner lookup) - exclude synthetic acp_summary_* ids from ResolvedRange.messageIds so they never leak into effectiveMessageIds/directMessageIds - activeOwnerAnchor: snap only for true ancestors (inherited content); directly-compressed content keeps the 'already compressed, use bN' guidance instead of a silent same-tier duplicate - syncBlocks: a block whose only visible representation is its rendered summary stays active (hosts passing pruned views) - prune: stable summary position + dedupe when re-pruning an already-pruned view Adds tests/regression-promote-after-prune.test.ts (6 cases incl. the issue's single-block, two-block, and inclusive bN..bM selection specs).
ranxianglei
force-pushed
the
2026-08-22_promote-after-prune
branch
from
August 22, 2026 12:03
e708043 to
8a4dc72
Compare
This was referenced Aug 22, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
compress(startId:"b2", endId:"b2")fails whenprocessTurn()has already replaced the block's raw messages with the syntheticacp_summary_b2summary message (i.e. every turn after prune):The retry it suggests is exactly what failed — an unresolvable loop. Active T1 blocks could never be promoted to T2 in a live session. Reported in ranxianglei/billion-context-pi#195. (Replaces #118, which was closed after the branch rename.)
Root cause:
resolveAnchorIndex()resolved an activebNref only viaearliestIndexOfIds(block.effectiveMessageIds, indexByRawId). Post-prune, those raw ids are absent from the visible list and onlyacp_summary_bNis present, so the resolver returned null and misclassified the block as "consumed". A secondary leak: ranges spanning a pruned region put the synthetic id intoResolvedRange.messageIds, which then persisted into new blocks'effectiveMessageIds(e.g.["raw-1","acp_summary_b2","raw-5"]).Fix
prune.ts: exportsummaryMessageId(blockId)/isSummaryMessageId(id); re-pruning an already-pruned view keeps the summary at its existing position (no jump to index 0) and dedupes stale copies.boundaries.ts: new exportedvisibleBlockAnchor(block, indexByMessageId)= summary index ?? earliest raw id. Used at every block-anchor site: active start/end boundary resolution, nested-block discovery inresolveBoundaries(), and the adjusted-range rescan inapplySingleRange(). Synthetic ids are excluded fromResolvedRange.messageIdsso they never enter durable coverage.activeOwnerAnchor: now snaps only for true ancestors (active block that inherited the content by consuming another block). If the active block directly compressed the message, callers keep the "already compressed — retry with bN" guidance instead of silently creating a same-tier duplicate block. This also makes the fix(compress): Bug 39 — protected tool messages excluded from effectiveMessageIds #32 snap work post-prune (owner visible via its summary).sync.ts: a block whose only visible representation is its rendered summary stays active (hosts passing pruned views no longer lose block activity each turn).Verification
tests/regression-promote-after-prune.test.ts(6 cases): single T1→T2 promotion post-prune (issue's exact fixture), two-T1→T2, inclusiveb1..b3selection consuming all three blocks incl. middle block visible only via summary, pre-prune control, syncBlocks on pruned view, prune idempotency/stable position. All fail on pre-fix code, pass on this branch.tsc --noEmitclean.No API removals; three new exports (
summaryMessageId,isSummaryMessageId,visibleBlockAnchor) added for hosts/tests.