Repository navigation
Let the Artifacts page list files past the newest 100 - #443
abhishekgahlot2 merged 2 commits into
Conversation
GET /api/artifacts stopped at the newest 100 artifacts with no way to
ask for more, and the Artifacts page called it without filters, so a
file older than the newest 100 could never be found there.
Backend (backend/src/artifacts/):
- GET /api/artifacts takes `limit` (1 to 100, default 100, clamped like
the runs list) and `cursor`, and answers `has_more` and `next_cursor`
beside `artifacts`. Sending `next_cursor` back as `cursor` with the
same filters gives the artifacts after the page. Without a cursor the
first page is the same newest 100 as before, so current callers and
the released web client see no change.
- The cursor (list-cursor.ts) is the last artifact's created_at and id.
The timestamp is Postgres' own text with microseconds, cast back with
::timestamptz, as the execution graph cursor does, because a
JavaScript Date rounds to milliseconds and would repeat or skip files
published within one millisecond. "After the cursor" is one row-value
comparison over (created_at, id), and the list is now ordered by id
after created_at, so a page cut between equal timestamps keeps a
stable order. A malformed cursor answers 400 {"error":"cursor is
invalid"}; the query stays scoped to the caller's org.
Frontend:
- The server snapshot (lib/fetch-artifacts.ts) carries the cursor, and
the Artifacts page shows "Show older files" under the list while the
backend reports more. Each click adds the next page without repeating
a file already shown; a second click while a page loads sends nothing.
- The newest page stays live as before. Once an older page is loaded, a
refresh puts the newest page in front of the loaded files and keeps
the rest, since artifacts are only ever added, and the cursor of the
next older page is kept. A failed page says "Couldn't load older
files." and the button becomes Try again with the same cursor.
- With a type filter and more to load, the empty message says there are
none "among the loaded files".
Docs: the GET /api/artifacts row and a Paging section on the Artifacts
API page, and the hub's Show older files on the Artifacts page.
Tests: test/artifact-pages.test.ts seeds 150 artifacts where ten share
one timestamp exactly and eight sit one microsecond apart, and checks
through the real route that the 101st newest is on page two, that pages
of 50 and of 7 match Postgres' own order with no gap or repeat, a run
filter, a file published mid-paging, the limit bounds, twelve bad
cursors, and that a cursor carries nothing across workspaces. With the
cursor at millisecond precision three of them fail. The page's
interaction test covers appending pages, the duplicate, refresh with
and without older pages loaded, a failed page and Try again, and the
double click; fetch-artifacts.test.ts covers the helpers.
Fixes useagenthq#210
abhishekgahlot2
left a comment
There was a problem hiding this comment.
Thanks @officialasishkumar, the backend cursor is solid: (created_at, id) < (ts, id) matches the ORDER BY, ties break on id, and it is org-scoped and strictly validated.
Same race as #440 on the frontend: pagedOlder.current = true is set only after the older fetch returns (live-artifacts.tsx:350). A refresh that lands meanwhile takes the replace branch (:289-:293) and resets nextCursor, so the file at position 100 disappears. Repro: newest [a,b], older [c] still loading, refresh to [n,a], and b.txt is gone.
Fix: set pagedOlder.current = true right after loadingOlderRef.current = true (:337). With that the probe keeps b.txt and all 47 artifact tests pass.
|
Good catch. |
|
Merged, thanks @officialasishkumar. The Artifacts page now reaches every file, and marking older pages before the fetch keeps the boundary file through a refresh. |
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 #210
GET /api/artifactsstopped at the newest 100 artifacts with no cursor, and the Artifacts page called it without filters. A file older than the newest 100 could never be found there.What changed
GET /api/artifactspages (backend/src/artifacts/)limit(1 to 100, default 100, clamped the way the runs list clamps it) andcursor. The response now carrieshas_moreandnext_cursornext toartifacts.next_cursorback ascursor, with the samerun_id,thread_idandlimit, to get the artifacts after the page. Without a cursor the first page is the same newest 100 as before, so current callers, the agent client and the released web client see no change.list-cursor.ts) is the last artifact'screated_atand id, base64url JSON.::timestamptz, the way the execution graph cursor does it. A JavaScriptDaterounds to milliseconds and would repeat or skip files published within one millisecond of each other.(created_at, id) < (cursor). The list is now ordered by id aftercreated_at, so a page cut between equal timestamps keeps a stable order.400 {"error":"cursor is invalid"}. The query is still scoped to the caller's org, so a cursor carries nothing across workspaces.listArtifactPageForOrginrepo.tsreads one row pastlimitto know whether another page follows.listArtifactsForOrgstays as it is for its two other callers.Artifacts page (
frontend/app/(library)/agent/artifacts/live-artifacts.tsx,frontend/lib/fetch-artifacts.ts)mergeNewestPage). Artifacts are only ever added, so a file that left the newest page is older than all of it and the order holds. The cursor of the next older page is kept.role="alert"). The button becomes Try again and resends the same cursor. Files already shown stay.Docs: the
GET /api/artifactsrow and a Paging section indocs-site/docs/api/artifacts.mdx, and Show older files ondocs-site/docs/product/artifacts.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.One limit: once older pages are loaded, an artifact removed by its run being deleted stays listed until a reload, because a refresh re-reads only the newest page. Artifacts have no delete route of their own.
Tests
backend/test/artifact-pages.test.tsruns through the real route and database. It seeds 150 artifacts one second apart, except indices 45 to 54, which share one timestamp exactly, and 98 to 105, which sit one microsecond apart. The expected order comes from Postgres directly, not from the code under test.has_more: falseandnext_cursor: nullrun_idfilter pages 50 artifacts as 20, 20, 10limitis held between 1 and 100, and a non-number gives 100As a check on the microsecond handling, I switched the cursor timestamp to millisecond precision and three of these tests failed.
Frontend:
live-artifacts.interaction.test.tsx(the Refresh the Artifacts page on changes, not every 5 seconds #441 harness, with?cursor=pages added to the stubbed fetch):lib/fetch-artifacts.test.ts: the request paths, a missing or malformednext_cursorread as the last page,mergeNewestPageandappendOlderPageChecks with Bun 1.3.14, backend tests on
pgvector/pgvector:0.8.6-pg16-bookworm:bun run typecheck(frontend and backend): passescd backend && bun run test: 3605 pass, 1 fail. The failure issrc/engines/repo-prep.test.ts"the generated clone shell replaces an empty placeholder...", which fails the same way on an unmodifiedmaincheckout on my machine.cd frontend && bun run test: 1953 pass, 0 failcd frontend && bun run lint: no new findings (248 warnings and 22 infos before and after)cd frontend && bun run build: passescd docs-site && bunx blume validate: no broken linksbun test scripts/agent-docs.test.ts: 5 passEnd to end
I ran a real backend on its own Postgres and a production build of the frontend (
next start). I signed up a workspace, published 105 artifacts to one run (report-001.txt, newest, toreport-105.txt), and drove/artifactswith Playwright:report-001.txttoreport-100.txt, with Show older files under the list.report-101.txtwas not on the page./api/artifacts?cursor=…. The list grew to 105 rows ending inreport-105.txt, and the button went away.GET /api/artifacts?limit=2answeredreport-001.txtandreport-002.txtwithhas_more: trueand a string cursor.GET /api/artifacts?cursor=nopeanswered400 {"error":"cursor is invalid"}.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.