Skip to content

[PR] batch: 20 verified fixes from Afloat16's open PRs (verbatim cherry-picks, authorship preserved) - #7074

Merged
ranxianglei merged 24 commits into
masterfrom
batch/afloat16-2026-11-17
Nov 18, 2026
Merged

ranxianglei merged 24 commits into
masterfrom
batch/afloat16-2026-11-17

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

What this is

A batch PR bundling 20 independently verified fixes from Afloat16's open PRs, each cherry-picked verbatim (original commits and authorship preserved — Afloat16 / ci-check). Each item is a small, self-contained bug or performance fix; none changes wire formats, storage formats, config schema, or protocol semantics.

Every item was reviewed against master (77fe0b1): the reported defect reproduces on master, the fix is semantically sound, and the regression tests fail on master and pass here. All 177 tests in the 21 touched test files pass locally; full npm run typecheck / npm run build pass. Full-suite and real-model gate run in CI.

Five related PRs are deliberately not included — they touch trust sets, signal lifecycles, credential semantics, or wire-visible behavior and are held for separate discussion (list at the bottom).

The 20 fixes

Performance (hot paths made linear)

# Fix What was wrong
6843 perf: scan cache body boundaries in linear time Settling cache bookkeeping rescanned the whole transcript body with repeated Buffer.indexOf calls — 1.3 s of blocked event loop on a 1.7 MB transcript. Now one linear pass. 44 ms → 4.5 ms / 1.3 s → 13.7 ms measured.
6853 perf: frame loop SSE chunks in linear time Every streamed chunk re-normalized and re-scanned the entire accumulated SSE buffer (quadratic; 2.8 s for one 8 MiB image event). Replaced with an incremental framer in src/sse-util.ts; old helpers kept for all other consumers. Exhaustive split-point equivalence tests included.
6999 perf: consume repeated canonical pointers in linear time Pointer upkeep used shift() on large duplicate-content buckets (array moved on every call). reverse() + pop() — element-identical output, 303 ms → 98 ms at 50k repeated rows.
7006 fix: preserve long histories when replacing the compression view A successful compression on a ~250k-message history crashed on V8's argument limit (push(...replacement)) and silently emptied the conversation history for the next request. Replaced with an in-place item-by-item helper at all three sites.

Correctness (wrong bytes / wrong refs / wrong data served)

# Fix What was wrong
6854 fix: recover each Responses image from its own ref Split multi-image Responses items bound every image ref to all images in the item: decompress({imageRef}) returned sibling files and 20 images produced 400 spill files. Recovery now reads only the part's own sidecar.
7036 fix: verify image spill bytes before advertising restore refs The last same-size/MIME spill candidate was advertised as the original without a byte comparison — a resized image could point the model at a different original. Sole candidates now go through the same exact-match check.
6848 fix: bound retained image encode cache payloads The rescale encode cache kept full base64 payloads until 512 entries displaced them — ~140 MiB retained after 20 images. Added a 64 MiB byte budget with deterministic re-encode on eviction (output stays byte-identical, cache-hit stability preserved).
7024 fix: retain prior summaries across Threads reforges On the second Anthropic-Threads reforge, only the newest raw slice was sent to the summarizer — goals/decisions folded in the first summary were permanently lost from the rebuilt thread. The previous folded summary is now carried forward into the side-call input. Rollout-gated path.
7020 fix: keep catalog invalidation effective across overlapping requests After a 401/403 invalidated the Codex catalog cache, an older in-flight fetch could revive the stale catalog (memory, disk rename, or a replayed 304) across restarts. Per-request generation tokens + serialized disk updates close the race. File format unchanged.
7002 fix: search ancestor originals in derived sessions A child session's search_context fallback pre-screened ancestors by summary text only, so keywords surviving only in folded originals were unfindable from the child even though an explicit parent search found them. Ancestors now get the full original-aware search.
6997 fix: retain active lanes during conversation recall eviction Recall-cache eviction compared one old sibling record per lane, evicting a freshly active lane before a fully idle one; lane count also overshot 64 after record-only traffic. Eviction now uses each lane's latest activity and enforces the bound on learn.

