Repository navigation
Let All threads load threads older than the newest 100 - #440
abhishekgahlot2 merged 5 commits into
Conversation
All threads, like the sidebar, read one bounded snapshot: the 100 most
recently active thread roots plus any older queued or running ones. A
thread outside that snapshot could only be opened by typing its URL.
GET /api/runs?view=summary now pages. Each response carries has_more and
next_cursor; sending next_cursor back as cursor, with the same all, limit
and include_active, returns the rows that sort after the page.
- The cursor is the last row's full sort key (latest turn update time,
latest turn creation time, latest turn id, root creation time, root id;
or creation time and id with all=1), so a page boundary inside rows that
share a timestamp keeps the id order. Timestamps keep Postgres' text
form with microseconds, as the execution graph cursor does: a
JavaScript Date would round them to milliseconds and repeat or skip
rows.
- Because the list is ordered by each thread's latest turn, a thread that
gets a new turn while someone pages moves to the front instead of
shifting every later page.
- With include_active, the first page still carries up to limit active
rows that sort after it, and later pages leave exactly those rows out,
so no thread is listed twice.
- A malformed cursor, or one from the other view, answers
400 {"error":"cursor is invalid"}.
listRunSummaries moves from runs/repo.ts, which sat at the 800-line cap,
into runs/run-summaries.ts with the cursor helpers.
The All threads page keeps the newest page live (stream and recovery
poll) and adds a "Show older threads" button under the table that appends
the next page. Rows from older pages that reappear in a refreshed newest
page are shown once, from the newest page. A failed page says so and
offers Try again with the same cursor. The search box now says it
searches loaded threads.
The API reference documents the cursor.
Closes useagenthq#219
Closes useagenthq#297
711b310 to
4d69d2c
Compare
abhishekgahlot2
left a comment
There was a problem hiding this comment.
Thanks @officialasishkumar, the backend cursor is solid: the full sort key ending in the root id, timestamps round-tripped with microseconds, one row-value comparison that matches the ORDER BY, and org-scoped throughout.
One thing to fix before merging: threads can drop out of the list once "Show older threads" has been used.
- Each refresh replaces the newest page with the current top 100 (
runs-list.tsx:265), while the older pages keep the cursor taken from the original newest page (runs-list.tsx:296,:308), andmergeRunPages(runs-data.ts:69) only de-duplicates. - When a new thread arrives (or an older one gets a new turn), the row that was 100th slides to 101st. It is no longer in the refreshed newest page, and the older pages start strictly after it, so it is in neither list until a reload. Search over loaded threads misses it too.
- Repro in the PR's own interaction test setup: newest
[a,b], older[c]; a new thread arrives and newest refreshes to[n,a]. Threadbdisappears and the list shows "3 of 3 runs".
A possible fix: while older pages are loaded, merge the previous newest rows back in (setNewest(prev => older ? mergeRunPages(page.runs, prev) : page.runs)), or re-read the newest page with a limit that covers every loaded row. A test for the new-thread-arrives case would lock it in.
Smaller, non-blocking: a cursor timestamp like 2026-02-30 ... passes Date.parse but Postgres rejects it, so it answers 500 instead of 400.
… loaded Refreshing the newest page replaced it with the current top 100 while the older pages kept the cursor from the original page, so a row pushed past the limit by a new thread was in neither list. Merge the previous newest rows back in while older pages are loaded. Also reject a cursor timestamp with an impossible date or time as an invalid cursor (400) instead of letting Postgres fail it with a 500. Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
|
Fixed in 4ea8d23: while older pages are loaded, a newest-page refresh now merges the previous rows back in, with a test for the new-thread case. Also made a cursor with an impossible date like 2026-02-30 answer 400. |
abhishekgahlot2
left a comment
There was a problem hiding this comment.
Thanks for the fix, the refresh-after-load case now holds and the new test covers it.
One window is still open: olderLoaded.current = true is set after await fetchRuns({ cursor }) returns (runs-list.tsx:310). A newest-page refresh that lands while the older request is in flight still takes the replace branch (:269), and the older page then starts after the old cursor, so the row at the boundary is in neither list.
Repro in the PR's interaction test setup: click "Show older threads", hold that request, refresh newest to [n,a], then release. The list shows "3 of 3 runs" and b is missing.
Fix: set olderLoaded.current = true before the fetch, right after setOlderFailed(false). With that the same probe shows "4 of 4 runs" and all 19 runs tests pass. A test for the in-flight case would lock it in.
A newest-page refresh that landed while the older request was in flight replaced the newest rows, so the row at the cursor boundary was in neither list.
|
Fixed in 5124b4f: |
|
Merged, thanks @officialasishkumar. Marking older pages loaded before the request closes the in-flight window too, so no thread drops out at the page boundary any more. |
By opening this pull request you agree to the Contributor License Agreement. On your first pull request a bot asks you to sign it with a one-line comment.
Fixes #219
Fixes #297
All threads reads one bounded snapshot: the 100 most recently active thread roots plus any older queued or running ones. A thread outside that snapshot could only be opened by typing its URL. The two issues ask for the same thing from the API side (#219) and the page side (#297), so this does both.
What changed
GET /api/runs?view=summarypages (backend/src/runs/run-summaries.ts,backend/src/runs/read-routes.ts)has_moreandnext_cursor. Sendnext_cursorback ascursor, with the sameall,limitandinclude_active, to get the rows that sort after the page.runsis unchanged, so current callers see the same first page.updated_at, latest turncreated_at, latest turn id, rootcreated_at, root id (orcreated_atand id withall=1). "After the cursor" is one row-value comparison, so a page cut between rows that share a timestamp keeps the id order.::timestamptz, the way the execution graph cursor does it. A JavaScriptDaterounds to milliseconds, which repeats or skips rows that fall inside one millisecond.include_active=1, the first page still carries up tolimitactive rows that sort after it, as before. Later pages leave out exactly those rows, so no thread is listed twice.all=1sort by different keys), answers400 {"error":"cursor is invalid"}. The query is still scoped to the caller's org, so a cursor carries nothing across workspaces.listRunSummariesmoves out ofruns/repo.ts, which was at the 800-line cap, intoruns/run-summaries.tsnext to the cursor helpers. The SQL that builds each row is the same as before.All threads page (
frontend/app/(workspace)/agent/runs/)mergeRunPages).role="alert") and a Try again button that resends the same cursor. Rows already shown stay.Docs: the
/api/runsrow and a short paging note indocs-site/docs/api/runs.mdx.Across a release: an old web client ignores the new fields. A new client talking to an old backend gets no
next_cursor, so the button stays hidden.Tests
backend/test/run-summary-pages.test.tsruns through the real route and database. It seeds 150 threads where indices 45 to 54 share one timestamp exactly and 98 to 105 sit one microsecond apart, so the page cuts land inside both groups:limit=50gives pages of 50, 50 and 50, and together they match the one-shotlimit=1000order exactlylimit=7(22 pages) matches the one-shot order too, cutting inside the tie groups at many pointsinclude_active=1gives pages of 54 (50 plus the 4 older active threads), 50 and 46: 150 distinct threads, and no active thread on a later pageall=1covers all 153 runs (replies included) in the one-shot orderAs a check on the microsecond handling, I switched the cursor timestamps to millisecond precision and four of these tests failed.
Frontend:
runs-list.interaction.test.tsxmountsRunsListunder happy-dom, using the realruns-datahelpers over a stubbed fetch. It covers:runs-data.test.ts: the request paths, cursor encoding, a missing or malformednext_cursorread as the last page, andmergeRunPagesruns-list.test.ts: the button renders only with a cursorChecks with Bun 1.3.14, backend tests on
pgvector/pgvector:0.8.6-pg16-bookworm:bun run typecheck(root): passescd backend && bun test test/run-summary-pages.test.ts test/runs.test.ts test/native-children-sidebar.test.ts test/slack-turn-identity.test.ts test/cancel.test.ts test/ratchet.test.ts test/persisted-names.test.ts: all passcd frontend && bun run test: 1939 pass, 0 failcd frontend && bunx biome lint "app/(workspace)/agent/runs": no new findings (the 5 warnings are the existing ones inruns-data.test.ts)bun test scripts/agent-docs.test.ts: 5 passI did not run the full backend suite or
bun run build, and I did not try the page in a browser, so I have no screenshots.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.