Repository navigation
fix: detect chained bili instances via x-bili-hop marker (#300) - #304
Conversation
When two bili instances are chained (A forward -> B), both run the compression pipeline on the same request, double-compressing and corrupting session state (root cause of #292). - Outbound: stamp x-bili-hop: <instance-uuid> on every request this instance actually processed (main forward + preflight summarization + compress-loop calls via shared headers). A passthrough forward does NOT claim processing, so a dumb-proxy bili in front of a processing one is unaffected; any inbound marker keeps propagating down the chain. - Inbound: if a request already carries x-bili-hop, an upstream bili already processed it. Skip ALL processing (no tool/tag injection, no acp-loop, no session state) and pass it through verbatim, logging a prominent [warn] naming the upstream instance (self-loop vs foreign chain). - e2e: two tests — B in isolation with a foreign marker (body reaches the LLM byte-identical, no tool/tag injection, marker propagated), and the full A->B chain (single-layer processing, B warns, one LLM request, marker is A's not B's). Clients never send this header, so single-instance use is unaffected.
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-304Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr304.tgz
npm install -g packageThis comment is automatically updated on each push. |
[bot] 已独立审查 PR #304(分支 Diff 范围:仅 代码审查要点(逐处核对过源码):
独立复跑 pre-flight(本地 checkout 分支后执行):
对照 #300 验收标准:串联拓扑单层处理 ✅;单实例使用完全不受影响 ✅;修复要求 1/2/3(出站标记、入站跳过+warn、e2e 测试)全部满足。 一个非阻塞观察:客户端若刻意发送 merge 后 CI 会自动发布(内容分支,无 version bump,走常规 release 流程)。 |
|
Model: glm-5.3 Reviewed (supervisor pass): per-server |
What
Fixes #300 (root cause of #292): two chained bili instances both ran the compression pipeline on the same request, double-compressing and corrupting session state.
How
Outbound marker (
src/server.ts)instanceId = randomUUID().x-bili-hop: <instanceId>— the main forward, preflight summarization calls, and compress-loop calls (the latter two share thebuildForwardTargetheaders).Inbound detection (
handle())x-bili-hop, an upstream bili already processed it → skip ALL processing (no tool/tag injection, no acp-loop, no session state) and pass it through verbatim.[warn]naming the upstream instance, distinguishing a foreign chain from a self-loop (upstream pointing back at itself).Why no false positives in single-instance use: clients never send
x-bili-hop— it only appears in bili's own forwards. Claude Code echoing back acp-tagged messages carries no such header, so normal turns are untouched.Tests
New
tests/e2e-bili-chain.test.ts(2 tests):[chain]warn naming the upstream marker, marker propagated unchanged.Pre-flight
npm run typecheck— cleannpm test— 693 pass (691 existing + 2 new), 0 failnpm run build— successNo dependency changes;
package.jsonversion untouched (content branch).