Repository navigation
perf(memory): one recall budget per turn, shared by every section - #425
Merged
Merged
Conversation
`recall_token_budget` (800 tokens by default) was meant to bound each turn's recall. In practice: - the budget was raised by `min(max_index_bytes, 2 x budget)` and lowered by the MEMORY.md index length, although the recall block does not carry the index; with a small index that tripled it; - recalled memories, code context and past sessions each started from zero against that raised budget. So one turn's `<recalled-context>` could reach about nine times the configured size (~7k tokens), and with turn context now kept on its prompt it stays in the history. The three sections now draw from one `RecallBudget` of exactly `recall_token_budget`, in priority order; a section that finds it spent adds nothing. The index keeps its own `max_index_bytes` cap. Code and session snippets cut each line at 200 chars, so a minified line or pasted log cannot fill the budget alone. The three copies of the fill loop became `RecallBudget::section`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
mrnasil
force-pushed
the
perf/recall-shared-budget
branch
from
November 7, 2026 14:08
39f425d to
cab2f6d
Compare
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.
Part of the token-efficiency series (#418–#424).
Problem
recall_token_budget(default 800 tokens; documented as "token budget for recalled facts") is meant to bound each turn's<recalled-context>. Ininject_parts, two things inflated it:min(max_index_bytes, 2 × budget)and then lowered by the MEMORY.md index length. But the recall block does not carry the index; only the system prompt path does. With a small or empty index the budget roughly tripled.As a result one turn's recall could reach about nine times the configured size, roughly 7k tokens instead of 800. With turn context now pinned to its prompt (#419), that text stays in the history, so the bound matters more.
Change
RecallBudgetof exactlyrecall_token_budget, in priority order: memories, then code, then past sessions. A section that finds the budget spent adds nothing. A section's first item still always goes in, so a section is never a bare header.max_index_bytescap and no longer affects which hits are recalled, sobuild_inject_blockandbuild_recall_blockstill recall the same hits.RecallBudget::section.docs/config.mdnow describes the shared budget.Checks
recall_sections_share_one_budgetandclipped_lines_keeps_snippets_short.whycodes-memory --lib89 passed. Theagentlib passes, and so does the TUI recall test (recall_rides_on_turn_context…).🤖 Generated with Claude Code