Commit c94798c
committed
fix: close 5 correctness findings from Oracle audit wave 2
Three parallel read-only Oracles (nudges/emergency-drop/reclaim; telemetry/
forward-pressure/boundary; historian pipeline/decay/recomp/migration). Cores
verified safe (Ch1/emergency-math/two-pass/defer-safety; forward-pressure floor;
protected-tail open-arc fence; decay defer-replay; parse/validate). Five
source-confirmed fixes; two design questions banked to
.alfonso/oracle-loop-findings.md (D3 emergency skeleton policy, D4 historian
publish atomicity — both structural/cache-path, need review before changing).
1. Channel 2 stale-delivery (event-handler.ts). deliverChannel2IfPending ignored
the baseline's reducedSinceRefresh flag, so if the agent already called
ctx_reduce since the last transform, delivery used stale-high tail tokens and
nudged the agent to drop output it just dropped. Skip when reducedSinceRefresh
(the pending intent stays armed for the next fresh re-eval). PARITY: Pi's
maybeDeliverChannel2Pi already had this guard — this is an OpenCode parity fix.
2. Discard-last user-observation gap (compartment-runner-incremental.ts + Pi
pi-historian-runner.ts). Facts are skipped on a discard-last run (the
provisional last compartment re-emits next run), but user_observations were
stored unconditionally → a reworded re-emission next run double-stores the
candidate. Gate observations on !discardedLast too (hoisted the Pi compute
above the observations block). Both harnesses.
3. Memory-migration apply+guard atomicity (memory-migration.ts + Pi
pi-memory-migration.ts). applyMemoryMigration (delete+reinsert+epoch bump) and
markMemoryMigrationDone ran separately; a crash between them left the project
migrated-to-v2 but UNGUARDED → a retry re-migrates v2 rows (new ids/stats/
embeddings, dup observation candidates). Wrap both in one db.transaction()
(nested = savepoint, inner tx still works). Both harnesses.
4. transform_decisions retention cap missing (transform-decision-log.ts). The
documented 2000-row/(session,harness) cap was never enforced — only full
session-delete pruned. A long session's cache-affecting passes grew the
telemetry table unbounded (dashboard loads all rows for attribution). Prune
newest-2000 after each insert on the same non-blocking handle. +tests.
5. Pi telemetry older-entry misattribution (transform-decision-log.ts). The
backward value-skip resolver returned an OLDER assistant when no new one had
arrived (branch still ends at snapshot) → this pass's cache decision recorded
against the wrong message. Made it index-aware: resolve the snapshot's index,
bind only to the first assistant AFTER it; refuse (null, stay pending) if the
snapshot is absent. Dashboard-attribution only (no runtime/cache corruption).
+tests.
Also: corrected the stale Channel-1 denominator comment (ctx-reduce-nudge.ts:
historyBudget → workingWindow). Gate: plugin 2174/0 (+6), Pi 471/0, tsc+biome
clean both harnesses.1 parent 7d8e4b0 commit c94798c
8 files changed
Lines changed: 228 additions & 22 deletions
File tree
- packages
- pi-plugin/src
- plugin/src
- features/magic-context
- memory
- hooks/magic-context
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
940 | 940 | | |
941 | 941 | | |
942 | 942 | | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
943 | 949 | | |
944 | 950 | | |
945 | 951 | | |
946 | 952 | | |
947 | 953 | | |
948 | 954 | | |
| 955 | + | |
949 | 956 | | |
950 | 957 | | |
951 | 958 | | |
| |||
971 | 978 | | |
972 | 979 | | |
973 | 980 | | |
974 | | - | |
975 | | - | |
976 | | - | |
977 | | - | |
978 | | - | |
979 | 981 | | |
980 | 982 | | |
981 | 983 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
203 | 205 | | |
204 | 206 | | |
205 | 207 | | |
| |||
Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
510 | 510 | | |
511 | 511 | | |
512 | 512 | | |
513 | | - | |
514 | | - | |
515 | | - | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
516 | 524 | | |
517 | 525 | | |
518 | 526 | | |
| |||
Lines changed: 121 additions & 0 deletions
| 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 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
Lines changed: 62 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
8 | 16 | | |
9 | 17 | | |
10 | 18 | | |
| |||
247 | 255 | | |
248 | 256 | | |
249 | 257 | | |
250 | | - | |
| 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 | + | |
251 | 287 | | |
252 | 288 | | |
253 | 289 | | |
254 | 290 | | |
255 | 291 | | |
256 | 292 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | 293 | | |
261 | 294 | | |
262 | 295 | | |
| |||
301 | 334 | | |
302 | 335 | | |
303 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
304 | 358 | | |
305 | 359 | | |
306 | 360 | | |
| |||
323 | 377 | | |
324 | 378 | | |
325 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
326 | 384 | | |
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
762 | 762 | | |
763 | 763 | | |
764 | 764 | | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
765 | 769 | | |
766 | 770 | | |
| 771 | + | |
767 | 772 | | |
768 | 773 | | |
769 | 774 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | | - | |
10 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
134 | 141 | | |
135 | 142 | | |
136 | 143 | | |
| |||
0 commit comments