Skip to content

fix: route the #1753 squatter wait diagnostic through the host-safe channel - #3585

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-17_fix-3575-squatter-diag-channel
Oct 18, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-17_fix-3575-squatter-diag-channel

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Closes #3575.

When a foreign proxy squats the preferred port and our laddered child has not published its instance record yet, the launcher waits — and announces that wait once. That announcement was still a raw console.error, the one remaining stderr path of the #1753 fix family: in native lanes (Pi native TUI, bili 0.1.198) stderr IS the screen, so the message painted into the input area even though every step of the sequence was self-recovering and the launch always succeeded.

The fix is one call site: route the message through attachDiag (bound at the top of ensureProxyRunning), exactly like every other launcher diagnostic since #3200. Default sink = durable log file (bili.log) only; explicit debug: true adds one controlled [info] stderr copy for CLI contexts. Host lanes hard-code debug: false and stay silent.

Behavior change (flagged)

  • Old: the "port N answers health (pid X) but is not the proxy this launcher spawned" notice printed to the terminal (stderr) by default, once per bring-up.
  • New: same message, same cadence (once per bring-up), same text including both pids — written to the log file by default; visible on the terminal only under explicit debug: true.
  • Reason: it is a progress diagnostic on a path that always recovers, and in native lanes the terminal is the TUI screen itself. Real failure paths (timeout, child death, gate refusals) keep their loud channels untouched — verified, see below.

Regression checks (per the issue)

  1. Foreign pid on preferred port + child record appears later → client exported to the child's real laddered origin; diagnostic recorded exactly once with both pids; default stdout/stderr byte-silent; file trace present. ✅ new hermetic test
  2. Preferred-port pid == child pid → existing success fallback unchanged. ✅ existing test (untouched)
  3. Foreign pid only, no matching child record → still times out, cleans up, fails loudly. ✅ existing test (untouched)
  4. Explicit-debug CLI visibility preserved; default silence NOT extended to real failure paths. ✅ new debug-variant test pins exactly one controlled stderr copy
  5. Async probe after the TUI is drawn cannot pollute the input area. ✅ asserted as zero terminal bytes

All three new tests fail on the unfixed code (verified by stash-revert) and pass with the fix; full tests/launcher.test.ts green locally (316 pass / 1 pre-existing skip); typecheck clean. Full-suite verdict comes from CI on this head.

Scope guardrails honored

Only the one branch changed. No global console muting, no console.error→console.log swap, no other console.error in ensureProxyRunning touched. PID identity verification, launchToken handshake, port selection, timeout budget, cleanup, and error propagation are all untouched. Message text byte-identical (grep continuity preserved).

Config surface

None. No new env var / config field / CLI flag.

awork added 2 commits October 17, 2026 22:01
…hannel (#3575)

The self-recovering 'foreign proxy squats the preferred port' notice was
the one #1753 path still on raw console.error: in native lanes (pi native
TUI) stderr IS the screen, so the message painted into the input area even
though the launch always recovered. Route it through attachDiag like every
other launcher diagnostic — durable log file by default, one controlled
stderr copy only under explicit debug. Message text, once-per-bring-up
latch, PID verification, launchToken handshake, timeout and cleanup are
all unchanged.
Three regression cases around the foreign-pid-squats-preferred-port
scenario (record gated to the second spawn-wait read so the branch
provably fires): non-debug leaves the terminal byte-silent with the
diagnostic exactly once in bili.log including both pids; an injected
attachDiag receives it verbatim with the default sink untouched; explicit
debug keeps exactly one controlled '[info]' stderr copy.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-17_fix-3575-squatter-diag-channel (df8cadb)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4233-pr.3585.6439670

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-pr3585.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 关闭 #3575(#1753 squatter 等待诊断分支)。与 #3404 / PR #3415(attach banner 分支)同属「launcher 诊断走 host-safe 通道」家族,但机制分支不同、互不重叠:#3415 覆盖正常 attach / 等待并发启动 / 后期发现三类 banner,本 PR 只动 squatter 通告这一个调用点;两 PR 触碰的是 launcher.ts 内不同行,合并顺序无依赖。已核对全部 50 个在途 PR,无其他 PR 触碰该调用点。

