Skip to content

fix(opencode): web UI sidebar not showing session history#17752

Closed
762278834 wants to merge 1 commit intoanomalyco:devfrom
762278834:fix/web-session-list-empty
Closed

fix(opencode): web UI sidebar not showing session history#17752
762278834 wants to merge 1 commit intoanomalyco:devfrom
762278834:fix/web-session-list-empty

Conversation

@762278834
Copy link
Copy Markdown

@762278834 762278834 commented Mar 16, 2026

Issue for this PR

Closes #15108
Closes #14572
Related #11331

Type of change

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

What does this PR do?

Root cause: The /session route uses Session.list() which always filters by Instance.project.id (session/index.ts line 549). The project ID is derived from the directory where opencode serve is started.

Trigger condition: When the directory used to start opencode serve (directory A, a git repo) differs from the directory where sessions were created (directory B, not a git repo or a different git repo), the project IDs do not match. Sessions from directory B get project_id = "global", but the API filters by directory A's project ID (e.g. 4b0ea68...), so the query returns zero results.

This is easy to reproduce:

  1. Create sessions from a non-git directory (they get project_id = "global")
  2. Run opencode serve from a git repo directory (project ID = git root commit hash)
  3. The /session API returns [] because WHERE project_id = '4b0ea68...' does not match "global"

Fix: Switch the /session route from Session.list() to Session.listGlobal(), which queries across all projects without filtering by Instance.project.id. This matches the behavior of the experimental session endpoint.

Also includes two frontend fixes:

  • global-sync.tsx: Use sdkFor(directory) instead of globalSDK.client so the correct x-opencode-directory header is sent with session list requests
  • helpers.ts: Case-insensitive path comparison in isRootVisibleSession for Windows path compatibility

How did you verify your code works?

  1. Ran opencode serve --hostname 127.0.0.1 --port 4096
  2. Before fix: curl http://127.0.0.1:4096/session returned []
  3. Confirmed database had sessions with project_id = "global" via sqlite3
  4. After fix: API returns all sessions correctly
  5. Sidebar displays session history in browser

Screenshots / recordings

N/A - backend API fix, verified via curl and browser

Checklist

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

The /session API route used Session.list() which filters by
Instance.project.id, causing empty results when sessions belong
to a different project (e.g. "global"). Switch to Session.listGlobal()
which queries across all projects.

Also fix loadSessions to use sdkFor(directory) instead of
globalSDK.client so the correct x-opencode-directory header
is sent, and add case-insensitive path comparison in
isRootVisibleSession for Windows compatibility.

Fixes anomalyco#11331
@762278834 762278834 requested a review from adamdotdevin as a code owner March 16, 2026 08:38
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

Based on my search results, I found two potentially related PRs:

  1. PR fix: normalize directory paths for session list queries on Windows #17067 - "fix: normalize directory paths for session list queries on Windows"

    • Related because it also addresses Windows path compatibility issues similar to the isRootVisibleSession case-insensitive path comparison mentioned in this PR
  2. PR fix: list all sessions regardless of git context (#15678) #15772 - "fix: list all sessions regardless of git context (opencode sessions command fails to list historical sessions when run inside a Git repository #15678)"

    • Related because it also addresses listing sessions across different contexts, which is similar to switching to Session.listGlobal() to query across all projects

These PRs appear to be addressing related session listing and compatibility issues. However, PR #17752 (the current PR) appears to be the most specific fix for the sidebar session history issue (#11331).

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

@762278834 762278834 closed this Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant