Repository navigation
feat(id/web): non-destructive identity registration admission bound (#1766) - #4143
Conversation
…1766) - IdentityStore gains max_identities: register holds the clients write lock across bound check + redb persist + insert, so concurrent registrations cannot race past the cap; at capacity it returns the typed IdentityCapacityError and deletes nothing - Config: ID_WEB_MAX_IDENTITIES env (positive count or none), default 10000, invalid/zero values warn and fall back to the default; AppState wires configured_max_identities() through new_with_max_identities - Register handler maps the capacity error to an observable 503 identity_capacity_reached JSON body instead of a generic 500 - Existing identities are unaffected at capacity: verify_and_refresh never inserts and ignores the bound; records loaded at startup count toward it - Tests: at/beyond limit, 16-way concurrent race for 5 slots, refresh at capacity, restart at bound serves existing and refuses new - Issue #1766 stays open per its acceptance: lifecycle deletion / legacy records are a separate design
|
Warning Review limit reachedYou'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 29 minutes. View limit details
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. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4e4b15a0b2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if let Some(db) = &self.db { | ||
| let db = Arc::clone(db); | ||
| let record = identity.clone(); | ||
| run_blocking(move || db.create(&record)).await?; |
There was a problem hiding this comment.
Preserve admission accounting when registration is cancelled
If a persistent registration future is cancelled while awaiting this write, its clients guard is released, but run_blocking's spawned blocking task can still commit the record. The subsequent in-memory insertion never happens, so later registrations see an unchanged clients.len() and can admit more records. Repeated cancellations therefore bypass the new on-disk admission bound, and those uncounted records are all loaded on restart. Keep the admission reservation and in-memory accounting alive through completion of the blocking write, independently of the requesting future.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🤖 Agent note · Codex finding disposition (task 4795, lane C)
Accepted — this P2 is real and blocks merge. The cancellation path in register (identity.rs) releases the clients guard when the requesting future is dropped, while the run_blocking write can still commit the record to disk; the in-memory admission count then under-counts persisted records and the bound can be bypassed across repeated cancellations (and the uncounted records load on restart).
Disposition: FIX in this PR before merge — keep the admission reservation / in-memory accounting alive through completion of the blocking write, independent of the requesting future. Recorded as the merge blocker on queue task 4795. Not fixed in this pass: CI for head 4e4b15a is still QUEUED (run 41381468560, fleet runner backlog) and the laptop load gate (<20 for targeted Rust tests) is far exceeded (~101), so the fix will land with the next resume when it can be verified. PR #4143 will not be merged past this finding.
There was a problem hiding this comment.
Fixed in 537e1d7 (pushed to this PR). The check + persist + insert critical section in IdentityStore::register now runs in a detached tokio::spawn that owns the clients write lock, the admission reservation, and the in-memory insert through completion of the blocking write — cancelling the requesting future drops only the JoinHandle observation, so a record the blocking task commits is always inserted and counted, and the bound can no longer be bypassed by repeated cancellations. register still returns IdentityCapacityError as the root anyhow error, so the downcast_ref refusal path in routes.rs is unchanged. Verification: CI on the new head (the guard/arm64 checks were still QUEUED against 4e4b15a at fix time — fleet runner backlog) plus a fresh Codex pass on 537e1d7; the laptop targeted-test gate (load <20) is currently exceeded (~189), so no local cargo run was attempted. — queue worker lane C, task 4795
… blocking write (#1766) Codex P2 on PR #4143 (finding 4438590534): if the requesting future was cancelled while run_blocking was in flight, spawn_blocking still committed the record, but the clients guard dropped and the in-memory insert never happened — persisted records went uncounted and repeated cancellations could bypass the admission bound. The check + persist + insert critical section now runs in a detached tokio::spawn that owns the lock, the reservation, and the insert through completion of the blocking write; register only observes the outcome. IdentityCapacityError is returned as the root anyhow error exactly as before, so the routes downcast_ref check is unchanged.
|
🤖 Agent note · done — both follow-up legs dispositioned (task 8529) Follow-up to task 8497's review of this merged PR. Both legs re-verified against fresh Leg 1 — concurrent-saturation test: already satisfied in Leg 2 — Task 8529 completes as |
Summary
Implements the non-destructive mitigation pinned by the #1766 triage (queue task 4795): a configurable admission bound on web identity registration. Issue #1766 stays open — lifecycle deletion / legacy-record handling is a separate design, per the packet acceptance.
What landed
pkgs/id/src/web/identity.rs—IdentityStoregainsmax_identities.registernow holds theclientswrite lock across bound check + redb persist + in-memory insert, so concurrent registrations cannot race past the cap (previously the persist happened before the insert with no lock spanning both). At capacity it returns the typedIdentityCapacityErrorand deletes nothing. Records loaded from disk at startup count toward the bound.verify_and_refreshnever inserts and ignores the bound, so existing identities keep authenticating and refreshing at capacity.ID_WEB_MAX_IDENTITIESenv var (positive count, ornonefor unbounded); default10_000. Invalid or zero values log a warning and fall back to the default rather than silently refusing every first visit.AppState(web/mod.rs) wiresconfigured_max_identities()through the newIdentityStore::new_with_max_identitiesconstructor.pkgs/id/src/web/routes.rs— the register handler downcasts the capacity error to an observable503with body{"error": "identity_capacity_reached", "detail": ..., "limit": ..., "registered": ...}plus a warn log, instead of a generic 500.Tests
Four new tests in identity.rs: registration at/beyond the limit, a 16-way concurrent race for 5 slots, token refresh at capacity, and restart with the store at bound (serves existing, refuses new).
Verification status: NOT yet run. The fleet laptop load gate (sustained <20 before a cargo cycle; load was ~46-55 throughout the shift) barred a local
cargo test; the code was syntax-checked with rustfmt (parses clean, no fmt diffs in the new hunks). CI on this PR is the first full verification — task 4795 is parked on it, and the resuming lane will disposition CI + Codex findings before merge.Need help on this PR? Tag
@codesmith-botwith what you need.