Finding
GET /api/session/:sessionID/message cursors are not self-contained: they encode only {id, order, direction} while the type filter lives only in the query string. Following a filtered cursor with a different (or omitted) type silently applies an old anchor to a new filtered sequence, causing gaps or duplicates. The OpenAPI text says "passing the same type when following cursors", but the server never enforces it and the cursor carries nothing to enforce it with.
Contrast session.list, whose cursor preserves every filter field except limit (withCursor spreads directory/project/subpath/search/parentID/order plus anchor).
Evidence (origin/main 99d219d283e0)
packages/protocol/src/groups/message.ts:8-40 — SessionMessagesQuery has limit (capped 1..200), order, cursor (opaque string), type (10 literals). Cursor documented as "Do not combine with order" only; nothing binds cursor to type.
packages/server/src/handlers/message.ts:11-26 — Cursor struct is {id, order, direction}; encode stores only those three; decode restores only those three.
packages/server/src/handlers/message.ts:35-49 — handler decodes cursor for order+anchor but takes type: ctx.query.type fresh from the new request. No comparison against the type used to mint the cursor.
packages/core/src/session/store.ts:177-209 — messages() looks up the anchor by (session_id, id) only (:182-189, no type check), builds a seq boundary (:192-196), then applies the new type filter (:204). An anchor of type A paging under type B filters "after A's seq, of type B" — neither page's sequence.
Repro sketch (no fix in this task): page 1 ?type=user&limit=2 → next cursor for last user message U; page 2 ?cursor=<that>&type=assistant (or omitted) returns assistants after U's seq, skipping assistants before U and duplicating none deterministically — a mixed sequence the client never asked for.
limit has the same drift (cursor drops it; next page falls back to default 50), but type is the correctness gap; session.list already preserves its filters (packages/protocol/src/groups/session.ts:84-94, packages/server/src/handlers/session.ts:102-139 spread ...query into the cursor).
Suggested fix
Make message cursors self-contained: encode type (and limit/order) into the cursor like session.list does, prefer the cursor's values on follow-up, and reject a request that combines a cursor with a conflicting explicit type/order with InvalidCursorError/InvalidRequestError. Alternatively validate the anchor row's type against the requested filter before paging.
Acceptance
- Following a
type=user cursor with type=assistant (or omitted vs explicit) is either rejected or yields the original filtered sequence, never a mixed one.
- Cursor stays opaque to clients; existing
order-mismatch rejection (message.ts:35-36) still holds.
- Focused test pins filtered pagination across two pages with unchanged and changed
type.
Related
No code, PR, or queue task in this report.