Skip to content

[PR] chore(batch): land 8 open fragmented fixes (ReineLan ×4, PatelVro ×2, dimas623 ×2) in one history-preserving batch - #6464

Merged
ranxianglei merged 16 commits into
masterfrom
batch3-dry
Nov 13, 2026
Merged

ranxianglei merged 16 commits into
masterfrom
batch3-dry

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

chore(batch): land 8 open fragmented fixes (ReineLan ×4, PatelVro ×2, dimas623 ×2) in one history-preserving batch

Same pipeline as #6439 / #6455: every commit cherry-picked with -x (original authorship preserved), line-by-line reviewed against the evolved master, no content dropped.

PR Author What it fixes
#4770 ReineLan Responses multipart image runs: exact source→part binding survives projection rebuilds and render (duplicates included); host encoding preserved
#4931 ReineLan Codex opaque native compaction checkpoints (type:"compaction" items): identity persisted, ACP state rebased only when fold coverage is actually missing (#4929)
#4932 ReineLan Preflight now re-measures the image reserve after folds: archived images leave the wire, futility math uses the post-fold view, pixel-billed wires get fresh upstream billing arbitration
#4933 ReineLan Zero-fold pass judges the same prepared wire with the same scoped calibration used at entry (no false fit from a fresh core-only estimate)
#6158 PatelVro Event-loop watchdog kills the WHOLE process (SIGKILL self-pid) — process.exit() inside the worker only ended the worker, leaving the wedged proxy running unwatched (#6157)
#6165 PatelVro Codex live-table windows already net codex's own output headroom (effective_context_window_percent) — stop reserving bili's default share on top (double-count that wall'd sessions below codex's auto-compact point) (#6164)
#6350 dimas623 Shadow-storage view verification aligns the envelope leg to the ROW TAIL by suffix (envelope keeps the newest N under persist.tailTokens): fixes the 44 full re-ingests / 170.8 s stalled-event-loop episode (#6349)
#6357 dimas623 Shadow-storage hashes the media-SPLIT form on both verification legs (rows are split, getMessages() returns hydrated): fixes the permanent drift latch from a 2 KB placeholder vs a 200 KB payload (#6356)

Merge notes

Verification

  • Typecheck: pass
  • All 10 touched test files: 65/65 pass locally (incl. new preflight-image-budget.test.ts, responses-block-wire.test.ts, folded-tail-suffix-alignment.test.ts, media-split-digest-parity.test.ts, codex-window-no-double-headroom.test.ts)
  • Per-PR line-set audit: every added line of each of the 8 official PR diffs is present on this branch
  • Full suite runs in CI on this branch

After merge (manual)

Close source PRs #4770 #4931 #4932 #4933 #6158 #6165 #6350 #6357 as superseded.

Closes #4929 #4930 #6157 #6164 #6349 #6356

Follow-up commit (CI fix, ours)

test(5631): bill the fake upstream at token scale with a disjoint anthropic cache partition — tests/issue5631-restart-survival.test.ts failed on all CI runners because of a pre-existing fixture bug that #4933's stricter (correct) zero-fold verdict surfaced:

  • the fake upstream billed whole-body bytes/4, ~2× any real tokenizer for these bodies (the JSON envelope is 2× the core text) → the per-route calibration factor (DSH: 切换模型后,preflight 在窗口远未满时提前触发压缩 #1933) learned a false k̂≈1.9;
  • and its anthropic frame put the full bill in input_tokens plus the cached prefix in cache_read_input_tokens — which promptInputTotal sums (anthropic partitions the prompt, the fields are disjoint) → the settle total double-counted the cached prefix.

After #4933 the zero-fold fit verdict runs on the calibrated scale, so the pi lane's post-restart baseline sat ~120 tokens over its 12288 wall → deterministic 413. The fixture now bills at tokenizer scale and emits a disjoint anthropic cache partition; the calibration ring settles at ~1.006 (≈1.000 on the dsh lane, unchanged). Suite verified green 3× locally.

ReineLan and others added 15 commits November 12, 2026 23:49
Retain exact source-part ownership when surviving cores are reminted or split by a summary. Cover partial folds, raw resends, short-view recovery, genuinely new identical images, cold loading, and byte-exact archived-image retrieval.

(cherry picked from commit 0ee6cb2)
Use the existing scoped payload fit result when no compression block lands. Integrate the home handoff regression fixture covering calibration direction, route and model provenance, unscaled image reserve, anonymous forwarding, cancellation, and refusal guards.

(cherry picked from commit 6c91881)
process.exit() inside a worker thread ends only the worker, so a wedged
proxy survived its own watchdog, kept the port and ran on unwatched.
SIGKILL the process from the worker instead, and cover the real "exit"
path with a child-process test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 5c650a8)
The codex clamp already applies effective_context_window_percent, which
codex defines as the input share after reserving model output. Reserving
bili's default 25% on top walled sessions below codex's own auto-compact
point, so long sessions hit an unrecoverable 413 futile round.

Skip the default reservation when the window came from codex-catalog or
codex-models-cache. An explicit operator outputHeadroomMaxPct, a proven
completion share and every raw-window source still reserve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit ac9b271)
…ew nit for #6165)

The #6165 change re-ran resolveCompress with identical arguments to read
outputHeadroomMaxPct, duplicating the resolution already done at the
headroomCap site whose comment says it is resolved once so the side-request
guard and the main-path reservation measure against the SAME capped window.
Capture the resolved config once and reuse it; behavior unchanged.

Reviewed by agent (ai: vllm-qwen/qwen3.8-27b).

(cherry picked from commit 0252702)
…kips the reservation (review nit for #6165)

The 'although protocol X is exempt' clause is now also reachable via the new
codex-netted skip path, where the protocol is NOT exempt — the default
reservation was skipped because the codex-aligned window already nets out
codex's own output headroom. Make the clause conditional so incident logs
attribute the right cause; old-path wording byte-identical.

Reviewed by agent (ai: vllm-qwen/qwen3.8-27b).

(cherry picked from commit 03af668)
The sampled read-back verifier compared the two legs of a session's tail
positionally from index 0, but they intentionally hold different SLICES of the
same log:

  - the rows hold the raw tail interned at save time (`tailSeqs`, oldest-first,
    the whole resident window), and
  - the envelope holds `boundedFoldedSnapshot`, which prunes from the FRONT and
    keeps the NEWEST messages under `persist.tailTokens` (#2960 (5), caveat 2a).

Measured on live sessions the envelope is an exact element-wise SUFFIX of the row
tail (tail=1095/envelope=10 and tail=752/envelope=22, zero id and zero content
mismatches inside the overlap, stable across a six-sample sweep). Walking both
legs from index 0 therefore compared the oldest row against the oldest RETAINED
message — off by `tail.length - messages.length` — so `want` was undefined for
every slot outside the envelope window and `changed("lastMessages")` fired for
every tailSeq on every sampled save.

The sampled digest could then never converge: the streak latched (#5677), the
delta fast path was disabled for that session by design, and every save paid a
FULL ingest. Measured on one affected session: 44 full ingests, avg 4522 ms, max
9363 ms, 170.8 s of stalled event loop in a single episode.

Fix: align the envelope to its suffix position and compare only the overlap. A
genuine divergence inside the window still reports; a leg that is not a suffix
produces mismatches rather than silence. Row PRESENCE is still enforced for every
seq (#4390) — a recorded tail pointer with no row now also raises `changed()`,
which it previously did not, and the loop advances its index on that branch so the
suffix offset cannot drift when a gap is present.

Absence of a whole leg stays with the header digest, which already distinguishes
`undefined` from `[]` via `withoutBulk`; it is not re-litigated here.

Tests: tests/folded-tail-suffix-alignment.test.ts pins both halves — a row tail
longer than the envelope with a matching overlap verifies clean, and a content
change inside the overlap still latches drift.

(cherry picked from commit 3a196c7)
The sampled view verifier compared the same message in two different media
representations and marked drift on every sample.

Rows are written media-SPLIT: `planIngest` runs `splitMediaContent`, which
replaces an `imageBase64` payload and every >= 2 KiB data URL with a
`{"$media": hash}` CAS reference. The verifier reads the tail back through
`UnifiedStore.getMessages()`, which returns those rows media-HYDRATED
(`hydrateMedia` inlines the payload again). The envelope's `lastMessages`
keeps the split form, so `messageSignature` hashed a placeholder against the
inlined payload for the SAME message: measured 1,991 vs 201,293 bytes on one
tool result (101x), and ten 390-byte user rows that hydrate to 112-672 KB.

That is a digest-shape mismatch (#4392 family) rather than a content change,
so the sample never converges: the session latches into the #5677 full-ingest
path and transforms its whole tail on every save (measured 8-9 s per save
while latched, starving the event loop).

Normalize both legs to the split form before hashing. `splitMediaContent` is
idempotent on already-split input, so the envelope leg passes through
unchanged, and `splitMediaContent(hydrate(x)) === x` was verified
byte-identical on every media-bearing row sampled, so a genuine edit still
changes the digest and still raises drift.

Tests: new `tests/media-split-digest-parity.test.ts` builds a fixture whose
stored bytes really are split (asserted against the CAS row), folds the
envelope to the newest messages, and requires a clean sample; a second case
rewrites a row's content bytes and requires that the drift is still reported.
Replacing the normalization with the raw JSON fails the first case and
leaves the second passing.

(cherry picked from commit 6919eef)
…udget repair

The budget repair replaced PreflightDeps.imageReserve's #1843 doc comment with a one-liner, dropping the load-bearing rationale for the limit-minus-reserve text-channel algebra and the conservative total-view direction. Restored it and recorded the new initial-view semantics introduced by measureImageReserve. Review-side fix, no behavior change.

(cherry picked from commit 8a57bd6)
…-body gate (#5000/#4543, 2e02110)

ReineLan's #4933 base (2026-10-31) predates the measured-body 413 tier that
dominates inside the unknown-baseline arbitration arm; with est~=measured, an
over-window estimate now dooms locally instead of forwarding. Pin the current
policy and note the superseded arbitration path in the comment.
@ranxianglei ranxianglei changed the title chore(batch): land 8 open fragmented fixes (ReineLan ×4, PatelVro ×2, dimas623 ×2) in one history-preserving batch [PR] chore(batch): land 8 open fragmented fixes (ReineLan ×4, PatelVro ×2, dimas623 ×2) in one history-preserving batch Nov 12, 2026
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: batch3-dry (a223959)

Latest build — install this exact version

npm install -g billion-context@0.0.9433-pr.6464.a4dc847

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
a223959 billion-context@0.0.9433-pr.6464.a4dc847 build
da2fa39 billion-context@0.0.9363-pr.6464.9eca334 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr6464.tgz
npm install -g package

Install instructions are refreshed on each push.

…hropic cache partition

The fake billed whole-body bytes/4 — ~2x any real tokenizer for these
bodies because the JSON wire envelope is 2x the core text — which taught
the per-route calibration factor (#1933) a false k~≈1.9 on the pi lane.
After #4933 the zero-fold fit verdict runs on the calibrated scale, so
the post-restart baseline (raw ≈6.4K, calibrated ≈12.3K) sat ~120 tokens
over the lane's 12288 wall and the pi lane got a deterministic 413 while
master (raw-scale verdict) forwarded the same payload fine.

Two fixture bugs fixed in UpstreamRecorder:
1. billing scale: bill the text a tokenizer sees (message/system text
   chars + tool-schema JSON chars, /4) instead of whole-body bytes/4, so
   the learned factor stays ~1.0 as on a consistent real route;
2. the anthropic usage frame reported the FULL bill in input_tokens AND
   the cached prefix in cache_read_input_tokens — but promptInputTotal
   sums the two (anthropic partitions the prompt; the fields are
   disjoint), double-counting the cached prefix. Now input_tokens is the
   uncached remainder. The OpenAI branch already reported prompt_tokens
   inclusively and is unchanged.

Verified: suite green 3x locally; calibration ring settles ~1.006 on the
pi lane.
@ranxianglei
ranxianglei merged commit 243709b into master Nov 13, 2026
56 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1183-master.243709b (rolling master tag).

npm install -g billion-context@0.0.1183-master.243709b  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

ranxianglei pushed a commit that referenced this pull request Nov 14, 2026
…merge commit

These files (issue-number lists recording the superseded closings of the
previous four batches #6439/#6455/#6464/#6482) are present in neither
parent of the #6574 merge commit yet appear in its result, and survive to
the branch tip. They are not part of any source PR, are referenced
nowhere, are not mentioned in the PR description, and the previous four
batch merges never committed such files to master. Process scratch data
does not belong at the repo root; the closing record already lives in
GitHub history.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment