Skip to content

fix(api): disable mongoose autoIndex in check-alerts worker - #2887

Open
Vansh98789 wants to merge 5 commits into
hyperdxio:mainfrom
Vansh98789:fix/check-alerts-mongo-session-error
Open

fix(api): disable mongoose autoIndex in check-alerts worker#2887
Vansh98789 wants to merge 5 commits into
hyperdxio:mainfrom
Vansh98789:fix/check-alerts-mongo-session-error

Conversation

@Vansh98789

Copy link
Copy Markdown

Summary

The check-alerts worker only reads from MongoDB and never needs to ensure indexes exist-the API service owns that responsibility.

Previously, Mongoose's autoIndex triggered background createIndexes calls that raced with the worker's short-lived connection closing (which sends endSessions). This surfaced as MongoExpiredSessionError on mongodb.createIndexes spans.

This PR:

  • Disables auto-indexing for the worker connection via connectDB({ autoIndex: false }).
  • Removes the now-redundant mongoose.set('autoIndex', false) from init().

Files Changed

  • packages/api/src/models/index.ts
  • packages/api/src/tasks/checkAlerts/providers/default.ts

How to Test on Vercel Preview

N/A - non-UI change.

References

Closes #2734

The worker only reads from MongoDB, so background createIndexes calls raced the short-lived connection close (endSessions) and failed with MongoExpiredSessionError on mongodb.createIndexes spans.

Closes hyperdxio#2734
@changeset-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 339430a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/api Patch
@hyperdx/app Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

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

@vercel

vercel Bot commented Aug 12, 2026

Copy link
Copy Markdown

@Vansh98789 is attempting to deploy a commit to the HyperDX Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps

greptile-apps Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR disables Mongoose automatic index creation for the short-lived check-alerts worker while preserving the existing defaults for other database consumers.

  • Extends connectDB to accept optional Mongoose connection options.
  • Connects the alert worker with autoIndex: false.
  • Adds a patch changeset documenting the worker-specific behavior.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
packages/api/src/models/index.ts Adds an optional, caller-controlled Mongoose options override while retaining the shared connection defaults.
packages/api/src/tasks/checkAlerts/providers/default.ts Disables automatic index creation specifically when the check-alerts provider initializes its MongoDB connection.
.changeset/dull-carrots-bow.md Records the worker connection fix as an API patch release.

Fix All in Greploop

Reviews (5): Last reviewed commit: "chore: add changeset for autoIndex fix" | Re-trigger Greptile

Comment thread packages/api/src/tasks/checkAlerts/providers/default.ts Outdated
Vansh98789 and others added 2 commits August 12, 2026 22:57
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@Vansh98789

Copy link
Copy Markdown
Author

Hi @pulpdrew
Deep review is failing due to pull_request_target fork-checkout restrictions since this is from a fork -might need maintainer approval or a workflow tweak.
Thanks

@karl-power

Copy link
Copy Markdown
Contributor

Hi @Vansh98789 Please add a changeset for this PR by running yarn changeset. Thanks!

@Vansh98789

Copy link
Copy Markdown
Author

Hi @karl-power, I've added the changeset as requested. Could you please review it? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot use a session that has ended on createIndexes spans from check-alerts task

2 participants