Repository navigation
fix(multiagent): prevent read_file pagination loops and context compaction amnesia - #380
Open
3099404236 wants to merge 1 commit into
Open
3099404236 wants to merge 1 commit into
3099404236 wants to merge 1 commit into
Conversation
…ction amnesia Fixes an interlocking infinite-loop bug during multi-file source code audits and long agentic runs: 1. Enrich read_file tool outputs with total line counts, shown line ranges, and explicit [EOF REACHED] / [PAST EOF] markers; coalesce micro-paginated limits and deduplicate redundant line-range and full-file reads within a session. 2. Exclude read_file/ls/glob from Reduction middleware truncation/clearing so read_file outputs are not replaced with '<persisted-output>...use read_file to view' self-reinforcing prompts. 3. Lower DefaultSummarizationOutputReserveTokens from 40960 to 8192 so summarization input budget is not starved into dropping the earliest rounds (including the user's initial prompt and early file reads). 4. Keep only the latest 1 round after <summary> in summarizeFinalizeWithRecentAssistantToolTrail and automatically append a deterministic Audited Files Ledger section (## 9) during context checkpointing.
3099404236
force-pushed
the
fix/context-compaction-readfile-loop
branch
from
November 1, 2026 07:39
e583004 to
a99506b
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
Fixes an interlocking infinite-loop bug during multi-file source code audits and long agentic runs where the agent repeatedly re-reads the same files (
read_file) after context reduction or summarization compaction.Root Causes Addressed
read_filePast-EOF Blindness & Micro-Pagination (internal/multiagent/eino_skills.go,internal/multiagent/tool_error_middleware.go):filesystem.read_filereturned raw numbered lines without total file line counts or EOF indicators. When models paginated through a file in small chunks (e.g.,limit=60) and requested anoffsetpast EOF,read_filereturned empty output without signaling EOF, causing models to either paginate infinitely past EOF or restart reading fromoffset=1.enrichReadFileToolResultto prepend[File: <path> | Total lines: <N> | Showing lines <start>..<end> (<rem> lines remaining)]and append explicit[EOF REACHED]/[PAST EOF]loop-breaker notices.normalizeReadFileArgumentsto coalesce tinylimitvalues into full-file reads for normal-sized source files (<= 600lines) or>= 500-line chunks for larger files.sessionReadFiles, reset at the start of each run) so redundant full-file reads of an already-read file in the same session return a compact notice instead of flooding the context window with duplicate tokens.ReductionMiddleware Prematurely Wipingread_fileOutputs (internal/multiagent/eino_middleware.go,internal/config/config.go):Reductiontruncated/clearedread_fileoutputs into<persisted-output>...使用 read_file 进行查看</persisted-output>, which actively instructed the model to callread_fileagain on files it had just finished reading."read_file", "ls", "glob"toTruncExcludeToolsand"read_file", "ls", "glob", "grep", "record_vulnerability", "update_vulnerability"toClearExcludeTools.ClearRetentionSuffixLimit(12) andClearAtLeastTokens(12000) whenReductionMaxTokensForClearEffective() >= 20000.Summarization40K Output Reserve Starving Input Budget (internal/config/config.go):DefaultSummarizationOutputReserveTokenswas set to40960tokens, which starvedsummaryInputMax = trigger - 40960and forcedbuildBudgetedSummarizationModelInputto drop the earliest 7–10 rounds (dropped_rounds > 0, including Round 1 with the user's initial prompt and early file reads) before generating the summary.DefaultSummarizationOutputReserveTokensfrom40960to8192.Post-Compaction Trail Momentum & Missing File Ledger (
internal/multiagent/eino_summarize.go,internal/multiagent/eino_agentic_summarize.go,internal/multiagent/eino_context_checkpoint.go):summarizeFinalizeWithRecentAssistantToolTrailappended up to 8–10 already-summarizedread_filerounds after<summary>, putting the model back into mid-exploration tool-calling momentum instead of following<summary>'s next step.maxKeepRounds = 1insummarizeFinalizeWithRecentAssistantToolTrail.buildAuditedFilesLedgerSection(## 9. 已读取文件台账) ineino_context_checkpoint.goto deterministically record all read file paths and line counts across compactions.Verification
go test ./internal/config/... ./internal/multiagent/...passes cleanly.agent-mcp): prior to this fix, the agent looped for 124+ turns re-reading the same files across compactions; with this fix, the agent reads all 31 files once without repetition and finishes naturally (reason=final) in 15 turns.