Conversation
The lookahead cost leaves out the intro that attach_children adds when the first proposed heading sits mid-page, and the same-page fusions after it. An expand it accepted could cost as much as the scan, so the next round's merge folded the node back after its children were marked final, and summarize_tree failed with "dropped or changed after it was marked final". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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
Flash indexing with
optimize="full"sometimes fails with:expandaccepts a split when its lookahead cost (expand_cost) beats a linear scan. The lookahead leaves out whatattach_childrenadds afterwards: when the first proposed heading sits mid-page, the intro node runs onto that page, and same-page siblings are fused. The attached node can then cost as much as the scan. The next round'smerge(span <= tree_cost) folds it back after its children were already marked final, andsummarize_treerefuses the changed tree.Example from a 471-page book (arXiv 2106.10165): node 8.3.2 spans pages 224-229 (S=6); the model proposes headings on pages 228 (mid-page) and 229.
expand_cost= 5, so the node is expanded; the intro covers 224-228, sotree_cost= 6 and round 2 merges it back.Fix
Before committing an expand, attach the children to a copy of the node, fuse same-page siblings, and keep the expand only if that copy's
tree_costbeats the scan - the same testmergeapplies next round.Verification
tests/test_expand_refold.pyreproduces the failure onmainand passes with the fix; an expand that pays off is still taken.gemma4E4B via Ollama) and replayed them: onmain2 of them fail with the error above; with the fix all 8 pass, and the 6 that passed before give identical trees.馃 Generated with Claude Code