Skip to content

启动期正常的 attach 跳过诊断默认只写日志文件,不再直写用户终端 - #3210

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-15_fix-3200-native-attach-skip-log
Oct 15, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-15_fix-3200-native-attach-skip-log

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3200

做了什么

pi(及其他 native lane)启动时扫描实例注册表,正常筛选结果——指纹不匹配 / lane 不匹配 / 端口不匹配 / 进程已死候选——此前经默认 attachDiag = teeLog("info") 直接写 stderr。宿主进程里 stderr 就是 TUI 屏幕,用户看到 native-attach: skip ... incompatible (...) 这类内部诊断,却没有任何需要处理的事项。本 PR 把这些诊断的默认输出去向改为只写日志文件(复用 #2841 的共享宿主安全渠道 logHostEvent),显式 debug 时才追加一份受控 stderr 输出。

行为变更(旧 → 新)

场景 旧行为 新行为
native lane(pi/omp/dsh/opencode/kimi/zcode/claude)启动发现不兼容候选 直写终端(TUI 画面);从不进 bili.log(宿主进程从未启用 logger 文件腿) 只写文件(bili.log,消息文本不变、grep 兼容);终端零字节
CLI 路径(bili <client>)同上 直写终端 只写文件;启用 --debug/ACP_DEBUG=1 时额外一行受控 stderr(行头格式与旧 teeLog 一致)
zcode MCP 子进程 bili.log + stderr(zcode 吞掉) 只写 bili.log(内容不变,不再写死管道)
findLiveAttachableInstance(zcode 退出交接 / watchdog 漂移修复) 完全静默(sink 为 undefined,无任何记录) 同样的 file-only 默认,补上 #1623 以来缺失的排障记录
生命周期 gate 拒绝、spawn 失败等用户可行动的错误/警告 可见 不变,保持可见

兼容性检查、lane 隔离、生命周期保护逻辑一律未动;诊断消息文本逐字节未变。

为什么这样修

验证

config surface: 无。kernel: 无。

…eractive terminal (#3200)

Normal candidate filtering (probe drops, fingerprint/lane/port skips) is not
user-actionable, but its default sink teed every line to stderr — on pi/omp/
dsh/opencode/kimi/zcode native lanes that stderr IS the TUI screen, and those
host processes never call configureLogger, so the lines never reached
bili.log either (terminal noise with no durable record).

- launcher: new exported defaultAttachDiag(debug) — file-only via the shared
  host-safe channel (logHostEvent); explicit debug adds one controlled stderr
  copy for CLI contexts (all native lanes hard-code debug:false). Applied to
  both ensureProxyRunning and findLiveAttachableInstance (the latter was fully
  silent before — raw undefined sink).
- host-log: empty origin allowed so the file line stays byte-identical to the
  legacy teeLog format (grep continuity, #1623 traceability). Message text
  unchanged everywhere.
- User-actionable output untouched: gate refusals keep their console.error,
  spawn failures keep their visible channels; compatibility/lane/lifecycle
  logic unchanged.

Tests: two hermetic XDG_STATE_HOME regressions pin 'reason in file + zero
terminal bytes' (debug=false) and the single debug-gated stderr copy with the
legacy head format; existing #1623 attach-diagnostic tests (injected sinks)
unaffected and green.

Closes #3200
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-15_fix-3200-native-attach-skip-log (fcd88e8)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3688-pr.3210.e2d0262

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-pr3210.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] 🏷 (ai: vllm-qwen/qwen3.8-27b)

查重: 不重复。 open+closed 全量检索(关键词 attach / diagnostic / native-attach skip / stderr):

这是 agent 自己开的 PR(带 ework-agent-pr 标记),按规范不重做——现在独立审 diff + 核对 CI,结论随后补上(结构化八问)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

独立审完(diff 逐段 + 本地定向验证 + CI job 日志取证)。结论:代码本身可合并;CI 的 7 个红分片是 master 既有红风暴,与本 PR 无关(证据见末节)。

先交代一个补充动作:首轮 CI 时 unused-exports gate 红(defaultAttachDiag 被导出但无跨模块引用)——本地复现确认后改为模块私有并推了 commit fcd88e805(纯可见性变更,无行为变化),gate 转绿。

结构化八问:

  1. 是什么问题:native lane(pi/omp/dsh/opencode/kimi/zcode/claude)与 CLI 启动扫描实例注册表时,正常的不兼容候选筛选诊断(指纹/lane/端口不匹配、死进程)默认直写 stderr = TUI 画面,污染用户终端;同时宿主进程从未启用 logger 文件腿,这些诊断历史上从不进 bili.log——「看见的」(污染)和「看不见的」(缺持久排障记录)是同一个渠道选择错误的两面。
  2. 什么原因导致的:fix(zcode): shared-store dead-port repair — exit handoff, watchdog drift fix, attach visibility #1624 加 attach 诊断时选错了渠道——无条件 tee-to-stderr 的 teeLog("info"),既无级别过滤也无宿主侧文件腿。这是设计期的渠道选择问题,不是某个函数的逻辑 bug;所以改级别治不了,只能换渠道。
  3. 影响范围与严重程度:所有 native lane 启动 + CLI 路径均受触发面影响;严重程度 = 体验瑕疵 + 排障记录缺失,无功能损害(候选筛选、attach 判定、spawn 全部正确工作)。
  4. 怎么修复的:换渠道不换文案——新增 defaultAttachDiag(debug)(src/launcher.ts):默认走 fix(#2831): route mid-session native-lane diagnostics to bili.log (shared host-safe helper) #2841 既有宿主安全渠道 logHostEvent 只写 bili.log(best-effort append、失败不炸宿主、按路径每次重开不受 rotation 影响);仅 debug=true 时追加一份受控 stderr(行头与旧 teeLog 字节一致)。配套两处最小改动:logHostEvent 允许空 origin(日志行与旧格式字节一致,保 grep 连续性与 [Bug] zcode 原生模式:代理实例生命周期与共享路由配置脱钩——实例死亡留死端口 + 客户端缓存不重读,单会话使用即中招(ECONNREFUSED) #1623 可追溯性);findLiveAttachableInstance 补上默认 sink([Bug] zcode 原生模式:代理实例生命周期与共享路由配置脱钩——实例死亡留死端口 + 客户端缓存不重读,单会话使用即中招(ECONNREFUSED) #1623 以来完全静默的路径首次有记录)。诊断消息文本逐字节未变。
  5. 是否有回归问题:对 diff 触碰路径的既有行为逐项清点——兼容性检查 / lane 隔离 / lifecycle gate / spawn 失败通知 / gate 拒绝通知:全部不变(只替换 sink 表达式,gate/spawn 逻辑零触碰);用户可行动的错误/警告保持可见不变;refusedLog 去重不变;核验了 logHostEvent 路径不做 masking 这一既有属性在本场景 N/A(attach 诊断只含回环地址+pid+原因码,回环地址本就在 maskIpsInText 豁免集)。披露一个小的既有副作用:少数非 hermetic 存量测试在未注入 sink 时走 skip 分支,现在会向 ambient bili.log 追加几行(此前是 stderr)——best-effort try/catch、断言不受影响,判定可接受。另发现并顺手修掉一处 unused-exports 违规(export→模块私有,commit fcd88e8)。
  6. 是否破坏缓存:不涉及(无缓存/重试/增量游标/去重键参与;refusedLog 去重语义未动)。
  7. 是否改了设计方向:没有。本 PR 是 [Bug][native lane] #2827 同机制的剩余面:其他 native 车道的会话中途 console.* 仍直写宿主终端 #2831/fix(#2831): route mid-session native-lane diagnostics to bili.log (shared host-safe helper) #2841 既定方向(宿主安全日志渠道、终端默认零字节)的延续,不引入新架构。两条启动横幅(attaching to running proxy... / another bili launch is bringing up...)仍属 [Bug][native lane] #2827 同机制的剩余面:其他 native 车道的会话中途 console.* 仍直写宿主终端 #2831 留给 owner 的产品决策,本 PR 不触碰。
  8. 是否引入了新的配置:无。复用既有 LaunchOptions.debug 语义(CLI --debug/ACP_DEBUG=1;native lane 硬编码 false → 宿主侧永远 file-only)。

CI 状态(head fcd88e8):33 项绿(含全部 e2e lane:real codex/pi/opencode/dsh、registry、build-artifact、docs-sync、unused-exports、kernel/pi-subagents guard);7 个 test 分片红。逐 job 日志核对,红的只有两个固定签名:port-zone-live EADDRINUSE 127.0.0.1:18787(#3044 用例)与 claude-native hook e2e「pinned port attach」把自起守护误判为 lifecycle-less 而拒绝(#1322/#1335/#1660 用例)。master 最近三轮 CI 的 shard 3 挂着完全相同的两个测试(早于本 PR 存在;本 PR 不触碰那两个代码路径,本地定向 launcher 套件 302 pass / 1 skip / 0 fail)→ 判定为继承的环境红,非本 PR 回归。已查证无既有跟踪条目(按失败签名查重:无),已立单跟踪:#3212

判定:代码审查通过、可合;CI 红为 master 既有环境问题,等 #3212 收敛或自然绿轮即可(也可由你按上述证据裁决)。合并按规则由你执行:#3210

@ranxianglei
ranxianglei merged commit 0cd865b into master Oct 15, 2026
33 of 40 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.439-master.0cd865b (rolling master tag).

npm install -g billion-context@0.0.439-master.0cd865b  # 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.

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.

[Pi native][启动日志] 正常的 native-attach 候选跳过信息不应默认输出到用户终端

1 participant