Skip to content

Let the Artifacts page list files past the newest 100 - #443

Merged
abhishekgahlot2 merged 2 commits into
useagenthq:mainfrom
officialasishkumar:feature/artifacts-load-more
Nov 12, 2026
Merged

abhishekgahlot2 merged 2 commits into
useagenthq:mainfrom
officialasishkumar:feature/artifacts-load-more

Conversation

@officialasishkumar

@officialasishkumar officialasishkumar commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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/artifacts stopped 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/artifacts pages (backend/src/artifacts/)

  • New query parameters: limit (1 to 100, default 100, clamped the way the runs list clamps it) and cursor. The response now carries has_more and next_cursor next to artifacts.
  • Send next_cursor back as cursor, with the same run_id, thread_id and limit, 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.
  • The cursor (list-cursor.ts) is the last artifact's created_at and id, base64url JSON.
    • The timestamp is Postgres' own text with microseconds, cast back with ::timestamptz, the way the execution graph cursor does it. A JavaScript Date rounds to milliseconds and would repeat or skip files published within one millisecond of each other.
    • "After the cursor" is one row-value comparison, (created_at, id) < (cursor). 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 is still scoped to the caller's org, so a cursor carries nothing across workspaces.
  • listArtifactPageForOrg in repo.ts reads one row past limit to know whether another page follows. listArtifactsForOrg stays as it is for its two other callers.

Artifacts page (frontend/app/(library)/agent/artifacts/live-artifacts.tsx, frontend/lib/fetch-artifacts.ts)

  • The server-rendered snapshot carries the cursor. While the backend reports more, a Show older files button sits under the list, styled like the page's Download all button. 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 Refresh the Artifacts page on changes, not every 5 seconds #441 set up (org stream, reopen, focus).
    • Before any older page is loaded, a refresh replaces the list as before and takes the newest page's cursor.
    • Once an older page is loaded, a refresh puts the newest page in front and keeps every other loaded file after it (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.
  • A failed page shows "Couldn't load older files." (role="alert"). The button becomes Try again and resends the same cursor. Files already shown stay.
  • With a type filter and more to load, the empty message reads "No docs artifacts among the loaded files." instead of "yet".

Docs: the GET /api/artifacts row and a Paging section in docs-site/docs/api/artifacts.mdx, and Show older files on docs-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.ts runs 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.

  • the first page is the newest 100, and the 101st newest is on page two, which ends with has_more: false and next_cursor: null
  • pages of 50 (50, 50, 50) and of 7 (22 pages) cut inside both groups and match the one-shot order with no gap or repeat
  • a run_id filter pages 50 artifacts as 20, 20, 10
  • an artifact published after page 1 is on neither later page, and the newest page leads with it
  • limit is held between 1 and 100, and a non-number gives 100
  • twelve bad cursors (garbage, wrong shape, wrong version, missing or extra keys, a non-uuid id, an impossible date or hour, non-canonical base64) each answer 400
  • a cursor from another workspace lists only the caller's own artifacts

As 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):
    • two older pages appended, a duplicate dropped, the button gone at the end
    • no button on a single page
    • a refresh with older pages loaded keeps them and the older cursor
    • a refresh before any is loaded takes the newest page's cursor
    • a 503 shows the alert, and Try again resends the same cursor
    • a double click sends one request; with a state-only guard this test fails
  • lib/fetch-artifacts.test.ts: the request paths, a missing or malformed next_cursor read as the last page, mergeNewestPage and appendOlderPage

Checks with Bun 1.3.14, backend tests on pgvector/pgvector:0.8.6-pg16-bookworm:

  • bun run typecheck (frontend and backend): passes
  • cd backend && bun run test: 3605 pass, 1 fail. The failure is src/engines/repo-prep.test.ts "the generated clone shell replaces an empty placeholder...", which fails the same way on an unmodified main checkout on my machine.
  • cd frontend && bun run test: 1953 pass, 0 fail
  • cd frontend && bun run lint: no new findings (248 warnings and 22 infos before and after)
  • cd frontend && bun run build: passes
  • cd docs-site && bunx blume validate: no broken links
  • bun test scripts/agent-docs.test.ts: 5 pass

End 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, to report-105.txt), and drove /artifacts with Playwright:

  • The page showed 100 rows, report-001.txt to report-100.txt, with Show older files under the list. report-101.txt was not on the page.
  • One click made one request, /api/artifacts?cursor=…. The list grew to 105 rows ending in report-105.txt, and the button went away.
  • GET /api/artifacts?limit=2 answered report-001.txt and report-002.txt with has_more: true and a string cursor. GET /api/artifacts?cursor=nope answered 400 {"error":"cursor is invalid"}.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

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 abhishekgahlot2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@officialasishkumar

Copy link
Copy Markdown
Contributor Author

Good catch. pagedOlder is now set right after loadingOlderRef, before the fetch, and I added a test for a refresh landing while an older page loads: f608e3c

@abhishekgahlot2
abhishekgahlot2 merged commit ec19ad0 into useagenthq:main Nov 12, 2026
22 checks passed
@abhishekgahlot2

Copy link
Copy Markdown
Contributor

Merged, thanks @officialasishkumar. The Artifacts page now reaches every file, and marking older pages before the fetch keeps the boundary file through a refresh.

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let the Artifacts page list files past the newest 100

2 participants