Skip to content

feat(hooks): send session_id on hook searches for server-side injection dedup#124

Merged
yyiilluu merged 1 commit into
mainfrom
feat/send-session-id-search
Jul 8, 2026
Merged

feat(hooks): send session_id on hook searches for server-side injection dedup#124
yyiilluu merged 1 commit into
mainfrom
feat/send-session-id-search

Conversation

@yyiilluu

@yyiilluu yyiilluu commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Hook searches now pass the Claude Code session_id to reflexio's unified /api/search, opting into the backend's session-scoped result dedup (ReflexioAI/reflexio#310): the server skips rules it already returned to this session and backfills next-best matches. A turn with ten tool calls injects each rule once instead of ten times, cutting repeated context injection without any client-side state.

Works with any backend: older reflexio versions simply ignore the field (today it is metering-only metadata), so this can merge and ship independently — dedup activates once the backend side is deployed/vendored.

Changes

  • reflexio_adapter.pysearch_all accepts session_id (default None) and forwards it on client.search(...).
  • context_inject.pyemit_context passes the hook payload's session id into search_all, covering both UserPromptSubmit and PreToolUse injection paths.
  • ARCHITECTURE.md — documents the per-session injection dedup and the post-compaction limitation (same session_id after compaction means rules that fell out of context are not re-injected for the rest of that session).

No vendored-client change needed — client.search already accepts and forwards session_id. No client-side filtering; the server owns dedup, and {session_id}.injected.jsonl remains citation-resolution-only.

Test Plan

  • Adapter tests: session_id forwarded when provided, defaults to None when omitted
  • Hook tests: both UserPromptSubmit and PreToolUse injection paths send the payload's session_id to search_all
  • Full suite: 115 tests in tests/test_adapter.py + tests/test_events.py pass; ruff clean

Summary by CodeRabbit

  • New Features

    • Context injection now tracks sessions to avoid repeating the same rules during repeated hook searches.
    • When results are already shown in a session, the next best matches are returned instead.
  • Bug Fixes

    • Improved behavior when no session ID is available by handling it consistently.
    • After conversation compaction, previously injected rules may not be re-added for the rest of that session.

…on dedup

UserPromptSubmit and PreToolUse searches now pass the Claude Code
session_id to /api/search, so the reflexio backend skips rules it
already returned to this session and backfills next-best matches —
repeated hook searches stop re-injecting the same rules. Documented the
dedup behavior and the post-compaction limitation in ARCHITECTURE.md.
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ae6e22a7-0c64-4120-8d28-6ac5749acad3

📥 Commits

Reviewing files that changed from the base of the PR and between 0f12576 and aa8777b.

📒 Files selected for processing (5)
  • ARCHITECTURE.md
  • plugin/src/claude_smart/context_inject.py
  • plugin/src/claude_smart/reflexio_adapter.py
  • tests/test_adapter.py
  • tests/test_events.py

📝 Walkthrough

Walkthrough

Adds an optional session_id parameter to Adapter.search_all, forwarding it from emit_context() through to the Reflexio backend search call to enable per-session deduplication of injected rules. Includes documentation updates and test coverage for the new parameter's propagation and default behavior.

Changes

Per-session injection dedup

Layer / File(s) Summary
Adapter session_id support
plugin/src/claude_smart/reflexio_adapter.py
Adapter.search_all gains an optional session_id: str | None = None parameter, documented and forwarded to the underlying client.search call for server-side dedup/backfill.
Context injection wiring
plugin/src/claude_smart/context_inject.py
emit_context() passes session_id=session_id or None to search_all with comments explaining dedup semantics.
Tests for session_id propagation
tests/test_adapter.py, tests/test_events.py
New adapter tests verify session_id is forwarded or defaults to None; event tests assert adapter calls include session_id for user_prompt and pre_tool hooks.
Architecture documentation
ARCHITECTURE.md
Updates the session_id mapping description and adds a "Per-session injection dedup" section explaining backend behavior and the compaction limitation.

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

Possibly related PRs

  • ReflexioAI/claude-smart#1: Also modifies how session_id is forwarded into the Reflexio adapter's search calls from hook/event handlers.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: sending session_id on hook searches for server-side deduplication.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/send-session-id-search

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.

@yyiilluu
yyiilluu merged commit 59cfecf into main Jul 8, 2026
8 of 9 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