Skip to content

feat: 辅助请求经 anchor affinity 路由到 side-passthrough(#1307 根治,#1309 拍板方案) - #1431

Closed
ranxianglei wants to merge 6 commits into
masterfrom
2026-09-26_anchor-affinity-side-routing
Closed

ranxianglei wants to merge 6 commits into
masterfrom
2026-09-26_anchor-affinity-side-routing

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #1309

#1307 止血(#1312)落地后遗留的根因隔离——按 owner 在 #1309 批准的 anchor affinity 设计实现。交叉链接:#1307(源头)、#1314(canonical 根因线程)。

改了什么

正常预算的辅助请求(DSH auto-review / classifier / title-gen:同 session key、无工具、≤2 条消息、全新合成内容)现在路由到既有 #388 side-passthrough 分支:不分 ref、不写 snapshot/remembered、不动 usage/nudge baseline、不喂 orphan-GC。#1312 的写点护栏保留为 routing 之后的 defense-in-depth。

判别器(owner 拍板:anchor affinity 为主,resend latch 降为 bootstrap 信号)

单一决策点 isAuxiliaryRequest(src/server/side-request.ts),当且仅当全部成立时判为辅助 side 请求:

  1. 无 tools 数组([bug] bili dsh 长会话中 max_output_tokens 被压到 ≤200,主请求被误判为 side request 并绕过压缩 #546 原则);
  2. 存在会话 anchor——此前记录过的 ≥3 条完整主对话视图;
  3. 该会话曾至少一次逐字续发历史(resend latch,仅作 bootstrap/corroborating 信号);
  4. wire 消息数 1–2;
  5. identity affinity:每条入站消息相对 anchor 视图均不可识别(第一条即分叉)。任何一条被识别(任意位置)→ 视为 continuation(trim/edit/retry)→ 走完整 pipeline。

anchor 记录 recordAnchorView 是 sticky 的:<3 条的视图既不 bootstrap 也不收缩 anchor——pre-main 的 side-shaped 请求无法污染 anchor(pinned edge rule ①)。affinity 失败一律落回今天的完整 pipeline,绝不落入隔离:把主对话误判为 side traffic 是不可恢复的,而让 side 请求漏隔离只是 #1308 时代的现状(pinned fail-safe 方向)。

用 membership 而非 positional-prefix 是刻意的:positional LCP 会把 front-trim/编辑过的主轮次([tailKnown, new],LCP=0)送进 side lane;membership 让 trim/edit/retry 留在完整 pipeline,同时仍抓住「全新合成 blob」这一生产 review 形态。

行为变更披露(旧 → 新)

请求类别 旧 新
latched 且 anchor 合格的会话上、无工具 ≤2 条全 novel 请求 完整 pipeline:消费 1 个 ref、重写 snapshot/lastMessages、移动 usage + nudge baseline、喂 orphan-GC side-passthrough:原样转发(+ tag strip),kernel state 不动
其余一切(有 tools / 无 anchor / latch 未 arm / >2 条 / 任一条被识别 / 未识别 wire shape) 完整 pipeline 不变(fail-safe 方向)

关于 #1309 标题里的「与 #1075 冲突」:本设计下该冲突消解——#1075 的 light-client e2e(单条主轮次 + side 请求)永远不会 arm latch,其钉死的行为(完整 pipeline、恰好消费一个 ref)逐字保持;tests/fix-1075-side-request.test.ts 在本 PR 中零改动(已验证 diff 为空)。当初 naive shape 分流导致 38 fail 的根因正是这类会话被误分流;latch+anchor 双门保证它们不受影响。

另:rebase 时发现 master 已有 reapOrphansLogged(#1206)补上了 orphan-GC 静默 deactivation 的可观测性缺口,我初版里重复的 GC warn 日志已丢弃,本 PR 不改 src/orphan-gc.ts。

已知残留 corner(披露,有界)

latch 之后永久把视图 trim 成 ≤2 条全 novel 消息的客户端会被隔离。有界:#1312 护栏仍保护 remembered snapshot,客户端一旦重新发送历史即自愈。已知生产客户端中无此形态。

Pinned edge rules(对应 owner 决定逐条钉测试)

证据

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-26_anchor-affinity-side-routing (c88ff28)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1746-pr.1431.be3d0fb

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

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到。这是带 ework-agent-pr 标记的已完成工作,我不重做——按 review 流程执行:拉取分支核对代码 → 审原 issue(#1307/#1309/#1314)方向 → 回归审查 + 代码审查 + 测试有效性 + diff 整洁度 → 核对 CI 状态后给出结论。稍等。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — direction check, regression audit, code/test review, plus one small direct fix.

① Direction (vs #1309 owner decision, floor 8)

Implementation matches the approved design point-by-point:

② Regression audit — existing behaviors touched by the diff

Behavior Verdict
#388 budget side-passthrough (max_tokens≤200) Unchanged — aux ORs into the SAME branch (same sideRequestGuard, same scrubAnthropicPck, same Prepared{processedMessages:[],sidePassthrough:true} → forward()). tests/side-request-isolation.test.ts green.
#546 no-tools principle Preserved as gate condition 1.
#1075 light-client contract git diff origin/master -- tests/fix-1075-side-request.test.ts = empty (verified). Its pinned assertion (single no-tools normal-budget req consumes exactly 1 ref) holds because stateless clients never arm the latch — now additionally pinned by a dedicated test.
#1312 write-point guard Untouched; stays defense-in-depth behind the routing layer.
orphan-GC src/orphan-gc.ts untouched (master's reapOrphansLogged #1206 already covers the observability gap).
refs / snapshot / usage / nudge baseline Unchanged for all existing traffic; only the newly-isolated aux class skips them (matches the disclosed old→new table, which I checked against the actual wiring).
Both compression modes Routing is mode-independent (orthogonal to pluginMode); the plugin-mode e2e proves the #1307 repro (remembered anchor clobber under review storms).

No unintended regressions found. The one real behavior change (aux class: full pipeline → side-passthrough) is disclosed old→new and is the owner-approved change itself.

③ Code review findings

  • Collision semantics are safe-direction only. Image-only/tool-call content collapses to shared identity keys → false-"recognized" → full pipeline. A false NOVEL verdict is impossible (novelty requires exact text match against the remembered view), so misclassification can only over-isolate nothing — it errs toward the full pipeline. Good.
  • WeakMap keyed on Session object: sound. getSession() (src/session.ts:287) returns a stable instance per id while resident; LRU eviction or disk reload creates a new object → anchor/latch reset → fail-safe direction (full pipeline until re-established). Same pattern as orphan-GC streaks (src/orphan-gc.ts:34).
  • Disclosed residual corner confirmed accurate. A latched session receiving persistent ≤2-msg fully-novel views stays isolated (anchor only updates via full pipeline); bounded by the fix: guard rememberedPluginMessages against side-shaped snapshot eviction (#1307) #1312 guard, self-heals on resend, no known production client has this shape. Acceptable as documented.
  • Memory nit (observation only, not blocking): the anchor known Set stores FULL message texts — steady-state ≈ one wire-body size per long session. Hashing the keys would tighten the bound; fine to defer.
  • Minor issue — fixed directly on the PR branch: the guard-blocked 413 body hardcoded side requests (max_tokens<=200) bypass compression by design (#388) — factually wrong when the blocked request is an auxiliary one (normal budget). Pushed 9817cc61 making the reason conditional on the routing decision. Verified safe: the only assertions on this endpoint check error.code, not the message text (tests/side-request-isolation.test.ts:413,461). Local typecheck clean + 35/35 targeted tests green after the fix.

④ Test effectiveness

Strong teeth, not ceremony: each pinned edge rule has a dedicated unit test (no-poisoning bootstrap, fail-safe fallback incl. front-trim [tailKnown,new] subcase, role-flip, retry-no-self-promotion, tools, >2 msgs, unrecognized shape, stateless-client #1075 contract), plus two real-proxy e2es that assert FROZEN kernel state under an aux storm (byRaw count, maxRefNum, contextTokens, active blocks, compactionBoundary) AND recovery afterwards (legit short followup consumes the next ref; full replay keeps original refs + exactly one new; preflight summary survives rebuild; plugin-mode remembered 25-msg anchor survives where pre-fix it was clobbered to 1 msg). These would have caught both the #1075-class misrouting and the #1307 snapshot clobber.

⑤ Diff cleanliness

Single feature commit (+ my labeled one-line-scope fix commit above). No version bump, no lockfile churn, no unrelated files, no whitespace noise. Branch was behind master only by the v0.1.158 release commit (version-only) — no real staleness; GitHub reports mergeable. One coordination note: src/server.ts is in flight in other open PRs — if any lands first, rebase and re-verify before merge.

Evidence: CI on a5e86fb6: all 13 check-runs green (test ubuntu/windows × node22/24, e2e, hermetic registry e2e, build-artifact, version-guard, codex/dsh/pi/opencode lanes). New head 9817cc61 triggers a CI re-run.


中文一句话总结: 按 owner 在 #1309 拍板的 anchor-affinity 方案审查了辅助请求的 side-passthrough 路由——方向与批准设计逐条吻合、既有行为(#388/#546/#1075/#1312/orphan-GC)均无回归、新测试有真断言且钉住了全部边界规则;顺手修了 413 报错文案对辅助请求的误述(已推送 9817cc61),CI 重跑绿后建议由人工合并(Agent 不合并)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Follow-up: CI on final head 9817cc61 (incl. the 413-wording fix) — all 13 check-runs green (test ubuntu/windows × node22/24, e2e, hermetic registry e2e, build-artifact, version-guard, codex/dsh/pi/opencode lanes). PR mergeable=True. Review complete; ready for human merge when you are.

中文一句话总结: 最终 head 9817cc61 的 CI 全绿,review 结论不变——方案与 #1309 拍板设计一致、无回归,可以人工合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Deep-review complete — one significant efficacy hole found and fixed on-branch (rebased onto current master + review commit).

Verified

Fixed on-branch

F1 (significant): extractWireTexts returned undefined for content: null — but content: null is the canonical agent shape for tool-calling assistant turns (this repo's own e2e fixtures send it, reasoning-only turns too). One unrecognized message abandoned the ENTIRE view → anchor never recorded → isAuxiliaryRequest stays false forever → the #1307 aux storm remains unisolated for exactly the sessions this PR targets. Fail-safe but silently inert. Fix: null/absent content contributes empty text (mirrors the array branch skipping non-text parts; identity rides role + position).

F2: e2e for the true discriminator boundary — a 2-message request carrying a recognized anchor message runs the full pipeline (overlap beats the ≤2 gate); previously only unit-tested.

F4: naming disambiguation comment (anchor view vs #1312's remembered view).

Gates on-branch: typecheck clean, auxiliary-side-routing 13/13.

Non-blocking follow-up

  • F3: the anchor retains full text of the last main view per session (~4MB for a 1M-token view, replaced on adoption). Bounded, but a per-message digest would shrink it to ~N×32B — worth a fast-follow if long-lived many-session hosts show memory pressure.

Ready to merge once CI is green. Fixes #1309; supersedes the #1312 stopgap path going forward.

ework-agent and others added 3 commits September 27, 2026 09:38
…1309)

The guard-blocked 413 body hardcoded '(max_tokens<=200) ... (#388)', which
is factually wrong when the blocked request is an auxiliary side request
(normal budget). Make the reason conditional on the routing decision.
…vs-remembered naming (#1431 review)

- F1: extractWireTexts treated content:null/absent as unrecognized and
  abandoned the whole view — but content:null is the canonical agent shape
  for tool-calling assistant turns (our own e2e fixtures send it), so the
  anchor was never recorded and auxiliary routing stayed silently inert for
  exactly the sessions it targets. Null/absent now contributes empty text
  (mirrors the array branch skipping non-text parts; identity rides
  role + position).
- F2: e2e the true discriminator boundary — a 2-message request carrying a
  recognized anchor message runs the full pipeline (overlap beats the ≤2
  gate), not side-passthrough.
- F4: one-line comment distinguishing the anchor view (side-request.ts,
  routing) from the remembered view (#1312 plugin.ts store, write guard).
…extraction (#1431 review)

The review fix for content:null (F1) covered the openai/anthropic
messages[] branch of extractWireTexts, but the responses input[] branch
still returned undefined for a message with null/absent content — the
same root cause: one unrecognized message abandons the whole view, so
recordAnchorView never runs and routing stays silently inert. content:null
is the canonical shape of tool-calling assistant turns on that wire too,
and src/loop/adapter-responses.ts already treats non-string/non-array
message content as no-text rather than fatal.

Parity fix + regression units pinning null/absent content to empty text
for both wires.
@ranxianglei
ranxianglei force-pushed the 2026-09-26_anchor-affinity-side-routing branch from d33c8d4 to 4d9edeb Compare September 27, 2026 01:55
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Verification of the deep-review round complete — F1 confirmed significant and correctly fixed, plus two corrections worth recording before merge.

F1 — mechanism independently confirmed, fix valid

Reproduced the reasoning against the pre-fix code: the chat-wire loop's else { return undefined; } meant ONE message with content: null abandoned the ENTIRE view → recordAnchorView never ran (server.ts only records when extraction succeeds) → no anchor → isAuxiliaryRequest false forever. Since tool-calling assistant turns canonically carry content: null, the feature would have shipped silently inert for exactly the sessions this PR targets. Fail-safe direction, zero visible symptom — good catch, this was the round's most important find.

Two notes on F1's coverage:

F2 — verified real teeth

The boundary e2e sends a 2-message request containing one recognized anchor message and asserts the full pipeline ran (ref 26→27, replay assertion updated 27→28) — overlap beating the ≤2 gate is genuinely pinned, not just unit-tested.

Gates on final head 4d9edeb1

  • Local: typecheck clean; full suite 2897 tests / 0 fail / 12 skipped; build OK (+ dist-import-annotations OK).
  • CI: 13/13 success (test ubuntu/windows × node 22/24, e2e, hermetic registry e2e, build-artifact, version-guard, codex/dsh/pi/opencode lanes).

F3 (full-text anchor retention) acknowledged as bounded fast-follow — agree it shouldn't block this merge; a per-message digest can land separately if long-lived many-session hosts show pressure.

Stack on the branch now: 7090b0a5 feat → 5a32b8c6 413 wording → 448d83bc review F1/F2/F4 → 4d9edeb1 F1-parity, all on current master. Merge remains human-only.


中文摘要:核实了 F1 根因与修复(content:null 导致整个视图不可提取、anchor 永不记录、功能静默失效,判断成立);另发现 responses wire 分支存在同一根因未修,已在分支上补齐并加双 wire 回归单测;发现分支实际并未 rebase 到最新 master,已代为 rebase(零冲突、与新增 gate 无语义交互、无回归);最终 head 本地全量测试与 CI 13/13 全绿,可以人工合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

⏸️ Parked pending the #1314 fact-finding (owner decision). This PR implements the session-identity half of #1314's scope; the OTHER half — whether large auxiliary (auto-review) requests themselves need compression — is disputed and under factual investigation by ework in #1314 (comment).

Why hold: if the investigation overturns the current shape assumption (side = no-tools, ≤2 messages, fire-and-forget), the discriminator semantics and the side lane's capability may change — merging now risks reworking the routing twice. The routing's core value (protecting the main session's bookkeeping from aux traffic) is not disputed and will survive any outcome.

Out of the merge queue until the #1314 report lands and the owner decides.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

收到,PR 保持 parked、退出合并队列,等 #1314 报告落地后由你拍板。期间分支无需任何动作。

Parked-state notes (so the hold costs nothing later):

  • Head 4d9edeb1 sits on current master (b371bd04), CI 13/13 green; stack: feat → 413 wording → review F1/F2/F4 → F1-parity.
  • If the investigation overturns the shape assumption (no tools / ≤2 messages / fire-and-forget), the rework surface is small and localized: the discriminator knobs are named exports in src/server/side-request.ts (AUXILIARY_MAX_MESSAGES, the no-tools clause in isAuxiliaryRequest), and all pinned edge-rule tests live in tests/auxiliary-side-routing.test.ts.
  • Consistent with your framing: the isolation mechanics (side-passthrough lane, anchor recording after the gate, fail-safe direction) are orthogonal to the shape question and survive any outcome. One code-side observation relevant to the disputed half — as implemented, aux traffic is forwarded byte-exact with zero compression, so if [design] 辅助请求的会话身份判定与审查请求自身的压缩 —— #1312 止血后的根治方向 #1314 concludes large aux requests need compression, that lands as a capability addition on the side lane, not a rewrite of the routing decision itself.

No action from me until you un-park.

中文摘要:确认 PR 按 owner 决定 parked(等 #1314 事实调查与拍板),分支停在最新 master 上 CI 全绿;若形状假设被推翻,改动面集中在 side-request.ts 的判别常量与对应测试文件,隔离机制本身不受影响。

@ranxianglei

Copy link
Copy Markdown
Owner Author

这个是让auto review穿过不压缩 不是设计目的 关闭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[跟进] 辅助请求(auto-review/classifier)需统一隔离策略——与 #1075 冲突,需 owner 拍板

1 participant