Repository navigation
fix: stop legacy-id migration destroying anonymous pfa sessions (#499 prerequisite) - #502
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-502Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr502.tgz
npm install -g packageThis comment is automatically updated on each push. |
[bot] 🏷 Reviewing this PR now — pulling the branch, re-running pre-flight (typecheck/test/build), and auditing the three fix pieces ( |
[bot] 🏷 Review complete — approved, merge-ready. ✅ Root-cause audit (both defects verified against code)Defect 1 — Defect 2 — missing re-seed: confirmed. Code quality
Pre-flight (re-run independently)PR head: Merge-readiness vs current master (branch base is 29 commits behind, incl. #404 timestamp restore, #473, #453 backstop): simulated merge is clean, zero conflicts. I actually merged it locally and re-ran everything on the combined tree: Minor observations (non-blocking)
No issues found that warrant a separate bug report. LGTM from my side — merge is yours to execute. |
…erequisite) migrateLegacyIds() re-keys sessions whose stored label differs from their id (#286 cleanup), deleting all but the newest sibling per label. Anonymous prefix-affinity sessions (#309) all carry the shared display label "prefix-affinity" != their pfa- id, so every boot re-keyed them all to the single id "prefix-affinity" and deleted every sibling but the newest — silent loss of saved compression state for anonymous clients on every restart. Exclude pfa- ids from the migration. True legacy derived-hash sessions are still re-keyed as before (regression-tested alongside the guard). Prerequisite for #504 P1a affinity-snapshot persistence: without it, routing restored across restarts lands on session files that no longer exist, so the folded view cannot be rebuilt.
d1b73aa to
3be6b6d
Compare
|
Independent review (second session) — defect confirmed real, fix correct for the intended path; one theoretical hardening nit below. Defect confirmed (traced against master): anonymous pfa sessions get Nit (theoretical clobber, 2-line reorder): the guard if (label === id) { claimed.add(id); continue; }
if (id.startsWith("pfa-")) continue;Anonymous pfa sessions (label Combined-tree pre-flight (this + #500 on current master): typecheck ✅, 1020/1022 (2 known env fails). |
Scope change (was: full restart-resume fix)
This PR originally shipped the complete #499 restart-resume fix (persist chain snapshots in session metadata +
reseed()+initSessions()hook). PR #504 now covers that half via a dedicated affinity-table snapshot (src/affinity-persist.ts, hydrate on boot / flush on shutdown) — a strictly more complete mechanism (preserveslastSeenfor TTL, independent of session-file lifecycle, covers the whole table). Keeping both would mean two competing persistence paths for the same table, so this PR was shrunk to its unique remaining piece: the bug neither PR addressed.The bug:
migrateLegacyIds()destroys every anonymous session on each bootThe #286 one-time migration re-keys sessions whose stored label ≠ their id, deleting all but the newest sibling per label. Anonymous prefix-affinity sessions (#309) all carry the shared display label
"prefix-affinity"≠ theirpfa-id — which trips the migration's self-termination invariant. Result, verified empirically before fixing:On every startup, all but the newest anonymous session's saved compression state is silently deleted, and the survivor is re-keyed away from its
pfa-id.Why this is a prerequisite for #504 P1a
P1a restores the routing table across restarts — it tells the proxy "this replay belongs to
pfa-8588…". But the folded view itself lives in the session state file, which the migration deletes/re-keys at boot before any request arrives. Without this guard, post-restart resolution lands on a non-existent session id → fresh empty session → raw history forwarded → 0% cache again. The two fixes are complementary: P1a restores routing, this guard keeps the routed-to state alive.Change
One guard in
migrateLegacyIds(): skip ids with thepfa-prefix (src/persist.ts). True legacy derived-hash sessions are still re-keyed exactly as before.Tests
New regression test in
tests/proxy-persist.test.ts(same style as the existing #286 migration test): two pfa sessions with the shared label + one true legacy session → after migration both pfa files survive intact (state round-trips) while the legacy session is still re-keyed under its label.Pre-flight: typecheck ✅ ·
tests/proxy-persist.test.ts22/22 ✅ · full suite 1000/1001 ✅ (the one failure,launcher.test.tscodex PATH resolution, pre-exists on master in environments where/usr/bin/codexis installed) · no build impact (no dist-affecting surface beyond persist.ts).Merge order: this can land before or alongside #504 — zero file overlap.