Repository navigation
Paginate automation history with limit and cursor - #454
Closed
sanketpatel32 wants to merge 1 commit into
Closed
sanketpatel32 wants to merge 1 commit into
sanketpatel32 wants to merge 1 commit into
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
GET /api/automations/:id/history and the bot routine history route now return at most a limit of firings (default 50, capped at 200) plus has_more and next_cursor. The cursor is a versioned keyset over (fired_at, id) passed back as ?before=, matching the artifacts list cursor convention, so frequent schedules no longer return every firing ever. Closes useagenthq#200
sanketpatel32
force-pushed
the
feat/automation-history-pagination
branch
from
November 22, 2026 02:31
20a567e to
6c43d42
Compare
Author
|
I have read the CLA Document and I hereby sign the CLA |
|
Thanks @sanketpatel32 for picking this up. #452 fixed the same issue (#200) and was merged first, so this one is closed as superseded. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
An automation that fires every minute accumulates tens of thousands of
schedule_firingsrows, andGET /api/automations/:id/history(plus the bot routine history route, which reads the same firing log) returned every row ever, each joined with its run summary. This PR bounds both routes with keyset pagination, reusing the same versioned base64url cursor convention as the artifacts list.listFirings(backend/src/schedules/repo.ts) now takeslimit(default 50, capped at 200, clamped to a minimum of 1) and an optionalbeforecursor, readslimit + 1rows, and returns a page: at mostlimitfirings plusnextCursorwhen another page exists.(fired_at, id), the same composite sort the history already used (fired_atthenid, newest first), so pages hold a stable order even when firings share a timestamp. It is encoded as versioned base64url JSON (backend/src/schedules/firing-cursor.ts) modeled onartifacts/list-cursor.ts, carrying the PostgreSQL timestamp text so microsecond precision survives.?limit=and?before=and answer{ firings, has_more, next_cursor };has_moreis true exactly when an extra row existed beyond the page.next_cursoris passed back as?before=to walk older firings. A malformedbeforeis a 400 on both routes.has_more/next_cursorare additive: existing clients that readfiringskeep working.automation_historytool (backend/src/knowledge/gateway/automation-tools.ts), the only otherlistFiringscaller, consumes the page shape and now surfaceshas_more/next_cursorin its structured result; its bounded text rendering is unchanged.Closes #200
Test plan
New end-to-end coverage in
backend/test/firing-pages.test.tsseeds 120 real firings through the app and walks the actual HTTP routes on a real Postgres (18.7 + pgvector 0.8.7): the limit is respected and the default is 50,has_moreflips false on the last page,beforereturns only older firings with none repeated or missing across all pages, a page cut inside a same-timestamp group still resumes correctly, malformed cursors get 400 on both routes, and the bot routine history pages identically.Direct neighbors also pass on the same database:
Other checks (run on Windows, real Postgres on port 5444):
bun run typecheck: backendtsc --noEmitexits 0; frontendtsc --noEmitexits 0; all 13packages/*tsc --noEmitpass.bun test scripts/agent-docs.test.ts: 5 pass.cd frontend && bun run lint: 0 errors (248 pre-existing warnings).cd frontend && bun run test: 2010 pass, 3 fail, all pre-existing environment failures in files this change does not touch (two CRLF-sensitive source assertions insession-rail-layout.test.ts, oneghostty-webfetch() URL is invalidinterminal-surface.test.ts).cd backend && bun run test: 3593 pass, 56 fail. Every failure is environmental to this Windows box (no/bin/sh, no~/.bun/bin/bun.exefor spawned tests,:in temp dir names, Unix permission bits, CRLF checkouts, missing engine binaries, one flaky 30 s timeout innextOccurrence); the representative subset was rerun on a cleanupstream/mainworktree and fails identically there. No failure is in the firing/history path:schedules.test.ts,bots-routines.test.ts,automation-tools.test.tsand the newfiring-pages.test.tsall pass.End-to-end demo of the new contract (from the test run, real route responses over 120 seeded firings):
The 120 firings paged in three
limit=50requests return exactly the same ids in exactly the same order as one unbounded query, and ten firings sharing onefired_atto the microsecond straddle a page cut without duplication or loss.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.