Skip to content

Specify an agent when attaching to server fails #6489

Closed

Description

@mschenk42

Description

This worked reliably until recently. I believe it might be related to this PR #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

Activity

  1. mschenk42 commented on Dec 31, 2025

    @mschenk42
    Author

    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.

  2. mschenk42 commented on Dec 31, 2025

    @mschenk42
    Author

    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
  3. anntnzrb commented on Dec 31, 2025

    @anntnzrb
    Contributor

    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

  4. mschenk42 commented on Jan 7, 2026

    @mschenk42
    Author

    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.

  5. mschenk42 commented on Jan 7, 2026

    @mschenk42
    Author

    @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!

  6. mschenk42 commented on Jan 9, 2026

    @mschenk42
    Author

    @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.

  7. koch-c commented on Jan 11, 2026

    @koch-c

    I am on 1.1.12 and I am experiencing the same bug

  8. added a commit that references this issue on Jan 13, 2026
    44dc124
  9. bpalomino5 commented on Jan 28, 2026

    @bpalomino5

    i'm on 1.1.25 with the same issue

  10. alberti42 commented on Feb 2, 2026

    @alberti42
    Contributor

    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
    
  11. alberti42 commented on Feb 2, 2026

    @alberti42
    Contributor

    I posted a PR #11812 with a fix to this issue.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions