Skip to content

Fix FaceTec duplicate enrollment race - #606

Open
sirpy wants to merge 2 commits into
masterfrom
fix/facetec-post-index-duplicate-check
Open

sirpy wants to merge 2 commits into
masterfrom
fix/facetec-post-index-duplicate-check

Conversation

@sirpy

@sirpy sirpy commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Serialize the FaceTec uniqueness search + 3D index insertion critical section across all enrollment identifiers using a global distributed lock (facetec-uniqueness:<indexName>).

  • Uses Redis (REDISCLOUD_URL via SET ... PX ... NX + Lua owner-checked renew/release) when configured, falling back to MongoDB (findOneAndUpdate lease document with periodic renewal and assertOwned() verification before indexing).
  • Preserves the indexed == verified unique invariant (unverified enrollments are never speculatively indexed), eliminating same-identifier pending-window and failed-cleanup bypasses.
  • Re-checks isEnrollmentIndexed inside the lock when alreadyEnrolled is true so concurrent requests for the same identifier do not double-search or double-index.
  • Adds configurable ZOOM_ENROLLMENT_LOCK_LEASE_SECONDS and ZOOM_ENROLLMENT_LOCK_TIMEOUT_SECONDS settings.

Tests

  • Unit tests for DistributedEnrollmentLock covering both MongoLockStore and RedisLockStore (serialization, acquisition timeout, stale-owner lease protection).
  • Concurrent enrollment tests in ZoomProvider covering cross-wallet duplicate serialization and same-identifier concurrent requests.

Summary by Sourcery

Serialize FaceTec uniqueness checks and indexing so concurrent enrollments cannot bypass duplicate detection.

New Features:

  • Add distributed lease-based locking backed by Redis or MongoDB to coordinate FaceTec uniqueness checks and indexing across requests.

Bug Fixes:

  • Prevent concurrent enrollments of the same face under different identifiers from both being accepted, and avoid indexing the same identifier more than once during concurrent requests.

Enhancements:

  • Recheck whether an enrollment is already indexed after acquiring the lock before performing duplicate checks and indexing.

Tests:

  • Add coverage for concurrent enrollment serialization, lock timeouts and stale lock ownership across MongoDB and Redis stores.

Chores:

  • Add MongoDB enrollment-lock model and configurable lease and acquisition timeout settings for FaceTec enrollment coordination.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 13:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Enrollment retries can bypass uniqueness checks during pending verification or after failed cleanup, allowing duplicate face enrollments.

2 open issues
What changed in this PR

This PR addresses FaceTec same-face enrollment races across wallets by adding a post-index uniqueness check without a distributed lock.

Changes:

  • Checks for duplicates before and after indexing.
  • Attempts cleanup after post-index failures or indexing timeouts.
  • Adds concurrency and cleanup tests and updates existing expectations.
File Description
src/​server/​verification/​processor/​provider/​ZoomProvider.js Adds post-index duplicate detection and cleanup handling.
src/​server/​verification/​processor/​provider/​__tests__/​ZoomProvider.js Covers concurrent enrollments and cleanup, and adjusts callback expectations.

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 14:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Lease expiry and zero-duration leases can allow duplicate face indexing, while stalled FaceTec requests can hold the enrollment lock indefinitely.

4 open issues
2 resolved since last review

Review effort: Balanced

},
zoomEnrollmentLockLeaseSeconds: {
doc: 'Lease duration in seconds for the global FaceTec uniqueness check + indexing lock',
format: 'nat',

// if not already enrolled or indexed - indexing
try {
await api.indexEnrollment(enrollmentIdentifier, defaultSearchIndexName, customLogger)
Comment on lines +161 to +164
const acquired = await this.store.tryAcquire(name, owner, leaseMs)

if (acquired) {
return this._createLease(name, owner, leaseMs)
throwException(message, { isEnrolled }, response)
}
// 3. checking for duplicates
const { results, ...faceSearchResponse } = await api.faceSearch(

This branch has not been deployed

No deployments
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.

3 participants