Skip to content

fix(memory): scope review transitions by session - #628

Merged
delete-cloud merged 3 commits into
mainfrom
fix/memory-review-session-scope
Jun 25, 2026
Merged

delete-cloud merged 3 commits into
mainfrom
fix/memory-review-session-scope

Conversation

@delete-cloud

@delete-cloud delete-cloud commented Jun 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • reject session-scoped memory review transitions unless the candidate provenance belongs to the path session
  • add session/tape/profile provenance to topic-derived memory candidates and reviewed-memory semantic metadata
  • scope reviewed-memory semantic deletes by session/profile and avoid side effects for legacy unscoped reviewed memory records

Verification

  • UV_PYTHON=3.12 uv run pytest tests/coding_agent/test_memory_review.py tests/coding_agent/test_topic_memory.py tests/coding_agent/test_semantic_sync.py tests/coding_agent/test_memory_switch.py tests/coding_agent/test_memory_index_backend_contract.py tests/ui/test_http_server.py::TestMemoryReviewTransitions tests/coding_agent/test_semantic_recall.py tests/coding_agent/plugins/test_semantic_memory.py tests/coding_agent/test_recall_context.py tests/coding_agent/test_cross_topic_memory_smoke.py -q -> 112 passed
  • uv run ruff check src/coding_agent/topics/memory.py src/coding_agent/topics/semantic_index.py src/coding_agent/topics/semantic_sync.py src/coding_agent/server/http_server.py tests/coding_agent/test_topic_memory.py tests/coding_agent/test_semantic_sync.py tests/ui/test_http_server.py -> All checks passed
  • uv run ruff format --check src/coding_agent/topics/memory.py src/coding_agent/topics/semantic_index.py src/coding_agent/topics/semantic_sync.py src/coding_agent/server/http_server.py tests/coding_agent/test_topic_memory.py tests/coding_agent/test_semantic_sync.py tests/ui/test_http_server.py -> 7 files already formatted
  • git diff --check -- src/coding_agent/server/http_server.py src/coding_agent/topics/memory.py src/coding_agent/topics/semantic_index.py src/coding_agent/topics/semantic_sync.py tests/coding_agent/test_semantic_sync.py tests/coding_agent/test_topic_memory.py tests/ui/test_http_server.py -> pass

Review

  • local read-only subagent review: no P1/P2 remaining
  • postmortem PM-0001 matched tests/ui/test_http_server.py; focused UI transition tests are included above

Notes

  • AGENTS.md references RTK.md and prompts/codex-delegatee.md, but those files are not present in this worktree; treated as setup risk, not loaded rules.

Summary by CodeRabbit

  • New Features
    • Session-scoped memory review and semantic indexing now carry session/tape/profile context end-to-end.
    • Accepted memory retrieval and recall are scoped to the current session.
  • Bug Fixes
    • Review transitions now reject candidates that don’t belong to the requested session, with no cross-session side effects.
    • Sync avoids unintended mutations when session scope can’t be determined.
  • Tests
    • Updated and expanded tests for session-scoped keys, document IDs, metadata, and safe deletion behavior.
  • Refactor
    • Runtime build-context hooks now receive arguments based on signature inspection.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@delete-cloud, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 44 minutes and 56 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cbc4e688-1b2a-4ab4-96e4-575c70a0ad80

📥 Commits

Reviewing files that changed from the base of the PR and between a49a9eb and cb388d9.

📒 Files selected for processing (2)
  • coding-agent/src/coding_agent/plugins/semantic_memory.py
  • coding-agent/tests/coding_agent/plugins/test_semantic_memory.py
📝 Walkthrough

Walkthrough

Memory candidates now include session, tape, and profile provenance. Reviewed-memory documents, sync, recall, and review transitions all use session-scoped identity. Build-context hook calls now adapt their arguments from hook signatures.

Changes

Session-scoped memory review and sync

Layer / File(s) Summary
Provenance fields and helpers
coding-agent/src/coding_agent/topics/memory.py, coding-agent/tests/coding_agent/test_topic_memory.py, coding-agent/tests/coding_agent/test_memory_review.py
Memory candidate provenance now carries session, tape, and profile values, helper functions read and validate those fields, and tests assert the expanded provenance and scoped candidate keys.
Session-scoped review store
coding-agent/src/coding_agent/topics/memory.py, coding-agent/tests/coding_agent/test_memory_review.py
Reviewed-memory records now use session-aware keys, load and transition through session-scoped methods, and tests cover separate sessions and dotted identifier values.
Reviewed-memory document identity
coding-agent/src/coding_agent/topics/semantic_index.py, coding-agent/tests/coding_agent/test_semantic_sync.py
Reviewed-memory document ids, metadata, and accepted-source validation now incorporate session and profile scope data, and sync tests assert the updated ids, metadata, and deletion scoping.
Scoped recall and context building
coding-agent/src/coding_agent/topics/semantic_recall.py, coding-agent/src/coding_agent/plugins/semantic_memory.py, coding-agent/tests/coding_agent/plugins/test_semantic_memory.py, coding-agent/tests/coding_agent/test_semantic_recall.py
Reviewed-memory recall now loads session-scoped records, semantic-memory context building filters accepted memories by pipeline session, and tests cover the scoped recall and filtered context output.
Session check for review transitions
coding-agent/src/coding_agent/server/http_server.py, coding-agent/tests/ui/test_http_server.py
The memory review transition endpoint now validates candidate ownership against the request session, routes session-scoped transitions, and HTTP tests cover cross-session rejection and session-scoped transition cases.

Build-context hook dispatch

Layer / File(s) Summary
Signature-based hook arguments
coding-agent/src/agentkit/runtime/pipeline.py
Build-context hook invocation now resolves kwargs from each hook’s signature and calls hooks with the inspected argument set.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant HttpServer as http_server.py
  participant MemoryStore as MemoryReviewStore
  participant MemoryHelpers as memory_candidate_belongs_to_session
  Client->>HttpServer: POST /sessions/{session_id}/memory/reviews/{candidate_id}
  HttpServer->>MemoryStore: load_memory_for_session(session_id, candidate_id)
  MemoryStore-->>HttpServer: reviewed memory record or missing
  HttpServer->>MemoryHelpers: verify candidate ownership
  MemoryHelpers-->>HttpServer: belongs or not belongs
  HttpServer->>MemoryStore: accept/reject/archive_candidate_for_session(...)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

