Repository navigation
feat: chain checkpoint step 3 — per-wire stamp shapes + first-processor-wins enforcement - #1441
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1401-pr.1441.ec1b3acThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1441.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Review complete — HOLD: one blocking regression found (both native-lane e2e jobs, root cause proven below). Everything else passes. CI final state @
|
| Behavior | Verdict |
|---|---|
| Every processed outbound now carries a ≤200-char carrier | disclosed, intended (the feature) |
| Relay w/ valid checkpoint: double-processed → byte-identical verbatim | disclosed, intended |
Log prefix [chain-shadow]→[chain], legacy advisory wording |
disclosed |
| Recognition widened (anthropic last-part / google any-part) | disclosed |
| Trailing-run scan now breaks at first non-admitted entry (was: skip & continue) | not explicitly disclosed — but conservative: worst case is missing a carrier → process normally; never a wrongful skip. Noted, no action |
| Skipped relays don't bind sessions downstream | consistent with #300 hop-marker semantics (pre-existing pattern) ✓ |
8 unit rigs opted out (chainContentDetection: false) |
justified churn — they pin pre-stamp exact shapes; each is one labeled line |
| native-lane e2e rigs (pi/opencode) | broken — see blocker |
③ Code review
- Stamp block is the last body mutation before send (
src/server.ts:4609-4616, after billion-context: 400 Bad Request when codex sendsrole: "developer"messages — request a request-body compat transform hook #552 compat roles :4584 and Feature: Output-side compression (verbosity steering + effort routing) #1093 steering :4596) → the digest covers exactly the forwarded bytes. Verified. - Processed-path
wireBodyis already canonical JSON, so the parse/stringify round-trip in stamping is byte-stable — no wire-fidelity churn. - Kill switch gates both enforcement (
server.ts:1252) and stamping (:4609);BILI_CHAIN_CONTENT=0env wins over file config (config.ts:880). - Best-effort failure handling correct: stamp throws → debug log + forward unstamped. Side passthroughs excluded.
- No wire-fidelity violations beyond the declared injection.
④ Test quality
The new suite has teeth, not tautologies: E1–E7 enforcement matrix through a real rig asserting byte equality of the captured upstream body; round-trip stampOutbound → evaluateChain=valid across 11 base bodies × all 4 wires (string input, compaction_trigger tail, tool_result tail, model tail, multi-part); must-fail twins proving the old google shape loses the carrier through the real kernel fusion. Gap: the stamped default-on wire is not exercised by any lane e2e (see below).
⑤ Diff cleanliness
Single commit, 12 files, every line purpose-related. Clean.
BLOCKER — deterministic breakage of both native lanes, root cause proven
The outbound carrier lands exactly where the lane fake-upstreams key their script/oracle logic — the last user message (part):
- pi (anthropic wire,
tests/e2e/fake-upstream.mjs:33-40):lastUserText()returns ONLY the last part's text. The merged carrier is that last part → the scripted model sees<bili-chain>…instead of请调用probe_tool;请调用compress;请调用acp_status→ never emits a compress call →'compress must have been called and its result re-sent'(tests/e2e/e2e-native-pi.test.ts:576). - opencode (openai wire,
tests/e2e/fake-upstream-chat.mjs): the oracle'slastUserRefis the ACP-ref regex over the last user message (:179-181). The openai carrier is a standalone user message appended post-pipeline, so it never gets an ACP ref tag →null→'filler message must carry its ACP ref tag, got null'(tests/e2e/e2e-native-opencode.test.ts:617-620). (The row'slastUserfield comes from the first user text, :205 — which is whyfillerRowwas still found.) The fold run additionally loses its directive: source selection (:133-137) checks the last user msg, falls back to the first (filler, no directives) → no compress call either.
Evidence this PR caused it: both lane workflows were green on their 9 most recent runs before this head — newest wt-1420-ework-daemon @ 2026-09-26T16:06Z, ~18 min before this head's 16:24Z run. Same assertion, ~3s durations, no flake signature: deterministic.
The PR opted out 8 unit rigs but missed these two e2e lanes.
Fix options
- A (recommended): make the two fixtures carrier-aware — in
fake-upstream.mjs, if the last part parses as a whole chain tag, fall back to the previous part; infake-upstream-chat.mjs, skip a trailing standalone whole-content chain-tag user message when selecting the directive source and computinglastUserRef. Keeps the lanes exercising the shipped default-on config. - B (minimal unblock): add
BILI_CHAIN_CONTENT: "0"to both lanes' spawn env (kill switch proven by E5). Zero fixture risk, but the default-on stamped wire then has no lane-e2e coverage (unit E-tests partially compensate).
I recommend A; happy to help land it or review the fix commit. Otherwise this is ready — merge once the two lanes are green.
中文摘要:方向关通过(与 #1421 owner 拍板的 per-wire 方案逐条一致)、代码与单测质量合格,但出站 <bili-chain> 盖章把 pi/opencode 两条 native-lane e2e 假上游的脚本逻辑(只认最后一条 user 消息/最后一个 part)确定性打红——根因已定位到具体行,需让这两个 fixture 识别并跳过尾部盖章(A 方案,推荐)或临时以 BILI_CHAIN_CONTENT=0 关闭(B 方案)转绿后再合并。
Deep review (head 9d381bd) — ✅ MERGEABLE, no code changes requiredAll six axes verified: per-wire stamp shapes match the #1421 owner decisions exactly (anthropic trailing-part merge / openai+responses append / google mandatory merge, F0 (perf) — measured, acceptable: ~1.2ms @100kb · ~3.1ms @1MB · ~5.6ms @2mb (JCS stringify + SHA-256, linear). A 1M-token session (~4MB) pays ~10ms sync per request — real but small against per-request network+LLM latency (seconds). If it ever matters, a body-size escape hatch is a one-line follow-up; not a blocker.Needs owner eyes (informational, none blocking)
Gatestypecheck ✓ · chain-checkpoint step2+step3 26/26 · wire-contract+issue1086 31/31 · 4 adjacent opted-out rigs 22/22 — full suite on remote CI. Per AGENTS.md §7.4 this changes wire shape in both compression modes → human merge either way. Merge order: this lands after #1397 (step 2, already in master) — branch is based on current master tip, no rebase needed. |
[bot] 🏷 Agree with the deep-review axes (decision tree, restamp, degradation paths all hold up) — but the MERGEABLE verdict rests on two things that are no longer true at head 1. Two lane jobs are red on this head — "full suite on remote CI" isn't green
2. Rebase is now required (wasn't yesterday)Master moved Informational items — my positions
Suggested sequenceAuthor rebases onto 中文摘要:深度审查各轴我同意,但「可合并」有两个失效前提——① 本 head 上 pi/opencode 两条 native-lane e2e 是红的(根因已定位,今天其他分支上同两条 lane 已转绿,证明是本 PR 确定性打红而非基建问题);② master 夜间前进了 12 个提交(#1419/#1285)且碰了 |
…or-wins enforcement (#1421) Owner-approved design (issue #1421, decision 2026-09-26): adopt carrier merge (a) with per-wire split on role-alternation-strict wires. Stamp shape per wire (insertCheckpointCarrier): - anthropic: merge as an extra trailing text part of the last user message (string content normalizes to parts); standalone append only when the body does not end in a user message. - google: merge into the last content's parts when it is not model-role (mandatory — mirrors appendGoogleNudge; the append form died inside bili's own pipeline because coreToGoogle fuses same-side runs). - openai: standalone trailing user message (unchanged from step 2). - responses: standalone trailing user message inserted before any trailing compaction_trigger (unchanged; #283 invariant preserved). Restamping an already-stamped body replaces the trailing carrier instead of stacking (idempotent re-stamp). Recognition relaxation (extractChainCarriers), matching each wire's emitted shape — still whole-part matching, ownership semantics unchanged: - anthropic: whole-content OR a LAST part that entirely is the tag. - google: ANY part that entirely is the tag (a later hop's nudge merge can push the tag off the end of parts). - openai/responses: unchanged. Strip is surgical: part-level removal for merged carriers, whole-slot for standalone ones; emptied entries are dropped. Enforcement (server.ts, first-processor-wins): - valid / recent-mismatch / stale+digest-matched → forward verbatim, pipeline skipped (log [chain] info/warn). - stale without digest match → strip the stale carrier(s), process normally (the request leaves re-stamped fresh by this instance). - invalid → never trusted, process normally + warn. - new ChainCheckpointContext.selectedMatched splits the stale verdict. - kill switch: both enforcement and outbound stamping respect opts.chainContentDetection !== false (BILI_CHAIN_CONTENT=0). Outbound stamping (forward()): every request that actually ran the kernel (prepared with non-empty processedMessages, not side passthrough) leaves with a <bili-chain> stamp computed over the exact bytes forwarded (placed after compat roles + output steering so the digest covers them). Best-effort: a stamp failure logs debug and forwards unstamped. requestId = first 8 hex of the digest (deterministic, constant-size). New stampOutbound() export; module header now carries the identification-contract-freeze warning carried forward from #1397 plus the #1421 per-wire shape decision. Legacy advisory text updated from 'until signed chain proof lands' to 'until both sides ship the request checkpoint'. Tests: new tests/chain-checkpoint-step3.test.ts (per-wire stamp shapes, restamp idempotency, recognition relaxation, google must-fail regression via real coreToGoogle fusion, round-trip invariant matrix, integration E1-E7 incl. kill switch and side-request no-stamp). Step-2 test file updated to step-3 semantics (T1/T2 now assert byte-identical verbatim forward; google two-part case is now a carrier under the any-part rule). Eight unrelated test rigs pin exact wire shapes and opt out via chainContentDetection:false.
The openai/responses carrier lands as a standalone trailing user message (#1421 step 3), which masked the real last user message in fake-upstream-chat's directive-queue source and lastUserRef oracle (and fake-upstream's ack oracle) — the scripted model-invoked compress never fired on the pi/opencode native lanes. Filter carrier items from last-user semantics; conversation content is untouched.
9d381bd to
b19e366
Compare
|
Rebase + fixture fix landed at
Local gates on the new head:
Remaining before merge is CI green on this head. F4's interop tradeoff ( |
[bot] 🏷 Verified at Fix review (
|
Closes #1421
Step 3 of the chain-checkpoint series (#1395 design; step 1 advisory #1364 and step 2 recognition contract #1397 already merged). Implements the owner-approved decision on #1421 (2026-09-26): adopt carrier merge (a) with per-wire split on the role-alternation-strict wires.
Stamp shape per wire (
insertCheckpointCarrier)appendGoogleNudge; the append form broke bili's OWN pipeline before any upstream saw it —coreToGooglefuses same-side runs into one multi-part content, so an appended standalone user entry no longer matched the recognition contract (pinned as a must-fail regression test through the real kernel function)compaction_trigger(unchanged)compaction_triggerstays the last input itemRestamping an already-stamped body REPLACES the trailing carrier instead of stacking (idempotent restamp).
Recognition relaxation (
extractChainCarriers)Still whole-PART matching (no substring scanning anywhere); ownership semantics unchanged (a client whose final message literally is a well-formed tag binding its own digest still self-opts out — accepted by design):
Enforcement (server.ts) — first-processor-wins
New
ChainCheckpointContext.selectedMatchedsplits the stale verdict. Kill switch: enforcement AND outbound stamping both respectopts.chainContentDetection !== false(BILI_CHAIN_CONTENT=0).Outbound stamping (
forward())Every request that actually ran the kernel (prepared with non-empty
processedMessages, not side passthrough) leaves with a<bili-chain>stamp computed over the EXACT bytes forwarded — placed after compat roles (#552) and output steering (#1093) so the digest covers them.requestId= first 8 hex of the digest (deterministic, constant-size). Best-effort: a stamp failure logs debug and forwards unstamped. Passthrough / side / forge / classifier forwards carry no stamp.The module header carries the identification-contract-freeze warning carried forward from #1397: the parser, JCS digest scheme, and verdict matrix are frozen — step 3 changed only WHERE the carrier sits, never WHAT a checkpoint is. Legacy advisory text updated from "until signed chain proof lands" to "until both sides ship the request checkpoint".
⚠ Intended behavior changes (old → new, why)
x-bili-hopis stripped in transit.<bili-chain>tag (~≤200 chars) in the trailing control slot (merged text part on anthropic/google, standalone user message on openai/responses). Rides the tail of the request; prefix-cache neutral by design.[chain-shadow]→[chain]; legacy advisory warning wording changed (see above).Tests
tests/chain-checkpoint-step3.test.ts: per-wire stamp shapes (exact-shape assertions), restamp idempotency, recognition-relaxation matrix, google must-fail regression through the realcoreToGooglefusion (the old append shape breaks recognition inside our own pipeline — pinned, not just against a fake upstream), round-trip invariant across wire × trailing shape, integration E1–E7 (valid → byte-identical verbatim forward; recent-mismatch → verbatim + warn; stale-unmatched → strip + process + fresh restamp; plain → processed + stamped outbound that verifies valid; kill switchBILI_CHAIN_CONTENT=0; side requests leave unstamped).tests/chain-checkpoint-step2.test.tsupdated to step-3 semantics (T1/T2 now assert byte-identical verbatim forward; the google two-part case IS now a carrier under the any-part rule).chainContentDetection: false.Pre-flight
npm run typecheck— cleannpm test— 2866 tests: 2854 pass, 0 fail, 12 skippednpm run build— cleansrc/server.ts) → CI e2e job will run the real-client suite on this PR