[Bug] `ocx opencode` injects nothing when an opencode v2 background service is already running

Đang mở
#9,045 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
cli

Hướng nghiên cứu

Start in src/cli/opencode.ts at buildOpencodeEnv and the spawn(inv.file, inv.args, { env }) call around lines 696-704, then reproduce with the isolated XDG home in the report by starting an opencode background service before running ocx opencode debug config. Read how the launcher detects or connects to an existing service, and compare the --standalone and cold-autostart paths that already work. Done means a warm service either receives the generated provider.opencodex / providers.opencodex blocks or the launcher stops printing the success line and fails loudly; the fix approach still needs a maintainer decision.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug cli
Client or integration

Other

Area

CLI

Summary

ocx opencode reports that it wired the proxy and injected its provider blocks, but when an
opencode v2 background service is already running, the launched instance never sees those
blocks. The launcher's only output is a success line, so the failure is silent: the models it
just advertised are absent from the running opencode.

--standalone, and a cold start where no service exists yet, both work.

Reproduction

Isolated home so the test cannot touch a real config; opencode v2.3.2:

export XDG_STATE_HOME=/tmp/ocx-bug1/state XDG_DATA_HOME=/tmp/ocx-bug1/data \
       XDG_CONFIG_HOME=/tmp/ocx-bug1/config XDG_CACHE_HOME=/tmp/ocx-bug1/cache
mkdir -p "$XDG_STATE_HOME" "$XDG_DATA_HOME" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME"

# 1. Start the background service the way an earlier plain `opencode` run would.
opencode service set port 51177
opencode service start            # -> http://127.0.0.1:51177

# 2. Launch through the launcher against that warm service.
ocx opencode debug config > c.json
# stderr: "✅ opencode wired to http://127.0.0.1:10100/v1 — 3 model(s) under provider `opencodex`."

# 3. Look for the injected blocks in what the instance actually loaded.
python3 -c '
import json; d=json.load(open("c.json")); out=[]
for s in d:
    info=s.get("info") or {}
    for blk in ("provider","providers"):
        b=(info.get(blk) or {}).get("opencodex")
        if b: out.append((blk,len(b.get("models") or {})))
print("opencodex blocks visible:", out or "NONE")'
# -> opencodex blocks visible: NONE

Controls, same isolated home:

Scenario opencodex blocks loaded
Warm background service, then ocx opencode NONE
ocx opencode debug config --standalone providers, 3 models
Service stopped, then ocx opencode (cold autostart) providers, 3 models
Expected behavior

The launched opencode should load the generated provider.opencodex / providers.opencodex
blocks in every case, or the launcher should refuse to claim success when it cannot deliver them.

Observed behavior

With a warm service the blocks are dropped entirely, and the launcher still prints the success
line, so the user only finds out when the models are missing from the picker.

Likely cause

src/cli/opencode.ts builds the env and spawns opencode with it
(buildOpencodeEnv -> spawn(inv.file, inv.args, { env }), around line 696-704). That env reaches
the client process only. When an opencode v2 background service is already listening, the
client connects to that daemon and the daemon serves config it loaded when it started — before
any OPENCODE_CONFIG_CONTENT existed in its environment. opencode's own help describes
--standalone as "Run with a private server instead of the background service", which matches
the observed split.

What I ruled out

A restart-with-the-runtime-layer fix does not work, so it is not on the table. I started the
service with OPENCODE_CONFIG_CONTENT already set in its own environment, and the daemon still
loaded no opencodex blocks — the variable is not present in the daemon process at all. A
background service therefore cannot be told about the proxy by injection under any restarted
state, which leaves only genuinely different approaches.

Still open, and a maintainer's call: run a private server (--standalone) whenever a service is
warm, which guarantees the injected layer applies but gives up the shared session the service
provides; or make the launcher fail loudly instead of printing the success line when the blocks
cannot be applied; or write a static block through the managed integration path. Each has a real
cost, so this is a report rather than a proposal.

Workaround

A static exported block on disk is read by the service and does work:

ocx export --client opencode   # merge the two blocks into ~/.config/opencode/opencode.json

The catch is that export is a snapshot: it does not follow catalog or visibility changes.

Version

opencodex 2.100.8 (npm install). Also reproduced from a local dev checkout at 9e0e298e
(the current dev tip, package.json version 2.100.0, run as bun bin/ocx.mjs).

Operating system

macOS 27.2.0 (Darwin), Bun 1.4.4, opencode v2.3.2

Logs or error output
$ ocx opencode debug config
✅ opencode wired to http://127.0.0.1:10100/v1 — 3 model(s) under provider `opencodex`.
   Your existing opencode config files are left untouched; only the runtime provider blocks are injected.
RESULT opencodex blocks visible to the warm daemon: NONE
Checks
  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.
Ngôn ngữ chính
TypeScript
Star
16.9k
Fork
1.3k
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
814

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của lidge-jun/opencodex

Tất cả issue của lidge-jun/opencodex

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.