Skip to content

Add regression test for stale cached-null + duplicate-key race condition in GrouperWorker#537

Closed
Copilot wants to merge 2 commits intofix-cachefrom
copilot/sub-pr-536
Closed

Add regression test for stale cached-null + duplicate-key race condition in GrouperWorker#537
Copilot wants to merge 2 commits intofix-cachefrom
copilot/sub-pr-536

Conversation

Copy link
Contributor

Copilot AI commented Mar 6, 2026

The existing CacheController mock always invokes the resolver and treats del as a no-op, making it impossible to reproduce the race condition where a stale null is cached and must be invalidated before a retry. Without a real caching layer in tests, the infinite-recursion bug introduced by a duplicate-key error could silently regress.

Changes

  • Regression test using real CacheController — uses jest.requireActual to bypass the global mock, giving the test genuine cache semantics (null is cached; del actually evicts)
  • Race condition simulation — pre-inserts the event in the DB (Worker B wins the race), then manually poisons the cache key with null (Worker A's stale entry); the unique index on groupHash causes the real insertOne to throw E11000
  • Two-pronged assertion — verifies cache.del was called with the exact stale key, and that totalCount increments to 2 (retry found the DB record and processed it as a repetition rather than recursing)
// Real cache so null is actually cached and del actually evicts
const RealCacheController = jest.requireActual('../../../lib/cache/controller').default;
const realCache = new RealCacheController();
(worker as any).cache = realCache;

// Stale null — Worker A cached "not found" before Worker B's insert
realCache.set(eventCacheKey, null);

await worker.handle(task);
// E11000 from DB → cache.del(eventCacheKey) → retry finds real event
expect(delSpy).toHaveBeenCalledWith(eventCacheKey);
expect(savedEvent.totalCount).toBe(2);

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: neSpecc <3684889+neSpecc@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 6, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fastdl.mongodb.org
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node ./postinstall.js /home/REDACTED/.cache/node-gyp/24.14.0/deps/uv/include -I /home/REDACTED/.cache/node-gyp/24.14.0/deps/zlib .node&#34; &#34;Release/sshcrypto.node&#34; 2&gt;/dev/null || (rm -rf &#34;Release/sshcrypto.node&#34; &amp;&amp; cp -af &#34;Release/obj.target/sshcrypto.node&#34; &#34;Release/sshcrypto.node&#34;)&#39; &gt; ./Release/.deps/Rele /home/REDACTED/.cache/node-gyp/24.14.0/deps/v8/include -I ../../../../../nan --64 -o Release/obj.target/sshcrypto/src/binding.o conf�� s. pull.rebase /usr/local/bin/bash (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node node_modules/.bin/jest --testPathPattern=workers/grouper/tests/index --testNamePattern=stale null conf�� e/common.gypi user.email tures/node_modules/.bin/as 14.0 /x64/lib/node_mo-c 14.0/&lt;(target_ar# remove blank lines; /hawk.workers/no-I e pu_features/src/-I (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Update event cache invalidation for duplicate key error Add regression test for stale cached-null + duplicate-key race condition in GrouperWorker Mar 6, 2026
@neSpecc neSpecc marked this pull request as ready for review March 6, 2026 18:46
@codex-assistant
Copy link

Thanks for adding a description — the PR is now marked as Ready for Review.

2 similar comments
@codex-assistant
Copy link

Thanks for adding a description — the PR is now marked as Ready for Review.

@codex-assistant
Copy link

Thanks for adding a description — the PR is now marked as Ready for Review.

@neSpecc neSpecc closed this Mar 6, 2026
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.

2 participants