mirror of
https://github.com/multica-ai/multica.git
synced 2026-08-12 10:59:06 +02:00
Bohan pushed back on the row-based `recent=N` shape: comments form a tree, not a list, and the newest N rows can come from N unrelated threads, giving the agent N disjoint conversational tails. Replace the row-based query with a thread-grouped one before #2787 merges so we never ship the wrong shape: - `recent=N` now returns the N most recently active threads (root + every descendant per thread). A thread's recency is MAX(created_at) across its whole subtree, so a stale-but-recently-replied thread outranks an old quiet one — exactly the property row-recent loses. - The cursor is now a *thread* cursor: `before` = a thread's last_activity_at, `before_id` = its root comment id. The pair walks threads strictly less recent than the page's oldest-active thread. The cursor surfaces via `X-Multica-Next-Before` / `X-Multica-Next-Before-Id` response headers (empty when there are no older threads); the CLI forwards the same pair to stderr after listing. - Row-based `recent` is gone — there is no internal caller and the prompt update has not shipped yet, so there is no compat surface to preserve. - Response body shape unchanged (flat JSON array, chronological). Default and `--since` paths untouched. Desktop UI keeps working. Tests: - recent=1 returns the freshest-active thread fully; recent=2 returns both with the older-active thread first (oldest-active → freshest tail). - Stale-but-fresh: a thread whose root is older but has a fresh reply outranks a thread whose root is newer but quiet. - Cursor headers emitted only on full pages; empty on the final page. - Pagination walks threads root2 → root1 → empty, no skips/duplicates. - Tie-break: three threads sharing last_activity_at paginate one-at-a-time using (last_activity_at, root_id) ordering — verifies the timestamp-only cursor failure mode is fixed for the thread case too. Co-authored-by: multica-agent <github@multica.ai>