进入审核:方向关(独立复核 #3575 的代码路径与证据)、diff 审查、既有行为回归清点、测试有效性(本地定向跑 + 反向验证新测试在未修复代码上确实失败)、CI 状态。结构化八问结论随后补上。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

审核结论(独立复核,非转述 issue)

① 方向关:独立复核成立。在 PR merge-base 494571fee 上逐行确认:src/launcher.ts:4375 的 if (info?.ok && !squatterAnnounced) 分支为裸 console.error,该分支不抛错、继续等待子进程实例记录——即完全自恢复的路径;src/agent/host-log.ts 头部注释钉死了「native 车道里 stdout/stderr 就是 TUI 屏幕,裸写绕过 renderer 落到光标行」。修的是输出通道选错,不是生命周期缺陷;修法(attachDiag 已在同一函数顶部 :4060 绑定)是 #3200 以来全部 launcher 诊断的既定机制,最小且归位。

② 回归清点(触碰路径的既有行为逐项判定):

  • squatter 等待分支:通道 console.error → attachDiag;频率不变(squatterAnnounced latch,每轮 bring-up 一次);文本字节级不变(diff 中模板串原样,grep 连续性保留)。= 有意变更,PR 正文已披露旧值→新值+原因;
  • 成功兜底(首选端口健康 pid == 子进程 pid → 导出首选 origin):未动,既有测试通过;
  • 无匹配记录 → 超时/清理/响亮失败:未动,既有测试通过;
  • ensureProxyRunning 内其余 console.error(并发启动等待、attach banner、后期发现 banner、spawn 失败/子进程死亡/超时杀进程等失败路径):对全文件 console.error 出现集做 base↔head 整体 diff,恰好删一处、其余全部字节级一致(仅行号平移)。banner 类属 fix: route attach startup banners through the host-safe diag channel (#3404) #3415 范围(仍 open、互补、无合并顺序依赖),失败路径按 issue 约束保持响亮;
  • PID 身份校验、launchToken 握手、端口选择、超时预算、killAbandonedChild 清理、错误传播:diff 仅一个调用点+3 行注释,全部未碰;
  • 日志文件:该消息从此恒落 bili.log(行格式 <ts> [info] [v=X] <msg>,与既有 teeLog 格式同构),纯增量;
  • pluginMode/proxyMode 双压缩模式:launcher 侧代码,零 wire 影响,不涉及。

③ 代码审查:单调用点替换,attachDiag 在使用点之前已绑定,deps.attachDiag ?? defaultAttachDiag(opts.debug) 保留宿主注入契约(host 车道硬编码 debug:false)。新增注释解释「为什么」(自恢复进度诊断 → host-safe 通道,native 车道终端即屏幕),issue 锚定风格与仓库一致。

④ 测试有效性:三条新测试有牙——本地做了反向验证:只把 src/launcher.ts 还原到未修复 base,三条逐一失败,失败形态正是缺陷本身(测试1捕获到原始 squatter 字节打上了终端、测试2注入的 attachDiag 收到空数组、测试3受控行格式不匹配);恢复修复后全过。断言钉住的合同:客户端仍导出到子进程真实阶梯 origin(不误连)、默认终端零字节、日志恰好一次且双 PID 齐全、注入通道逐字接收且默认 sink 不被双写、显式 debug 恰好一行受控 [info] [v=…] 拷贝且无其他终端输出。场景确定性构造(spawn 时刻取读次快照门控,使 squatter 分支可证明地先于握手落定触发;sleep 立即返回,无真进程无等待)。本地整跑 tests/launcher.test.ts:316 pass / 1 既有 skip,与 PR 声明一致;新 helper(withHomeSandbox/captureStderr)在 finally 还原 env/stderr,整文件跑无跨测试污染。测试2里 readFileSync 的空 catch {}:审过,属可接受——注入 sink 时默认日志文件本就可能不存在,紧随断言对两种情况都成立,非缺陷。

⑤ diff 整洁度:2 文件 +142/-1,每一行都服务本 PR 目的,无跑题文件、无空白重排、无生成物/锁文件波动。干净。

陈旧度与 CI:head 落后 master 31 个提交,已核对这 31 个提交无一触碰 src/launcher.ts / tests/launcher.test.ts,GitHub 报 mergeable=true,rebase 平凡干净、触碰路径无语义漂移。CI(head 上):静态门禁全绿(static-gates ×2、docs-sync、docs-coverage、config-surface-guard、unused-exports、test-import-graph、lock-sync、lane-guard、pi-subagents-guard、version-guard、kernel-guard、gate);test 分片 6 中 5 已完成且全绿(ubuntu 22×3、windows 22×2),剩 1 个 node-24 分片 in_progress。


结构化八问

  1. 是什么问题:首选端口被外部 bili 占用、我们的子进程阶梯换端口尚未发布实例记录的等待窗口里,launcher 那条「等待子进程上报真实 origin」的进度提示走的是裸 console.error——Pi native TUI 里 stderr 就是屏幕,于是这条必然自恢复的提示被画进输入框区域。它是 launcher: spawn 等待的 pre-handshake fallback 把首选端口上的健康外来实例当成自己 spawn 的 child,客户端被 export 到错误 origin(绕过 #1225 指纹门) #1753 修复家族里唯一漏掉的 stderr 路径。
  2. 什么原因导致的:launcher: spawn 等待的 pre-handshake fallback 把首选端口上的健康外来实例当成自己 spawn 的 child,客户端被 export 到错误 origin(绕过 #1225 指纹门) #1753 当年加这条提示时 host-safe 通道还不存在;[Pi native][启动日志] 正常的 native-attach 候选跳过信息不应默认输出到用户终端 #3200 后来把 launcher 其余诊断全部迁到 attachDiag(默认只落盘、显式 debug 才拷 stderr)时漏掉了这个自恢复分支。根因是输出通道选错,不是生命周期缺陷。
  3. 影响范围与严重程度:仅 native/TUI 宿主 + 「首选端口被占且子进程记录未发布」时序窗口;纯视觉污染,启动始终成功,无数据/功能影响。体验瑕疵级。
  4. 怎么修复的:一个调用点改走 ensureProxyRunning 顶部已绑定的 attachDiag——与 [Pi native][启动日志] 正常的 native-attach 候选跳过信息不应默认输出到用户终端 #3200 以来所有 launcher 诊断同一机制:默认只落 bili.log,显式 debug:true 多一行受控 stderr 拷贝,host 车道保持静默。消息文本、单次通告 latch、双 PID 内容全部不变。
  5. 是否有回归问题:无。审过的既有行为:成功兜底保持;无匹配→响亮失败保持;函数内其余 console.error 出现集逐一对比字节级一致(失败路径响亮渠道未动);PID 校验/launchToken/端口选择/超时预算/清理/错误传播未变。唯一变更即上面披露的行为变更本身。
  6. 是否破坏缓存:不涉及(纯输出通道变更,无缓存/游标/去重键)。
  7. 是否改了设计方向:不涉及。方向即 [Pi native][启动日志] 正常的 native-attach 候选跳过信息不应默认输出到用户终端 #3200 已确立的「launcher 诊断一律走 host-safe 通道」,本 PR 把最后一个例外归位;与在途的 fix: route attach startup banners through the host-safe diag channel (#3404) #3415(banner 分支)互补、无顺序依赖。
  8. 是否引入了新的配置:不涉及。行为变更披露:旧值=该提示默认打到终端(stderr)、每轮 bring-up 一次;新值=同文本同频率默认只进 bili.log,仅显式 debug:true 时在终端保留一行受控拷贝。原因:它是必然自恢复路径上的进度诊断,而 native 车道的终端就是 TUI 屏幕本身。

合并判定:可合 —— 等最后一个 node-24 CI 分片转绿即可(当前 5/6 分片绿 + 静态门禁全绿;本地定向验证与反向验证均绿)。

@ranxianglei
ranxianglei merged commit 08e4829 into master Oct 18, 2026
40 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.562-master.08e4829 (rolling master tag).

npm install -g billion-context@0.0.562-master.08e4829  # 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.

[Bug][Pi native/TUI] Recoverable proxy identity wait message pollutes the input area (remaining #1753 stderr path)

1 participant