I twitched my nose at the sessioned moon,
And hopped through provenance fields in tune.
Tape and profile shone bright in the hay,
While sync and recall kept scoping at play.
Thump! said the bunny: all paths know their way.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.97% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: memory review transitions are now scoped and validated by session.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/memory-review-session-scope

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@coding-agent/src/coding_agent/server/http_server.py`:
- Around line 2693-2697: The transition logic is still keying lookup and
mutation by candidate_id alone, then checking session ownership afterward, which
can allow cross-session shadowing or stale prevalidation in a shared review
store. Update the session-scoped transition path in the http_server flow around
the memory candidate handling to use a composite store key like (session_id,
candidate_id), or ensure the validated record is rechecked inside the actual
mutation step before any state change. Apply the same fix to the later memory
candidate transition block referenced by the review comment so both paths are
atomic and session-bound.

In `@coding-agent/src/coding_agent/topics/semantic_index.py`:
- Around line 248-251: The reviewed-memory semantic key is still based only on
the candidate id, so it can collide across sessions even though the metadata is
session-scoped. Update the reviewed-memory ID generation in
SemanticDocId.for_reviewed_memory(record) (or the call site in
semantic_index.py) to include session_id and profile, or otherwise namespace the
backend key by session, so each session writes to a distinct
SemanticMemoryDocument memory_id.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 09137d5c-574f-4c15-89c1-9db40f966e3e

📥 Commits

Reviewing files that changed from the base of the PR and between 88a8fd1 and 4b36a15.

📒 Files selected for processing (7)
  • coding-agent/src/coding_agent/server/http_server.py
  • coding-agent/src/coding_agent/topics/memory.py
  • coding-agent/src/coding_agent/topics/semantic_index.py
  • coding-agent/src/coding_agent/topics/semantic_sync.py
  • coding-agent/tests/coding_agent/test_semantic_sync.py
  • coding-agent/tests/coding_agent/test_topic_memory.py
  • coding-agent/tests/ui/test_http_server.py

@delete-cloud
delete-cloud deleted the fix/memory-review-session-scope branch June 25, 2026 09:30
@delete-cloud delete-cloud reopened this Jun 25, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
coding-agent/tests/coding_agent/plugins/test_semantic_memory.py (1)

177-180: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add one pipeline-level regression for ctx injection.

This verifies SemanticMemoryPlugin.build_context() once ctx is already passed in, but it does not exercise Pipeline._call_build_context_hooks(), which is the dispatch path changed in this PR. A small integration test that runs a build_context hook through the pipeline would catch regressions in _build_context_hook_kwargs().

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@coding-agent/tests/coding_agent/plugins/test_semantic_memory.py` around lines
177 - 180, Add a pipeline-level regression test for ctx injection by exercising
Pipeline._call_build_context_hooks() instead of calling
SemanticMemoryPlugin.build_context() directly. Update the existing test in
test_semantic_memory.py or add a small integration test that runs a
build_context hook through Pipeline so the dispatched kwargs path in
_build_context_hook_kwargs() is covered and ctx is verified to be injected
correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@coding-agent/src/coding_agent/plugins/semantic_memory.py`:
- Around line 77-92: The session-scoped memory lookup is incorrectly falling
back to tape.tape_id in _session_id_from_context_or_tape(), which causes
_accepted_memories_for_session() and the SemanticRecallPlanner path in
semantic_memory.py to miss valid session memories. Update the
build_context/planning flow to require an explicit ctx.session_id when using
_accepted_memories_for_session(), or add a separate legacy/unscoped branch when
no session_id is present, and apply the same fix to the other referenced call
sites using the same session lookup logic.

---

Nitpick comments:
In `@coding-agent/tests/coding_agent/plugins/test_semantic_memory.py`:
- Around line 177-180: Add a pipeline-level regression test for ctx injection by
exercising Pipeline._call_build_context_hooks() instead of calling
SemanticMemoryPlugin.build_context() directly. Update the existing test in
test_semantic_memory.py or add a small integration test that runs a
build_context hook through Pipeline so the dispatched kwargs path in
_build_context_hook_kwargs() is covered and ctx is verified to be injected
correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 55a045dd-c6ab-431a-90e6-13bce8c8375a

📥 Commits

Reviewing files that changed from the base of the PR and between 4b36a15 and a49a9eb.

📒 Files selected for processing (11)
  • coding-agent/src/agentkit/runtime/pipeline.py
  • coding-agent/src/coding_agent/plugins/semantic_memory.py
  • coding-agent/src/coding_agent/server/http_server.py
  • coding-agent/src/coding_agent/topics/memory.py
  • coding-agent/src/coding_agent/topics/semantic_index.py
  • coding-agent/src/coding_agent/topics/semantic_recall.py
  • coding-agent/tests/coding_agent/plugins/test_semantic_memory.py
  • coding-agent/tests/coding_agent/test_memory_review.py
  • coding-agent/tests/coding_agent/test_semantic_recall.py
  • coding-agent/tests/coding_agent/test_semantic_sync.py
  • coding-agent/tests/ui/test_http_server.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • coding-agent/src/coding_agent/server/http_server.py
  • coding-agent/tests/ui/test_http_server.py
  • coding-agent/tests/coding_agent/test_semantic_sync.py

@delete-cloud
delete-cloud merged commit 6d9aa65 into main Jun 25, 2026
2 checks passed
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.

1 participant