You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
opencode run --agent crashes with "InstanceRef not provided" #27833
opencode run --agent <name> crashes with InstanceRef not provided, while opencode run "message" (without --agent) works fine.
Reproduction
# ✅ Works
opencode run "hi"# ❌ Crashes
opencode run --agent myagent "hi"# ❌ Crashes
opencode run --agent myagent --model 'provider/model''message'
Output:
Error: Unexpected error, check log file at /home/.../.local/share/opencode/log/...log for more details
InstanceRef not provided
Environment
opencode version: 1.15.1
Root Cause
Commit 0c9cfe923 (refactor(instance): remove legacy runtime fallback #27757) removed Instance.restore() ALS fallback in effect-cmd.ts. The handler now calls AppRuntime.runPromise(opts.handler(args).pipe(Effect.provideService(InstanceRef, ctx))) directly without the ALS bridge.
In packages/opencode/src/cli/cmd/run.ts, the localAgent() function (line 507-529) is called inside Effect.promise(async () => { ... }). It does:
Effect.runPromise() creates a new fiber that does not inherit the parent fiber's InstanceRef context. Without the ALS fallback, InstanceRef is lost across this async boundary, causing agentSvc.get(name) to fail when it internally tries to access InstanceRef.
Without --agent, localAgent() returns undefined immediately and never calls Effect.runPromise, so the bug doesn't trigger.
Suggested Fix
In run.ts, capture InstanceRef before entering the Effect.promise block and re-provide it when calling Effect.runPromise:
// In the handler, before Effect.promise:constinstanceCtx=yield*InstanceRef// Then inside localAgent(), change:constentry=awaitEffect.runPromise(agentSvc.get(name))// To:constentry=awaitEffect.runPromise(agentSvc.get(name).pipe(Effect.provideService(InstanceRef,instanceCtx)))
Alternatively, move localAgent() out of the Effect.promise block entirely so it runs in the outer Effect fiber where InstanceRef is available.
Activity
github-actions commentedon May 16, 2026
This issue might be a duplicate of existing issues. Please check:
opencode run --agent, same regression introduced by the same commitIf this is the same issue, please consider adding any additional reproduction details or context to #27829 instead.
javazys commentedon May 16, 2026
Duplicate of #27829 — same root cause (0c9cfe9 removed Instance.restore ALS fallback).