Skip to content

fix(#2827): route native fetch-chain diagnostics to bili.log instead of console.* - #2829

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-12_fetch-chain-log-channel
Oct 12, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-12_fetch-chain-log-channel

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2827

Problem

In Pi native / plugin mode (and every bili-native lane), the fetch-chain diagnostics fire INSIDE the host agent process, where stdout/stderr IS the interactive TUI terminal. The unconditional console.log of the pi-web-access coexistence adopt note (#2435) landed on the physical screen bypassing Pi's renderer — text appeared appended to the input-box draft line until the next redraw (#2827).

Fix

Route ALL FOUR fetch-chain diagnostics through a new logChainEvent() into the shared bili.log (~/.local/state/billion-context/bili.log), following the established persistClientEvent pattern (dsh-native): best-effort appendFileSync, reopen-by-path per call so the proxy's rotation cannot strand writes, never breaks the host. Line grammar matches the proxy logger so mixed-version hosts self-identify each physical line: <ts> [info|warn] [v=<version>] [native-client] <msg>.

Sites moved (wording, severity and issue refs unchanged; routing logic untouched):

Behavior change (intended, per issue request)

Old → new for every diagnostic above: written to host-process stdout/stderr (visible in the terminal, pollutes active TUIs) → written ONLY to the shared bili.log file (visible via the proxy Web UI / log file / bili doctor; zero terminal traffic). This is the channel fix requested in #2827 ("送至宿主认可的 UI 安全日志通道、日志文件或真正的 debug-only 通道"). Diagnostic capability is preserved and more durable than console output that scrolls away under TUI redraws.

Tests (tests/native-intercept-selfheal.test.ts)

Local verification on rebased head (master @ 47386e6): typecheck clean; 128/128 across native-intercept-selfheal / native-intercept / issue1958-routed-warn / dsh-native suites; full build green. Full regression left to CI.

No config surface change. No kernel/ change.

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-12_fetch-chain-log-channel (aafdee6)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3138-pr.2829.644ee40

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-pr2829.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] 🏷 ## PR #2829 review 结论(已在当前 master head 上完成 rebase + 定向验证)

重复判定:已检索 open/closed issues+PRs,仅本 PR 引用 #2827,无重复项。

① 原 issue 审核(方向关)— 通过

#2827 证据充分:用户做了隔离复现 + 对照组(真实 TuiAltScreen/Editor、离线 fetch stub),4 个场景污染、对照组干净,且 Editor.getText() 全程不变——确认是纯画面污染、无数据损坏。根因链:fetch-chain 诊断在宿主 agent 进程内触发,该进程的 stdout/stderr 就是交互式 TUI,console.* 直写物理屏幕、绕过 Pi 渲染器。issue 明确请求「送至宿主认可的 UI 安全日志通道、日志文件或真正的 debug-only 通道」——本 PR 把 fetch-chain 全部四个诊断改道共享 bili.log,正是对 offending bytes 的产生机制(console 写入本身)做根修,不是症状遮蔽;措辞/严重度/issue 引用逐行比对未变,routing 决策逻辑零改动。方向正确。

② 回归审查(既有行为清单)

触碰路径的既有行为 结论
四个诊断的终端输出 有意变更(PR 正文已按旧→新披露:终端可见 → 仅 bili.log),即 #2827 请求的通道修复 ✓
诊断措辞 / 严重度 / issue 引用 保持(逐行 diff 比对)✓
adopt/re-arm/re-anchor/re-entry 路由决策逻辑 保持,零改动 ✓
一次性/上限语义(#1410 one-shot、#1662 one-shot、REARM_LIMIT=16) 保持 ✓
新增 paths.js/version.js import 进入 pi-native 车道 dsh-native 早已同样 import;发布版 dist 有 build-info.json 只走 readFileSync,dev 环境 git rev-parse 是 #2441 既有模式(windowsHide+10s 超时),无外部影响 ✓
bili.log 轮转兼容性 logger.ts 10MB rename→.old 轮转;appendFileSync 每次调用按路径重开,不会被轮转卡死(与 dsh-native persistClientEvent 同模式,已核对其实现)✓
日志行语法 <ts> [level] [v=X] [native-client] msg 与 proxy logger / [dsh-client] 风格一致;现有消费者(Web UI raw tail、acp-cache-diff marker 搜索)不严格解析该 tag,无破坏风险;混版本宿主可自识别 ✓
日志量 四个事件均 one-shot 或 REARM_LIMIT 封顶,无无界增长 ✓

高危模式逐项过:无语义漂移、无 fail-fast 变吞错(try/catch 仅包日志写入,主路径不受影响)、无阈值/时序/输出格式漂移。

③ 代码审查

logChainEvent 完全沿用 persistClientEvent(src/agent/dsh-native.ts:434)的 best-effort 模式(mkdirSync recursive + appendFileSync + try/catch never breaks host);level 参数化合理;无命名/空指针/安全问题。未发现需直接修复的小缺陷。

④ 测试有效性 — 真测试

⑤ diff 整洁度

2 files +141/-28,每行都与本 PR 目的相关,无跑题文件、无空白重排、无生成物连带。✓

验证证据(rebased head)

PR base(master@47386e6f0)之后 master 前进了存储域提交(#2825 better-sqlite3 移除)与 v0.1.194 release merge(cd02d2dc5)——与本 PR 触碰路径零重叠,cherry-pick 干净。已将分支 rebase 到当前 master head 并 force-push(PR 头现为 6461effc4,CI 重新运行中)。本地在 rebased head 上:typecheck clean;native-intercept-selfheal / native-intercept / issue1958-routed-warn / dsh-native 四套 128/128(与作者本地数字一致);full build green,且 dist/agent/pi-native.js bundle 中确认含 [native-client] tag。全量回归交给 CI。


结构化八问

  1. 是什么问题:Pi native/TUI 模式下,bili 首次 adopt pi-web-access 的 proxy fetch 时,共存提示经 console.log 直写宿主终端,绕过 TUI 渲染器,文字出现在输入框草稿行上直到下次重绘。
  2. 什么原因导致的:这四个 fetch-chain 诊断运行在宿主 agent 进程内,其 stdout/stderr 就是交互式 TUI;无条件 console.* 落到物理屏幕。是通道选择错误,不是路由逻辑错误。
  3. 影响范围与严重程度:仅影响在 TUI 宿主(Pi native/plugin)中运行 bili+pi-web-access 共存的用户;纯视觉瑕疵——输入内容不被修改(用户隔离复现证实各阶段 Editor.getText() 不变),重绘即自愈。低中严重度,无数据丢失。
  4. 怎么修复的:四个诊断统一经新 logChainEvent() 写入共享 bili.log(best-effort appendFileSync、按路径重开防轮转卡死、try/catch 永不破坏宿主),行语法与 proxy logger 对齐([v=X] [native-client])使混版本宿主自识别;措辞/严重度/routing 逻辑全部不变。
  5. 是否有回归问题:无。有意行为变更(必须披露):上述诊断从「终端可见」变为「仅 bili.log 可见」——这正是 [Bug][Pi native/TUI] pi-web-access 共存提示 console.log 污染输入框画面,点击重绘后消失(0.1.193) #2827 请求的通道修复,能力保留且比会被 TUI 重绘冲掉的 console 输出更持久。routing 决策、one-shot/limit 语义、wire 格式均未变。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:否。机制内通道替换,沿用既定 persistClientEvent(dsh-native)模式,未引入新架构。
  8. 是否引入了新的配置:无。

分析中发现的新问题(已立项)

其他 native 车道仍存在会话中途可能触发的 console.* 直写(与 #2827 同一机制、不同代码位置):如 src/agent/native-intercept.ts:674/777/829(代理掉线/恢复期间模型请求路径)、src/agent/pi.ts:946/994/1067(sendMessage 失败回退)等。已立跟踪 issue #2831,带逐站点 triage checklist(启动期有意用户可见错误 vs 会话中途应入 bili.log,是否一律入文件由 owner 拍板)。

判定

可合并(等本轮 CI 绿即可)。review 期间唯一动作为把分支 rebase 到当前 master head(内容零改动),CI 结果出来后如全绿,请人工合并。

…of console.*

The four fetch-chain diagnostics (web-access adopt note, third-party
install warning, #1410 re-anchor, #1662 re-entry) run inside the host
agent process, where stdout/stderr IS the interactive TUI terminal. A
console write lands on the physical screen bypassing the host renderer,
so the pi-web-access coexistence note appeared appended to the Pi input
box until the next redraw (#2827).

All events now go through logChainEvent into the shared bili.log with
the proxy's own line grammar ([v=...] [native-client] ...), following
the established persistClientEvent pattern (dsh-native, #1158-era):
best-effort append, reopen-by-path per call so proxy rotation cannot
strand writes, never breaks the host. Message wording, severity levels
and issue refs are unchanged; routing logic untouched.
@ranxianglei
ranxianglei force-pushed the 2026-10-12_fetch-chain-log-channel branch from 6461eff to aafdee6 Compare October 11, 2026 18:00
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 补充(状态更新):上一条 review 后 PR 头又前进了一个提交 aafdee6bf(ework-agent 推的同一内容 rebase——与我验证过的 6461effc4 树完全相同,git diff 为空,同样坐在当前 master cd02d2dc5 之上)。结论不受影响。

当前 CI(aafdee6bf):27 项 check 中 23 项已完成且全部 success、零失败,含全部 e2e 车道(real codex/pi/opencode/dsh、hermetic registry、build-artifact、各 guard);剩 4 个 full-unit-test 矩阵任务(ubuntu/windows × node 22/24)仍在跑。旧 head run 的 cancelled 是并发组被新提交顶替的正常行为,不是失败。

等这 4 个 test 矩阵任务转绿即可人工合并;若其中任何一个红了,我会定向排查并跟进。

@ranxianglei
ranxianglei merged commit 56b3ca3 into master Oct 12, 2026
27 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.301-master.56b3ca3 (rolling master tag).

npm install -g billion-context@0.0.301-master.56b3ca3  # 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.

ranxianglei pushed a commit that referenced this pull request Oct 12, 2026
… shared host-safe helper

Promote #2829's logChainEvent into a shared logHostEvent(level, origin, msg) in src/agent/host-log.ts and move every remaining mid-session console.* diagnostic in the native lanes onto it (terminal -> shared bili.log). Startup-time banners and the /acp render-failure notices (the host render IS the only user channel there) stay on the terminal by design. Message texts are byte-identical; only the channel changes.
ranxianglei pushed a commit that referenced this pull request Oct 12, 2026
…rtions

Six suites asserted the moved diagnostics on console.*; they now read the redirected XDG_STATE_HOME bili.log for the same lines and additionally assert the terminal surface stays clean (#2831), mirroring #2829's hermetic pattern in native-intercept-selfheal.test.ts.
@ranxianglei
ranxianglei deleted the 2026-10-12_fetch-chain-log-channel branch October 15, 2026 05:33
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] pi-web-access 共存提示 console.log 污染输入框画面,点击重绘后消失(0.1.193)

1 participant