Skip to content

RATE_MEMORIES: directive names its session id; rating tools accept it - #128

Merged
emp3thy merged 7 commits into
mainfrom
fix/rate-memories-session-id
Aug 31, 2026
Merged

RATE_MEMORIES: directive names its session id; rating tools accept it#128
emp3thy merged 7 commits into
mainfrom
fix/rate-memories-session-id

Conversation

@emp3thy

@emp3thy emp3thy commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes the session-id split-brain that made the RATE_MEMORIES Stop-hook directive impossible to satisfy: the hook counts unrated exposures by its stdin-payload session id, while the MCP rating tools resolved a different id (spawn-env var after MCP respawns; per-project marker file that loses last-writer-wins races between concurrent sessions).

  • session_close: the directive now prints Session: <id> as its second line — the id it actually counted with. Line survives the 8 KB truncation by construction.
  • memory.list_session_exposures / memory.apply_session_ratings: optional session_id argument (explicit stripped non-empty > env/marker resolution; whitespace = absent; both sqlite and agentcore branches). Backward compatible — omitted param behaves exactly as before, including apply's ValueError-when-unresolvable contract.
  • rate-session-memories skill: reads the Session: line and passes it to both tools, with a no-Session:-line fallback for older hooks.
  • Docs synced: README, website/mcp-tools.md, website/architecture.md.

Live-validated mid-development: both stranded unrated pools on the reference machine (7 hook-counted rows + 9 server-side rows under a divergent env id) were rated using the directive-named id through the same service path this PR wires up.

Test plan

  • Full suite: 1815 passed, 30 skipped.
  • New tests: directive Session-line presence + truncation survival; explicit-override, whitespace-fallback, and omitted-param regression per handler on both storage branches; pyright clean on the touched test file (CI typecheck gate).

🤖 Generated with Claude Code

emp3thy and others added 7 commits August 31, 2026 13:40
Three tasks: directive names its session id, rating tools accept an
explicit session_id (explicit > env > marker), skill and docs pass it
through. Fixes the counter/list mismatch diagnosed 2026-08-31.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
memory.list_session_exposures and memory.apply_session_ratings now accept
an optional session_id argument that overrides env/marker resolution when
non-empty (whitespace-only values fall back to the existing resolution).
This lets the RATE_MEMORIES directive pass the session id it already
resolved instead of relying on the handler re-deriving it independently.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
tool.description is typed str | None, so a bare `"session_id" in
tool.description` trips pyright's reportOperatorIssue (typecheck.yml runs
pyright on tests/**). Add the `is not None` guard already used elsewhere
in this file before the two new session_id description checks.

Also rename test_tool_schema_has_no_required_properties to
test_tool_schema_shape_and_optional_session_id — it now asserts the
session_id property's shape too, not just the absence of required fields.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Claude BugBot Analysis

This PR adds an explicit optional session_id parameter to the two rating MCP tools and threads it through the Stop-hook directive and skill. The handler logic, schema changes, hook directive construction, and doc updates all match the accompanying tests and plan precisely; no defects were found in the added/modified lines.

No bugs were detected in this PR.

@emp3thy
emp3thy merged commit 0079565 into main Aug 31, 2026
3 checks passed
@emp3thy
emp3thy deleted the fix/rate-memories-session-id branch August 31, 2026 13:34
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