[PR #9474] fix(session): add cross-project session lookup with fallback search #13121

Open
opened 2026-02-16 18:17:59 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/9474

State: open
Merged: No


What does this PR do?

Fixes session lookup failing when sessions are accessed from a different project context (e.g., SDK clients connecting to opencode serve from different directories).

Problem: Session.get() uses Instance.project.id directly, causing NotFoundError when sessions are stored in a different project directory than the current context.

Solution:

  • Add resolveProjectID() helper that searches project directories to find the session
  • LRU cache (1000 entries) for resolved projectIDs to avoid repeated directory scans
  • Update get(), update(), remove() to use the helper

Fixes #8538
Related to #7773

Credit: This builds on the approach identified by @zenyr in #3018. That PR falls back to [current_project, "global"] only. This PR extends the fallback to search all project directories and adds caching for performance.

How did you verify your code works?

  1. Started opencode serve in project A
  2. Connected via SDK from project B context and attempted to access sessions created in project A - got NotFoundError
  3. After fix: Sessions resolve correctly across project contexts
  4. Build passes: ./packages/opencode/script/build.ts --single
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/9474 **State:** open **Merged:** No --- ### What does this PR do? Fixes session lookup failing when sessions are accessed from a different project context (e.g., SDK clients connecting to `opencode serve` from different directories). **Problem:** `Session.get()` uses `Instance.project.id` directly, causing `NotFoundError` when sessions are stored in a different project directory than the current context. **Solution:** - Add `resolveProjectID()` helper that searches project directories to find the session - LRU cache (1000 entries) for resolved projectIDs to avoid repeated directory scans - Update `get()`, `update()`, `remove()` to use the helper Fixes #8538 Related to #7773 **Credit:** This builds on the approach identified by @zenyr in #3018. That PR falls back to `[current_project, "global"]` only. This PR extends the fallback to search all project directories and adds caching for performance. ### How did you verify your code works? 1. Started `opencode serve` in project A 2. Connected via SDK from project B context and attempted to access sessions created in project A - got `NotFoundError` 3. After fix: Sessions resolve correctly across project contexts 4. Build passes: `./packages/opencode/script/build.ts --single`
yindo added the pull-request label 2026-02-16 18:17:59 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13121