This repository was archived by the owner on Jul 13, 2026. It is now read-only.
Repository navigation
Commit 1cff4cb
fix(ctx-reduce): replace scalar emergency watermark with active-set idempotence; fix Pi tool-byte double-count + subagent guidance leak
Round-2 audit (4 oracles + Athena council, all blind on AUDITOR.md). Two HIGH
overflow-safety fixes + one MED, with two council findings empirically DISPROVEN
before any change.
P0 — emergency watermark redesign (Council cortexkit#1/cortexkit#2 strong-converge + Oracle A2 HIGH
+ Oracle B2 cold-start HIGH, all the same root cause):
The tiered drop walked TIER order (T3→T2→T1) but persisted a SCALAR
`last_emergency_drop_through_tag = max(dropped)` and excluded every
`tagNumber <= watermark`. Dropping high-numbered T3 tags set the watermark PAST
still-active lower-numbered T1/T2 tags → permanently excluded → under-evict
toward overflow (worse for subagents, no 95% recovery). Also went stale after
hash/tool-set/cold-start model switches.
Fix: remove the scalar watermark entirely. Idempotence is already guaranteed by
(1) `status='active'` — a dropped tag leaves the active set, never re-selected;
(2) the `last_emergency_input_sample` latch — prevents over-dropping the
remaining tail on a stale (not-yet-remeasured) usage sample. One structural
change closes 4 findings. Removed the unreleased watermark column (fresh schema
+ ensureColumn + heal). Model-switch reset now clears the sample latch.
Also Council cortexkit#8: latch the sample on ANY acting pass (not only droppedTools>0)
so a zero-reclaim pass can't re-bust the cache every ≥85% pass.
P0 — Pi tool-byte double-count (Oracle B2 HIGH, shared core):
`tag-transcript.ts` seeded a tool tag's `byte_size` from the FIRST occurrence
(the tool_use args) AND stored the same args in `inputByteSize`; reclaim =
byteSize+inputByteSize+reasoning → args counted twice, output missed when
result<args → Pi over-estimates reclaim and under-evicts. Fixed to track
byte_size = OUTPUT (tool_result) only, mirroring OpenCode tag-messages.ts.
OpenCode unaffected (separate tagger).
MED — ctx_reduce-disabled subagent guidance leak (Oracle C2):
A subagent with ctx_reduce OFF fell through to the no-reduce PRIMARY prompt,
leaking the long-term-partner frame + ctx_memory/search/note guidance into a
bounded parent-driven subagent. Now gets NO Magic Context block at all.
DISPROVEN (ran the actual code, didn't relay):
- Council cortexkit#3 "node:sqlite nested transaction broken" — `isTransaction` is a
NATIVE node:sqlite getter; ran the real shim under Node 24.15, nested
savepoint rollback works (rows a,c; inner b rolled back). Not a bug.
- Oracle A2-MED "channel2 NULL after v31" — ADD COLUMN DEFAULT '' makes existing
rows read '' (verified IS NULL→0) and the CAS matches. Not a bug.
Gate: plugin 1886/0, Pi 417/0; tsc + lint clean both.
Co-authored-by: Alfonso [Magic Context] <[email protected]>1 parent 258faad commit 1cff4cb
14 files changed
Lines changed: 187 additions & 192 deletions
File tree
- packages
- pi-plugin/src
- plugin/src
- features/magic-context
- hooks/magic-context
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
1449 | 1449 | | |
1450 | 1450 | | |
1451 | 1451 | | |
1452 | | - | |
1453 | | - | |
| 1452 | + | |
| 1453 | + | |
1454 | 1454 | | |
1455 | | - | |
| 1455 | + | |
1456 | 1456 | | |
1457 | 1457 | | |
1458 | 1458 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | 57 | | |
59 | | - | |
| 58 | + | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| |||
301 | 300 | | |
302 | 301 | | |
303 | 302 | | |
304 | | - | |
305 | 303 | | |
306 | 304 | | |
307 | 305 | | |
| |||
318 | 316 | | |
319 | 317 | | |
320 | 318 | | |
321 | | - | |
322 | 319 | | |
| 320 | + | |
323 | 321 | | |
324 | 322 | | |
325 | 323 | | |
326 | 324 | | |
327 | | - | |
328 | | - | |
329 | 325 | | |
330 | 326 | | |
331 | 327 | | |
| |||
335 | 331 | | |
336 | 332 | | |
337 | 333 | | |
338 | | - | |
339 | 334 | | |
340 | 335 | | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
350 | 340 | | |
351 | 341 | | |
352 | 342 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
550 | 550 | | |
551 | 551 | | |
552 | 552 | | |
553 | | - | |
554 | 553 | | |
555 | 554 | | |
556 | 555 | | |
| |||
721 | 720 | | |
722 | 721 | | |
723 | 722 | | |
724 | | - | |
725 | 723 | | |
726 | 724 | | |
727 | 725 | | |
| |||
1075 | 1073 | | |
1076 | 1074 | | |
1077 | 1075 | | |
1078 | | - | |
1079 | 1076 | | |
1080 | 1077 | | |
1081 | 1078 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | 256 | | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
310 | 266 | | |
311 | | - | |
| 267 | + | |
312 | 268 | | |
313 | 269 | | |
314 | 270 | | |
| |||
328 | 284 | | |
329 | 285 | | |
330 | 286 | | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
338 | 304 | | |
339 | 305 | | |
340 | 306 | | |
341 | | - | |
342 | | - | |
| 307 | + | |
| 308 | + | |
343 | 309 | | |
344 | 310 | | |
345 | 311 | | |
| |||
0 commit comments