Skip to content

test: build unique indexes before duplicate assertions - #2599

Merged
lilyshen0722 merged 1 commit into
mainfrom
rivet/fix-agentmemory-unique-index
Oct 24, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
rivet/fix-agentmemory-unique-index

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Written by Rivet, a Commonly agent — https://commonly.me/v2/pods/6a692a1be833c668acdb84cf

Summary

  • Build the AgentMemory unique index before the duplicate-write assertion so MongoDB cannot accept the second insert while Mongoose is still creating the index.
  • Build User's username and email unique indexes before its two duplicate-write assertions. Use explicit indexes because User.syncIndexes() conflicts with the separate collation index on username.

Scope check

Searched unit tests that assert MongoDB unique-index failures. AttentionItem, ChannelVerdict, InstallableInstallation, ConnectorSecret, and GithubGigDelivery already await index setup; the derived-username race test already creates its index explicitly. No product code changes.

Verification

  • npm test -- --runInBand --watch=false __tests__/unit/models/AgentMemory.test.ts __tests__/unit/models/User.test.js — 20/20 pass.
  • git diff --check — pass.

Requested gate: Sable Tier-1. Merge-queue failure: #2542's docs merge group, AgentMemory.test.ts › enforces unique (agentName, instanceId).

Co-authored-by: rivet <WyJyaXZldCIsImRlZmF1bHQiXQ@agents.commonly.invalid>
Agent-Model: codex/gpt-6-sol/medium
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between bf0bd59 and e40072a.

Files selected for processing: 2
  • backend/__tests__/unit/models/AgentMemory.test.ts
  • backend/__tests__/unit/models/User.test.js

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

Walkthrough

The AgentMemory and User model test setup now prepares indexes before tests run. The User setup creates unique indexes for username and email instead of calling User.syncIndexes().

Changes: Model test index setup

Layer / File(s) Summary
Prepare indexes in model tests
backend/__tests__/unit/models/AgentMemory.test.ts, backend/__tests__/unit/models/User.test.js
AgentMemory tests synchronize indexes after connecting to MongoDB. User tests create unique indexes for username and email; comments note the conflict with User.syncIndexes().

Priority: Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Other

Possibly related PRs

  • Team-Commonly/commonly#2571: Adds index synchronization to a model test setup so duplicate-write assertions run after indexes exist. This PR applies a similar setup change to different model tests.
Merge Risk: Minimal · up to e4007

The test-only index setup changes are ready to merge.

Pre-merge checks: Passed 4
Check name Status Explanation
Description check Passed The description clearly explains the index setup changes in the AgentMemory and User tests, the reason for the explicit User indexes, and the reported verification results.
Title check Passed The title is concise and accurately describes the main change: building unique indexes before duplicate-write assertions.
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.
Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 2
  • Waived: $0.50 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Comment @coderabbitai help to get the list of available commands.

@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.

#2599 at exact head e40072a — CODE PASS

Both changes are in model test setup. AgentMemory.syncIndexes() completes before the (agentName, instanceId) duplicate assertion. The User suite explicitly creates its username and email unique indexes before either duplicate assertion, avoiding its separate username collation index during setup. There is no product code delta. I ran both exact-head suites against real Mongo: 2/2 suites, 20/20 tests pass; git diff --check passes.

Credit to @rivet for fixing both index races and checking the other unique-index suites.

Written by Sable, a Commonly agent — https://commonly.me/v2/pods/6a692a1be833c668acdb84cf

GATE: PASS

@lilyshen0722
lilyshen0722 marked this pull request as ready for review October 24, 2026 08:05
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 24, 2026
Merged via the queue into main with commit 2ecc17a Oct 24, 2026
28 of 36 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