Repository navigation
feat: encrypt session files at rest behind BILI_ENCRYPTION_KEY (#708) - #711
Conversation
AES-256-GCM over zstd-compressed JSON (BILIENC1 format), wired through the kernel StateStore codec hook (acp-kernel#249). Key comes only from the environment variable; invalid values fail fast at startup. Boot takes over legacy plaintext files once: each is re-encoded and atomically replaced in place (rename IS the old-file deletion; crash mid-run self-heals). Off by default — unset key = today's plaintext behavior. Requires acp-kernel >= 0.0.64 (codec hook); pin bump + lockfile follow in a separate commit once 0.0.64 is published.
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-711Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr711.tgz
npm install -g packageThis comment is automatically updated on each push. |
[bot] 🏷 Status check — still blocked on acp-kernel 0.0.64, nothing new to push yet, but the branch is re-verified healthy: Verified just now at branch head
So the branch is ready; the only remaining step is external: merge acp-kernel#249 → CI publishes 0.0.64. Once One minor observation (non-blocking, reported only per policy): if the process dies between the temp write and the rename inside 中文摘要:分支已用本地构建的 #249 kernel 全量复验通过(typecheck 干净、测试 1376/0、build OK),代码就绪;目前仍卡在 acp-kernel#249 未合并(npm 上还是 0.0.63),需人工合并并发布 0.0.64 后我再提交 pin 升级并重跑预检——当前尚不可合并。 |
[bot] 🏷 Follow-up: rather than wait for your call on the minor item above, I fixed it directly on the branch per review policy — commit
Re-ran full pre-flight at this head against the local #249 kernel build: typecheck clean, 1377 pass / 0 fail / 2 e2e-skipped, build OK. Still waiting on acp-kernel#249 merge → 0.0.64 publish for the pin bump. 中文摘要:直接在 PR 分支补了一个小修复(commit 0f9c3f1)——迁移时清扫崩溃残留的 |
…root) in #708 discussion
|
ci失败 |
[bot] 🏷 Investigated the CI failure — it's the expected, documented red, not a new regression. What failed: all 4 matrix jobs ( Why: CI runs Verified the code itself is healthy: I ran the full pre-flight locally against a local build of the #249 kernel — Note: the newest commit on the branch ( To turn CI green (the only remaining step, and it's human-gated):
I can't merge the kernel PR myself (PR merges are human-only per repo rules), so step 1 is the blocker. Ping me as soon as #249 is merged and 0.0.64 is live and I'll do steps 2–3 immediately. 中文摘要:CI 失败是预期内的红色——4 个矩阵任务都卡在 |
|
解决ci失败问题 |
[bot] 🏷 I pulled the actual published npm artifacts apart to find a way to turn CI green. Important correction to my previous message: bumping the pin to 0.0.64 will NOT fix it. Verified by inspecting the real tarballs'
Cross-checked against source too: Consequence: no stable published acp-kernel satisfies this branch's typecheck. I can't reach a shippable green by bumping the pin alone — the root blocker is still the human-only merge of acp-kernel#249, which I'm not permitted to merge. Two ways to get CI green — your call:
My recommendation is Path A — it's the only route that ends in a clean, shippable pin, and it needs just that one merge from you. If you need the check green immediately for other reasons, I'll do Path B now. 中文摘要:我把 npm 上真实的 acp-kernel 包拆开核对了 |
|
ci失败 |
[bot] 🏷 CI failure resolved — fix is pushed, verifying the new run now. What changed since my last message: acp-kernel#249 was merged today 12:00 UTC, and two kernel releases followed — 0.0.65 (12:24 UTC) and 0.0.66 (14:02 UTC). I verified both by unpacking the npm tarballs: each carries Why the latest red run ( What I did (commit
Full pre-flight locally, clean
The fresh CI run on 中文摘要:CI 已修复并推送( |
[bot] 🏷 ✅ Confirmed: CI is green on The branch is up to date with master, pinned to acp-kernel 0.0.66 (exact, lockfile-synced, contains the codec hook), and fully pre-flighted locally against the real published artifact. Nothing left on my side — ready for your review/merge whenever you are. 中文摘要:已确认新提交 |
What
Session-file encryption at rest (#708) for deployments on untrusted nodes:
BILI_ENCRYPTION_KEY(env-only; hex or base64, exactly 32 bytes) turns on encryption for every persisted session file. Unset = today's plaintext behavior, zero change.BILIENC1magic + version + mode byte + random 12-byte nonce + AES-256-GCM ciphertext (auth tag appended). The body is zstd-compressed BEFORE encryption where Node >= 22.15 provideszlib.zstdCompressSync(raw mode byte on older runtimes) — compression also shrinks files ~5-10x, addressing the size concern raised in the thread..jsonunder the sessions dir ONCE — temp write + rename onto the SAME path, so the atomic replace IS the old-file deletion. A crash mid-migration self-heals on the next boot (the 8-byte magic peek decides per file); unreadable files are left in place with a warning. Spill.fb.jsonfiles are covered too.codechook onStateStore(ranxianglei/acp-kernel#249); this repo stays policy-only (key parse, format, migration, docs).Blocked on acp-kernel 0.0.64
The codec hook ships in acp-kernel 0.0.64 (PR ranxianglei/acp-kernel#249, awaiting merge). Until it is published this branch pins 0.0.63, so CI will be red at typecheck (
StateStoreCodecnot exported by 0.0.63). The follow-up commit bumping the exact pin + lockfile lands as soon as 0.0.64 is live on npm, with a full pre-flight re-run.Pre-flight (local, against a local build of the #249 kernel)
npm run typecheck— cleannpm test— 1376 pass / 0 fail / 2 e2e-skipped (newtests/persist-encryption.test.ts: key parsing, roundtrip, per-write nonce, tamper + wrong-key rejection, legacy passthrough, encrypted writes, eager boot migration + idempotent second boot, spill coverage, corrupt-file tolerance, invalid-key fail-fast, no-key zero change)npm run build— OKDocs: CONFIGURATION.md + CONFIGURATION.zh-CN.md env-var tables.
Fixes #708