Skip to content

fix(notifications): avoid quadratic provider candidate scans - #588

Merged
imshashank merged 9 commits into
mainfrom
codex/fix-notification-candidate-query
Nov 16, 2026
Merged

imshashank merged 9 commits into
mainfrom
codex/fix-notification-candidate-query

Conversation

@imshashank

@imshashank imshashank commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

The provider notification candidate query repeatedly scans the earlier-delivery backlog for each eligible row. Move the current source join into the outer query and place the email exemption inside a top-level NOT EXISTS predicate, allowing PostgreSQL to plan a hash anti join while preserving ordering, workspace isolation, eligibility and leases.

Only the query and its regression tests change. No schema, migration, index or dependency change.

Validation at dc35503:

  • Integrated actual main 11332e2. Tree 144ae9ac2228696ade4ff125beb2a308246c78ea exactly matches the frozen full-verification tree.
  • Full local verification: 7,067 passed, 0 failed, 0 skipped; all static and type checks passed.
  • Focused notification suites: 43 passed. The actual emitted SQL regression fails before the fix with 66,560 logical row visits against a 5,120-row budget.
  • Bounded local 1,024-conversation comparison returned identical ordered candidate IDs: original 351.074 ms and 1,052,672 row visits; repaired 2.949 ms and 5,124 row visits. These are local measurements, not production latency guarantees.
  • Covers email exemption, future-available and ambiguous earlier deliveries, ingestion ties, workspace/conversation boundaries, deduplication and lease boundaries.
  • Fresh exact-head CI is running. Draft remains until final review and checks complete.

ayam04 and others added 8 commits November 16, 2026 08:33
The formatting popover was anchored at the selection midpoint, shifted left by
half its own width through a CSS transform, and pinned 44px above the selection
top. Neither axis was bounded, and the surface scrolls inside an overflow
container, so a selection starting at the left edge of the narrow drawer put
roughly half the popover outside it, and a selection on the first line put the
popover above the box entirely (#515).

The popover now measures itself after mount, centres on the selection only where
the result fits, clamps into the editor box otherwise, and flips below the
selection when there is no room above it. The placement rule is a pure exported
helper, so the reported geometry is a unit test.

Verified:
- bun test tests/features/docs/editor/rich-text-editor.test.tsx: 31 passed
- bun test tests/features/docs: 487 passed, 3 failed, and the same three fail on
  a clean main checkout (useAutosave x2 under full-suite timing, and the outline
  memo setext underline case), so they are pre-existing
- RED both ways: restoring the pre-fix arithmetic fails the six placement tests
  and both component tests; restoring only the pre-fix rendering fails the two
  component tests (left 12px instead of 8px, top -40px instead of 28px)
- biome check, check-comments, check-bytes and check-deps are clean
- apps/web tsc --noEmit names neither touched file (the checkout reports
  pre-existing errors elsewhere)

Fixes #515

Signed-off-by: ayam04 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The provider-outbox candidate query now joins deliveries to their source events and applies an earlier-delivery exclusion to non-email candidates. New tests cover candidate ordering, filtering, lease boundaries, and query work.

Changes: Provider Outbox Candidate Selection

Layer / File(s) Summary
Join source events and apply delivery ordering
packages/services/src/notifications/provider-outbox.ts
The candidate query selects delivery columns and joins each delivery to its source event. For non-email candidates, it excludes deliveries with an earlier delivery in the same conversation, using the joined source event’s ingestion sequence.
Verify candidate selection behavior
packages/services/tests/notifications/provider-outbox-candidates.test.ts
Tests check selection order, email independence from Slack barriers, blocking by unavailable earlier deliveries, tie-breaking, organization scope, lease boundaries, deduplication, and logical row work.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Merge Risk: Minimal · up to dc355

This change rewrites the provider-outbox candidate query to avoid quadratic scans while keeping ordering, email exemption, leases and organization scope. No concrete defect was found, and the added tests cover those behaviors. It looks safe to merge once CI passes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a fix that avoids quadratic scans in the provider candidate query. The raw summary and objectives confirm the query rewrite (moving the source join to the outer query …
Description check Passed The description states the purpose (reduce repeated backlog scans in the provider candidate query), the query change, the email exemption placement, and the test-only scope. It also lists validation r…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a fix that avoids quadratic scans in the provider candidate query. The raw summary and objectives confirm the query rewrite (moving the source join to the outer query and using a top-level NOT EXISTS for the email exemption) is the primary change. The title is concise and specific, and it follows the scope described in the objectives.

Full details: Description check

Explanation

The description states the purpose (reduce repeated backlog scans in the provider candidate query), the query change, the email exemption placement, and the test-only scope. It also lists validation results. It relates directly to the changeset, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Noveum/orbit
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 11332e2
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cce332ad-d371-417b-87f4-d5b7a6399b14
Commits

Reviewing files that changed from the base of the PR and between 11332e2 and dc35503.

Files selected for processing: 2

  • packages/services/src/notifications/provider-outbox.ts
  • packages/services/tests/notifications/provider-outbox-candidates.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@github-actions github-actions Bot added tests Test coverage and test infrastructure area: web The Next.js app and its UI area: docs-feature The docs product and its editor area: integrations GitHub, Slack and webhooks labels Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Independent production diagnosis confirms this exact candidate SELECT is active on the served release, with multiple CPU-bound copies and no blocking locks. pg_stat_statements provided the full normalized SQL; activity text alone was truncated. Independent review checked the two-part rewrite and the actual emitted-SQL workload test, including email exemption, ordering, leases and workspace isolation. The local 1,024-conversation fixture returns the same ordered candidates while reducing measured logical row work from 1,052,672 to 5,124. No production EXPLAIN ANALYZE, load test, schema change or index change was performed. Full verification is active; actual-main integration and fresh CI still precede merge.

@github-actions github-actions Bot removed area: web The Next.js app and its UI area: docs-feature The docs product and its editor area: integrations GitHub, Slack and webhooks labels Nov 16, 2026
@imshashank
imshashank marked this pull request as ready for review November 16, 2026 18:25
@imshashank
imshashank requested a review from pulkitxm as a code owner November 16, 2026 18:25
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
orbit Ready Ready Preview Nov 16, 2026 6:40pm UTC

Request Review

@imshashank
imshashank merged commit c71be0b into main Nov 16, 2026
16 checks passed
@imshashank
imshashank deleted the codex/fix-notification-candidate-query branch November 16, 2026 18:41

Copy link
Copy Markdown
Contributor Author

Production verification: the merged c71be0b artifact is serving the public alias. The scheduler allowance was rotated to its exact current hostname, with the previous hostname retired and no broader API/OAuth/MCP exception. All five cron definitions point to the same production artifact. No migration was needed; Postgres remains 3.4.9.

After more than 330 seconds of natural scheduling, all 11 retrieved notification/sprint-rollover requests returned 200 and no Task timed out event was retrieved for the new deployment. Public health, realtime readiness and an authenticated read passed. The daily/hourly jobs were not manually invoked. One separate Redis rate-limiter connection timeout remains under investigation; this does not claim all production issues are resolved.

This branch was successfully deployed

1 active deployment
Preview — dc355036 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test coverage and test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants