Skip to content

fix(opencode): strip directory query when proxying to remote workspace#26076

Open
MichielMAnalytics wants to merge 1 commit intoanomalyco:devfrom
MichielMAnalytics:fix/workspace-routing-strip-directory-query
Open

fix(opencode): strip directory query when proxying to remote workspace#26076
MichielMAnalytics wants to merge 1 commit intoanomalyco:devfrom
MichielMAnalytics:fix/workspace-routing-strip-directory-query

Conversation

@MichielMAnalytics
Copy link
Copy Markdown

@MichielMAnalytics MichielMAnalytics commented May 6, 2026

Issue for this PR

Closes #26075

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

workspaceProxyURL strips ?workspace= before forwarding a request to a remote workspace, but it doesn't strip ?directory=. The SDK rewrites the client's x-opencode-directory header into a ?directory= query for GET/HEAD (packages/sdk/js/src/v2/client.ts), so when a request flows through the workspace-routing middleware, the local client's directory leaks to the remote.

The remote then tries to resolve a path that doesn't exist on its filesystem, falls back to worktree: "/", and that broken path corrupts downstream path.relative() callers — most visibly sessionListQuery in the TUI sync context, which then returns no sessions and the session route renders empty.

Adding proxyURL.searchParams.delete("directory") next to the existing workspace strip lets the adapter's target.headers["x-opencode-directory"] (the workspace's own directory on the remote) win, which is the intended contract.

How did you verify your code works?

  • Added a unit test in packages/opencode/test/server/workspace-routing.test.ts asserting both workspace and directory are stripped. Full file: 16/16 pass via bun --cwd packages/opencode test test/server/workspace-routing.test.ts.
  • Reproduced the bug directly without the fix: curl 'https://<remote>/path?directory=<some-local-path-not-on-remote>' returns {"worktree": "/", ...}. Removing the directory param returns the correct workspace path. Confirms why the proxied request was triggering the wrong fallback.
  • Reproduced end-to-end with a custom remote WorkspaceAdapter: before the fix, /warp succeeded but the TUI showed a blank session view. After the fix, the session view renders correctly.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The SDK rewrites x-opencode-directory header to a ?directory= query for
GET/HEAD requests. When proxied to a remote workspace, the local path
leaks through, the remote can't resolve it, falls back to worktree="/",
and corrupts sessionListQuery's path.relative() — which empties the
TUI's session list and renders a black screen.

Add the directory strip alongside the existing workspace strip so the
adapter's target.headers["x-opencode-directory"] wins.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels May 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Bug: workspaceProxyURL forwards local 'directory' query to remote workspace, breaking sessionListQuery

1 participant