Skip to content

List opencode 2 sessions - #61

Merged
nihen merged 1 commit into
mainfrom
feature/opencode-v2-sessions
Nov 24, 2026
Merged

nihen merged 1 commit into
mainfrom
feature/opencode-v2-sessions

Conversation

@nihen

@nihen nihen commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Summary

opencode 2 keeps its sessions in new tables of the same database, session_v2 and session_message, and stops writing to session / message / part. ah read only the old tables, so every session created after the upgrade was missing from ah log, search, show and stats.

When both new tables exist, ah now reads sessions from them. Upgrading copies the 1.x sessions and their messages there, so the old tables are not read in that case. A database that has not been upgraded is read as before.

  • Sessions come from session_v2; a NULL title falls back to the first prompt, like a placeholder title does.
  • Only user and assistant rows are conversation, ordered by seq. system, synthetic, compaction and idle rows are left out of turns, the transcript and search.
  • The model comes from model.id of the assistant rows that answered; the session-level model column is not used, since it can be NULL.
  • Search covers prompts, answers, and each tool call's name, input, text output and error message. Files in a tool's output (an image as a data URI) are not searched.
  • ah show --raw prints one line per row as {"id":…,"type":…,"data":…} for such a database (README updated).

Fixes #52

Known limitations

  • The session_part table of opencode 2 is not read. It is empty in the databases checked (opencode 2.2.5 as reported, 2.3.2 and 2.4.1 locally): everything is inline in session_message.data.
  • Checked against a database upgraded on Linux only; the reporter's upgraded macOS database has not been tried yet.

Verification

  • Unit tests with a second fixture that has the opencode 2 tables next to the 1.x ones: listing, NULL title, subagents, seq order, rows of other types, values of the wrong JSON type, rows that are not JSON, export size, search, models, and the fallback when only session_v2 exists. cargo test, cargo clippy --all-targets, cargo fmt --check, cargo +1.85 check --all-targets --locked pass.
  • Real data: a database upgraded to opencode 2.4.1 with 775 sessions. The previous build listed 774; this build also lists the one created by opencode 2. For the 774 others, title, project, cwd, times, model, models, turns, messages and prompt times are identical to the previous build, as are the sessions matched by several search queries (prompt text, tool input, tool output, tool errors).
  • ah -a log --agent opencode takes 0.18s, as before.

https://claude.ai/code/session_013M2MLzr8wBaPiqkJbD3AD2

opencode 2 keeps its sessions in new tables of the same database
(session_v2 and session_message) and stops writing to the 1.x ones, so
sessions created after the upgrade were not listed. Read the new tables
when both exist; a 1.x database is read as before.

Fixes #52

Claude-Session: https://claude.ai/code/session_013M2MLzr8wBaPiqkJbD3AD2
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T09:59:32.918849Z c7f542e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@nihen
nihen merged commit fe6c32e into main Nov 24, 2026
4 checks passed
@nihen
nihen deleted the feature/opencode-v2-sessions branch November 24, 2026 10:00
@nihen nihen mentioned this pull request Nov 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

Development

Successfully merging this pull request may close these issues.

opencode: sessions created by OpenCode 2.x are not listed (stored in session_v2 / session_message)

1 participant