fix: batch consolidation for large entry counts#474
Merged
Conversation
When entry count massively exceeds maxEntries (e.g., 1143 vs 25), sending all entries in a single consolidation prompt overflows the context window and the 4096 output token budget can't express enough delete ops. The LLM can only output ~80-100 ops per call. Adds batched consolidation: when entries > 50, takes the lowest- confidence entries (tail of the confidence-sorted list) as candidates. Each pass deletes ~25 entries (half the batch). The idle scheduler's cooldown clears when entry count changes, triggering the next batch automatically. Converges to maxEntries over multiple idle ticks. For small overshoots (≤50 entries), behavior is unchanged — all entries sent in a single prompt.
93b2ae2 to
e8a73f9
Compare
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.
Summary
Follow-up to #473. Onur's logs revealed 1143 knowledge entries — far beyond what the single-pass consolidation can handle. The previous consolidation sent all entries in one prompt, but with 1143 entries (~343K tokens of input) this overflows the context window, and the 4096 output token budget can only express ~80-100 delete ops (vs the ~1118 needed).
Context from Onur's logs
The retry storm (#473) burned $1,138 in consolidation calls that could never succeed due to the token budget constraint.
Changes
Adds batched consolidation mode in
curator.ts:forProject()) as candidates for deletion. Each pass targets removing ~25 entries (half the batch).maxEntriesover multiple passes: 1143 → 1118 → 1093 → ... → 25For Onur's case: ~45 passes × 1 Sonnet call each ≈ $2-3 total to clean up 1143 entries, spread across idle periods. vs the previous behavior of infinite retries that never made progress.