Skip to content

Fix/cursor pagination#742

Open
sakeena-7878 wants to merge 10 commits into
SdSarthak:mainfrom
sakeena-7878:fix/cursor-pagination
Open

Fix/cursor pagination#742
sakeena-7878 wants to merge 10 commits into
SdSarthak:mainfrom
sakeena-7878:fix/cursor-pagination

Conversation

@sakeena-7878
Copy link
Copy Markdown
Contributor

@sakeena-7878 sakeena-7878 commented May 27, 2026

Summary

Closes #663
This PR replaces offset-based pagination in the LLM Guard /history endpoint with cursor-based pagination using a base64-encoded (scanned_at, id) cursor.

A dedicated CursorPaginatedResponse schema is introduced to avoid breaking the existing PaginatedResponse contract used elsewhere in the system.
SQLite compatibility handled (no tuple comparison operator used; logic uses explicit and_/or_ filtering)
Frontend has been updated to support cursor-based pagination instead of page/offset.

Type of Change

  • Bug fix
  • New feature
  • Refactor

Checklist

  • I have read CONTRIBUTING.md
  • My code follows the project style (PEP 8 for Python, ESLint for TS)
  • pytest backend/tests/ passes locally
  • I have not committed .env or any secrets

Screenshots (if UI change)

Replaced page/limit pagination with cursor/next_cursor

@SdSarthak SdSarthak added gssoc:approved GSSoC approved contribution — required for points to count level:advanced Advanced difficulty task type:performance Performance improvement type:refactor Code refactoring labels May 27, 2026
Copy link
Copy Markdown
Owner

@SdSarthak SdSarthak left a comment

Choose a reason for hiding this comment

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

Two regressions need to be fixed before this can merge:

  1. The empty-prompts validation was removed (if not self.prompts: raise ValueError). Batch requests with zero prompts will now silently succeed with an empty response — please restore that guard.
  2. db: Session was removed from scan_prompt along with the webhook delivery block. That coupling was intentional — the webhook trigger relies on the db session. If the goal is to separate concerns, use BackgroundTasks to deliver the webhook asynchronously, but don't drop it entirely.

The CursorPagination helper itself and the CursorPaginatedResponse schema are the right direction — just fix the two regressions above.

@sakeena-7878
Copy link
Copy Markdown
Contributor Author

Ok got it

@SdSarthak
Copy link
Copy Markdown
Owner

The two regression fixes are in — the empty-prompts guard is restored and the db: Session + webhook delivery block are back. The implementation now looks correct. Please rebase on main to resolve the current conflicts and it will be ready to merge.

@SdSarthak SdSarthak added the type:feature New feature label May 28, 2026
@sakeena-7878 sakeena-7878 force-pushed the fix/cursor-pagination branch from e51033c to a84d739 Compare June 1, 2026 17:08
@sakeena-7878
Copy link
Copy Markdown
Contributor Author

This PR resolves guard module merge conflicts and completes the cursor-based pagination refactor.

Key updates:

  • Backend: cleaned guard endpoints, fixed schema imports, resolved pagination logic conflicts
  • Frontend: fixed API typing issues (RagSource, Guard interfaces), removed duplicates
  • Lint/build: frontend passes lint and production build successfully
  • Tests: updated and passing for guard API and related modules

Please let me know if any adjustments are needed.

@sakeena-7878 sakeena-7878 force-pushed the fix/cursor-pagination branch from d958c87 to 0fc4778 Compare June 2, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC approved contribution — required for points to count level:advanced Advanced difficulty task type:feature New feature type:performance Performance improvement type:refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrade /guard/history pagination from offset-based to cursor-based system

2 participants