fix(session-store): fix phantom sessions and the contract #4 gap that let them through #1547
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 416 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.361
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #1547"
general
weight: 0.35
tonydzi
Summary
Fixes #1520.
InMemorySessionStore.appendran its key creation, mtime stamp and summary fold unconditionally, soappend(key, [])on a fresh store created a session that was never written —load()returned[]instead ofNone,list_sessions()reported it andsizecounted it, violating theSessionStore.loadcontract and conformance contract #4.The one-line guard is the fix. The reason this PR also touches the conformance harness is that contract #4 could never have caught this: it only appends
[]to a key that already exists (session_store_conformance.py:109-113), so a store that creates a phantom key on an empty append passes the suite unchanged.Worth noting that all three reference adapters — Postgres (
postgres_session_store.py:170), Redis (redis_session_store.py:121) and S3 (s3_session_store.py:180) — already guardif not entries: return. The shipped in-memory store was the only one that didn't, and the shared suite could not tell the difference.Changes
_internal/session_store.py— return early fromappendwhenentriesis empty, before key creation, the mtime stamp and the summary fold.testing/session_store_conformance.py— extend contract #4 to the fresh-key case:load()isNone, andlist_sessions()/list_session_summaries()stay empty where the store implements them (guarded by the suite's existinghas_list_sessions/has_list_summariesprobes). The contract count is unchanged at 14.tests/test_session_store_conformance.py— the strengthened contract surfaced the same phantom-key pattern in the twoMinimalStoretest doubles; both now carry the guard.This matters beyond the bundled store:
claude_agent_sdk.testingis a public export, and the harness already runs against five implementations in this repo (in-memory, S3, Redis, Postgres, plus the live variants). Any adapter author — including the pending MongoDB adapter — now gets this checked.Verification
Also run against both CI test configurations, since fork PRs can't start their own checks: Python 3.13 with mcp 2.3.0, and the
test-mcp-v1-floorjob'smcp==1.23.0withmypy src/ scripts/— 1755 passed, 6 skipped and mypy clean on each.The strengthened contract is a genuine regression test: with the
appendguard reverted and everything else in place,tests/test_session_store_conformance.pyfails ontest_conformanceandtest_conformance_with_async_factoryunder both asyncio and trio. The issue's own repro now printsNone/0/0, and a real append followed by an empty one still returns the appended entry.Note on overlap
#1541 and #1525 propose the same one-line
appendguard. Neither touches the exported harness (#1525 adds its test totests/test_session_store_conformance.py, which covers onlyInMemorySessionStore), so contract #4's blind spot stays open under both. If one of those lands first, happy to rebase this down to just the harness change.