Skip to content

Guard factory initialization concurrency#781

Merged
EffortlessSteven merged 2 commits into
mainfrom
codex/build-edge-case-tests-and-refactor-code-ofs0xa
May 17, 2026
Merged

Guard factory initialization concurrency#781
EffortlessSteven merged 2 commits into
mainfrom
codex/build-edge-case-tests-and-refactor-code-ofs0xa

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Motivation

  • Prevent duplicate expensive initializers and races when multiple threads concurrently call Factory::get_or_init for the same (domain, label, spec, variant) identity.
  • Preserve existing fast-path cache behavior and reentrant semantics while ensuring only the first initializer runs for a given identity.

Description

  • Add a std-gated InitLocks (backed by Mutex<BTreeSet<ArtifactId>> and a Condvar) and an InitGuard type, and wire an init_locks field into Inner to coordinate per-artifact initialization.
  • Acquire an initialization guard in Factory::get_or_init (init_locks.acquire(&id)) and re-check the cache after acquiring the guard so waiters return the already-cached value instead of duplicating work.
  • Add a concurrency regression test concurrent_same_identity_runs_initializer_once demonstrating eight simultaneous callers run the initializer exactly once and receive the same cached Arc.
  • Include small formatting/lint tidy-ups to satisfy the project linting scripts.

Testing

  • Ran cargo test -p uselesskey-core concurrent_same_identity_runs_initializer_once --lib and it passed.
  • Ran cargo test -p uselesskey-core --lib and the full unit test suite passed (129 passed; 0 failed).
  • Ran cargo check -p uselesskey-core --no-default-features and it completed successfully.
  • Ran cargo clippy -p uselesskey-core --all-targets -- -D warnings and the crate passed clippy checks; also ran the workspace lint fixes (cargo xtask lint-fix) to apply formatting when cargo xtask lint-fix --check initially flagged a formatting diff.

Codex Task

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@EffortlessSteven has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 43 minutes and 53 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1aa7ff82-4642-4933-9503-5a19abd8f325

📥 Commits

Reviewing files that changed from the base of the PR and between 9756a7d and fd98b84.

📒 Files selected for processing (1)
  • crates/uselesskey-core/src/srp/factory.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/build-edge-case-tests-and-refactor-code-ofs0xa

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

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

@EffortlessSteven EffortlessSteven merged commit 712742f into main May 17, 2026
6 checks passed
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.

1 participant