Skip to content

[BUG]: Prune clears read results causing instruction re-attachment; prune early-exit skips older prunable tools #30807

Closed

Description

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

Activity

  1. lexlian commented on Jun 5, 2026

    @lexlian

    I fixed the issue with PR #30979.

    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.

  2. lexlian commented on Jun 8, 2026

    @lexlian

    @LifetimeVip, I think we need to ask @StarpTech for help on the approval of the emerge for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions