You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description Two bugs in the pruning mechanism. Bug 1: Prune causes instruction file re-attachment instruction.ts:20 鈥?when scanning previously read file paths for auto-attaching instruction files (AGENTS.md, CLAUDE.md), if part.state.time.compacted is set, the read result is skipped. After prune() clears old tool output, all read results that were pruned are invisible to this scan. The system re-attaches instruction files that were already loaded in the current session, causing duplication or re-sending instructions that were already applied. Bug 2: Prune early-exit breaks loop compaction.ts:325 鈥?if (part.state.time.compacted) break loop. This breaks out of the entire message loop, not just the current message's parts. If a more recent message has a compacted tool from a previous prune run, pruning stops entirely, leaving older prunable tools uncleaned. Focused follow-on to #30376. Suggested fix: (Bug 1) preserve read-file metadata separately from tool output so it survives pruning. (Bug 2) change break to continue so the loop checks the next message. ### OpenCode version
main
Steps to reproduce 1. Session reads AGENTS.md via Read tool (turn 5) 2. After many turns, prune() clears older tool output 3. instruction.ts re-attaches AGENTS.md in next turn (turn 50+) even though it was already loaded 4. AI receives duplicate instructions
Bug 1 was in instruction.ts:extract() — it skipped read parts with time.compacted set, but metadata.loaded (the list of instruction files already attached) survives compaction unchanged. This caused resolve() to re-attach AGENTS.md/CLAUDE.md/CONTEXT.md on every read after prune.
Bug 2 was in compaction.ts:prune() — break loop when encountering an already-compacted part exited the outer message scan, so older prunable tools were silently skipped on all subsequent prune runs.
Both are 1-line fixes. Regression tests added for each.
Activity
lexlian commentedon Jun 5, 2026
I fixed the issue with PR #30979.
Bug 1 was in
instruction.ts:extract()— it skipped read parts withtime.compactedset, butmetadata.loaded(the list of instruction files already attached) survives compaction unchanged. This causedresolve()to re-attachAGENTS.md/CLAUDE.md/CONTEXT.mdon every read after prune.Bug 2 was in
compaction.ts:prune()—break loopwhen encountering an already-compacted part exited the outer message scan, so older prunable tools were silently skipped on all subsequent prune runs.Both are 1-line fixes. Regression tests added for each.
lexlian commentedon Jun 8, 2026
@LifetimeVip, I think we need to ask @StarpTech for help on the approval of the emerge for this PR.