bug: delegate_task fails with NotFoundError when using external OpenCode Server #8071

Closed
opened 2026-02-16 18:09:05 -05:00 by yindo · 6 comments
Owner

Originally created by @cooooooooooode on GitHub (Jan 30, 2026).

Originally assigned to: @adamdotdevin on GitHub.

Description

When connecting OpenCode Desktop App to an external OpenCode Server, calling delegate_task fails with NotFoundError, indicating that session files cannot be found. The error message shows that the system is searching for session files in the wrong project directory.

OpenCode version

OpenCode Desktop v1.1.45

Steps to reproduce

  1. Start OpenCode Server from project A:

    cd /path/to/projectA
    opencode serve
    
  2. Open OpenCode Desktop App and connect to the external server (http://localhost:4096)

  3. In the Desktop App, open project B (different from project A)

  4. Create a session in project B and perform an action that calls delegate_task

  5. Error occurs:

    NotFoundError: Resource not found: /Users/xxx/.local/share/opencode/storage/session/2c0eea82.../ses_xxx.json
    

The hash 2c0eea82... in the error path corresponds to project A's directory, but the session was actually created in project B.

Screenshot and/or share link

Error stack trace:

200 |   async function withErrorHandling<T>(body: () => Promise<T>) {
201 |     return body().catch((e) => {
202 |       if (!(e instanceof Error)) throw e
203 |       const errnoException = e as NodeJS.ErrnoException
204 |       if (errnoException.code === "ENOENT") {
205 |         throw new NotFoundError({ message: `Resource not found: ${errnoException.path}` })
                    ^
NotFoundError: NotFoundError
 data: {
  message: "Resource not found: /Users/xxx/.local/share/opencode/storage/session/2c0eea82d3c8202f8ebde7f7df0f58791cefa314/ses_3fc7f0023ffefWOpwUd2aM8GWC.json",
}

      at <anonymous> (src/storage/storage.ts:205:15)

Operating System

macOS

Terminal

OpenCode Desktop App

Originally created by @cooooooooooode on GitHub (Jan 30, 2026). Originally assigned to: @adamdotdevin on GitHub. ### Description When connecting OpenCode Desktop App to an external OpenCode Server, calling `delegate_task` fails with `NotFoundError`, indicating that session files cannot be found. The error message shows that the system is searching for session files in the wrong project directory. ### OpenCode version OpenCode Desktop v1.1.45 ### Steps to reproduce 1. Start OpenCode Server from project A: ```bash cd /path/to/projectA opencode serve ``` 2. Open OpenCode Desktop App and connect to the external server (http://localhost:4096) 3. In the Desktop App, open project B (different from project A) 4. Create a session in project B and perform an action that calls `delegate_task` 5. Error occurs: ``` NotFoundError: Resource not found: /Users/xxx/.local/share/opencode/storage/session/2c0eea82.../ses_xxx.json ``` The hash `2c0eea82...` in the error path corresponds to project A's directory, but the session was actually created in project B. ### Screenshot and/or share link Error stack trace: ```typescript 200 | async function withErrorHandling<T>(body: () => Promise<T>) { 201 | return body().catch((e) => { 202 | if (!(e instanceof Error)) throw e 203 | const errnoException = e as NodeJS.ErrnoException 204 | if (errnoException.code === "ENOENT") { 205 | throw new NotFoundError({ message: `Resource not found: ${errnoException.path}` }) ^ NotFoundError: NotFoundError data: { message: "Resource not found: /Users/xxx/.local/share/opencode/storage/session/2c0eea82d3c8202f8ebde7f7df0f58791cefa314/ses_3fc7f0023ffefWOpwUd2aM8GWC.json", } at <anonymous> (src/storage/storage.ts:205:15) ``` ### Operating System macOS ### Terminal OpenCode Desktop App
yindo added the web label 2026-02-16 18:09:05 -05:00
yindo closed this issue 2026-02-16 18:09:05 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 30, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #8538: Session lookup fails with NotFoundError when PTY spawned from non-git directory context (similar root cause - session lookup using wrong project directory)
  • #7773: Service crashes on missing session file (NotFoundError) (related NotFoundError handling)
  • #10959: delegate_task not working for windows 11! (similar delegate_task failure)

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 30, 2026): This issue might be a duplicate of existing issues. Please check: - #8538: Session lookup fails with NotFoundError when PTY spawned from non-git directory context (similar root cause - session lookup using wrong project directory) - #7773: Service crashes on missing session file (NotFoundError) (related NotFoundError handling) - #10959: delegate_task not working for windows 11! (similar delegate_task failure) Feel free to ignore if none of these address your specific case.
Author
Owner

@manascb1344 commented on GitHub (Jan 31, 2026):

Facing the same issue

@manascb1344 commented on GitHub (Jan 31, 2026): Facing the same issue
Author
Owner
@manascb1344 commented on GitHub (Jan 31, 2026): Linking some related issues for reference: https://github.com/anomalyco/opencode/issues/8538 https://github.com/anomalyco/opencode/issues/7773 https://github.com/code-yeongyu/oh-my-opencode/issues/1215 https://github.com/code-yeongyu/oh-my-opencode/issues/1264
Author
Owner

@ArielSulton commented on GitHub (Feb 1, 2026):

i got the same issue

@ArielSulton commented on GitHub (Feb 1, 2026): i got the same issue
Author
Owner

@benoitheinrich commented on GitHub (Feb 4, 2026):

Repro confirmation on v1.1.51 (Desktop/Web -> external server)

Summary

  • Still reproducible when OpenCode Desktop/Web connects to external server (http://127.0.0.1:4096).
  • Lookup resolves under session/global, causing NotFoundError.
  • Initializing a git repo in the launch directory does not fix it.

Sanitized stack excerpt

NotFoundError: NotFoundError
data: {
  message: "Resource not found: ~/.local/share/opencode/storage/session/global/ses_<id>.json",
}

    at <anonymous> (src/storage/storage.ts:205:15)

Minimal repro

  1. Start external server and web/desktop UI (latest):
    • opencode upgrade && opencode web (server listening at 127.0.0.1:4096)
    • Connect Desktop/Web UI to http://127.0.0.1:4096
  2. Create a session and perform an operation that triggers a session read (e.g., session.get/messages, delegate_task)
  3. Observe NotFoundError reading from storage/session/global/ses_<id>.json

Notes

  • git init in the launch directory does not change the outcome here.
  • This aligns with directory/context propagation gaps discussed in this issue (SDK/UI → server): when the server resolves Instance.project.id to "global", subsequent session reads go to session/global/... instead of the originating project directory.

Environment

  • OpenCode v1.1.51
  • Linux (web/desktop connected to external server at 127.0.0.1:4096)

Suggestions (concise)

  • Ensure directory context is consistently sent for all session endpoints (header/query) from SDK and Desktop/Web.
  • Server-side fallback: sessionID→projectID index or cross-project lookup when a read under current context fails.

[ref: session/global]

@benoitheinrich commented on GitHub (Feb 4, 2026): Repro confirmation on v1.1.51 (Desktop/Web -> external server) Summary - Still reproducible when OpenCode Desktop/Web connects to external server (http://127.0.0.1:4096). - Lookup resolves under session/global, causing NotFoundError. - Initializing a git repo in the launch directory does not fix it. Sanitized stack excerpt ``` NotFoundError: NotFoundError data: { message: "Resource not found: ~/.local/share/opencode/storage/session/global/ses_<id>.json", } at <anonymous> (src/storage/storage.ts:205:15) ``` Minimal repro 1) Start external server and web/desktop UI (latest): - `opencode upgrade && opencode web` (server listening at 127.0.0.1:4096) - Connect Desktop/Web UI to http://127.0.0.1:4096 2) Create a session and perform an operation that triggers a session read (e.g., session.get/messages, delegate_task) 3) Observe NotFoundError reading from `storage/session/global/ses_<id>.json` Notes - `git init` in the launch directory does not change the outcome here. - This aligns with directory/context propagation gaps discussed in this issue (SDK/UI → server): when the server resolves Instance.project.id to "global", subsequent session reads go to `session/global/...` instead of the originating project directory. Environment - OpenCode v1.1.51 - Linux (web/desktop connected to external server at 127.0.0.1:4096) Suggestions (concise) - Ensure directory context is consistently sent for all session endpoints (header/query) from SDK and Desktop/Web. - Server-side fallback: sessionID→projectID index or cross-project lookup when a read under current context fails. [ref: session/global]
Author
Owner

@maou-shonen commented on GitHub (Feb 5, 2026):

I've encountered the same issue and traced it to a more specific root cause.

Finding: In opencode web mode, when a child session is created with ?directory= query parameter, subsequent POST /session/{id}/message returns HTTP 200 with Content-Length: 0 (empty body). Without the directory parameter, the same endpoint works correctly.

Controlled experiment (only variable is directory):

POST /session                              → prompt ✅ body=1261 bytes
POST /session?directory=/home/user/project → prompt ❌ body=0 bytes
POST /session?directory=/home/user         → prompt ❌ body=0 bytes

Full reproduction steps and details in #12271.

@maou-shonen commented on GitHub (Feb 5, 2026): I've encountered the same issue and traced it to a more specific root cause. **Finding**: In `opencode web` mode, when a child session is created with `?directory=` query parameter, subsequent `POST /session/{id}/message` returns HTTP 200 with `Content-Length: 0` (empty body). Without the `directory` parameter, the same endpoint works correctly. Controlled experiment (only variable is `directory`): ``` POST /session → prompt ✅ body=1261 bytes POST /session?directory=/home/user/project → prompt ❌ body=0 bytes POST /session?directory=/home/user → prompt ❌ body=0 bytes ``` Full reproduction steps and details in #12271.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8071