Skip to content

perf(capture): avoid session scans for durable replays - #1773

Closed
zack-dev-cm wants to merge 2 commits into
rohitg00:mainfrom
zack-dev-cm:fix/1734-durable-replay-lookup
Closed

zack-dev-cm wants to merge 2 commits into
rohitg00:mainfrom
zack-dev-cm:fix/1734-durable-replay-lookup

Conversation

@zack-dev-cm

@zack-dev-cm zack-dev-cm commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Durable observation replays currently load the whole session before finding an already-stored record. Read its key first, validate the stored ID, and use the existing list lookup when the point read fails, misses, or finds a mismatched record.

Keep the session lock, live-prompt bookkeeping and index repair. New observations still load the existing rows for source budgeting and cap eviction. This implements the dedup-lookup part of #1734; the compression path and running byte totals remain separate.

Validation:

  • Eleven regression/control tests: 5 failed and 6 passed before the change; all 11 pass after it. Covers both StateKV backend formats, legacy keys, read failures, concurrent replay, prompt/index repair, source budget and cap eviction.
  • Build, generated skills, docs sync/check and CI eval typecheck pass. Full suite: 4,929 passed, 7 skipped, with the same 13 baseline mesh failures; broad typechecking has the same 28 baseline diagnostics.
  • Freshly extracted npm archives with cached dependencies and native iii 0.25.1 on Linux/Node 22 pass all four original/corrected fixtures. Existing records and new-write controls agree. One replay among 21 records with 20 MiB of stored history took 269 ms before and 3 ms after; this is a fixture timing, not a general benchmark.

Refs #1734

Summary by CodeRabbit

  • Bug Fixes
    • Durable observation replays can retrieve existing records directly, even when reading the full observation list fails.
    • If a direct lookup fails or finds no matching record, the existing list-based lookup remains available.
    • Replaying an existing durable observation preserves its stored state and updates the replay ledger when applicable.
    • Non-durable observations continue to use the list-based lookup.

Signed-off-by: zack-dev-cm <112114097+zack-dev-cm@users.noreply.github.com>
@vercel

vercel Bot commented Nov 13, 2026

Copy link
Copy Markdown

@zack-dev-cm is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

For durable observation IDs, mem::observe checks the observation store directly before listing session observations. If the point read does not return a matching record, the handler retains the list-based lookup. Tests cover replay behavior and fallback paths.

Changes: Durable observation replay

Layer / File(s) Summary
Point lookup, fallback, and replay
src/functions/observe.ts, test/observe-durable-lookup.test.ts
Durable IDs use a direct lookup when it returns a matching record. Otherwise, the handler searches the session list. Tests cover replay and indexing, legacy records, failed reads, source budgeting, cap eviction, non-durable IDs, and concurrent replays.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Possibly related issues

  • Issue 1734 reports that durable-event lookup loads the full session observation list. This change adds a point lookup with list-based fallback.

Possibly related PRs

  • rohitg00/agentmemory#1174: Adds session-cap eviction in the observe path. This change preserves that behavior for new observations and includes cap-eviction coverage.
Merge Risk: Minimal · up to 3da8b

Durable observation replays now read the stored record directly and fall back to the existing lookup when that read fails or does not match. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: durable observation replays in capture no longer scan session lists. The perf(capture) prefix and the 'avoid session scans for durable replays' wording match the summa…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: durable observation replays in capture no longer scan session lists. The perf(capture) prefix and the 'avoid session scans for durable replays' wording match the summary, which says mem::observe fetches durable IDs directly by ID and only lists sessions on a miss.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 73216085-5ab9-4288-8b4e-edfc8feaf734
Commits

Reviewing files that changed from the base of the PR and between 8e3e3eb and 3da8b57.

Files selected for processing: 1

  • test/observe-durable-lookup.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

coderabbitai[bot]

This comment was marked as resolved.

Signed-off-by: zack-dev-cm <112114097+zack-dev-cm@users.noreply.github.com>
@rohitg00

Copy link
Copy Markdown
Owner

Merged as part of #1811, which kept your commits and added review fixes on top (details in its description). Thanks for the contribution.

@rohitg00 rohitg00 closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants