Skip to content

feat(session): add messageCount endpoint for efficient message counting#13795

Open
sjawhar wants to merge 1 commit intoanomalyco:devfrom
sjawhar:feat/session-message-count
Open

feat(session): add messageCount endpoint for efficient message counting#13795
sjawhar wants to merge 1 commit intoanomalyco:devfrom
sjawhar:feat/session-message-count

Conversation

@sjawhar
Copy link

@sjawhar sjawhar commented Feb 16, 2026

Summary

  • Adds a Session.messageCount() function that uses SELECT COUNT(*) to efficiently get the number of messages in a session without loading all message data
  • Adds a GET /:sessionID/message/count API route exposing this function
  • Avoids the overhead of streaming and deserializing every message when only the count is needed

Changes

  • packages/opencode/src/session/index.ts: New messageCount export using Drizzle sql template for COUNT(*)
  • packages/opencode/src/server/routes/session.ts: New route with OpenAPI docs, param validation, and error responses

Closes #14602

@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.

@sjawhar
Copy link
Author

sjawhar commented Feb 17, 2026

@adamdotdevin this is ready for review: issue linked, CI passing, and mergeable. Could you take a look when you have a moment?

@sjawhar sjawhar force-pushed the feat/session-message-count branch from c032465 to df09665 Compare February 21, 2026 00:25
@sjawhar sjawhar force-pushed the feat/session-message-count branch 4 times, most recently from 3207b65 to 1b58318 Compare February 27, 2026 20:05
@sjawhar sjawhar force-pushed the feat/session-message-count branch 3 times, most recently from be5126c to 0a3687d Compare March 5, 2026 00:03
resolve: merge conflicts in generated SDK files
@sjawhar sjawhar force-pushed the feat/session-message-count branch from 0a3687d to a4a0828 Compare March 6, 2026 19:07
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.

[FEATURE]: add session message count endpoint for efficient counting

1 participant