Repository navigation
feat(api): cursors on the events and incidents APIs - #640
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #640 +/- ##
==========================================
+ Coverage 83.67% 83.70% +0.03%
==========================================
Files 1268 1269 +1
Lines 129705 129785 +80
==========================================
+ Hits 108535 108643 +108
+ Misses 21161 21133 -28
Partials 9 9
🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Incidents now read their cursor back (keyset on started_at, uid). Events and incidents accept order=asc: oldest first, cursor means strictly after, the cursor is always returned, rows younger than 5 s are held back. MCP list_incidents takes cursor and order. OpenAPI, wiki and docs updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Adds handler tests for order=bogus (400) on the events and incidents lists and an MCP list_incidents test for order=asc, cursor and the invalid order result. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Makes the events and incidents list APIs usable by a program that follows alerts (an agent, a script, a bridge) and must resume where it stopped after a restart. Implements
specs/done/2026/10/2026-10-22-06-events-and-incidents-cursors.md.Problem
GET /incidentshanded outpagination.cursorbut never read it back (// TODO: Parse cursor), so page 2 returned page 1. Events had a cursor but no way to read forward in time.What changed
ListIncidentsreads the cursor and filters on(started_at, uid). Incidents are now ordered bystarted_at DESC, uid DESC, so ties no longer skip or repeat rows.pagination.cursoris now an opaque base64 string. A bare-UID cursor from before is ignored and gives the first page.order=ascon events and incidents (GET /events,/checks/{uid}/events,/incidents/{uid}/events,GET /incidents). The cursor then means "strictly after this one" and is always returned. An empty page returns the cursor it was given.descstays the default and is unchanged. Any otherordervalue gives a 400.ascmode. Rows younger than 5 s are held back so a consumer never skips a late commit. The clock is injectable (WithClock) for tests.EncodeCursor/DecodeCursormoved tohandlers/base/cursor.go. The events cursor format is unchanged, so old events cursors still decode.list_incidentstakesorderandcursorand returns the next cursor.wiki/api-specification/results-incidents.md, and a new "Follow events from a program" section inweb/docs/docs/features/live-updates.md.Tests
Table-driven tests on SQLite and Postgres: walks over tied timestamps (8 incidents, page size 3, both orders), resume after new rows, empty page, settle window with a fake clock, bare-UID cursor,
order=bogusreturning 400 on all four endpoints, and the MCP tool.make build-backend lint-back testpasses locally.make test-postgresis left to CI.Decided by autopilot
order=ascwith no cursor and nosince: starts at the oldest event, not at now (spec's recommended answer).🤖 Generated with Claude Code