Skip to content

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

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

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