Skip to content

Conversation

@oussamadouhou
Copy link

@oussamadouhou oussamadouhou commented Jan 19, 2026

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

Session.get() was failing when sessions were accessed from a different
project context (subagents, nested PTYs, SDK clients with different dir).

- Add resolveProjectID() helper that searches all project directories
- LRU cache (1000 entries) for resolved projectIDs
- Update get(), update(), remove() to use the helper

Fixes anomalyco#8538
Related to anomalyco#7773
Builds on approach from anomalyco#3018 by @zenyr
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

The search confirmed that PR #9474 (the current PR) is the only active PR addressing the cross-project session lookup issue. While PR #3018 appears in results as a related historical PR that implemented an earlier version of the fallback approach (as credited in the description), it is a distinct, prior implementation and not a duplicate.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session lookup fails with NotFoundError when PTY spawned from non-git directory context

1 participant