Repository navigation
📜 fix: Read a Child Thread's Messages a Page at a Time - #18424
Conversation
The child messages route read a thread's whole stored history, and a card previewing a running child triggers that read without anyone asking. Every read is now one page (50 rows or 2 MiB, newest first) with a cursor for the page before it, the followed pane keeps the pages it has read and offers the earlier ones, and a client or server that predates paging still gets a list.
Codex Review Summary: ✅ CompletedThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 24701edcdc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (joinsAt > 0) { | ||
| await chat.setMessages([...held.slice(0, joinsAt), ...page.messages]); | ||
| return; |
There was a problem hiding this comment.
Restore the paging cursor when reusing cached history
If a reader loads an earlier page without reaching the beginning, then closes and reopens the child thread, the new follower reuses the messages in ReactQueryChatState but initializes earlier to null and hasEarlier to false. The newest page joins those cached rows here, so this early return preserves the messages without restoring their paging metadata. Consequently, “Show earlier messages” disappears and the remaining history becomes inaccessible. The same issue occurs when retry() recreates the effect. Persist the cursor alongside the retained history, or replace the cached list and initialize pagination from the fetched page when no cursor has been restored.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid, fixed in 8c08cca. A follower now joins a re-read onto the rows it holds only after it has placed a page of its own; its first read replaces whatever an earlier follower left in the cache and takes that page's cursor, so the control is back and the rest is reachable (re-read a page at a time rather than trusted from the cache). Test: "offers the earlier rows again to a follower that starts on rows another one left" (fails without the check: eight rows held, no control).
A follower recreated over rows another one left in the cache kept them without knowing where they began, so the earlier-messages control was gone. It now places its first page itself and takes that page's cursor.
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
GET /api/convos/:parentConversationId/subagents/:threadId/messages(added in #18188) read a child thread's entire stored history: no row limit, no cursor, no size bound. Since #18279 a card that previews a running child follows that thread, so the read happens for up to three children at a time without the reader asking for it. A long or heavy thread was materialized whole on the server and sent whole to the browser; an independent review reproduced 80 messages totalling 10 MiB from one request,limit=50included, because the route never looked at it.Every read of that route is now one page: the thread's newest rows, at most 50 of them or 2 MiB as stored, whichever is reached first. The page before it is read by a cursor, on request. Nothing is dropped: the followed pane shows a "Show earlier messages" control above the oldest row it holds and reads back a page at a time until the first row is in.
How it works
The byte bound is enforced while reading rather than with
$bsonSizeor a window stage, so it does not depend on what the database engine supports. The two bounds are constants beside the thread view's ownMAX_THREAD_MESSAGES: they cap a response and are paired with the client's page request, not something a deployment tunes.Type of change
Testing
Tested environments/configuration:
Chromium on the mock e2e lane, against this branch's own server: the whole
subagent-activity.spec.ts(7 scenarios, including the retained-history ones that open long threads) and the new paging scenario twice. That scenario serves the fixture's real two rows as two pages of one, since the fixture cannot write a thread longer than a page; the server's own paging is covered by the storage and route tests below.Automated tests:
packages/data-schemas/src/methods/message.cursor.spec.ts(4, real MongoDB in memory): a page stops before the row that would pass the budget and paging continues without skips; one row over the budget is returned alone with a cursor; the row limit still applies under a roomy budget; a thread that fits both bounds is read whole.packages/api/src/agents/view.spec.ts(7 new): the default read is one bounded page as a list; a paged request returns{ messages, earlier }oldest first; a cursor is passed through;limit=5000is clamped; four malformed page requests answer 400 and read nothing.packages/data-provider/specs/subagent-messages.spec.ts(3) andapi-endpoints.spec.ts(1): the page request's URL, and a bare list taken as the whole thread.packages/chat/src/react/__tests__/follow.spec.tsx(7): newest page andhasEarlier; each earlier page prepended until the first row; earlier rows kept across a re-read; a page that joins nothing replaces the list and offers the rest; a failed earlier read reported and retried; a plain list as the whole conversation; a recreated follower starting from its own newest page with the control back. Removing the join makes the third fail, and removing the first-read rule the last.packages/chat/src/components/pane/__tests__/followed.spec.tsx(4): the control above the first row and the rows it adds; loading, disabled and not asked twice; the failure and Retry; nothing drawn for a thread that fits a page.client/src/Providers/__tests__/SubagentsHostFollow.spec.tsx: the app passes the cursor through.e2e/specs/mock/subagent-activity.spec.ts, new@scenario:subagent-panel-pages-child-history.packages/chatnpx jest(245 suites) andtsc;packages/data-provider,packages/data-schemastsc;packages/apiview.spec.tsandtscfiltered to the route;npm run build:api(declarations included);npm run static-checks -- --against origin/dev.Risk / compatibility
useFollowChatis also changed by 🚦 feat: Drive a Followed Chat With Main Chat's ask #18413 (in review). Whichever merges second needs a rebase infollow.ts; the changes do not overlap in behaviour.