Skip to content

[BUG] compaction causes AGENTS.md to be re-attached because extract() skips compacted Read results #31764

Closed

Description

Description

After session compaction, the extract() function in instruction.ts skips tool results that were compacted (part.state.time.compacted). This means the system forgets which AGENTS.md/CLAUDE.md files were already loaded by Read tool calls, causing duplicate re-attachment of instruction files.

Root Cause

packages/opencode/src/session/instruction.ts:21-22:

if (part.type === "tool" && part.tool === "read" && part.state.status === "completed") {
  if (part.state.time.compacted) continue  // <-- this skips after compaction

When compaction summarizes old messages, the Read tool results are marked as compacted. The extract() function skips these, returning an empty set. The resolve() function then re-loads and re-attaches AGENTS.md files that were already loaded, causing:

  1. Duplicate instructions in the AI context window
  2. Wasted tokens
  3. AGENTS.md being re-read multiple times across compaction boundaries

Steps to reproduce

  1. Start a session with an AGENTS.md file in the project
  2. The instruction file is loaded via system() at startup
  3. Let the conversation grow long enough for compaction to trigger
  4. After compaction, a new Read tool call triggers resolve()
  5. The extract() function returns empty (compacted results skipped)
  6. AGENTS.md is loaded again as a new instruction

OpenCode version

1.17.3

Activity

  1. github-actions commented on Jun 10, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If #31764 is intentionally a focused follow-on to #30807 (compaction-only, as opposed to prune + compaction), please clarify that in the description so maintainers can track them separately.

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