Skip to content

Evaluate Redis for tracking memories injected since the last compaction #3784

Done

Description

@sentry-junior

#3764 stopped memory recall from injecting a memory that the replayed history already holds. In its review thread, @BYK proposed Redis for this state. We agreed to evaluate that proposal in a follow-up.

Current design

  • UserPromptContext.loadHistory() reads the plugin's turn_context events in the current History version, and the time of the newest compaction or handoff.
  • turn_context is saved in the same append as its Turn's messages. A compaction starts a new History version, so the set resets with no hook.
  • Since 78d151201, the History version filter runs in SQL (loadCurrentEventsOfType). Rows of older versions are not read.

Proposal

  • A Redis set of injected memory ids, keyed by Conversation id, reset on each compaction.
  • Also record the version and archival state of each memory, so a new version of a memory can be injected again.

What to measure before we decide

  • Production loadHistory latency: p50, p95 and max.
  • Rows read per call.
  • The share of recall Turns that call it.

Then compare those numbers with a Redis round trip. If Redis wins, the design must also cover:

  • the reset on compaction;
  • History replacement and handoff;
  • what happens when Redis fails or evicts a key;
  • the TTL.

via @BYK.

--

View Session [Sentry]

Activity

  1. sentry-junior commented on Nov 24, 2026

    @sentry-junior
    ContributorAuthor

    Decision: keep the turn_context event log. No Redis.

    Production data for plugin.prompt_history.load, 2026-11-21 to 2026-11-24 (5,511 reads):

    • Latency: p50 22 ms, p95 113 ms, max 1,287 ms.
    • Rows read: p50 0, p95 21, max 59.
    • 41% of memory userPrompt hooks ran recall and read prompt history. The other 59% have no request text and skip recall.
    • The read runs in parallel with the recall embedding call, and recall's vector search takes seconds after both finish. So the read adds almost nothing to recall latency. Redis would save time that is already hidden.
    • Latency barely grows with rows. A read with 0 rows already takes about 19 ms at p50, so database round trips set the floor.

    The one real cost was an unused third query that runs in sequence when the Conversation has a compaction or handoff. #4231 removes it.

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions