Skip to content

[BUG] session_list returns empty despite sessions existing in database #15108

Closed as not planned

Description

@ludwiklisowski80

Bug Report: session_list Returns Empty Despite Sessions Existing in Database

Date: 2026-02-25
User: gromada project (/home/lu/Documents/gromada)
OpenCode Version: 1.2.13

Summary

The session_list tool returns an empty list despite sessions existing in the SQLite database. Sessions ARE being saved correctly to ~/.local/share/opencode/opencode.db, but the list function fails to return them.

Reproduction

  1. User works on project /home/lu/Documents/gromada for several hours
  2. Multiple sessions are created and saved (verified in database)
  3. User runs session_list() - returns empty list []
  4. User runs session_search() - finds sessions successfully
  5. User runs direct SQL query - sessions exist in database

Evidence

Database Query (works correctly)

SELECT id, slug, title, time_created 
FROM session 
WHERE project_id = '0414ba0fb05af3df687d6e70501ee7febfcc7f8d'
ORDER BY time_created DESC;

Returns: 100+ sessions including:

  • ses_36a097a42ffepWYz5H1l6jJKOY (current session, 18:01)
  • ses_36a341e68ffe2PEYbaF2Yqe7sW (17:14)
  • ses_36ae4dc54ffeb42G7NrhUIAx4k (14:01)
  • ses_36b7be405ffebyxrRCtLTlh8uZ (11:16)

session_list (returns empty)

session_list({})
// Returns: []

session_search (works correctly)

session_search({query: "gromada"})
// Returns: Found matches with session data

Analysis

The sessions ARE being saved correctly to the database. The bug appears to be in the session_list function implementation, not in the session saving mechanism.

Possible causes:

  1. Query filtering issue - session_list may be applying incorrect filters (e.g., filtering by wrong project_id, date range, or archived status)
  2. Database connection issue - session_list may not be connecting to the correct database or using correct schema
  3. API response handling - the list may be returned but filtered out before being returned to the user

Impact

  • Users cannot see their session history through the list interface
  • Users must use session_search to find sessions (workaround works)
  • Users must know exact session IDs to resume sessions

Recommendation

Investigate the session_list function implementation:

  1. Check the SQL query being generated
  2. Verify filtering parameters (project_id, date range)
  3. Check for any error handling that might suppress results
  4. Compare with session_search implementation to identify differences

Workaround

Use session_search() with a query term to find sessions, or query the database directly:

sqlite3 ~/.local/share/opencode/opencode.db "SELECT id, title, time_created FROM session WHERE directory LIKE '%gromada%' ORDER BY time_created DESC LIMIT 20;"

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Feb 25, 2026
  2. github-actions commented on Feb 25, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of an existing issue. Please check:

  3. lukaboulpaep commented on Feb 25, 2026

    @lukaboulpaep

    Having the same problem

  4. huayu0721 commented on Mar 7, 2026

    @huayu0721

    A possible temporary solution :entry ~/.local/share/opencode/storage and run opencode db migrate ,then my sessions came back

  5. assigned and unassigned on Apr 26, 2026
  6. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  7. codeg-old commented on May 8, 2026

    @codeg-old

    Additional reproduction on macOS with OpenCode 1.14.41.

    Observed behavior:

    • opencode session list -n 5 --format json returns recent sessions normally for the active project.
    • The MCP/session tool session_list({ project_path: <active project path> }) returns No sessions found.
    • For a session ID returned by the CLI:
      • session_info(session_id) succeeds and reports message count/date range/transcript metadata.
      • session_read(session_id) fails with Session not found.
    • session_search(...) also returns no matches for terms present in the active session context.
    • The legacy session storage directory (~/.local/share/opencode/storage/session/) exists but contains 0 entries.
    • opencode db path points to the SQLite DB under the normal OpenCode data directory.

    This looks like the session tools and the CLI/runtime are not reading the same source of truth. The CLI sees sessions in the current SQLite-backed store, while session_list/session_read appear to miss them, possibly by consulting legacy file storage or applying a different project/session filter.

    I did not modify the database while testing; the checks above used the OpenCode CLI plus the session MCP/tool surface.

    Authorship disclosure: this reproduction note was prepared with AI assistance.

  8. codeg-old commented on May 9, 2026

    @codeg-old

    Related PR for the TUI session picker side: #26432.

    That PR fixes the root-session dilution in the TUI dialog by querying root sessions directly for /sessions while leaving the shared session bootstrap unchanged for child-session navigation.

    It does not claim to fix the separate MCP/session-tool source-of-truth mismatch reported here (session_list/session_read behavior). I am calling that out so the two layers do not get conflated.

    Authorship disclosure: prepared with AI assistance.

  9. github-actions commented on Jul 9, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions