Repository navigation
fix(engine): list a workspace's DM conversations in D1-safe chunks - #519
Conversation
listAllDmConversations bound every conversation and channel id of the workspace into single IN clauses. D1 allows at most 100 bound parameters per statement, so GET /v1/dm/conversations/all failed with internal_error for any workspace with more than about 100 DM conversations, for workspace keys and Relay Connect observers alike (prod: 20/20 requests 500). The participant, message-count, latest-id and latest-message lookups now run through queryInChunks (D1_SAFE_IN_QUERY_CHUNK_SIZE), as action.ts, agent.ts and attachments.ts already do. Per-channel grouping stays complete because one channel's rows never span chunks. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Session-Id: 2bc8f2ec-40dd-4818-8b2d-1b4952383604
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to The change is mergeable based on the available evidence. Listings above D1’s parameter limit are covered by the new test; the hosted deployment plan remains undocumented here. Pre-merge checks |
|
Why
GET /v1/dm/conversations/allreturns 500internal_errorin production for a workspace with many DM conversations. A sanitized tail ofrelaycast-cloud-apifrom 2026-10-11 05:13 to 08:00Z showed 20 of 20/allrequests failing (clientfleet-watchdog, workspace key). The same route backs the Relay Connect observer's room list, so observer links for that workspace cannot load. #518 made that failure show as "temporarily unavailable" instead of "revoked", but the read itself still fails.listAllDmConversations(engine/dmAll.ts) bound every conversation and channel id of the workspace into singleINclauses. Cloudflare D1 allows at most 100 bound parameters per statement, so any workspace with more than about 100 DM conversations fails every call. The engine already has the fix pattern:queryInChunkswithD1_SAFE_IN_QUERY_CHUNK_SIZE(90), whichaction.ts,agent.tsandattachments.tsuse.dmAll.ts's filtered-count query already chunks; these four lookups did not.What
The four lookups in
listAllDmConversations(participants, per-channel message counts, latest message ids, latest messages) now run throughqueryInChunks. Grouping by channel within a chunk stays complete, because one channel's rows never span chunks. No other behaviour changes.Test
New conformance test in
connectObserver.test.ts:delivery.test.tsuses for its D1 regression)/v1/dm/conversations/allwith the workspace key and with a Connect observer tokenmessage_count: 1and the rightlast_messagefor eachOn current
main(unfixed) the test fails withexpected 500 to be 200, reproducing production; with this change it passes.Verification (local, Node 22 as in CI)
npx vitest runinpackages/engine: 117 files, 1369 passednpm run typecheck -w @relaycast/engine: cleannpm run lint -w @relaycast/engine: cleangit diff --check: cleanRollout
Authorized by Khaliq: after review, release
@relaycast/enginethrough the reviewedpublish-npmworkflow, then bump it in relaycast-cloud and deploy through that repo's normal gates. Then live-verify/alland observer loading.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Low Risk
Targeted read-path change reusing an established chunking helper; behavior is unchanged except fixing failures above the D1 bind limit.
Overview
Fixes
GET /v1/dm/conversations/allreturninginternal_errorwhen a workspace has more than ~100 DM conversations on Cloudflare D1 (100 bound parameters per statement).listAllDmConversationsindmAll.tsnow runs the four follow-up lookups—participants, per-channel message counts, latest message IDs, and latest message bodies—throughqueryInChunksinstead of one giantIN (...)per query. Response shape and aggregation logic are unchanged; Relay Connect observer room lists use the same route.A conformance test creates 105 DMs, patches SQLite
prepareto enforce D1’s bind cap, and asserts 200 plus correct counts for both workspace key and observer credentials.Reviewed by Cursor Bugbot for commit a5def39. Bugbot is set up for automated code reviews on this repo. Configure here.
Agent Relay sessions
claudesession2bc8f2ec· opened viagh pr create· last active 2026-10-11