Skip to content

[Bug]: session_list returns empty in opencode web / opencode serve — all sessions invisible in web sidebar #4704

Description

@EvillingDark

Prerequisites

  • I will write this issue in English (see our Language Policy)
  • I have searched existing issues to avoid duplicates
  • I am using the latest version of oh-my-openagent
  • I have read the documentation or asked an AI coding agent with this project's GitHub URL loaded and couldn't find the answer

Bug Description

When using opencode web (terminal/npm version), the web UI sidebar is completely empty — zero sessions shown, including the currently active conversation. This is especially disruptive for users who mix desktop (Electron), terminal CLI, and web versions of OpenCode, as sessions created in any client become invisible in the web UI.

    **What happens:**
    1. I have a 46 MB database (`opencode.db`) full of sessions from desktop and terminal usage
    2. I start `opencode web` and open the browser
    3. The left sidebar shows **no sessions at all** — not desktop sessions, not terminal sessions, not even the current web conversation
    4. `session_search("keyword")` finds sessions just fine — proving the data is intact
    5. `session_read("ses_xxx")` and `session_info("ses_xxx")` also work perfectly
    6. Only `session_list` (which powers the sidebar) returns empty

    Related: #1902 (different root cause — that one is a TUI picker date cutoff, this one is a web sidebar path-filtering mismatch)

Steps to Reproduce

  1. Create sessions via desktop OpenCode or terminal CLI (opencode run "test")
  2. Start web server: opencode web
  3. Open http://localhost:4096 in browser
  4. Look at left sidebar → empty
  5. In the web chat, run session_search("test")finds sessions correctly

Expected Behavior

The web UI sidebar should show all sessions, matching the behavior of session_search. When in multi-project server mode (server root ctx.directory = "/"), the filter should be skipped so all sessions are visible — same as how getAllSessions() works.

Actual Behavior

The sidebar is empty. Investigation shows the root cause:

    **Root Cause:**
    `opencode web` is a multi-project server — its `ctx.directory` is set to `"/"`. Sessions store their `session.directory` as actual project paths (e.g., `D:\root\my-project`). The filter in `getSdkMainSessions` and `getFileMainSessions` uses strict string equality:
    ```js
    // dist/index.js ~line 107085
    if (directory) {
      return mainSessions.filter(s => s.directory === directory).sort(...)
      //                     "/" === "D:\root\..."  →  always false
    }
    ```
    Since `"/"` never equals any real project path, **all sessions are filtered out**.

    **Why `session_search` works:**
    `session_search` → `getAllSessions()` has **no directory filter**.

Doctor Output

`bunx oh-my-openagent doctor` requires `bun` and platform binary — not available on this Windows npm-based terminal setup. Equivalent info:

        
        ✓ OpenCode version: 1.15.13
        ✓ oh-my-openagent version: 4.7.2 (also reproduced on 4.5.12)
        ✓ Plugin loaded: oh-my-openagent@latest
        ✓ Database: ~/.local/share/opencode/opencode.db (46 MB, hundreds of sessions)
        ✓ OS: Windows 11 (win32-x64)

Error Logs

Configuration

Additional Context

Affected code locations (in oh-my-openagent/dist/index.js):

    SDK path (~line 107085):
    ```js
    // Current (broken)
    if (directory) {
      return mainSessions.filter(s => s.directory === directory).sort(...)
    }
    // Fix
    if (directory && directory !== "/") { ... }
    ```

    File-based fallback (~line 106851):
    ```js
    // Current (broken)
    if (directory && meta.directory !== directory) continue;
    // Fix
    if (directory && directory !== "/" && meta.directory !== directory) continue;
    ```

    **Suggested Fix:** When `directory` is `"/"` (server-root sentinel for multi-project mode), skip directory filtering — same behavior as `getAllSessions`. The value `"/"` is never a valid project path on Windows.

    **Alternative Fix:** Apply `toCanonicalPath()` (already defined at line ~2956, currently only used in `containsPath()`) to normalize both sides before comparison.

Operating System

Windows

OpenCode Version

1.15.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions