Skip to content

Prompt loop reloads all messages from DB every iteration, breaking prompt cache byte-identity #31525

Closed as not planned

Description

@BYK

Describe the bug

filterCompactedEffect(sessionID) reloads ALL messages from the DB at the start of every prompt loop iteration. Between reloads, the DB can return rows with different object identity (new allocations), even though the message content hasn't changed. This breaks Anthropic's prompt cache, which relies on byte-identical prefixes to avoid reprocessing cached content.

Steps to reproduce

  1. Start a session with many messages
  2. Observe that each prompt loop iteration reloads all messages from the DB
  3. Prompt cache hit rate drops because message object identity changes between iterations

Expected behavior

Messages should be cached across prompt loop iterations, with only new messages appended. A full reload should only happen after operations that modify the message list (subtasks, compaction, overflow).

System info

  • OpenCode version: v1.15.3
  • OS: Linux

Activity

  1. github-actions commented on Jun 9, 2026

    @github-actions
    Contributor

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

    If this is intentionally a follow-up or refinement of those issues, please reference them in the description.

  2. rekram1-node commented on Jun 9, 2026

    @rekram1-node
    Collaborator

    ?? Are u mutating historical messages or somehting??

  3. BYK commented on Jun 9, 2026

    @BYK
    ContributorAuthor

    I did yes through a plug-in

  4. rekram1-node commented on Jun 9, 2026

    @rekram1-node
    Collaborator

    well thats expected behavior then haha ur breaking the prompt cache urself

  5. BYK commented on Jun 10, 2026

    @BYK
    ContributorAuthor

    You're right — I was mutating historical messages via a plugin, so I was breaking the prompt cache myself. The byte-identity framing here is wrong: Anthropic's cache is content-based, not object-identity-based, so a plain DB reload that produces identical content wouldn't break it.

    The only real remnant is a minor perf angle — filterCompactedEffect does a full message-table reload on every loop iteration even when nothing changed — but that's redundant DB I/O at most, not a cache-correctness issue, and it overlaps with #24841 / #22208 anyway.

    Closing this. Apologies for the noise.

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