Skip to content
This repository was archived by the owner on Nov 12, 2026. It is now read-only.

fix(monitor list): page through the REST list, forward --limit/--offset — HAT-1264 - #26

Merged
beengud merged 1 commit into
mainfrom
hat-1264-monitor-list-paging
Nov 10, 2026
Merged

beengud merged 1 commit into
mainfrom
hat-1264-monitor-list-paging

Conversation

@beengud

@beengud beengud commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Jira: HAT-1264. Found in the HAT-1219 review.

Problem

src/rest/monitor/list-monitors.ts called the versioned GET /v1/monitors without limit and ignored meta. The command's --limit/--offset only sliced, on the client, the one page the server chose to return. The server returns every monitor today (135), so nothing is lost yet; once it pages by default the list is silently truncated, and mop-config's check-monitor-collisions.sh --limit 1000 and mop observe monitor list would both miss monitors.

Change

  • listMonitors sends limit/offset and follows the paging: pages of at most 1000 (the largest the server accepts; limit=5000 is a 400), until the requested window is full, the server returns an empty page, or meta.totalCount is reached (-1 = unknown, pages until an empty page). The legacy bare-array fallback (403 on the version header) ignores limit/offset, so the window is applied locally there. A 403 after the first page is an error, not a fallback.
  • monitor list forwards --limit/--offset to the API when no local filter applies. With --kind/--disabled/--sort it fetches the whole list (paged) and windows locally, as before. The table's Found N is the window size on the server path.
  • Fork patch; upstream observeinc/cli main has the same code and is unchanged by this.

Tests

Paged mock in list-monitors.test.ts: multi-page window (2345 → 3 calls), stop at totalCount without an extra request, a limit larger than a page, window inside the list, offset alone, server page cap below ours, unknown total, filter on every page, 403 after page one, legacy window. Command tests: limit/offset forwarded, default limit forwarded, local window with --kind / --sort.

bun test src/commands/monitor/list.test.ts src/rest/monitor/list-monitors.test.ts
 40 pass / 0 fail / 95 expect() calls
bun test src: 720 pass, 23 fail, 16 errors (743 tests) — main cef2a8e: 705 / 23 / 16 (728); every failure is in a trimmed area, unchanged
tsc: 0 errors in src/rest/monitor and src/commands/monitor (the 260 repo-wide errors are the trimmed areas, unchanged)
eslint + prettier: clean on both directories
bun run build: All builds succeeded (6 targets)

Live (tenant 109601619518, darwin-arm64 build)

Call Result
monitor list --json --limit 1000 135 rows, identical ids to ts-cef2a8e
monitor list --json 100 rows (default limit, now the server's window) + the --offset 100 hint
monitor list --json --limit 5 --offset 133 2 rows (43383174, 43383547)
monitor list --json --match mop --limit 1000 12 rows (meta.totalCount 12)
monitor list --json --kind Threshold --limit 3 3 Threshold rows, windowed locally
REST probe limit=5 → 5 + totalCount 135; limit=1000 → 135; limit=5000 → 400; legacy shape ignores limit

🤖 Generated with Claude Code

`listMonitors` called the versioned `GET /v1/monitors` without `limit`
and ignored `meta`, so the command's --limit/--offset only sliced the one
page the server chose to return. Once the server pages by default the
list would be silently truncated (HAT-1264).

- `listMonitors` now sends `limit`/`offset` and follows the paging:
  pages of at most 1000 (the largest the server accepts; 5000 is a 400),
  until the requested window is full, the server returns an empty page,
  or `meta.totalCount` is reached (-1 = unknown pages until empty). The
  legacy bare-array fallback ignores limit/offset, so the window is
  applied locally there.
- `monitor list` forwards --limit/--offset to the API when no local
  filter applies; with --kind/--disabled/--sort it fetches the whole list
  (paged) and windows locally as before.
- Unit tests with a paged mock: multi-page windows, totalCount stop,
  server page cap below ours, unknown total, filter on every page, 403
  after the first page is an error not a fallback, legacy window.

Live (tenant 109601619518, 135 monitors): --limit 1000 -> 135 (same ids
as ts-cef2a8e), --limit 5 --offset 133 -> 2, --match mop -> 12.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@beengud
beengud merged commit 58481aa into main Nov 10, 2026
4 checks passed
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.

2 participants