Specify an agent when attaching to server fails #4019

Open
opened 2026-02-16 17:42:19 -05:00 by yindo · 10 comments
Owner

Originally created by @mschenk42 on GitHub (Dec 30, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

This worked reliably until recently. I believe it might be related to this PR https://github.com/sst/opencode/pull/5843.

The primary agent explore is only available in the server being connected to.

opencode run --print-logs --attach "http://ssds-meta-store-api:4096" --model "mercury-sa/Claude-4.5-Opus" --agent "explore"  "lightning"
INFO  2025-12-30T23:37:29 +381ms service=default version=1.0.217 args=["run","--print-logs","--attach","http://ssds-meta-store-api:4096","--model","mercury-sa/Claude-4.5-Opus","--agent","explore","lightning"] opencode
ERROR 2025-12-30T23:37:29 +385ms service=default name=instance message=No context found for instance stack=instance: No context found for instance
    at use (src/util/context.ts:16:21)
    at directory (src/project/instance.ts:41:20)
    at <anonymous> (src/project/instance.ts:50:31)
    at <anonymous> (src/project/state.ts:14:19)
    at get (src/agent/agent.ts:281:12)
    at get (src/agent/agent.ts:280:29)
    at <anonymous> (src/cli/cmd/run.ts:230:35)
    at <anonymous> (src/cli/cmd/run.ts:228:48)
    at <anonymous> (src/cli/cmd/run.ts:247:21)
    at async <anonymous> (src/cli/cmd/run.ts:311:20)
    at processTicksAndRejections (native:7:39) fatal
Error: Unexpected error, check log file at  for more details

instance: No context found for instance
      at use (src/util/context.ts:16:21)
      at directory (src/project/instance.ts:41:20)
      at src/project/instance.ts:50:31
      at src/project/state.ts:14:19
      at get (src/agent/agent.ts:281:12)
      at get (src/agent/agent.ts:280:29)
      at src/cli/cmd/run.ts:230:35
      at src/cli/cmd/run.ts:228:48
      at src/cli/cmd/run.ts:247:21
      at src/cli/cmd/run.ts:311:20
      at processTicksAndRejections (native:7:39)

OpenCode version

1.0.217

Steps to reproduce

opencode run --print-logs --attach "http://ssds-meta-store-api:4096" --model "mercury-sa/Claude-4.5-Opus" --agent "explore"  "lightning"

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Originally created by @mschenk42 on GitHub (Dec 30, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description This worked reliably until recently. I believe it might be related to this PR https://github.com/sst/opencode/pull/5843. The primary agent `explore` is only available in the server being connected to. ``` opencode run --print-logs --attach "http://ssds-meta-store-api:4096" --model "mercury-sa/Claude-4.5-Opus" --agent "explore" "lightning" INFO 2025-12-30T23:37:29 +381ms service=default version=1.0.217 args=["run","--print-logs","--attach","http://ssds-meta-store-api:4096","--model","mercury-sa/Claude-4.5-Opus","--agent","explore","lightning"] opencode ERROR 2025-12-30T23:37:29 +385ms service=default name=instance message=No context found for instance stack=instance: No context found for instance at use (src/util/context.ts:16:21) at directory (src/project/instance.ts:41:20) at <anonymous> (src/project/instance.ts:50:31) at <anonymous> (src/project/state.ts:14:19) at get (src/agent/agent.ts:281:12) at get (src/agent/agent.ts:280:29) at <anonymous> (src/cli/cmd/run.ts:230:35) at <anonymous> (src/cli/cmd/run.ts:228:48) at <anonymous> (src/cli/cmd/run.ts:247:21) at async <anonymous> (src/cli/cmd/run.ts:311:20) at processTicksAndRejections (native:7:39) fatal Error: Unexpected error, check log file at for more details instance: No context found for instance at use (src/util/context.ts:16:21) at directory (src/project/instance.ts:41:20) at src/project/instance.ts:50:31 at src/project/state.ts:14:19 at get (src/agent/agent.ts:281:12) at get (src/agent/agent.ts:280:29) at src/cli/cmd/run.ts:230:35 at src/cli/cmd/run.ts:228:48 at src/cli/cmd/run.ts:247:21 at src/cli/cmd/run.ts:311:20 at processTicksAndRejections (native:7:39) ``` ### OpenCode version 1.0.217 ### Steps to reproduce ``` opencode run --print-logs --attach "http://ssds-meta-store-api:4096" --model "mercury-sa/Claude-4.5-Opus" --agent "explore" "lightning" ``` ### Screenshot and/or share link _No response_ ### Operating System _No response_ ### Terminal _No response_
yindo added the bug label 2026-02-16 17:42:19 -05:00
Author
Owner

@mschenk42 commented on GitHub (Dec 30, 2025):

I traced this error to this version: https://github.com/sst/opencode/releases/tag/v1.0.181. The previous version, v1.0.180, worked perfectly.

@mschenk42 commented on GitHub (Dec 30, 2025): I traced this error to this version: https://github.com/sst/opencode/releases/tag/v1.0.181. The previous version, v1.0.180, worked perfectly.
Author
Owner

@mschenk42 commented on GitHub (Dec 31, 2025):

I conducted additional tests. The latest release is 1.0.219, and it fails for any agent. It appears that specifying the agent when using run with attach is no longer possible.

Image
@mschenk42 commented on GitHub (Dec 31, 2025): I conducted additional tests. The latest release is `1.0.219`, and it fails for any agent. It appears that specifying the agent when using `run` with `attach` is no longer possible. <img width="1465" height="868" alt="Image" src="https://github.com/user-attachments/assets/a327c440-3def-4d4a-adcd-6132911d020d" />
Author
Owner

@anntnzrb commented on GitHub (Dec 31, 2025):

Root Cause Analysis

This is a regression introduced in #5843. That PR added agent validation logic at run.ts:228-248 which calls Agent.get(args.agent). This function requires Instance context (via AsyncLocalStorage) that is established by bootstrap().

The problem: In attach mode (line 274), bootstrap() is never called - the code directly creates an SDK client and executes. Without bootstrap(), there's no Instance context, causing context.use() to throw NotFound.

Mode bootstrap() called? Instance Context? Agent.get() works?
Normal Yes Available Yes
Attach No Missing Crashes

Fix

PR #6541 skips local agent validation in attach mode, letting the remote server handle it instead.

CC @rekram1-node

@anntnzrb commented on GitHub (Dec 31, 2025): ## Root Cause Analysis This is a regression introduced in #5843. That PR added agent validation logic at `run.ts:228-248` which calls `Agent.get(args.agent)`. This function requires `Instance` context (via `AsyncLocalStorage`) that is established by `bootstrap()`. **The problem:** In attach mode (line 274), `bootstrap()` is never called - the code directly creates an SDK client and executes. Without `bootstrap()`, there's no `Instance` context, causing `context.use()` to throw `NotFound`. | Mode | `bootstrap()` called? | Instance Context? | `Agent.get()` works? | |------|----------------------|-------------------|---------------------| | Normal | Yes | Available | Yes | | Attach | No | Missing | Crashes | ## Fix PR #6541 skips local agent validation in attach mode, letting the remote server handle it instead. CC @rekram1-node
Author
Owner

@mschenk42 commented on GitHub (Jan 7, 2026):

This was fixed in the 1.1.4 release. Thank you!

Darn, meant this for another issue, this one is still broken :(. @rekram1-node can you reopen this? Sorry about that.

@mschenk42 commented on GitHub (Jan 7, 2026): This was fixed in the 1.1.4 release. Thank you! Darn, meant this for another issue, this one is still broken :(. @rekram1-node can you reopen this? Sorry about that.
Author
Owner

@mschenk42 commented on GitHub (Jan 7, 2026):

@rekram1-node As you can see, I've figured out how to reopen the issue. I wanted to ask if it would be possible to release this soon. Thanks again for everything you and your team are doing. This is great stuff!

@mschenk42 commented on GitHub (Jan 7, 2026): @rekram1-node As you can see, I've figured out how to reopen the issue. I wanted to ask if it would be possible to release this soon. Thanks again for everything you and your team are doing. This is great stuff!
Author
Owner

@mschenk42 commented on GitHub (Jan 9, 2026):

@rekram1-node I tested this with version 1.1.8, and it seems to be fixed. It no longer errors when providing an agent, but it doesn't execute the request and simply returns to the client. However, if I don't use the --agent flag, it respects the default agent set on the server. So, that's a good workaround for now.

@mschenk42 commented on GitHub (Jan 9, 2026): @rekram1-node I tested this with version 1.1.8, and it seems to be fixed. It no longer errors when providing an agent, but it doesn't execute the request and simply returns to the client. However, if I don't use the --agent flag, it respects the default agent set on the server. So, that's a good workaround for now.
Author
Owner

@Zak9O commented on GitHub (Jan 11, 2026):

I am on 1.1.12 and I am experiencing the same bug

@Zak9O commented on GitHub (Jan 11, 2026): I am on 1.1.12 and I am experiencing the same bug
Author
Owner

@bpalomino5 commented on GitHub (Jan 28, 2026):

i'm on 1.1.25 with the same issue

@bpalomino5 commented on GitHub (Jan 28, 2026): i'm on 1.1.25 with the same issue
Author
Owner

@alberti42 commented on GitHub (Feb 2, 2026):

Yes, indeed. The code crashes with a fatal error, but it remains silent. You only see in the log:

INFO  2026-02-02T14:10:28 +165ms service=default version=0.0.0-dev-fork-202602021405 args=["run","--format","json","--attach","http://localhost:4096","--log-level","DEBUG","--model","google/gemini-2.5-flash","--agent","shell_cmd_generator","--title","shell assistant","<user>personal prompt here</user>"] opencode
ERROR 2026-02-02T14:10:28 +221ms service=default name=instance message=No context found for instance stack=instance: No context found for instance
    at use (src/util/context.ts:16:21)
    at directory (src/project/instance.ts:46:20)
    at <anonymous> (src/project/instance.ts:67:31)
    at <anonymous> (src/project/state.ts:14:19)
    at get (src/agent/agent.ts:250:12)
    at <anonymous> (src/cli/cmd/run.ts:234:35)
    at <anonymous> (src/cli/cmd/run.ts:251:21)
    at async <anonymous> (src/cli/cmd/run.ts:338:20)
    at processTicksAndRejections (native:7:39) fatal
@alberti42 commented on GitHub (Feb 2, 2026): Yes, indeed. The code crashes with a fatal error, but it remains silent. You only see in the log: ```log INFO 2026-02-02T14:10:28 +165ms service=default version=0.0.0-dev-fork-202602021405 args=["run","--format","json","--attach","http://localhost:4096","--log-level","DEBUG","--model","google/gemini-2.5-flash","--agent","shell_cmd_generator","--title","shell assistant","<user>personal prompt here</user>"] opencode ERROR 2026-02-02T14:10:28 +221ms service=default name=instance message=No context found for instance stack=instance: No context found for instance at use (src/util/context.ts:16:21) at directory (src/project/instance.ts:46:20) at <anonymous> (src/project/instance.ts:67:31) at <anonymous> (src/project/state.ts:14:19) at get (src/agent/agent.ts:250:12) at <anonymous> (src/cli/cmd/run.ts:234:35) at <anonymous> (src/cli/cmd/run.ts:251:21) at async <anonymous> (src/cli/cmd/run.ts:338:20) at processTicksAndRejections (native:7:39) fatal ```
Author
Owner

@alberti42 commented on GitHub (Feb 2, 2026):

I posted a PR https://github.com/anomalyco/opencode/pull/11812 with a fix to this issue.

@alberti42 commented on GitHub (Feb 2, 2026): I posted a PR https://github.com/anomalyco/opencode/pull/11812 with a fix to this issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4019