Skip to content

fix: align opencode plugin-channel messaging with the accepted #1234 in-place self-update - #2208

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-06_opencode-cache-channel-consistency
Oct 6, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-06_opencode-cache-channel-consistency

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What & why

Fixes #2199 — the OpenCode plugin list / plugin update channel messaging contradicted the accepted #1234 decision (the v2 cache copy is bili-owned in place and self-updates through its own proxy), and disk vs running state were conflated.

Root cause was two-fold:

  1. hostManagedInstall() only recognized the opencode data-home tree (~/.local/share/opencode). The actual load path lives under XDG_CACHE_HOME (~/.cache/opencode/npm/billion-context@<spec>/<ts>/node_modules/billion-context), so the in-place exception depended on the cache path accidentally missing every host home — fragile and invisible from the code.
  2. The channel text still said "opencode owns the copy / never overwrites" (native模式下自动更新问题需要解决 #991 wording), which is false for the cache copy and reads as if a global update check had activated it.

Changes

  • src/update.ts — new isOpencodeCacheBiliCopy() recognizes the opencode cache home explicitly (XDG_CACHE_HOME + realpath, …/node_modules/billion-context) and returns bili-owned (self-update allowed); the data-home tree stays host-managed. The guard sits before the homes loop with a comment forbidding folding the cache path into homes (that would re-close Investigate: does the opencode lane auto-update, or is it an #1196-class silent freeze? #1234). Behavior-preserving: the cache path already fell through to undefined; this makes it explicit and regression-proof.
  • src/plugin-install.ts — rewrote UPDATE_CHANNEL[opencode] and the pluginUpdate opencode lane to say: the cache copy self-updates in place via its own proxy (Investigate: does the opencode lane auto-update, or is it an #1196-class silent freeze? #1234); OpenCode v2 plugin update is only an extra manual channel; reload/restart after a disk update to activate. Dropped "never overwrites". Added read-only opencodeCacheCopyRoot() (newest spec slot / newest timestamp) so doctor and plugin update report the actual load path + disk version instead of "version not resolvable". Updated the two single-writer comments to state the cache/data distinction.
  • src/doctor.ts — the opencode lane now shows the resolved cache copy path + disk version (enabling an honest stale verdict) plus the reload hint.
  • Tests — tests/update-host-guard.test.ts: cache layout (default + custom XDG_CACHE_HOME) → bili-owned, data-home → host-managed, global standalone unaffected. tests/plugin-update.test.ts: wording consistency (no "never overwrites"; has Investigate: does the opencode lane auto-update, or is it an #1196-class silent freeze? #1234/reload hint), opencodeCacheCopyRoot resolver (newest-wins, absent→undefined, non-bili slot ignored), and the plugin update opencode report end-to-end (surfaces the disk version, drops "never overwrites").

Behavior changes (flagged per policy)

  • bili doctor opencode lane: previously always ok + "copy managed by opencode's plugin manager (version not resolvable here)". Now, when a cache copy exists and the npm registry leads its on-disk version, the lane reports stale (vX → vY) and shows the actual load path + disk version. Intended honesty (part 3 of [OpenCode] plugin list/update 渠道提示与已接受的自更新行为不一致,磁盘与运行版本混淆 #2199), not a regression — ok when the cache copy is current is unchanged.
  • plugin list / plugin update opencode text: reworded as above. No status-detection or install-write-path change (opencodeStatus, pluginInstall untouched) — repeated bili plugin install opencode still only installs/repairs config.
  • No wire / persistence / config-schema change. No new env var or config key — reading XDG_CACHE_HOME is standard path resolution (same discipline as the existing XDG_DATA_HOME read), not a new knob.

Verified (local, targeted)

npm run typecheck clean · npm run build clean · targeted suites green: update-host-guard (14), plugin-update (7), doctor (12), plugin-install-opencode + issue927-opencode-install + plugin-agent (86). Full regression left to CI.

Closes #2199

…in-place self-update

The opencode v2 cache copy (~/.cache/opencode/npm/...) is bili-owned in place
and self-updates through its own proxy (#1234), but hostManagedInstall only
recognized the data-home tree (~/.local/share/opencode), so the in-place
exception relied on the cache path accidentally missing every host home. The
plugin list/update channel text still said "opencode owns the copy / never
overwrites", contradicting the accepted behavior and confusing disk vs running
state.

- recognize the opencode CACHE home explicitly (XDG_CACHE_HOME + realpath) and
  return bili-owned (self-update allowed); data-home stays host-managed (#1234)
- rewrite UPDATE_CHANNEL[opencode] + `plugin update opencode` to describe
  self-update-in-place + v2 manual channel + reload-to-activate; drop "never overwrites"
- surface the actual cache load path + disk version in doctor / `plugin update`
  (new read-only opencodeCacheCopyRoot); global-check success no longer reads as
  opencode-copy activation
- document the outer-lockfile vs inner-package accounting boundary
- regression tests: cache vs data-home vs global policy, wording consistency,
  cache-root resolver

Closes #2199
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-06_opencode-cache-channel-consistency (406ae9b)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2275-pr.2208.e02d166

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-pr2208.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] 🏷 Review 完成:方向正确、实现扎实、无回归发现;发现一个测试缺口已直接在 PR 分支修掉(commit 406ae9b6d)。判定:可合并(等 CI 在新提交上重跑绿;按 §7.4 触碰 src/update.ts 保持人工合并)。

结构化七问

1. 是什么问题:OpenCode 的 plugin list / plugin update 通道文案与已拍板的 #1234 决策(v2 cache 副本 bili-owned、经自身代理就地自更新)相矛盾——仍写着 #991 的 "opencode owns the copy / never overwrites";且诊断面看不到真实加载路径,doctor 永远报 "version not resolvable",磁盘态与运行态混为一谈。

2. 什么原因导致的(已在代码中逐层核实,非凭描述开工):

  • 机制层:hostManagedInstall() 的 homes 表里只有 opencode data-home($XDG_DATA_HOME/opencode),真正的加载路径在 $XDG_CACHE_HOME/opencode/npm/billion-context@<spec>/<ts>/node_modules/billion-context——cache 副本能享受就地自更新例外,纯粹是因为它碰巧不落在任何 host home 前缀下。例外成立与否对代码不可见、不可测。
  • 文案层:Investigate: does the opencode lane auto-update, or is it an #1196-class silent freeze? #1234 拍板后 UPDATE_CHANNEL[opencode] 与 updateLane 文案从未同步。

3. 怎么修复的(机制层面):把隐式例外显式化——新增 isOpencodeCacheBiliCopy()(XDG_CACHE_HOME + realpath,叶子锚定 node_modules/billion-context),置于 homes 循环之前,并带注释禁止把 cache 路径折进 homes(那会静默重关 #1234)。通道文案改写为「cache 副本就地自更新(#1234)+ v2 plugin update 只是额外手动通道 + 磁盘更新后需 reload/restart」。新增只读 opencodeCacheCopyRoot()(newest spec slot / newest timestamp)让 doctor 与 plugin update 报告真实加载路径 + 磁盘版本。守卫本身行为保持:此类路径此前也是 fall-through 到 undefined(bili-owned),现在只是把它钉死。

4. 是否有回归问题:无。既有行为清点(逐项读过改动前代码,非只读 diff):

  • hostManagedInstall 全部调用点(update.ts:1040/1065/1328/1630、doctor.ts:108):分类差异仅限 cache 锚点下的 billion-context 叶子路径,这些路径旧代码同样 fall-through 到 bili-owned → 行为保持。唯一角落差异:XDG_CACHE_HOME 嵌套在某 host home 内时,由 host-managed 翻转为 bili-owned——更正确(该副本确实从 cache 加载)。pnpm store 检测、dsh desktop 例外(dsh 渠道把桌面应用独占的 profiles/desktop 当普通 profile 驱动 —— 第二写者冲突 #1575)、其余 homes lane、npm global 安装均未触达(测试覆盖)。
  • inspectLanePresence("opencode") npm 分支 targets 从 [] 变为 [cacheRoot]:唯一消费者是 doctor.ts:141。后果即披露的 stale 判定能力;cache 不存在时 resolver 返回 undefined → targets 仍为空 → 判定不变(ok)。
  • 残留措辞扫描:全仓 "never overwrites" 仅剩 pi lane(pi 的 npm 副本确属 host-managed,保留正确)与 config.ts 一处无关幂等注释;"opencode owns"/"not resolvable here" 已清零。
  • opencodeStatus(plugin list)只报 installed/not installed,无所有权声明,无需改;pluginInstall 未动 → 重复安装仍是 config-only([OpenCode] plugin list/update 渠道提示与已接受的自更新行为不一致,磁盘与运行版本混淆 #2199 验收项满足)。
  • 陈旧基线核查:PR 基 5e43209 是当前 master(tip e5a0066)的祖先;master 自基线以来动了 149 个文件,但对本 PR 触碰的全部路径(src/update.ts、src/plugin-install.ts、src/doctor.ts、src/dsh-channel.ts、两个测试文件)git diff base..master 为空 → 无语义冲突风险,GitHub mergeable=true。
  • 高危模式逐项:无 fail-fast 变吞错、无阈值/时序漂移、无输出格式意外变更(仅有的输出变化均已披露)、wire/持久化零触碰。

5. 是否破坏缓存:不涉及——代理缓存、会话持久化、重试、去重键逻辑零触碰(本 PR 只动安装通道分类与诊断展示)。

6. 是否改了设计方向:没有。#1234 的方向(cache 副本 bili-owned in place)从"碰巧成立"变为"显式成立 + 回归测试钉死";单写者契约(#991/#1196)完整保留——data-home 树仍是 host-managed,两处单写者注释现在明确区分 cache/data 两棵树。

7. 是否引入了新的配置:没有。XDG_CACHE_HOME 读取是标准路径解析,与既有 XDG_DATA_HOME 读取(update.ts:489)同纪律,不是新 knob;CONFIGURATION.md 无需新增条目(docs-sync CI 已过)。

顺手修掉的测试缺口(小问题直接修,未另立项)

发现:本 PR 最大的行为变化——doctor opencode lane 的新 stale 判定 + 加载路径展示——没有任何测试钉住(doctor.test.ts 只覆盖 broken-probe 与空沙箱 absent;update-host-guard/plugin-update 钉的是分类与文案,不钉 doctor 接线)。若日后有人弄断 npm 分支的 targets/copyVersion 接线,CI 全绿而 doctor 悄悄退回谎报 ok。

处置:直接在 PR 分支补 commit 406ae9b6d(test(#2199): pin doctor opencode cache-copy stale verdict + load path):同一沙箱内双向钉死——registry 领先 → stale + detail 含真实加载路径 + 渲染出 stale (v0.1.143 → v999.0.0);registry 与磁盘同版 → 必须 ok(防 false-stale,对齐该文件既有的 unreachable-registry 先例)。本地定向验证:doctor 套件 13/13 绿、typecheck 干净;全量回归交 CI(已对新提交重跑)。

流程标记(给 owner 的一个判断点)

§5 规定改 src/update.ts 需先做 NO-OP 验证发布以证明升级链健康。我的评估:本改动可证明地不改升级机制——纯分类守卫,两侧都有回归测试(cache 布局 → bili-owned;data-home → host-managed),updater 本体(下载/校验/回滚/重启)零触碰,no-op 发布的立法目的(保护升级链)已由现有证据覆盖。是否豁免 no-op 前置请 owner 拍板;若不需要,本 PR 可直接人工合并。另按 §7.4,触碰 src/update.ts 的 PR 属 must-stay-human,不满足自动合并条件——这一点 PR 自身标注正确。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 补报(新提交 406ae9b)

新提交首跑 18/19 绿,唯一红:test (windows-latest, 24)。已定位并复跑,确认为环境性 flake,与本 PR 无关:

  • 唯一失败用例:python plugin runtime (subprocess) 里的 attach: registers the proxy tools, stamps gated headers, forwards tools, reports runtime info(hermes Python 插件子进程测试,tests/hermes-native.test.ts:434),耗时 60561ms —— 恰好等于该测试 runDriver 的 spawnSync 硬超时 timeout: 60_000(tests/hermes-native.test.ts:421)。Windows runner 负载下 Python+Node 双进程启动撞穿 60s 预算。
  • 同一次运行中:同套件其余 attach-* 变体全过、ubuntu-24 / windows-22 全绿、本 PR 新增的 doctor 测试在同一 windows job 里通过(✔ #2199: opencode npm lane surfaces... 18.37ms)。PR diff 与 hermes 代码路径零交集。
  • 处置:仅重跑失败 job → success,workflow run 37352989809 现已全绿(19/19)。

结论不变:可合并(§7.4:触碰 src/update.ts,人工合并;§5 no-op release 问题仍待 owner 拍板,我的评估见上条回复)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 补记:上条所述 hermes 测试 60s 超时预算的结构性脆弱(负载下会复发)已单独立项 → https://github.com/ranxianglei/billion-context/issues/2216(带来源标记)。本 PR 侧无遗留动作。

@ranxianglei
ranxianglei merged commit f704b43 into master Oct 6, 2026
27 of 28 checks passed
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.64-master.f704b43 (rolling master tag).

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