Skip to content

Add BILLION_CONTEXT_NATIVE stand-down guard (coexistence with bili native plugin) #438

Closed

Description

@ranxianglei

Problem

opencode-acp has two bili-related guards:

  1. Load-time: BILLION_CONTEXT_PROXY env → disabled
  2. Config hook: /bili/ prefix in provider baseURLs → disabledByBiliProxy + deny own tools

Neither checks BILLION_CONTEXT_NATIVE. billion-context's host-native plugin (bili plugin install opencode, ships in billion-context v0.1.x, see billion-context#918/#919) sets BILLION_CONTEXT_NATIVE=opencode synchronously at module load and spawns its proxy asynchronously, rewriting baseURLs in its own config hook.

What happens today when both are installed (manual case)

  • Load order opencode-acp first: its load-time check sees no BILLION_CONTEXT_PROXY (native's proxy isn't up yet) → stays armed. If its config hook also runs before the native plugin's rewrite, findBiliProxyProviders finds nothing → ACP stays armed for the whole process (guards are only re-evaluated on config reload).
  • Both register tool.compress/decompress/search_context/acp_status — last registration wins; hooks (experimental.chat.messages.transform etc.) from opencode-acp still run with ITS ref space while tools route to billion-context's kernel → double machinery / mismatched refs.

billion-context's installer now strips opencode-acp entries from the global opencode.json (74701fb), but project-local installs and hand-edited configs can still produce the conflict.

Suggested fix

Mirror the pi extension (billion-context-pi) behavior: in the config hook (and ideally each tool/hook action), also stand down when process.env.BILLION_CONTEXT_NATIVE === "opencode":

// config hook, alongside findBiliProxyProviders
if (process.env.BILLION_CONTEXT_NATIVE === "opencode") disabledByBiliProxy = true

The env var is set synchronously at native plugin module load, so by the time any config hook or LLM request runs it is visible regardless of plugin load order.

Repro

  1. opencode.json (global): "plugin": ["opencode-acp", "<configDir>/plugins/billion-context"] (the latter from bili plugin install opencode)
  2. Start opencode 1.18.31 with a provider that has an explicit baseURL
  3. Depending on hook order you get double-registered compress tools and/or both kernels armed

(Reported from billion-context PR #919 review — user spotted the coexistence hazard.)

Activity

  1. ranxianglei commented on Sep 18, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    重复判定:与 #405 一模一样,且修复已在 PR #406 实现(CI 全绿,待人工合并)。 建议关闭本条并打 重复 标签。

    共同点(一句话):两条指向同一根因——ACP 现有两个 bili guard(BILLION_CONTEXT_PROXY 加载期检查 + config hook 的 /bili/ baseURL 检查)都不看 BILLION_CONTEXT_NATIVE,与 billion-context native 模式共存时 ACP 不会退让、双压缩;解法也相同——动作时(config hook + 各 tool/hook 调用)依据该 env 退让。

    核对结果(对照当前 master 06efd39c):

    • 你的描述属实:index.ts:38 只在 setup 时读一次 BILLION_CONTEXT_PROXY;lib/bili-proxy.ts 只认 provider baseURL 里的 /bili/ 前缀;全仓库 BILLION_CONTEXT_NATIVE 出现 0 次——master 上确实没有这个 guard。
    • 你提议的修复(config hook + 每个 tool/hook 动作在 BILLION_CONTEXT_NATIVE === "opencode" 时退让)是 PR fix: yield to billion-context native mode via action-time env re-check (#405) #406 实现的严格子集。fix: yield to billion-context native mode via action-time env re-check (#405) #406 覆盖三处采样点(setup fast path、每次 hook 调用的 guard() 重采样、每次 config run 重采样)+ resolveToolContext() 单点拦截(全部 5 个工具 execute 的第一句),并顺带把 BILLION_CONTEXT_PROXY 也改为动作时重采样;非 latching(marker 移除即恢复);新增 10 个测试且经变异验证(回退修复后 7/10 失败)。
    • 你带来的新信息不改变所需改动:正因为 marker 落地时机取决于插件加载顺序,fix: yield to billion-context native mode via action-time env re-check (#405) #406 采用动作时重采样(而不是只在 config hook 采样)——hook 以何种顺序执行都命中;installer(74701fb)从全局 opencode.json 移除 opencode-acp 条目只是缩小冲突面(project-local 安装 / 手编配置仍靠这个 guard 兜底)。
    • 你提到的双注册风险(双方都注册 compress 系工具、last-wins、ref space 错配):退让后 ACP deny 全部自有工具 + 所有 hook no-op,压缩所有权完全交给 native,该风险随之消除。
    • PR fix: yield to billion-context native mode via action-time env re-check (#405) #406 现状(刚经 API 复核):open,head 32d94ac,CI 6 项全部 success(pr-validation / build / build-artifact / test 22 / test 24 / e2e);按仓库规范还差第二个独立 agent review + 人工合并,我不会代合并。

    本会话没有 issue 管理权限,无法代为执行关闭 / 打标签操作,请 @ranxianglei 按重复处置约定确认关闭。

    一句话总结:#438 与 #405 完全相同(同根因、同方案),所需 guard 已在 PR #406 实现且 CI 全绿,建议按重复关闭本条,评审精力集中在 #406 上。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions