Skip to content

fix(cli): session list --max-count not honored, shows too few sessions#14162

Merged
rekram1-node merged 1 commit intoanomalyco:devfrom
mharris717:fix-session-list-maxcount-021826
Feb 18, 2026
Merged

fix(cli): session list --max-count not honored, shows too few sessions#14162
rekram1-node merged 1 commit intoanomalyco:devfrom
mharris717:fix-session-list-maxcount-021826

Conversation

@mharris717
Copy link
Contributor

@mharris717 mharris717 commented Feb 18, 2026

Fixes #14163

Summary

opencode session list shows far fewer sessions than expected and --max-count has no effect for values above ~24.

Root cause: The CLI handler calls Session.list() with no arguments, so the DB query applies LIMIT 100 (the default). It then filters out child/delegation sessions in JS, and only after that applies --max-count via Array.slice(). Since many of the 100 rows are child sessions, the user sees far fewer root sessions than exist — and passing -n 1000 can never return more than the ~24 that survive the JS filter.

Fix: Pass roots: true and limit: args.maxCount to Session.list(), matching what the server HTTP API already does. This moves both the parent filter (WHERE parent_id IS NULL) and the limit into the SQL query where they belong. The redundant in-memory sort is also removed since Session.list() already returns results ordered by time_updated DESC.

Related: #13877 (same root cause affecting TUI /sessions picker)

(FYI I am a human being that experienced this bug and wanted a fix. Obviously I prompted an LLM on what to do, etc, but just making clear this fix was the idea of a human being. Love the project)

The CLI was calling Session.list() with no arguments, hitting a default
LIMIT 100 that included child/delegation sessions, then filtering them
out in JS. This meant --max-count could never show more than ~24 root
sessions. Now passes roots: true and limit: maxCount to the DB query.
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@rekram1-node rekram1-node merged commit d27dbfe into anomalyco:dev Feb 18, 2026
13 checks passed
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 session list shows too few sessions and --max-count is not honored

2 participants

Comments