Repository navigation
[PR] fix: cap x-bili-pf-tail-ids at 160 ids and decouple the pf-seq stamp from the fastpath gate (#7367) - #7381
Conversation
…from the fastpath gate (#7367) With pluginFullResendWatermark gated off, the watermark fastpath never evaluated, so the x-bili-pf-seq response stamp (the client's watermark advance) was never emitted. The client's k2 froze while its captured msgid list kept growing, so x-bili-pf-tail-ids grew unbounded and eventually overflowed Node's 16 KB header limit — the proxy's HTTP parser dropped the connection before any handler ran, and the session was wedged on every retry. Two-part fix: 1. Client safety net (src/agent/pf-channel.ts): cap the tail-ids list at the newest 160 ids. The capped tail still ends at the true window origin; a delta wider than 160 degrades to a conservative server-side miss (the width check fails) instead of a header overflow. 160 ids ≈ 5.8 KB for UUIDs, well under the limit. 2. Server root fix (src/server/fastpath.ts + prepare-openai.ts): emit the x-bili-pf-seq stamp via a structural scan even when the fastpath gate is off. The stamp is the client's watermark advance, not fastpath-only state — decoupling it from the gate keeps k2 advancing, which is what bounds the tail list at its natural width. Behavior change (disclosed per owner policy 2026-09-22): with pluginFullResendWatermark OFF, the proxy now emits x-bili-pf-seq on plugin-lane non-title-gen openai responses (old: never emitted). The client-visible x-bili-pf-tail-ids is now capped at the newest 160 ids (old: unbounded from a frozen k2). Both changes are the fix. Fixes #7367
PR Review: cap x-bili-pf-tail-ids at 160 ids and decouple the pf-seq stamp from the fastpath gateDuplicate screening: Not a duplicate. The PR targets a specific bug (#7367) where the Direction (方向关): The PR targets a real bug. When the Regression review (回归审查): I reviewed the existing behaviors touched by the diff:
Code review (代码审查): The code is clean and correct. The cap is a simple Test effectiveness (测试有效性): The tests are focused and verify the key behaviors:
The tests would catch a regression in the cap or the stamp emission. Diff cleanliness (diff 整洁度): The diff is clean. 5 files, 75 insertions, 3 deletions. Every line relates to the PR's purpose. No unrelated changes, no mass whitespace/reformat, no generated or lock-file churn. Code quality (代码整洁): The code is clean. Naming is clear ( Verification:
结构化八问
结论The PR is ready to merge. The fix is correct (verified by tracing the control flow and running the targeted tests), the tests are sufficient (real assertions that would catch a regression), and the CI is green. The two-part fix (client cap + server stamp decoupling) addresses both the root cause and the safety net, and the behavior change is properly disclosed in the PR body. |
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.11067-pr.7381.642e759-a2This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr7381.tgz
npm install -g packageInstall instructions are refreshed on each push. |
ranxianglei
left a comment
There was a problem hiding this comment.
Approved — this is the complete fix for the pf-tail-ids 16 KB overflow (#7367, same root cause as #7212). It handles both legs:
- Bounded tail (
src/agent/pf-channel.ts,MAX_TAIL_IDS = 160):pfRequestHeadersnow slices fromMath.max(k-1, ids.length-160), so a frozen stamp can't grow the header unbounded, and the tail still ends at the true window origin (ids.length-1). A wider delta degrades to a conservative server-side miss. - Stamp decoupling (
src/server/fastpath.tsstampOnlyWatermarkTurn+src/server/prepare-openai.ts:679else-if): whenpluginFullResendWatermarkis off the fastpath never runs, sox-bili-pf-seqstopped and the client's k2 froze — the exact #7367 wedge. Now the stamp is emitted on its own (T from the same zero-allocationscanMessagesSpanspass) so the watermark keeps advancing and the window self-heals. The else-if is the correct complement of the fastpath-evaluated branch (I checked the if/else structure) and is gated to plugin / non-title / flag-off.
This supersedes #7219: both edit the same pfRequestHeaders lines, so only one can land. #7219 (byte-cap + drop the header) only prevents the overflow — it does NOT decouple the stamp, so on the #7367 flag-off path the watermark stays frozen (permanent full-parse, no self-heal). Recommend closing #7219 in favor of this one.
One optional hardening (nit, not a blocker): the cap is id-count-based (160), not byte-based. Real msgids are short content-hashes so 160 × ~30 B ≈ 4.8 KB sits safely under the 16 KB limit, but #7219's byte-cap idea is more rigorous. If you want belt-and-braces, cap at min(160, 2 KB encoded) — happy to add it on this branch.
Housekeeping: 52 behind master (update); build-artifact is the stale pre-token-fix 404, re-running.
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.1246-master.bf778d9 # this exact build
npm install -g billion-context@master # always the newest merged build
|
…-decouple) Conflicts resolved: 1. src/server/prepare-openai.ts: union of fastpath imports (PR's DeltaReanchorError/PF_TAIL_IDS_HEADER/evaluateDeltaResend/parseTailIdsForPin + master's stampOnlyWatermarkTurn). 2. tests/fastpath.test.ts: union of fastpath imports (PR's evaluateDeltaResend/PF_DELTA_HEADER + master's stampOnlyWatermarkTurn). 3. src/agent/pf-channel.ts: kept PR's TAIL_MAX_BYTES byte-budget (supersedes master's MAX_TAIL_IDS count-cap; the byte check is stricter and tailPayloadFor is the single source of truth for both header emit AND full-form suppression). 4. src/server/fastpath.ts: kept BOTH evaluateDeltaResend (PR #6785 delta arm) AND stampOnlyWatermarkTurn (master #7367 stamp-only turn). 5. src/storage/shadow.ts: kept master's fileJsonWriter parameter (new in master, not in PR branch). 6. tests/pf-channel.test.ts: updated #7367 tail-cap test to match PR branch's byte-budget behavior (full slice under 8 KB, not capped to 160).
…lict at 0.0.202 Master advanced 122 commits past the PR base (batch-seam double-claim fix #7428 -> kernel 0.0.201, storage backup/repair #7156/#7431, ingest-band default-off #7426, pf-tail-ids cap #7381, OpenAI reasoning alias #7432, dsh-mneme scan #7430, and more). Content hunks auto-merged (kernel/src/ compress.ts, all four storage-render goldens); the only conflicts were the three kernel version lines, resolved at 0.0.202 = master's 0.0.201 + this PR's kernel/src change, per the CI-enforced kernel version discipline. Targeted local verification: tests/golden-storage-render.test.ts + tests/storage-state-fields.test.ts 7/7, kernel issue6116/issue3769/ hide-consumed suites 27/27.
Two conflicts, both in the shared pf-plane client/server seam where master's #7381 (pf-tail-ids cap + stamp decouple) crossed the lane's v6 re-land: - src/agent/pf-channel.ts: kept the lane's v6 fixed-window tail form (last PF_TAIL_WINDOW=64 ids, F1 owner ruling) — the merged function body has no k binding, so master's origin-slice form would not compile; the fixed window is inherently bounded, superseding the #7367 160-cap (removed the dead MAX_TAIL_IDS constant). - src/server/prepare-openai.ts: union import — kept the lane's v6 imports and added master's stampOnlyWatermarkTurn (#7367 root fix: stamp advances even with the fastpath gate off). - tests/pf-channel.test.ts: the auto-merged #7367 test asserted the superseded v5 cap-160 form (contradicted the lane's fixed-window test); updated it to pin the #7367 intent (bounded header on a frozen stamp) under the v6 form: 200 ids -> 64, 10 ids -> 10.
What
With
rollout.features.pluginFullResendWatermarkgated off, the watermark fastpath never evaluated, so thex-bili-pf-seqresponse stamp (the client's watermark advance) was never emitted. The client'sk2froze while its captured msgid list kept growing, sox-bili-pf-tail-idsgrew unbounded and eventually overflowed Node's 16 KB header limit — the proxy's HTTP parser dropped the connection before any handler ran, and the session was wedged on every retry.Two-part fix:
Client safety net (
src/agent/pf-channel.ts): cap the tail-ids list at the newest 160 ids. The capped tail still ends at the true window origin; a delta wider than 160 degrades to a conservative server-side miss (the width check fails) instead of a header overflow. 160 ids ≈ 5.8 KB for UUIDs, well under the limit.Server root fix (
src/server/fastpath.ts+src/server/prepare-openai.ts): emit thex-bili-pf-seqstamp via a structural scan even when the fastpath gate is off. The stamp is the client's watermark advance, not fastpath-only state — decoupling it from the gate keepsk2advancing, which is what bounds the tail list at its natural width.Behavior change (disclosed per owner policy 2026-09-22)
pluginFullResendWatermarkOFF, the proxy never emittedx-bili-pf-seq; the client'sx-bili-pf-tail-idsgrew unbounded from a frozenk2.pluginFullResendWatermarkOFF, the proxy emitsx-bili-pf-seqon plugin-lane non-title-gen openai responses (whenever the structural scan measures T). The client-visiblex-bili-pf-tail-idsis now capped at the newest 160 ids.k2advancing (root cause), and the cap is a safety net that would have prevented the outage on its own.Tests
tests/pf-channel.test.ts: new test "pf-channel: tail-ids capped at 160 when the stamp freezes ([Bug][dsh] Turning off pluginFullResendWatermark stops x-bili-pf-seq, so x-bili-pf-tail-ids grows unbounded until it overflows Node's 16 KB header limit and every request fails with "Connection error." (0.1.216) #7367)" — learns k2=2, captures 200 ids, asserts the tail is capped to 160 ids ending at the true window origin; narrow deltas are sent whole.tests/fastpath.test.ts: new test "stampOnlyWatermarkTurn: flag off still emits the seq heartbeat ([Bug][dsh] Turning off pluginFullResendWatermark stops x-bili-pf-seq, so x-bili-pf-tail-ids grows unbounded until it overflows Node's 16 KB header limit and every request fails with "Connection error." (0.1.216) #7367)" — asserts the stamp is emitted when the flag is off; unscannable bodies degrade to no stamp.All targeted suites green:
tests/fastpath.test.ts+tests/pf-channel.test.ts(36/36),tests/issue5403-watermark-fastpath.test.ts+tests/watermark-cache-eviction.test.ts+tests/issue6752-watermark-output-budget-restore.test.ts+tests/native-intercept.test.ts(96/96),tests/openai-plugin-postfold-seam.test.ts+tests/lane-decisions-matrix.test.ts+tests/side-lane-invariants.test.ts(130/130).npm run typecheckclean.Closes #7367