Skip to content

feat(id/web): non-destructive identity registration admission bound (#1766) - #4143

Merged
dezren39 merged 2 commits into
mainfrom
queue/4795-1766-identity-admission-bounds
Nov 2, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/4795-1766-identity-admission-bounds

Conversation

@dezren39

@dezren39 dezren39 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

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 — IdentityStore gains max_identities. register now holds the clients write 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 typed IdentityCapacityError and deletes nothing. Records loaded from disk at startup count toward the bound. verify_and_refresh never inserts and ignores the bound, so existing identities keep authenticating and refreshing at capacity.
  • Config — ID_WEB_MAX_IDENTITIES env var (positive count, or none for unbounded); default 10_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) wires configured_max_identities() through the new IdentityStore::new_with_max_identities constructor.
  • pkgs/id/src/web/routes.rs — the register handler downcasts the capacity error to an observable 503 with 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.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…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
@dezren39
dezren39 requested a review from a team as a code owner November 2, 2026 03:08
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b50ba04f-2420-4aa2-82a9-102d47e1ac8c
Commits

Reviewing files that changed from the base of the PR and between c8a2191 and 537e1d7.

Files selected for processing: 3
  • pkgs/id/src/web/identity.rs
  • pkgs/id/src/web/mod.rs
  • pkgs/id/src/web/routes.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T05:54:30.450993Z 537e1d7 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread pkgs/id/src/web/identity.rs Outdated
Comment on lines +317 to +320
if let Some(db) = &self.db {
let db = Arc::clone(db);
let record = identity.clone();
run_blocking(move || db.create(&record)).await?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.
@dezren39
dezren39 merged commit 2b7b246 into main Nov 2, 2026
2 of 4 checks passed
@dezren39
dezren39 deleted the queue/4795-1766-identity-admission-bounds branch November 2, 2026 15:39
@dezren39

dezren39 commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

🤖 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 main (a65000aea, laptop primary clone, 2026-11-04):

Leg 1 — concurrent-saturation test: already satisfied in main; no new test needed.
pkgs/id/src/web/identity.rs carries test_register_admission_bound_concurrent_race — present in this PR's own merge commit 2b7b246f30eda0a79ee37d7bc72bf5f979f31252 and still in current main. It spawns 16 concurrent registrations against an admission bound of 5 (new_ephemeral_with_limit(Some(5))), asserts exactly 5 succeed, the other 11 are refused with the typed IdentityCapacityError, and the store holds exactly 5 afterwards. The store is ephemeral (identities lost on drop), so cleanup is by construction. This is the equivalent the packet allowed citing: the packet's named concurrent_bounded_registration_exposure / registration_tests.rs never existed — the identity tests live inline in identity.rs, alongside the sequential test_register_admission_bound_at_and_beyond_limit. Adding a duplicate under a new name would be manufactured work.

Leg 2 — world/core.rs production line guard: violation live, fix already owned by PR #5365.
Current main: pkgs/id/src/world/core.rs is 2515 lines, over the 2500 production line limit (.github/workflows/production-line-guard.yml). The fix is PR #5365 (task 9340, issue #5358), which extracts pkgs/id/src/world/core/checkpoint_parts.rs: OPEN, MERGEABLE, its basic: production line limit (2500) check pending in the runner queue. No competing PR was created from task 8529 — that leg completes when task 9340 merges PR #5365.

Task 8529 completes as triaged with task 9340 cited as the follow-up for leg 2.

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