feat: Plan 7 PR B — sync_cursors, lag endpoint, SSE integration - #16
Conversation
Plan 7 PR B: resolve edge nodes from API keys, monotonic cursor upserts from last_written_hw, GET /v1/admin/sync/lag, and sse-sync integration coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 8 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (10)
Comment |
Co-authored-by: Cursor <cursoragent@cursor.com>
PR Summary by QodoPersist SSE sync cursors, add admin lag endpoint, and expand integration coverage
AI Description
Diagram
High-Level Assessment
Files changed (9)
|
Code Review by Qodo
Context used✅ Compliance rules (platform):
18 rules 1.
|
messagesgoel-blip
left a comment
There was a problem hiding this comment.
Review: PR #16 — Plan 7 PR B
Well-structured follow-up to PR #15. Here is my review:
What it adds
syncCursorRepository.ts— resolves edge nodes from API keys, monotonicGREATEST()cursor upserts,listSyncLag()with per-edge lagsseSession.ts— periodic + event-count-based cursor persistence,finish()function that persists cursor on disconnect,apiKeyIdpassthroughrequireStaff.ts— middleware forisStafforadmin:readscoperoutes/admin.ts—GET /v1/admin/sync/lag- Integration tests — 278 lines: 400 parsing, bootstrap cursor id 0 + ping, 503 cap, 429 backlog, cursor persist + lag, forbid without
admin:read, score.upsert streaming
What looks good
| Area | Notes |
|---|---|
| Cursor persistence | Monotonic GREATEST(), errors caught and logged. Correct. |
| Edge node resolution | Auto-creates row on first connect from API key (informational per plan). |
finish() consolidation |
Eliminates scattered cleanup, fires persist on disconnect. Cleaner. |
| Integration tests | Comprehensive. Uses ControlPlaneHarness. Score tests skip gracefully without trust-engine. |
| Lag endpoint | Properly auth-gated via requireStaff. Bigint-safe with ::text. |
Minor notes (non-blocking)
listSyncLagrunsMAX(sync_version)twice — negligible at this scaleedge_nodesnot cleaned up on API key revocation — acceptable for v1durableEventsWrittenis cumulative across initial batch + poll — threshold fires slightly early on first poll, functionally fine
Verdict
Clean, well-tested, integrates correctly with PR #15. Ready to merge.
Address PR #16 review: scope admin:read lag to the caller's tenant, ORDER BY numeric lag, and enforce one edge_nodes row per API key. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Addressed the three Qodo findings in a9e51b3:
@coderabbitai review |
|
✅ Action performedReview finished.
|
messagesgoel-blip
left a comment
There was a problem hiding this comment.
Review of latest commit (a9e51b3)
This is a cleanup/fix commit that addresses several real issues from the initial PR B implementation.
Changes
1. Migration 013 — unique edge_nodes per API key ✅
Adds a unique index on (tenant_id, api_key_id) with deduplication of existing rows first (cleans up related sync_cursors, decision_aggregates, decision_samples, decision_batches before deleting duplicate edge_nodes). This eliminates the race where concurrent SSE connections from the same API key created duplicate rows.
2. resolveEdgeNodeForApiKey — now upsert instead of select-then-insert ✅
Uses INSERT ... ON CONFLICT ... DO UPDATE — eliminates the race between the SELECT and INSERT. Much cleaner.
3. listSyncLag — tenant-scoped + CTE optimization ✅
- Accepts optional
tenantIdparameter for tenant-scoped queries - Uses CTE to compute
MAX(sync_version)once instead of two subqueries ORDER BY (hw.high_water_version - sc.last_cursor) DESC— numeric sorting, fixing lexicographic ordering (where "9" > "100" as text)
4. routes/admin.ts — proper tenant isolation ✅
Staff sees global lag; API key callers see only their own tenant. The scopeTenantId logic correctly gates this.
5. Integration tests — 2 new tests ✅
tenant admin:read lag is scoped to own tenant only— multi-tenant isolation verifiedorders lag rows by numeric lag descending— edge_low (lag=9) after edge_high (lag=100), confirming numeric sort
Any issues?
None. Every change is correct and improves the original code.
Verdict
Clean, well-motivated fix commit. Ready to merge.
- timeWindow: reject Date-parseable but non-ISO 8601 forms (e.g. 01/02/2024) to avoid ambiguous from/to; accept date-only + zoned timestamps. (+tests) - ProviderHomePage: embed active tenant id in query keys so a tenant switch partitions the cache and refetches instead of showing stale data. (providerQueryKeys helper + tests) - badge--passthrough: darken text to #6b5d23 (5.4:1 on #f0ead2) for WCAG AA. Skipped (replied inline): - edge-node high-water tenant scoping: sync_version is a global monotonic counter (global advisory-lock allocator); matches merged listSyncLag (#16). - scores/graph tenant scoping: trust graph + network scores are global/shared by Plan 9 Decision 5; any authenticated tenant member may read them.
Summary
sync_cursorsfrom authenticated edge nodes (last_written_hwonly), with periodic + disconnect writesadmin:readGET /v1/admin/sync/lagfor per-edge lagsse-syncintegration coverage (bootstrap/heartbeat, 503, 429 backlog, cursor persist + lag, scope forbid); score cases whenTRUST_ENGINE_ADDRis setTest plan
cd control-plane && npm run test:unitcd control-plane && npm run test:integration(Postgresverilink_teston 15432)npx tsc --noEmitin control-plane@coderabbitai review