Server / process lifecycle

# Fix What was wrong
7018 fix: close pending WebSocket upgrades during server shutdown A WS upgrade whose destination check was still in flight belonged to neither sessions nor wss.clients: shutdown hung on it, and a late "ok" could create a session after teardown. Pending upgrades are tracked and destroyed on close.
7028 fix: relay root JSON arrays without conversation preparation A request whose root is a JSON array (legal on some endpoints) entered the conversation-preparation pipeline and was mutated or rejected locally instead of being forwarded for the upstream to judge. Arrays now take the raw-forward path. Note: this is protocol-agnostic, so anthropic/openai endpoints' root-array malformed requests now get the upstream's 4xx instead of a local 4xx — legitimate clients unaffected.
7030 fix: preserve image exports while session twins survive Session GC deleting one expired envelope co-deleted the shared image-restore spill dir while a fresh twin of the same session was still using it. Co-delete now skips when any surviving twin matches. Conservative direction: over-retention possible, wrong-deletion not. GC stays opt-in.
7032 fix: expire writer conflict verdicts with session retention The conflict-verdict map in served-markers.ts never pruned (marker map is capped at 128, verdict map wasn't) — unbounded daemon memory growth; evicted sessions also inherited stale verdicts for 60 s. Verdicts now expire on the existing prune pass.
7040 fix: release completed reasoning-round response bodies After a round's terminal event, the HTTP reader lock was released but the response body was never cancelled — with a single-connection pool, the next continuation waited forever on its own previous round. Bodies are now cancelled (fire-and-forget, matching the existing pipeThroughRaw pattern) when a round ends before EOF.

Upstream protection / egress

# Fix What was wrong
7015 fix: retain the longest active upstream throttle deadline A concurrent 429 without Retry-After replaced an active 300 s hold with a few seconds of jitter, releasing egress early. The max of the two deadlines now wins — consistent with the settled-observation path that already used Math.max.
7034 fix: scope restored-image shedding exemptions to their tool result If any tool_result in a message was a read_original_image result, the whole message was exempt from image shedding — the normal tool results' images in it could never be archived, so byte/over-count budgets were unreachable. Exemption now applies per tool_result part (anti-loop property preserved).
7042 fix: isolate egress module cache generations across reloads A plugin ESM import started before a config reload could land its (old-code or cached-error) result in the freshly cleared module cache after the reload. Cache writes are now gated on the module generation captured at import start.
7044 fix: isolate binary body drafts from failed egress plugins Egress plugins received the live outbound Buffer; a plugin that mutated it and then threw/timed out left the corrupted bytes to be sent by the fail-open path. Each plugin now gets a private Buffer.from() draft — only a successfully returned body commits. Note: plugins relying on the undocumented "mutate in place, return undefined" side effect silently no longer apply — behavior now matches the documented plugin contract (docs/configuration.md).

Verification

  • Per item: regression tests fail on master and pass here (claimed in each PR; re-verified by cross-reading against 77fe0b1).
  • Local (this branch): npm run typecheck, npm run build, all 21 touched test files — 177/177 pass. Partial local full-suite run: ~1900 tests pass; the only failures are 70 daemon-attach readiness timeouts (~15 s watchdog) in tests/dsh-native.test.ts / tests/advisory.test.ts — reproduced identically on clean master on the same machine (shared-machine noise, none of the 20 fixes touch those paths).
  • CI: full sharded suite + gate on this head is the final word.

Authorship & the individual PRs

All commits are cherry-picked verbatim from Afloat16's PR branches — original authors (Afloat16, ci-check) and messages preserved, with -x origin trailers. This PR adds no re-authored changes.

After this merges, each of the 20 bundled PRs will contain nothing new (its commits are already on master) and can be merged or closed directly as-is:
#6843 #6848 #6853 #6854 #6997 #6999 #7002 #7006 #7015 #7018 #7020 #7024 #7028 #7030 #7032 #7034 #7036 #7040 #7042 #7044

Held for separate discussion (not included)

PR Why held
6845 (#6842) Google signed-text preservation + replay — wire-visible behavior; two edge cases to settle first (broad anyPending() bypass in plugin mode; signature split across stream chunks).
7004 (#7003) Outbound TLS trust when network.caFile is set changes from bundled roots to Node's effective default trust — direction is correct (matches the unconfigured path) but the trust-set change warrants explicit sign-off.
7022 (#7021) Tunnel self-check loopback coverage — the fix is right, but it also shrinks localMachineIps, which changes how selfAddressedLocalPath treats non-127.0.0.1 loopback aliases (403 where self-served before). Needs a documented decision or a one-line classifyIp guard.
7026 (#7025) Embedded-server signal-handler release — correct, but removes handlers as soon as server.close fires; during the standalone final flush window a second Ctrl+C would skip flush (one-line shuttingDown guard suggested).
7038 (#7037) Empty host provider report clears all agent recipes/keys — semantics intended ("empty re-report clears the layer"), but the pi reporter is one-shot, so a transient empty registry or auth read failure would wipe working credentials with no re-report. Needs a design decision.

Closes

Fixes #6839
Fixes #6846
Fixes #6849
Fixes #6851
Fixes #6995
Fixes #6998
Fixes #7001
Fixes #7005
Fixes #7014
Fixes #7017
Fixes #7019
Fixes #7023
Fixes #7027
Fixes #7029
Fixes #7031
Fixes #7033
Fixes #7035
Fixes #7039
Fixes #7041
Fixes #7043

Afloat16 and others added 24 commits November 17, 2026 23:25
Avoid repeated suffix searches when settling a long transcript and defer
boundary work until append/head checks need it.

Fixes #6839

(cherry picked from commit 43dfba5)
Match the issue3400 suite's BILI_CONFIG_FILE isolation so the
admission/eviction tests run on the default (enabled) rescale posture
regardless of any host config file.

(cherry picked from commit 01ff01a)
Preserve existing newline and EOF semantics while scanning only newly
received text in the four SSE loop adapters.

Fixes #6849

(cherry picked from commit 7a1f401)
Use split image sidecars instead of expanding the whole carrier under
every image ref; preserve unsplit and tool-result image groups.

Fixes #6851

(cherry picked from commit f5aeb28)
…sation

The fix adds a trailing sweep(now) that enforces the 64-lane limit and
refreshes stats after the insertion. The leading sweep(now) ran the same
TTL + lane-limit + stats work with the same `now` moments earlier, so it
is redundant. Removing it keeps one sweep per learn (the hot path taken on
every attributed dispatch) with no behavior change: the per-lane LRU plus
the trailing sweep reach the identical final state (verified: 18/18
targeted recall/fingerprint/dsh tests pass with and without it).

(cherry picked from commit 3c9d19b)
The repeated-pointer assertions use the unified session sidecar. Pin the fixture to full storage mode, matching the neighboring canonical-pointer suite, so the legacy CI default does not prevent the tests from reaching their assertions.

(cherry picked from commit 5704fc5)
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: batch/afloat16-2026-11-17 (23a9108)

Latest build — install this exact version

npm install -g billion-context@0.0.10657-pr.7074.2dc590d

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
23a9108 billion-context@0.0.10657-pr.7074.2dc590d build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title batch: 20 verified fixes from Afloat16's open PRs (verbatim cherry-picks, authorship preserved) [PR] batch: 20 verified fixes from Afloat16's open PRs (verbatim cherry-picks, authorship preserved) Nov 17, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

查重 (dedup): Not a duplicate. This is a new consolidated batch PR — 20 verbatim cherry-picks from Afloat16's 20 open PRs (#6843, #6848, #6853, #6854, #6997, #6999, #7002, #7006, #7015, #7018, #7020, #7024, #7028, #7030, #7032, #7034, #7036, #7040, #7042, #7044). No other open PR targets this same consolidation; the 20 source PRs are the individual versions this batch supersedes (all 20 confirmed still open). The 5 held PRs (#6845/#7004/#7022/#7026/#7038) are correctly excluded per the body.

标签: Applied bug + p1 + scope/wiring to this thread (most severe bundled fixes are a data-loss-class history-emptiness #7005 and an unbounded-growth encode cache #6846 → p1; dominant failure domain is the request pipeline → scope/wiring). Added bug + p1 to the GitHub PR (it carried only root-cause).

Review verdict — the batch is sound and mergeable. What I verified independently (not from the PR description):

  • Verbatim integrity (the PR's core claim): all 24 commits match their (cherry picked from commit X) originals by git patch-id --stable — every one VERBATIM. Each original confirmed an ancestor of its claimed source-PR head (fetched refs/pr/N for all 20). The two non-Afloat commits are accounted for: a6006e58da (ci-check, test isolation) and aa4a23dad1 (ework-agent, cherry-picked from [PR] fix: retain active lanes during conversation recall eviction #6997's branch — a prior agent fix already on the contributor's branch, so "no re-authored changes" holds).
  • Per-fix review: read all 22 changed src/ files in full context (not just the diff). Every fix addresses its own root cause at the decision point, not a mask. Highlights I traced to the byte: the SSE framer (createSseFramer) is equivalent to the old whole-buffer scan across CRLF-split/lone-CR/EOF-residual cases; replaceMessages fixes the V8 arg-limit throw that silently emptied >~125k-message histories; the codex-catalog generation counter closes the stale-refresh/304-replay races; the session-GC twin check matches on the bare hash stem so all namespace variants are covered (over-retention possible, wrong-delete not).
  • Test validity: all 21 test files are real, teeth-bearing tests that pin the exact bug scenarios (e.g. the 250k-message history tests, the exhaustive CR/LF split enumeration, the deferred-gate race tests, the real-proxy e2e for root-array relay and egress body isolation). No tautologies, no mock-only tests.
  • CI: core matrix 12/12 test legs green (ubuntu/windows × node 22/24 × shards) + all static gates green, 0 failures on head 23a9108a. The real-client e2e lane is skip-scoped by design (three-layer CI: PRs pay the CORE matrix; e2e runs on the ci:full label or master's 30-min cron — this PR has no ci:full). If you want real-client e2e before merge, add the ci:full label.
  • Behind-master: the PR is behind master, but master has touched none of the 47 files this PR changes since the merge-base → no semantic conflict; mergeable: true. Safe to merge as-is (or rebase for cleanliness).
  • Closes list: all 20 referenced issues exist, are open, and their titles map 1:1 to the 20 fixes.

Disclosed behavior changes (all stated in the PR body — flagged here per policy): #7028 root-array requests now get the upstream's 4xx instead of a local 4xx (the fix — bili no longer mangles them); #7044 an undocumented mutate-in-place+return-undefined egress-plugin side effect no longer applies (now matches the documented contract); #7024 the threads-lane summarizer input gains a "# Previously folded history" section (model-facing text, rollout-gated path); #6848 the image encode cache is now byte-bounded at 64 MiB (evicted images re-encode byte-identically); #6997 recall eviction is now by latest activity with the lane bound enforced on learn.

One non-blocking note: the ework-agent commit aa4a23dad1 message claims "no behavior change" for dropping the leading sweep in learnConversation; that is accurate in the common case but slightly imprecise at an edge (a leading sweep could evict the current lane's older siblings before the re-add, a trailing sweep cannot). The shipped code (trailing sweep only) is correct and is what the retention tests pin — this is a commit-message nuance on a verbatim cherry-pick, not a code defect, so I'm noting it rather than acting on it.

No kernel/ changes, no config-schema changes, no version bump — matches the body's claims.


结构化八问

  1. 是什么问题:这不是单一缺陷,而是把 Afloat16 的 20 个已验证独立修复(各自独立根因)合并成一个 batch PR 以减少合并开销;PR 本身是流程性归并,不是某一个 bug。
  2. 什么原因导致的:20 个独立根因——二次方扫描(cache-ledger/SSE 前缀重扫/canonical 指针)、无界缓存(image-rescale 编码缓存 140MiB+、verdict 内存)、并发竞态(codex catalog 失效后复活、egress 模块重载覆盖)、关闭时序泄漏(ws-bridge 挂起 upgrade、reasoning-guard 占用连接池)、大历史数据丢失(V8 参数上限致 push(...arr) 抛错清空历史)等。
  3. 影响范围与严重程度:横跨请求管线;最重的两处是 Successful compression can empty long histories while refreshing the next request #7005(>~12.5 万条消息的会话在压缩刷新时历史被清空=数据丢失类)和 Image rescale cache retains over 140 MiB after only 20 images #6846(编码缓存只增不减=缓存泄露类),按 owner 2026-10-19 口径均为 p1;其余为 p2/p3 的健壮性/性能问题。
  4. 怎么修复的:每个修复都打在各自根因的决策点上(非堵症状):线性单遍扫描替代二次方、字节预算+计数双上限的有界缓存、generation 计数器隔离陈旧刷新、关闭标志+挂起集合在 teardown 时统一销毁、replaceMessages 原地填充替代展开参数;verbatim cherry-pick 保留原作者与原 PR 的已测方案。
  5. 是否有回归问题:逐文件审了 22 个 src + 21 个测试,未发现无意回归。5 处已披露的有意行为变更(见上):[PR] fix: relay root JSON arrays without conversation preparation #7028(本地 4xx→上游 4xx)、[PR] fix: isolate binary body drafts from failed egress plugins #7044(未文档化的原地突变副作用失效)、[PR] fix: retain prior summaries across Threads reforges #7024(summarizer 输入新增折叠历史段=模型可见文本,rollout 门控路径)、[PR] fix: bound retained image encode cache payloads #6848(编码缓存 64MiB 字节上限)、[PR] fix: retain active lanes during conversation recall eviction #6997(按最近活动驱逐+learn 时强制车道上限)。高危模式逐项过:无 fail-fast 变吞错、无阈值/时序/输出格式静默漂移。
  6. 是否破坏缓存:[PR] fix: bound retained image encode cache payloads #6848 给编码缓存加了 64MiB 字节上限——被逐出的图片重新编码是确定性的、输出字节一致,不破坏缓存正确性;[PR] fix: expire writer verdicts with their tracked session window #7032 把 verdict 内存与持久化窗口一起限界(128);未破坏任何缓存失效/去重策略。
  7. 是否改了设计方向:无架构/边界/数据流转向;无 kernel/ 改动、无 config schema 改动、无版本号 bump。
  8. 是否引入了新的配置:不涉及——无新 env/config/CLI 面。

合并判定:可合。 代码、测试、CI(核心矩阵)、verbatim 完整性、Closes 列表全部独立核验通过;5 处行为变更均已披露且属修复本意。两点留给你(均为 human-only):① 是否先加 ci:full 标签补跑真实客户端 e2e 再合;② 合并后 20 个源 PR 需按 superseded 关闭。PR 落后 master 但与 master 无文件交集,直接合或 rebase 后合都安全。

@ranxianglei ranxianglei added the ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR label Nov 17, 2026
@ranxianglei
ranxianglei merged commit adfa675 into master Nov 18, 2026
219 of 295 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1225-master.adfa675 (rolling master tag).

npm install -g billion-context@0.0.1225-master.adfa675  # 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.

This was referenced Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment