Repository navigation
Commit 4bd7e7f
* fix(hooks): inject only the session's project and global memories (#604)
session_start and auto_recall queried memories with no project
predicate, so a session under one project received the hot and
protected memories of every project the store held. The PostgreSQL
recall function already scoped by directory_context; the two hooks
bypassed that column entirely.
Both hooks now apply one rule, shared across the PostgreSQL and
SQLite paths (mcp_server/shared/project_scope.py, ADR-1080): a memory
injects when it is global, or its directory_context is the session's
project root or an ancestor of it. An empty directory_context is not
a wildcard. The project root comes from CLAUDE_PROJECT_ROOT or the
hook event's cwd; when neither resolves, the hook logs it and
restricts injection to global memories, never everything. Team
decisions stay global by design and are unaffected. The recall tool
is untouched.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cz7A6goxVzfKL9NT7k4zDH
* fix(hooks): push project predicate into the query, before LIMIT (#604)
Review of 7f27b41 found the predicate ran in Python after the SQL
LIMIT: a store with more out-of-project rows above the heat floor than
the LIMIT allowed let those foreign rows consume the candidate window,
starving the project's own rows out of the banner entirely. That is
the reporter's own situation (#604), and the acceptance criteria only
held in a three-row fixture.
The predicate now runs inside the query, before ORDER BY/LIMIT, on
both backends. mcp_server/shared/project_scope.py's project_ancestors
feeds a new directory_ancestors parameter on get_hot_memories and
search_fts (both stores, default None, every other caller unaffected),
built into SQL via the new pg_scope_clause.py / sqlite_scope_clause.py.
The two hooks' own raw SQL (auto_recall._recall_memories,
session_start._fetch_anchors/_fetch_hot_memories) carry the same
predicate directly.
project_ancestors had its own bug, caught by the new starvation tests
running against real SQL: it included an empty-string "ancestor" for
any leading-slash root, which the old Python-side memory_matches_project
never surfaced (a separate empty-directory_context guard ran first) but
which a query built straight from the list would have matched against
every empty-directory_context row.
tests_py/integration/test_cold_start.py seeded a memory with an empty
directory_context and no is_global, expecting injection under the old
behaviour; updated to the new rule and the CHANGELOG/ADR now name the
migration consequence for stores with such rows.
test_sqlite_hook_paths.py and test_auto_recall.py split their scoping
coverage into test_sqlite_hook_scope.py / test_auto_recall_scope.py to
clear the craftsmanship file-size cap after the added regression tests.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cz7A6goxVzfKL9NT7k4zDH
---------
Co-authored-by: Claude Fable 5.1 <[email protected]>
1 parent 84c0a3b commit 4bd7e7f
21 files changed
Lines changed: 1244 additions & 100 deletions
File tree
- docs/adr
- mcp_server
- hooks
- infrastructure
- tests_py
- hooks
- integration
- wiki
- adr/cortex
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
69 | 90 | | |
70 | 91 | | |
71 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
122 | | - | |
| 123 | + | |
123 | 124 | | |
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
130 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
131 | 135 | | |
132 | 136 | | |
| 137 | + | |
133 | 138 | | |
134 | 139 | | |
135 | 140 | | |
| |||
149 | 154 | | |
150 | 155 | | |
151 | 156 | | |
| 157 | + | |
152 | 158 | | |
153 | 159 | | |
154 | 160 | | |
155 | 161 | | |
156 | | - | |
| 162 | + | |
157 | 163 | | |
158 | 164 | | |
159 | 165 | | |
| |||
204 | 210 | | |
205 | 211 | | |
206 | 212 | | |
207 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
208 | 231 | | |
209 | 232 | | |
210 | 233 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
215 | 241 | | |
216 | 242 | | |
217 | 243 | | |
218 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
219 | 249 | | |
220 | | - | |
| 250 | + | |
221 | 251 | | |
222 | 252 | | |
223 | 253 | | |
224 | 254 | | |
225 | 255 | | |
226 | 256 | | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
| 257 | + | |
240 | 258 | | |
241 | 259 | | |
242 | 260 | | |
243 | 261 | | |
244 | 262 | | |
245 | 263 | | |
246 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
247 | 271 | | |
248 | 272 | | |
249 | 273 | | |
250 | 274 | | |
251 | | - | |
| 275 | + | |
252 | 276 | | |
253 | 277 | | |
254 | 278 | | |
| |||
358 | 382 | | |
359 | 383 | | |
360 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
361 | 392 | | |
362 | | - | |
| 393 | + | |
363 | 394 | | |
364 | 395 | | |
365 | 396 | | |
| |||
0 commit comments