Skip to content

fix(#2831): route mid-session native-lane diagnostics to bili.log (shared host-safe helper) - #2841

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-12_native-lane-console-sites
Oct 12, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-10-12_native-lane-console-sites

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2831

Depends on #2829: this branch is based on #2829's head (6461effc4). Once #2829 merges into master, this PR's diff shrinks automatically to my two commits below.

Mechanism (same as #2827/#2829)

Native-lane diagnostic code runs inside the host agent process, whose stdout/stderr IS the interactive TUI terminal. A mid-session console.* write lands on the physical screen, bypassing the host renderer (text appears on the cursor line — e.g. the input-box draft — until the next redraw). #2829 fixed the four fetch-chain sites; this issue tracks the remaining facets across the other native lanes.

What changed

  • New shared host-safe helper src/agent/host-log.ts: logHostEvent(level, origin, msg) — best-effort append to the shared bili.log (proxy line grammar <ISO> [<level>] [v=<ver>] <origin> <msg>; reopens by path on every call so the proxy's 10MB rotation can never strand a writer).
  • fetch-chain/index.ts: fix(#2827): route native fetch-chain diagnostics to bili.log instead of console.* #2829's local logChainEvent now delegates to the shared helper (no behavior change).
  • dsh-native.ts: persistClientEvent() delegates to the shared helper with byte-identical line format; the terminal-side copy was removed from every double-written site; the previously missing file copy was added for manifest registration failed.
  • Every remaining mid-session console.* diagnostic in the native lanes moved to the shared helper, origin [native-client]:
    • native-intercept.ts ×8 (signed-direct-forwarded, bootstrap timeout, held request, beforeSend-hook-failed ×2, no-live-proxy, proxy-not-ready [checklist], respawn-failed [checklist])
    • pi.ts ×24 (incl. the three /acp* sendMessage failed sites [checklist], dropped-tools re-assertion, manifest/register retries, compaction probe, omp setModel, fork adoption, wire-mode fallbacks, subagent self-registration)
    • opencode-v2.ts ×5 (window-limit degradation, forkAdopter callback, WS-handshake-hook unavailable, conditional-tool registration rejected [checklist], /acp command registration unavailable)
    • opencode-native.ts ×8 (conflicting configuration, proxy-unavailable direct, bootstrap failed, attach healthy/down/unhealthy, model-channel pinned, v1 baseURL rewrite notice)
    • opencode.ts ×2 (respawn failed, no-live-bili-proxy route warning)
    • pi-native.ts ×6 and omp-native.ts ×5 (bootstrap/attach/rebinding + legacy bcp co-residence warning)
    • native-ws-intercept.ts ×4 (WS constructor threw [checklist], bootstrap-not-settled direct send, non-constructor replacement, third-party WS adopt)
    • pi-subagents.ts ×1 (unreadable user config)
  • Message texts are byte-identical everywhere — only the channel changes; anyone grepping these strings finds them in bili.log.

Behavior changes (old → new) — mandatory disclosure

Class Old New Why
All mid-session lane diagnostics listed above written to the host terminal (stdout/stderr), polluting the active TUI appended to the shared bili.log; terminal stays clean GUI hosts swallow stderr anyway; TUI hosts get polluted mid-session; bili.log + web UI remain the documented diagnostic channel (#2827/#2829 precedent)
dsh-native double-written sites terminal + file file only the terminal copy was the pollution vector; the file copy already existed
dsh manifest registration failed terminal only file (copy added) retry-loop diagnostic; invisible to GUI users before

Kept on the terminal by design (startup-time or sole-channel deliverables, not diagnostics):

  • Startup banners: plugin active, v1: fetch patch installed, v1 active, v1: no live proxy at startup, v1: zod unavailable, extension-load-time registerProvider failures, BILI_PROVIDER_REWRITES invalid JSON.
  • dsh boot-time unresolved-schemes reminder (fires once at boot, before the TUI takes over).
  • /acp & /acp-cache render-failure errors + missing-sessionID notices (opencode lanes): when rendering fails, the host render channel IS the only user-visible surface — silencing it would make total failure invisible.
  • pi-subagents acp.json deprecation warning (once per process at load; actionable config-migration notice).

Product-decision items flagged for owner (the issue explicitly punts these): (a) whether the kept startup banners should also be demoted to file/debug-only; (b) I judged the two opencode-v2 capability warnings (WS handshake hook unavailable, /acp command registration unavailable) as diagnostics rather than user-must-see deliverables and routed them to the file — trivially reversible if the owner disagrees.

Tests

  • Six suites migrated from console-capture to hermetic bili.log-file assertions (XDG_STATE_HOME redirect), each additionally asserting the terminal surface stays clean: agent-providers, dsh-native, issue1569-window-stamp-and-anchor, issue1958-routed-warn, opencode-native, opencode-v2 — mirroring fix(#2827): route native fetch-chain diagnostics to bili.log instead of console.* #2829's pattern in native-intercept-selfheal.test.ts.
  • Local targeted run: 217/217 green across all affected suites plus adjacent suites touching the converted paths (fork-adoption ×3, dsh recovery/spawn-retry, pi-subagent-registry, opencode launcher/v1). Typecheck clean. Full suite + e2e gates left to CI.

No config-surface change. No wire/message-shape 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_native-lane-console-sites (5a46c5b)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3255-pr.2841.cfb2b8f

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-pr2841.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 #2841 复审结论:发现并修复了我自己上一版遗漏的两处测试迁移

背景:#2841 是我(ework-daemon)为 #2831 开的 PR。按「识别自己的 PR」规则,本次是核对代码 + CI + 报告,不重做。核对时发现 CI 四个 test 矩阵全红,定位后确认是我的 commit d27b6c798 测试迁移不完整——已修复并 push(新 head aa2dc5772,CI 重跑中,当前 pending)。

八问:

  1. 是什么问题:PR 把若干 native-lane 诊断从 console.* 改写到 bili.log,但漏迁了两个测试文件——它们仍用 console.warn monkeypatch 抓终端输出再断言;诊断已进文件、终端为空,断言落空。
  2. 什么原因导致的:d27b6c798 只迁了 6 个套件,漏了 tests/plugin-agent.test.ts(pi-native: tools register once per session id, so a pi tool-registry rebuild silently removes compress/decompress/... for the rest of the session #2708 self-heal)与 tests/pi-omp-fork-adopt.test.ts([Bug][pi] fork adoption masks the root cause of snapshot 409; lineage-only subtask falsely triggered and Responses clien | [Bug][pi] fork adoption 隐藏 snapshot 409 原因,lineage-only 子任务误触发且 Responses 客户端未支持 #2469 lineage-only skip)。对应源点 src/agent/pi.ts:628("dropped from the host registry")和 pi.ts:1191("lineage-only child")现走 logHostEvent(文件),终端捕获数组恒空 → 断言失败。确定性失败,故 4 平台同红。
  3. 影响范围与严重程度:仅 CI 门禁。上线行为本身正确(诊断确实写进了文件,正是本 PR 意图);只是两个回归测试在错误的面上断言。严重度 = 挡住合并,无运行时 / 用户影响。触发条件 = 任何完整测试跑(所有平台)。
  4. 怎么修复的:把这两个测试改成既定模式——断言该行出现在 $XDG_STATE_HOME/billion-context/bili.log 且不出现在终端捕获。pi-native: tools register once per session id, so a pi tool-registry rebuild silently removes compress/decompress/... for the rest of the session #2708 用 withEnv({ XDG_STATE_HOME: mkdtemp }) 包住 before_provider_headers 再读日志;[Bug][pi] fork adoption masks the root cause of snapshot 409; lineage-only subtask falsely triggered and Responses clien | [Bug][pi] fork adoption 隐藏 snapshot 409 原因,lineage-only 子任务误触发且 Responses 客户端未支持 #2469 直接读 h.dir/billion-context/bili.log(harness 本就按 run 隔离 XDG)。语义原样保留:pi-native: tools register once per session id, so a pi tool-registry rebuild silently removes compress/decompress/... for the rest of the session #2708 仍断言 drop 有记录且点名 "compress";[Bug][pi] fork adoption masks the root cause of snapshot 409; lineage-only subtask falsely triggered and Responses clien | [Bug][pi] fork adoption 隐藏 snapshot 409 原因,lineage-only 子任务误触发且 Responses 客户端未支持 #2469 仍断言恰好一行(两次请求 verdict 只算一次)且含 sub-sid。另补「终端零字节」断言,与已迁的 6 套件对齐做回归护栏。本地两文件全绿(91/91)。
  5. 是否有回归问题:无。只改了 2 个测试文件的断言来源(console→file),未动任何 src/,无 wire / config / kernel / persistence 变更。被测行为(self-heal 重注册、once-per-sid fork verdict 缓存)不变,只是观察日志的位置变了。首个全量跑显示这两条是 6382 个用例里仅有的 2 个失败。
  6. 是否破坏缓存:不涉及——未触碰 cache / retry / cursor / dedup。
  7. 是否改了设计方向:无——这正是补齐本 PR 自己声明的意图(诊断进文件 + 迁移全部受影响断言),无架构转向。
  8. 是否引入新配置:无——没有新增 env / config / CLI。(XDG_STATE_HOME 是既有标准变量,6 个已迁套件本就在用。)

收工判定:修复已作为增量 commit aa2dc5772 推到 PR 分支,CI 重跑中(pending)。转绿后即可合并——但合并按规矩留给人工。注意:本 PR 仍叠在未合并的 #2829 之上,宜随 / 在 #2829 之后落地(届时 diff 收敛到我的两个 commit + 本次修复)。

过程说明:本地只做定向复现(先跑单套件区分「模块级 vs 断言级」失败,再全量一次定位失败点,最后定向重跑验证),符合本地测试纪律。

来源核对:#2831(原始 issue)→ 本 PR #2841。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 补充(CI 进展):新 head aa2dc5772 的 test 矩阵已出结果——test (ubuntu-latest, 24) 与 test (ubuntu-latest, 22) 均 success(这两台正是之前全红的机器),确认修复生效。两台 Windows 仍在跑(runner 较慢),但代码用的是跨平台正确的 path.join / os.tmpdir(),且与已迁的 6 个套件同一模式,预期同样绿。全绿后本 PR 即可合并(合并留给人工)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 全绿,收工。 head aa2dc5772 的 28/28 checks 全部 success(含四个 test 矩阵:ubuntu-24/ubuntu-22/windows-24/windows-22),零失败。之前全红的根因(d27b6c798 漏迁 plugin-agent.test.ts #2708 与 pi-omp-fork-adopt.test.ts #2469 两处 console-capture 断言)已由本次增量 commit 修复并验证。

判定:PR #2841 现已可合并——合并按规矩留给人工。提醒:本 PR 仍叠在未合并的 #2829 之上,宜随 / 在 #2829 之后落地(届时 diff 收敛到我的两个 commit + 本次修复)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

冲突

ework-agent added 3 commits October 12, 2026 19:05
… 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.
…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.
…to bili.log

Completes the #2831 test migration: plugin-agent.test.ts (#2708 self-heal) and pi-omp-fork-adopt.test.ts (#2469 lineage-only skip) still captured the now-file-routed diagnostics via a console.warn monkeypatch, so their terminal capture came back empty and failed on all 4 CI matrix platforms. Assert against $XDG_STATE_HOME/billion-context/bili.log instead (file-present + terminal-absent), matching the six already-migrated suites.
@ranxianglei
ranxianglei force-pushed the 2026-10-12_native-lane-console-sites branch from aa2dc57 to 5a46c5b Compare October 12, 2026 11:15
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷

上游冲突已解决 — 已将本 PR rebase 到当前 master,零文本冲突;PR 现可直接叠于最新 master(不再依赖之前未合并的 #2829)。

是什么问题
不是代码缺陷,是分支落后:master 在我开这个 PR 之后前进了约 40 个 PR(其中 #2829 已被合并),而我的 PR base 还停在旧 master,GitHub 因此报 merge_conflict。

什么原因导致
我分支底部原本带有一个 #2827/#2829(fetch-chain 路由)commit。#2829 合入 master 后这个 commit 变成冗余;同时我的测试迁移是基于旧 master 的 helper 形态写的,必须重新落到新 master 上才能对齐。

影响范围与严重程度
仅 PR 分支自身需要重放,没有任何已发布行为变化。冲突属「分支落后」型而非逻辑冲突——实际 rebase 零文本冲突。

怎么修复的
git rebase --onto origin/master <#2829-commit>:丢弃与 master 重复的那个 #2829 commit,只把属于 #2831 的 3 个 commit 重放到当前 master。旧历史保留在备份 ref backup/pre-rebase-2841(= aa2dc57)。用 --force-with-lease 推送更新 PR(只动我自己的 PR 分支,绝不碰 master)。新 head 5a46c5bd0。

是否有回归问题

是否破坏缓存:不涉及(无游标/去重键/重试策略改动)。

是否改了设计方向:不变。仍是把各 native-lane 诊断从 terminal 收敛到 bili.log、并统一到单一共享 helper;差别只是现在直接叠在当前 master 上。

是否引入了新的配置:无(无新 env/config/默认值)。

判定:冲突已解除,mergeable=true,PR 现干净叠于最新 master;等 CI 在新 head 5a46c5bd0 上跑绿即可由你合并(合并按规约由人操作)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷

CI 状态更新:新 head 5a46c5bd0 上 32 项检查已 31 绿、零失败;四个 test 矩阵里 ubuntu-24 / ubuntu-22 / windows-24 均已通过,只剩最慢的 test (windows-latest, 22)(全量套件)还在收尾——本机我已对受影响的 8 个套件做过定向验证(194/194)+ typecheck 通过,且四个矩阵里其余三个全绿,故该项预计随到随绿。

冲突已解除、mergeable=true,PR 现干净叠于最新 master,可放心合并(合并按规约由你操作)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷

已核查当前真实状态:这条「冲突」是 force-push 之后 GitHub 重算 mergeability 时的瞬时标记,不是现存冲突。实测:

  • base = 当前 master 9972ff2df(即我上次 rebase 的目标;此后 master 未再前进,0 个新提交);
  • mergeable = true / mergeable_state = clean(无冲突);
  • CI 在新 head 5a46c5bd0 上 32/32 全绿、零失败,无进行中项。

无需再处理,PR 现已干净叠于最新 master、可直接合并(合并按规约由你操作)。若你的界面仍显示冲突徽标,刷新一下即可——GitHub 侧已是 clean。

@ranxianglei
ranxianglei merged commit fbba1f7 into master Oct 12, 2026
32 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.329-master.fbba1f7 (rolling master tag).

npm install -g billion-context@0.0.329-master.fbba1f7  # 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][native lane] #2827 同机制的剩余面:其他 native 车道的会话中途 console.* 仍直写宿主终端

1 participant