Skip to content

fix: route attach startup banners through the host-safe diag channel (#3404) - #3415

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-16_fix-3404-attach-banner-host-safe
Oct 18, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-16_fix-3404-attach-banner-host-safe

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3404

What

The two remaining startup banners in ensureProxyRunning went out through raw console.error:

  • attachTo(): bili: attaching to running proxy at <origin> (pid <pid>)
  • waitForOtherStarter(): bili: another bili launch is bringing up a proxy — waiting for it instead of spawning a second

In native host processes (pi/omp/dsh lanes) stderr IS the TUI screen — src/agent/host-log.ts documents that a raw console.* write lands on the physical cursor line bypassing the host renderer (e.g. Pi's input draft after herdr session restore, the #3404 screenshot). A healthy attach needs no user action, so both banners now ride the #3200 host-safe channel (defaultAttachDiag): durable log file by default, one controlled stderr copy under explicit debug. Message text, origin/PID detail, watcher registration and all attach/spawn/lifecycle logic are unchanged.

Behavior change (deliberate, disclosed per policy)

Old -> new for these banners: before they were always written to process stderr (visible in host TUIs AND CLI terminals); after they go to the durable log file (~/.local/state/billion-context/bili.log) by default, with a stderr copy ONLY when launched with explicit debug (host lanes hard-code debug:false and stay silent; CLI --debug keeps seeing them). Reason: in-host raw terminal writes corrupt the rendered UI (#2827/#2831 mechanism), and normal startup progress is not user-actionable. User-actionable output is UNTOUCHED — gate refusals (#1335), squatter announcements (#1753), child-death/slow-start/killed-child notices all keep their visible channels; a new test pins that boundary.

Same-mechanism sweep (second commit)

While implementing #3404 I found a third instance of the same class: rediscoverAfterChildExit()'s successful-attach announcement (bili: attached to ... after the initial discovery, src/launcher.ts:4304 pre-fix) — converted the same way, own labeled commit + regression test. Its adjacent FAILURE notice (spawned proxy exited before becoming healthy — re-checking...) deliberately stays visible.

Not changed

attach/spawn selection, compatibility checks, shared-proxy dedup, lifecycle logic; no global console mute; no config surface change; no kernel/pi-subagents change; no version bump.

Regression tests (tests/launcher.test.ts)

  1. non-debug normal attach: zero terminal bytes, bili.log keeps attaching to running proxy at ... (pid ...), watcher registration unchanged;
  2. concurrent-startup wait branch: wait-then-attach behavior unchanged (no second spawn), both banners file-only;
  3. explicit debug: exactly one controlled stderr copy with the legacy head format;
  4. user-actionable gate refusal still reaches the terminal (not hidden with the banners);
  5. recovery path: child-death failure notice stays on the terminal, success announcement moves to the file.

Local: typecheck clean, targeted tests/launcher.test.ts 307 pass / 0 fail; full-suite verdict = CI.

查重: 无(与 #2827/#2831、#3200/#3210 的区别见 issue 正文)。

awork added 2 commits October 16, 2026 21:48
…3404)

The two normal-startup banners in ensureProxyRunning (attachTo's 'attaching to running proxy' and waitForOtherStarter's 'another bili launch ...') went out through raw console.error. In native host processes (pi/omp/dsh lanes) stderr IS the TUI screen — host-log.ts documents that a raw console.* write lands on the physical cursor line, e.g. Pi's input draft after herdr session restore. Route both through the #3200 defaultAttachDiag channel instead: durable log file by default, one controlled stderr copy under explicit debug. Message text, origin/PID detail, watcher registration and all attach/spawn/lifecycle logic are unchanged; failure-path console.error lines (gate refusals, squatter announcements, child-death notices) stay visible.

Regression tests pin: non-debug attach/wait emit zero terminal bytes with the banners in bili.log; debug emits exactly one controlled copy; user-actionable gate refusals still reach the terminal.
…e channel too (#3404)

Same-mechanism sweep found while implementing #3404: rediscoverAfterChildExit's successful-attach announcement ('bili: attached to ... after the initial discovery') was a third raw console.error success banner in the same function — same class as attachTo, same TUI-pollution risk on host lanes. Converted to the shared attachDiag channel with its own regression test; the adjacent child-death failure notice deliberately stays visible.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-16_fix-3404-attach-banner-host-safe (83f2f3f)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4012-pr.3415.4e30488

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-pr3415.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

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

PR review(独立重审,未沿用 #3404 线程结论)

查重: 不重复。 这是 #3404 的唯一实现 PR;近期 open/closed PR 中无其他触碰这三条 banner 或 ensureProxyRunning 输出渠道的并行工作。#2827/#2831、#3200/#3210 是同一机制家族的前序已合入阶段(会话期 console 输出通道、候选筛选诊断),本 PR 是其收尾,非重复立项。

独立验证过程:拉取分支逐行读 diff(对照改动前代码);核对 defaultAttachDiag(src/launcher.ts:3705)实现与三处调用点的作用域绑定(:3969 之后);全仓 grep 三条 banner 字符串确认无遗漏实例;逐条清点 ensureProxyRunning 内剩余全部 console.error 的保留理由;本地 typecheck 干净、定向 tests/launcher.test.ts 307 pass / 0 fail(含 5 条新回归测试,1 skip 为既有平台门控);API 核实 head 83f2f3fc4 CI 27 success / 11 skipped / 0 fail;分支落后 master 9 个提交但 merge-tree 零冲突,且这 9 个提交无一触碰 launcher/host-log/对应测试文件。

按八问:

  1. 是什么问题:正常启动通告(attach 成功、等待并发启动、恢复路径迟发布者 attach)用裸 console.error 直写 stderr;native 宿主进程里 stderr 就是 TUI 屏幕本身,文本落在物理光标行——Pi 会话恢复后即输入区污染([Bug][Pi native/TUI] Attach startup banner pollutes the Pi input area after herdr session restore | [Bug][Pi native/TUI] herdr 恢复会话后 attaching 启动提示污染输入区(剩余启动 banner) #3404 截图)。
  2. 什么原因导致的:这两条 banner 早于 [Pi native][启动日志] 正常的 native-attach 候选跳过信息不应默认输出到用户终端 #3200 宿主安全通道存在,当时被划为「另一个待决定的范围」未改。机制层:裸 console.* 绕过宿主 renderer(src/agent/host-log.ts:1 注释即此机制)。herdr 恢复只是提供了「TUI 已绘制 + attach 输出随后到达」的现场时序,任何宿主内 attach 都可能触发。
  3. 影响范围与严重程度:所有走 ensureProxyRunning 正常 attach / 等待分支 / spawn-wait 恢复路径的 native lane 会话(pi/omp/dsh 等,宿主 lane 硬编码 debug:false)。程度:显示污染——banner 出现在终端画面、可落进输入区光标行;无机制指向输入内容修改或会话损坏。代理功能本身不受影响。
  4. 怎么修复的:复用 [Pi native][启动日志] 正常的 native-attach 候选跳过信息不应默认输出到用户终端 #3200 已有的 defaultAttachDiag 通道——先写持久日志文件(best-effort,日志失败不破坏宿主),显式 debug 时追加一份带时间戳 head 的受控 stderr 副本;原文、origin/PID 逐字保留。同类扫描发现的第三个同机制实例(rediscoverAfterChildExit 成功通告)一并转换,独立 commit + 独立测试。失败路径上真正需要用户处理的行逐条核实原样保留:gate 拒绝(:3643)、慢启动(:4236)、squatter 通告(:4289)、re-check 提示(:4300)、killed-child(:4348)。
  5. 是否有回归问题:无意外回归。diff 仅改 3 个调用点的输出渠道,attach/spawn 选择、兼容性检查、watcher 注册参数、共享代理去重、生命周期逻辑逐行核对均未动(测试对注册参数 deepEqual、reads 次数、attached/origin 逐一钉住)。唯一行为变化即下方披露的有意变更。一处细节备注:CLI --debug 用户看到的 banner 行从裸文本变为带 <iso-ts> [info] [v=x.y.z] head 前缀——与 debug 模式下所有其他诊断行的格式一致,属披露范围内的一致性变化,非回归。
  6. 是否破坏缓存:不涉及(无缓存/重试/增量游标/去重键触碰)。
  7. 是否改了设计方向:没有——是 [Bug][Pi native/TUI] pi-web-access 共存提示 console.log 污染输入框画面,点击重绘后消失(0.1.193) #2827/[Bug][native lane] #2827 同机制的剩余面:其他 native 车道的会话中途 console.* 仍直写宿主终端 #2831/[Pi native][启动日志] 正常的 native-attach 候选跳过信息不应默认输出到用户终端 #3200 已确立方向(「向用户可见的内容必须走宿主认可的渠道」)的收尾延续。
  8. 是否引入了新的配置:无。无新 env/config/默认值。

行为变更复核(旧→新,PR 描述准确):三条 banner 默认从「总是上 stderr」改为「只写 ~/.local/state/billion-context/bili.log;显式 debug 启动时额外一份带 head 前缀的 stderr 副本」。原因成立:宿主内裸写终端会污染 TUI,且这三条是非可行动的正常进度。边界两侧均有测试钉住(非 debug 零终端字节 + 文件留痕;gate 拒绝仍上终端且文件留痕)。

测试有效性:5 条新测试断言有牙——回退到 console.error 会被 stderrWrites.length 抓到、文案漂移会被 includes 抓到、行为漂移(二次 spawn、watcher 参数变化、等待分支语义)会被 counts/deepEqual 抓到;第 4 条专钉「可行动错误不被一起隐藏」的边界。非恒真、非 mock-only。

判定:可合并(CI 绿、base 无冲突、diff 干净每行相关;合并由人工执行)。

@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.563-master.f5fee79 (rolling master tag).

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

1 participant