Skip to content

test(api): pin the alert history index in the query shape test - #3764

Merged
jordan-simonovski merged 1 commit into
mainfrom
jordansimonovski/fix-flaky-alert-history-index-test
Nov 23, 2026
Merged

jordan-simonovski merged 1 commit into
mainfrom
jordansimonovski/fix-flaky-alert-history-index-test

Conversation

@jordan-simonovski

Copy link
Copy Markdown
Contributor

Summary

Fixes the integration shard flake in checkAlerts › alert history query shape › scans the {alert, createdAt} index with tight createdAt bounds, added in #3702. It accounts for every failed integration job in the last 200 main.yml runs.

  • DocumentDB plans queries with Postgres's cost model. On the test's 10-row collection a seq scan is often estimated cheaper than alert_1_createdAt_-1, so the plan flips between runs depending on table stats left by earlier tests.
  • The test now hints the index. The totalKeysExamined <= 2 assertion still checks that the createdAt bounds from perf(api): bound check-alerts history lookup by alert interval #3702 stay tight, and hint throws if the index is ever renamed or dropped.
  • Test-only, no changeset.

How to reproduce

On main: run make dev-int FILE=checkAlerts.int.test.ts a few times. Some runs fail with a COLLSCAN winning plan (example: Integration - Shard 4).

On this branch: the same command passes (198/198 locally).

References

DocumentDB's cost-based planner often chooses a seq scan over
alert_1_createdAt_-1 on the test's 10-row collection, failing the
integration shard. Hinting the index keeps the check on what matters:
the createdAt bounds stay tight.
@jordan-simonovski
jordan-simonovski requested a review from a team as a code owner November 22, 2026 22:43
@changeset-bot

changeset-bot Bot commented Nov 22, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5573755

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 22, 2026 10:46pm UTC
hyperdx-storybook Ready Ready Preview Nov 22, 2026 10:46pm UTC

Request Review

@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Nov 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 0
  • Production lines changed: 0 (+ 5 in test files, excluded from tier calculation)
  • Branch: jordansimonovski/fix-flaky-alert-history-index-test
  • Author: jordan-simonovski

To override this classification, remove the review/tier-2 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 108 in total (1.13%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

1 finding(s): 🔴 0 P0/P1 · 🟡 0 P2 · 🔵 1 P3

No inline comments. 1 P3 folded at the bottom.

🔵 1 P3 — no action needed before merge
  • 🔵 P3 packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts:12795 — With .hint(), the winningPlan toContain('alert_1_createdAt_-1') assertion can no longer fail → Delete the winningPlan assertion, or keep it with a comment saying it only guards against the hint being ignored. With the hint in place the plan must contain the index, and if the index is missing the hint throws before this line runs. The test's real job now is the totalKeysExamined <= 2 bound. Retitle the test to match (e.g. 'keeps createdAt bounds tight on the {alert, createdAt} index'). It no longer checks that the planner picks this index for the unhinted query in getPreviousAlertHistories (packages/api/src/tasks/checkAlerts/index.ts:2122), so the current title overstates what it covers.

Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@github-actions

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

This is a focused, test-only change: it adds .hint('alert_1_createdAt_-1') before .explain('executionStats') in the alert-history query-shape test to stop DocumentDB's cost-based planner from flipping to a seq scan on the 10-row fixture. The correctness of the surrounding assertions holds — getAlertHistoryLookbackMs('5m') clamps to a 1-day minimum, so the $gte bound and the totalKeysExamined <= 2 check remain consistent, and pinning the index makes the key-count assertion more meaningful rather than less.

🟡 P2 -- recommended

  • packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts:12795 -- Forcing the index with hint makes the winningPlan toContain('alert_1_createdAt_-1') assertion tautological, so the test no longer verifies that the planner selects the index on its own and a future production regression where index selection degrades would not be caught here.
    • Fix: Drop the now-redundant winningPlan assertion or rely on totalKeysExamined plus the hint-throws guard as the intended signal, and update the test name/comment to reflect that it checks bound tightness rather than natural index selection.
    • testing, maintainability

Reviewers (4): correctness, testing, maintainability, project-standards.

Testing gaps: Natural (unhinted) index-selection for this query shape is no longer under test; the remaining assertions cover bound tightness and index existence only.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

@github-actions

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 471 passed • 1 skipped • 1092s

Status Count
✅ Passed 471
❌ Failed 0
⚠️ Flaky 13
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@jordan-simonovski
jordan-simonovski merged commit 54d9d51 into main Nov 23, 2026
32 checks passed

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 5573755f Deployed Nov 22, 2026 by vercel[bot]
Preview – hyperdx-storybook — 5573755f Deployed Nov 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants