Skip to content

test(tier1): the per-file drop keeps each model's indexes - #3717

Merged
lilyshen0722 merged 4 commits into
mainfrom
swe/tier1-indexes
Nov 7, 2026
Merged

lilyshen0722 merged 4 commits into
mainfrom
swe/tier1-indexes

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

stalledConnectMcpSeen.test.js ejected #3496 from the queue (run 42386512527). Five tests failed, and each one leans on the unique index on StalledConnectEpisode: a second scan posted again, and two episodes existed where one should. The same code passed one slot later. The log shows the file failed once; the second listing is jest's summary.

Cause: in Tier 1, setupMongoDb connects, then drops the shared database. Connecting starts each loaded model's index build, and dropDatabase removes any index that has already finished. Mongoose doesn't rebuild it, so that file runs with no unique index. Which index goes depends on timing, so any Tier 1 test that relies on one can flake this way.

Fix: wait for the loaded models' index builds, drop, then build their indexes again. The setup change is Tier 1 only. Memory-server runs gain the one new test, which does a drop and rebuild of its own. A model first loaded after setup still builds its own.

Proof

  • New tier1-setup-keeps-indexes.test.js runs in every tier, needs no Tier 1 job, and is deterministic. It sets up a second time after the model's build has finished, which is the case where the build beats the drop. On main's testUtils.js it failed 3 of 3 runs; with this change it passes. It names the (installationId, tokenIssuedAt) index.
  • A loop through the real setupMongoDb with INTEGRATION_TEST=true on mongod 7.0.14, one model with a unique index: missing 40 of 40 on main, 0 of 40 with this change.
  • How often the build wins is timing, and I haven't measured it in CI. The review's own harness, on a different mongod and with its own ordering, lost the index 0 of 100 times. The queue failure fits this mechanism: every failed test leans on that index, and two episodes existed where it allows one. I haven't reproduced the failure in the real job.

A real conflict this turned up: User declares a unique username index and a collated one, and both get the name username_1. Mongo refuses the second. autoIndex swallows that, so an awaited Promise.all failed the whole Tier 1 job on an earlier head of this PR. The setup uses allSettled, which keeps autoIndex's behaviour. The schema is left alone here because changing it builds a new index on the real users collection, so it needs its own change.

Cost: each Tier 1 file builds its models' indexes once more, on empty collections. Compare the job's time here against main.

🤖 Generated with Claude Code

https://claude.ai/code/session_015AKgpQtAEnhB56gowm8yYg

@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a0db746 and 06a18a2.

Files selected for processing: 2

  • backend/__tests__/service/tier1-setup-keeps-indexes.test.js
  • backend/__tests__/utils/testUtils.js
  • 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

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

06a18a2

One review round, author's subagent (Haiku, effort medium), four passes. Test infra only.

Covered: the new test's reconnect, env restore in every tier, and that allSettled doesn't hide the guarded case, since the test still fails if the index is missing. Both Tier 1 shards pass at this head, which is the evidence over the whole service directory.

The reviewer didn't reproduce the author's 40-of-40 and 3-of-3 runs. Their own harness, on another mongod with a different order, lost the index 0 of 100 times. The PR body says so.

Not fixed: allSettled drops rejection reasons, so a future conflict stays as quiet as it is in autoIndex. _connectionString is a private mongoose field. User's index conflict is on the board.

GATE: PASS

@lilyshen0722

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 7713c5b Nov 7, 2026
36 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant