Repository navigation
[PR] feat: neutralize TRAE Code native auto-compact instruction (#2411) - #2415
ranxianglei wants to merge 9 commits into
Conversation
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.6206-pr.2415.0d14942This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr2415.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR #2415 Review — feat: neutralize TRAE Code native auto-compact instruction (#2411)审了代码、本地复现了失败的门禁并直接修好推回 PR 分支(additive commit 结构化八问1. 是什么问题 2. 什么原因导致的
3. 影响范围与严重程度
4. 怎么修复的
5. 是否有回归问题
6. 是否破坏缓存 7. 是否改了设计方向 8. 是否引入新配置 测试有效性强,非恒真断言:单元级字节校验(head/tail 完整、幂等、无句直通、句中漂移 no-op、非 bullet no-op、CRLF)+ strip 级(就地改写 / parts-array no-op / 非数组)+ knob(默认/env/大小写/乱码)+ 全 server e2e(startServer 真转发:出站 body 不含跟踪句、compress 工具仍在、周边字节完整;continuation 干净; 本地验证与 CI
判定方向正确、实现干净、测试有牙。首遍不完整(3 个红 gate)已由我在分支补全( |
[bot] 🏷 CI 更新(新 head |
343fa68 to
48a0574
Compare
|
小问题直接修复 |
[bot] 🏷 收到,小问题都直接修好了(不是只报告):
结论:无遗留小问题,代码/测试/文档三者一致。待测试矩阵收尾即可合并(合并由你执行)。 |
48a0574 to
0a2d84f
Compare
|
冲突 |
0a2d84f to
85a68f7
Compare
(ai: vllm-qwen/qwen3.8-27b) 冲突已解决,分支已 rebase 到最新 master( 1. 是什么问题:本 PR 分支落后 master 多个合并(#3196 redacted-thinking 门、#3298 ptc-runcode、#3248 phase-2 增量轮次、#3252 attribution、#3309 absorb 移除等),与 master 在同一批文件上产生文本冲突,无法合并。 2. 什么原因导致的:两层叠加——① master 近期重写了本 PR 触碰的热点文件( 3. 影响范围与严重程度:只影响本 PR 的合并进度,对用户行为零影响——冲突纯属分支滞后,不是功能分歧。 4. 怎么修复的:按提交逐个 rebase(保留原 3 个提交与作者信息),每处冲突按「保留 master 语义 + 保留本 PR 意图」取并集: 5. 是否有回归问题:逐项审过——钩子仍在 6. 是否破坏缓存:不涉及(不碰缓存、重试、增量游标、去重键)。 7. 是否改了设计方向:无。Stage A 继续按 triage 决定不带配置面上线。 8. 是否引入了新的配置:无。原计划的 行为变更披露:① 钩子执行位置从「旧的逐条 strip 之后」变为「 收工判定:冲突清零、diff 收敛到最小、本地定向验证全绿,等 CI 全局把关即可合并。 |
85a68f7 to
483a19c
Compare
483a19c to
ec9e5e5
Compare
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复于本 PR——这个 docs-sync 红是仓库级红风暴,已有跟踪条目(#4520、#4533)且修复已落 master(commit 标签:bug, scope/ci, p2(CI 门禁缺陷,跨客户端无宿主车道;开发流受阻但有绕行,已自愈中) 结论:本轮不向分支推任何提交(auto-fix lane attempt 1/2 → verdict 路径),理由如下。 八问
我做的验证(证据链)
收工判定:verdict,停。docs-sync 这一项无需再修(上游已修);等分支解完与 master 的冲突、CI 对新 base 重跑后自然转绿。如果你希望我接手做 |
ec9e5e5 to
70252f4
Compare
(ai: vllm-qwen/qwen3.8-27b) 冲突已解决并推送: 解了什么冲突 两处冲突都在 顺手修掉一个 master 自身的红(独立标注 commit 70252f4) rebase 后本地 typecheck 报 本地验证(定向,非全量):typecheck 干净; 八问
备注:兄弟会话 ci-worker-r1 正在自己的分支(wt-2415-ci-worker-r1)处理本 PR 之前的 docs-sync CI 失败;若它后续向本 PR 分支推提交,可能再触发一轮冲突唤醒,届时同样流程处理即可。判定:冲突已解,等 CI 绿后可合。 |
Stage A of the owner-triaged plan: when bili injects its own compression surface, remove the host's conflicting auto-compact instruction line from the system prompt so the model sees exactly one compression philosophy. Tracked sentence pinned as a versioned constant with drift tolerance (shape drift -> passthrough + warn). No config surface (behavior first per triage).
…uests (#2411) When a host (unified Trae client) fires its own auto-compact, it sends its summarization template as the last user message on the normal chat endpoint. bili used to inject its own compression philosophy + compress tool + preflight folding into that same request - two compression philosophies in one turn, and bili's preflight fighting the host's compaction act. Detection is an evidence-permitlist predicate (src/server/native-compact-shape.ts): last user message string starts with the template lead anchor AND includes its tail anchor, or is trim-exact /compact (manual form from static bytecode). Fails open on any structural deviation. The compaction product shape is deliberately not matched (model free-form). On match: tool/doctrine/nudge injection off for that turn only, tags-only system note off, overhead measurement skipped (title-gen-style), preflight compression skipped (codexForge precedent); processTurn/snapshot/unannounced-rewrite detection stay active so session state continuity and the #1001/#2373 aftermath paths keep working. OpenAI lane only - no evidence of other wires yet.
70252f4 to
3984067
Compare
… help-merge sweep)
… help-merge sweep)
… help-merge sweep)
… help-merge sweep)
master window commits 293ae65/de5e03659 bumped kernel/package.json to 0.0.165 without regenerating the lockfiles; lock-sync re-resolution then rewrites the stale recorded versions (root 0.0.163, kernel 0.0.164) and fails. Pure recorded-version sync via npm install --package-lock-only; no dependency or semantic change.
Refs #2411 — full three-stage fix: instruction unification (Stage A) + surface stand-down (Class A) + local forge of the compaction completion (Stage B), from the live-evidence rounds in the issue thread
What & why
TRAE Code / unified Trae client (closed-source AI IDE, no plugin system) has a native auto-compact that collides with bili's ACP compression when routed through the proxy in proxy mode. Live evidence (reporter, 2026-10-18~24): when the host fires its auto-compact it sends its ~6.9KB summarization template as the LAST user message on the normal chat endpoint (17/17 captured events; template byte-stable across 21 days / 9 models / 2 channels, store original sha256 d56eeae3…), and bili used to (a) ship its own conflicting compression doctrine in the same request as the host's "output only a summary" instruction, (b) let preflight fold the very history the host was asking to summarize, and (c) forward the request upstream so the model produced a host-shaped summary that then replaced the folded span IDE-side, destroying ACP anchors (the #2360/#1729 pathology class). The E2 capture further proved the backend's response to this request shape is an ORDINARY chat completion (no private progress frames / pseudo-tool events; terminal frame = finish_reason stop + usage + [DONE]) — so bili can serve the answer itself.
This PR fixes all three at the openai prepare seam:
src/server/traecode-compact.ts): removes the tracked native instruction line from role=system string content exactly when bili presents its own compression surface, so the model sees one philosophy. Versioned constant + drift-tolerant no-op (sentence reworded upstream → passthrough + warn once per session, never mis-strips).src/server/native-compact-shape.ts): detects the host-native compaction REQUEST (last user message = summarization template via strict-AND lead+tail anchors, or trim-exact/compactmanual form) and stands down bili's whole compression surface for that turn: no tool/doctrine/nudge injection, no tags-only system note, overhead measurement skipped (title-gen-style), preflight compression skipped (codexForge precedent). Session state continuity stays active: processTurn/snapshot/unannounced-rewrite detection (模型切换后压缩块跨模型失配,新模型收到 61.3 万 token 全量上下文 #1001) all keep running, so the aftermath path for the compaction PRODUCT keeps working (master's [bug] DSH 桌面端 0.1.188:宿主原生压缩落地摧毁折叠基底 → 同一区间永久不可锚定、compress 连片失败并熔断(compaction-basic auto:false 仍无效) #2432 all-lane native-compaction rebase picks up IDE-side landings).src/server/openai-compact-forge.ts): when Class A fires AND the session has healthy active ACP blocks (reusescodexCompactGate: transform ok + baseline < 90% window + ≥1 active block), bili serves ITS OWN fold summaries as the completion — standard chat.completion / chat.completion.chunk pair matching the captured terminal form,chatcmpl_bili_id sentinel, upstream never contacted (zero-egress contract, same class as codexForge/autoModeForge; served at theforward()choke point). Captured summaries are append-only deduped per session (mergeForgedSummaries), so a second compaction hands off everything folded so far. No active block yet → gate fails → honest passthrough (nothing folded to hand off).Per owner triage on #2411: behavior first, no config switch (same rollout order as the dsh guard — an opt-out is added only if users ask, shaped like
codexCompact). The first-passtraeCompactknob added during development was removed again after the triage landed.Behavior change (flagged per policy): old → new
/compact): previously received bili's full compression surface (doctrine,compresstool schema, nudge eligibility, preflight folding) on top of the host's own summarization act, AND were forwarded upstream; now: zero bili surface for that turn, and when healthy ACP blocks exist the request is ANSWERED LOCALLY with bili's fold summaries (upstream not contacted, no billing); next ordinary turn gets the full surface back (not latched).<example>).config surface
None. Deliberate: owner triage chose "behavior first, opt-out added only if users ask" for this rollout (dsh-guard order). If an escape hatch becomes necessary later it will be proposed separately before implementation (owner-gated per Configuration Surface Discipline). No
BILI_*env var, no config key, no default-value change anywhere else.Regression review (existing behavior touched)
Touched paths: inbound openai chat-completions preparation (
src/server/prepare-openai.ts) between the existing #359/#1029/#1542 strips andopenaiToCore; preflight gate insrc/server/handle.ts; local serve branch insrc/server/relay.ts(new, after codexForge).injectToolsexcludes title-genmax_tokens<=200and pluginMode); side passthrough forwards verbatim as before.openaiSystemText→ outbound re-injection only.reconcileSystemAnchor: new sessions see clean text from turn 1 (stable anchor); sessions live across an upgrade get one transition note, then stable.nativeCompactForge(gated by predicate + transformOk + codexGate); every other prepared/passthrough flow passes through the newifuntouched (same pattern as the adjacent codexForge/autoModeForge branches).injectToolsgate; proxy mode is the only affected lane.Tests
tests/traecode-native-compact.test.ts(25 tests, all green locally):compresspresent + surrounding bytes intact; continuation stays clean)./compact±whitespace; ACP render-tag prefix tolerance; fail-open negatives: lead-without-tail, tail-without-lead, non-last position, assistant-carried, parts-array, degenerate inputs, case mutation) + e2e (host-compaction-shaped request → forwarded system byte-stable, NO doctrine, NOcompresstool, native tools deepEqual, no ephemeral injections; control request keeps full surface — negative direction Test Blind Spot Retrospective: Reinforcing Negative Assertion Discipline, Tightening Fake Upstream Strictness, Thin Inst | 测试盲区复盘:补反向断言纪律、假上游严格化、薄安装冒烟、形态矩阵与生命周期覆盖 #3617; continuation restores surface — not latched).chatcmpl_bili_sentinel; non-stream JSON keys) + e2e through the real server (setup conversation folds m00001..m00004 server-side → template request on the SAME session (prefix affinity, verified against real bili behavior) → response served locally carrying[Compressed conversation section]+ the folded-range summary text, zero egress (upstream call count frozen); gate fail-open control: template-shaped request on a session without active blocks passes through normally).CI note
Rebased onto
bd29924d4(current master tip); the unrelated dsh typecheck fix that had been stacked on this branch (70252f42a) was dropped — master already carries the same fix upstream (de296983+ follow-ups), so no standalone PR was needed. The earlier expecteddocs-syncred on master (#4530) has since been fixed upstream via #4520 (missing config seed added). All lanes expected green; local gates green (typecheck / targeted suite / build / unused-exports / docs-coverage).Phase 2 status
Closed: trigger shape (template as last user message, 17/17), product landing (IDE-side head replacement, measured 502→37 msgs in 29s), E2 response shape (ordinary completion — forge authorized), aftermath safety net (#2432 all-lane rebase already on master). Remaining: production validation after merge (upgrade + real-session observation; the once-per-session log lines mark every interception).
Fixes #2411
(孤儿认领:标题本已指向 #2411,补上关闭关键字 —— 第三批清理)