Repository navigation
Commit e768750
committed
fix: full-codebase audit findings (data-integrity, fail-closed, security, robustness)
Athena full-codebase audit (3 members, dashboard-excluded). Each finding verified
against source; real ones fixed, false positives + accepted tradeoffs documented.
HIGH — data integrity:
- #3 v22 memory rekey UNIQUE collision: the deferred backfill did a blind
UPDATE memories SET project_path=identity, which trips
UNIQUE(project_path, category, normalized_hash) and aborts the whole batch
transaction when two legacy raw paths for one project share a
(category, normalized_hash). Now detects the target collision and merges
(keep max seen_count, delete source, embedding FK-cascades) instead. +test.
- #5 CLI migration dropped v2 compartment tiers: the Pi-session migrator's
bespoke INSERT omitted p1-p4/importance/episode_type/legacy, so migrated rows
landed legacy=0 + NULL tiers and the decay renderer fell back to full content
for every tier (no decay, prompt bloat). Now carries all v2 fields faithfully
(legacy v1 rows keep legacy=1). +test.
MEDIUM — robustness / correctness:
- #1 openDatabase() honest type: JSDoc promised "throws" but the schema-fence
path returned `null as unknown as Database` (a type lie). Return type is now
Database | null; every call site null-checks (plugin + Pi + CLI). The two
sites the audit flagged were already safe, but the contract is now
compiler-enforced. recordChildInvocation tolerates a null db (skip telemetry).
- #7 CLI migration non-transactional: copyMagicContextState now returns a
plan whose commit() runs all INSERTs inside BEGIN IMMEDIATE, and the caller
writes the Pi JSONL file BEFORE committing DB rows — so an interruption never
orphans shared-DB rows pointing at a session file that was never written.
- #8 auto-update npm install pipe deadlock: spawn used stdio:"pipe" with no
readers; once npm output exceeds the OS pipe buffer the child blocks forever
and the updater spuriously times out. Switched to stdio:"ignore" (output is
never read; failure still detected via exit code).
- #10 key-files trust: the validator enforced path/size/budget but not
candidate-set membership or doc/lockfile exclusion (prompt-only). Both are now
enforced in code (the persisted key-files set is injected into every future
prompt — a trust boundary). +tests.
- #11 RPC auth: the localhost RPC server set wildcard CORS and required no auth
on side-effecting endpoints (recomp/upgrade/dismiss). Now generates an
unguessable per-process token, publishes it in the (user-private) port file,
requires it as Bearer auth on all non-health calls, and drops wildcard CORS.
Health stays open for discovery. +tests.
Dashboard (user-reported regression from f5cfa31):
- resolve_paths_for_table_filter read `SELECT DISTINCT project_path` into a
non-Option String; the notes table holds many NULL-project_path rows
(session notes), so opening any session detail threw "Invalid column type
Null at index: 0, name: project_path" and crashed the whole view. Now reads
Option<String> and drops NULLs. +test.
Docs:
- #9 ARCHITECTURE.md reconciled with the supersede-delta design: in-session
ctx_memory mutations (additive AND non-additive) route through m[1], not a
project_memory_epoch bump; the epoch is bumped only by dashboard mutations and
/ctx-session-upgrade migration.
- AUDIT-KNOWN-ISSUES A11: key-files lazy pickup (next natural cache-bust) is the
chosen behavior, and not a Pi divergence in v2 (Pi's eager system-prompt
signal no longer touches m[1]-resident key-files).
Verified FALSE POSITIVE:
- #2 (contested HIGH) m[0] rematerialize-on-defer: Opus correct. materialize
fires only on genuine content-change markers (epoch/seq/mutation-id/docs-hash/
upgrade-state); Date.now() is deliberately excluded. Defer replay stays
byte-identical (test-locked). GPT 5.5 conflated "not gated on isCacheBusting"
with "rebuilds spuriously".
Deferred (need decisions/sourcing): #6 (Electron native-binding integrity —
needs a trusted checksum/signature source). LOW hygiene (#12-#18) batched separately.
plugin 1717/0, Pi 403/0, CLI 148/0, dashboard cargo + 18 Rust tests, tsc + biome
clean, dist rebuilt.1 parent f5cfa31 commit e768750
25 files changed
Lines changed: 632 additions & 129 deletions
File tree
- docs
- packages
- cli/src/commands
- dashboard/src-tauri
- src
- tests
- pi-plugin/src
- plugin/src
- features/magic-context
- key-files
- hooks
- auto-update-checker
- magic-context
- plugin
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
| 112 | + | |
112 | 113 | | |
113 | | - | |
| 114 | + | |
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
164 | 186 | | |
165 | 187 | | |
166 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
503 | 503 | | |
504 | 504 | | |
505 | 505 | | |
506 | | - | |
507 | | - | |
508 | | - | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
509 | 510 | | |
510 | 511 | | |
511 | 512 | | |
512 | | - | |
| 513 | + | |
513 | 514 | | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
514 | 524 | | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
525 | 536 | | |
526 | | - | |
527 | | - | |
528 | | - | |
529 | | - | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
530 | 542 | | |
531 | 543 | | |
532 | 544 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
160 | 167 | | |
161 | 168 | | |
162 | 169 | | |
| |||
365 | 372 | | |
366 | 373 | | |
367 | 374 | | |
368 | | - | |
369 | | - | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
370 | 394 | | |
371 | | - | |
| 395 | + | |
| 396 | + | |
372 | 397 | | |
373 | | - | |
374 | | - | |
| 398 | + | |
| 399 | + | |
375 | 400 | | |
376 | 401 | | |
377 | 402 | | |
| |||
403 | 428 | | |
404 | 429 | | |
405 | 430 | | |
406 | | - | |
| 431 | + | |
407 | 432 | | |
408 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
409 | 444 | | |
410 | 445 | | |
411 | 446 | | |
412 | 447 | | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
413 | 461 | | |
414 | 462 | | |
415 | 463 | | |
| |||
0 commit comments