Skip to content

Return 400 for an invalid audit cursor instead of 500 - #426

Merged
davidmckayv merged 2 commits into
CopilotKit:mainfrom
Ayush7614:fix/audit-cursor-400
Sep 8, 2026
Merged

Return 400 for an invalid audit cursor instead of 500#426
davidmckayv merged 2 commits into
CopilotKit:mainfrom
Ayush7614:fix/audit-cursor-400

Conversation

@Ayush7614

Copy link
Copy Markdown
Contributor

What

decodeCursor in server/src/audit.ts threw a generic Error that escaped the admin audit-events route's AuditQueryError catch as an unhandled 500. A stale or hand-edited bookmark is a caller error, like a bad from/to which already answers 400 since #378.

This throws AuditQueryError from decodeCursor and validates the cursor up front in auditQueryFromUrl, so GET /api/admin/audit-events?cursor=… answers 400 { error: cursor must be a valid audit page cursor } before reaching the store.

Why it matters

API contract gap on an admin-visible endpoint: corrupt pagination state produced 500s and log noise instead of a 400 the surface can explain. Fail-fast validation also keeps a bad cursor from ever reaching the database query builder.

Verification

  • New suite server/tests/audit-cursor.test.ts: corrupt cursor throws AuditQueryError; valid cursor still parses; route returns 400 with the cursor message without touching the store; valid cursor still pages (200).
  • bun test server/tests/audit-cursor.test.ts — 4 pass.
  • bun run --filter server typecheck — clean. Biome format + lint — clean.

decodeCursor threw a generic Error that escaped the admin audit-events
route's AuditQueryError catch as an unhandled 500. A stale or
hand-edited bookmark is a caller error, like a bad from/to/limit which
already answers 400.

Throw AuditQueryError from decodeCursor and validate the cursor up front
in auditQueryFromUrl, so the route answers 400 with a cursor message
before reaching the store.

@davidmckayv davidmckayv 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.

Deep-reviewed against live code (correctness, governance, no vendor/secret/scale issues). Composed build+tests green. CHANGELOG/format rebase on CI-validated substance.

@davidmckayv
davidmckayv merged commit 2d248d8 into CopilotKit:main Sep 8, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants