Repository navigation
feat: bili handoff <session> — mint rollover tokens for ACP state inheritance (#1539) - #1543
ranxianglei wants to merge 2 commits into
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1487-pr.1543.72ba9c8This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1543.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 ## Review: ① Direction (original issue). Matches the owner-approved #1539 design point-for-point: token shape ② Regression surface. Audited the touched paths against prior behavior:
③ Code review. Logic is sound: pure
④ Test validity. 11 tests, all with teeth: round-trip incl. unicode/spaces/2000-char ids; canonical-decode rejection of padded/garbage/oversized payloads; version gate + first-match-wins; kill-switch env variants; each blankness-gate component individually; carrier determinism ( ⑤ Diff cleanliness. Single linear commit, every line on-purpose, no whitespace/reformat churn, no unrelated files. My fix commit is 10 insertions across the two files, clearly labeled. Verification: local pre-flight on the branch — Verdict: mergeable once the CI lanes on head 中文摘要:review 了 #1539 第一阶段( |
[bot] 🏷 CI update: all 12 lanes now green on head 中文摘要:新 head 的 CI 已全部通过(12/12,含 Windows 与全部 e2e 车道),无阻塞项,可以合并。 |
Phase 1/3 of the session-rollover feature from #1539 (design approved in the issue thread). This PR ships the offline CLI side; server-side adoption (token detection → state clone → carrier injection) lands as a follow-up PR against this module's API.
What
src/handoff.ts(new) — core rollover module:[BILI_SESSION_HANDOFF v1 <base64url(sessionId)>]with strict round-trip decode, version check, length bounds; malformed tokens fail open (stay literal text)isBlankForHandoff(state)— blankness = no blocks + no refs + empty token accounting, deliberately NOTstats.requests === 0(owner refinement: pre-first-message probes/side requests must not disqualify a fresh session)planHandoff/applyHandoff— pure plan + idempotent apply. Inherits the minimal visible set per owner decision: fullmessageRefsmaps (hash→number, content-free), active-block summaries as a frozen carrier (kernel render format viarenderForgedSummary),metadata.handoffFrom+derivedFromSessionId(reuses the existing [pi plugin] Prime RLM inline 派生子会话在代理模式下零继承:搜不到也解压不了父会话压缩块(billion-context-pi#531 同场景) #1333 ancestor fallback). Deliberately NOT inherited: blocks/blockContents/CCR store (cloned old blocks would be deactivated by syncBlocks on turn 1 anyway; older content stays reachable through the [pi plugin] Prime RLM inline 派生子会话在代理模式下零继承:搜不到也解压不了父会话压缩块(billion-context-pi#531 同场景) #1333 chain), nudge/stats/tokenSnapshot/rules/absorbed/terminalStreak (the context genuinely reset)decompress(<old block>)miss deterministically and fall back to the source sessionhandoffSession(selector, {dir, output})— offline, mirrorsexportSessionselector semantics (list / resolve / mint)handoffEnabled()—BILI_HANDOFF=passkill-switch, read per-request likecodexCompactMode; consumed by the server in phase 2src/cli.ts—bili handoff [session] [--output FILE]wired through parseArgs/help/dispatch (same pattern asbili export)tests/handoff.test.ts(new) — 11 unit tests: codec round-trip/rejection, blankness gate, plan purity + all rejection paths, apply seeding (refs/counters/metadata, source untouched, double-adoption refused), carrier format/stability, large-rollover at the issue's repro scale (11699 refs)Config surface
One new user-facing CLI subcommand (
bili handoff,--output FILEreusing export's flag) — explicitly requested and named in #1539, design approved in the issue thread before implementation. No config.json fields; no new persisted state shape beyond threemetadata.*keys plus reuse of the existingderivedFromSessionId. TheBILI_HANDOFF=passenv kill-switch is defined here and consumed in phase 2 (documented there).Behavior disclosure
Purely additive. Zero behavior change for any request that does not contain a handoff token — this PR adds no server code path at all (detection lands in phase 2). Normally-created sessions are unaffected.
Related prior work
#1486 (
BILI_RESUME_INHERITANCE, merged as #1519) inherits refs/blocks/lineage across resume forks (client restarts resuming one conversation). Handoff is complementary: user-initiated rollover into a new session where client history is cut. No shared state or key collisions (verified:handoffFrom/handoffToken/handoffCarrierare unique;derivedFromSessionIdis reused read-only through the #1333 chain).Pre-flight (rebased onto d42baaa, master @ v0.1.164, acp-kernel 0.0.97)
npm run typecheck✓npm test: 3039 pass / 0 fail / 12 skipped — two consecutive green runs (one unidentified transient failure on the first run did not reproduce; CI re-runs everything)npm run build✓bili handoff <id>mints[BILI_SESSION_HANDOFF v1 …]; unknown id → clean error exit 1; no arg → session listPhases
isBlankForHandoffat the fork-hook slot, per-turn carrier substitution across all four wires, integration tests (fake upstream), docs en/zhPart of #1539 (not auto-closing: the feature completes in phase 2).
Fixes #1539
(孤儿认领:标题本已指向 #1539,补上关闭关键字 —— 第三批清理)