Skip to content

feat(account-management): add child_count to tenant read shape#4

Closed
diffora wants to merge 1 commit into
mainfrom
am/list-children-child-count
Closed

feat(account-management): add child_count to tenant read shape#4
diffora wants to merge 1 commit into
mainfrom
am/list-children-child-count

Conversation

@diffora

@diffora diffora commented Jun 23, 2026

Copy link
Copy Markdown
Owner

What

Adds a child_count field to the public tenant read shape — the number of direct children visible to the caller. It is filled on every read path that returns a Tenant: listChildren page rows, and the single-tenant get / update / suspend / unsuspend / delete / create responses.

Behavior

child_count =, for the tenant in the response, the number of its direct children that the caller may see:

  • Scope-filtered — bounded by the caller's AccessScope via SecureORM. A self-managed child's own subtree stays behind its barrier, so its child_count collapses to 0 for an outside caller (same visibility rule the rest of the read surface obeys).
  • Excludes Provisioning — AM-internal rows have no public representation anywhere on the SDK boundary.
  • Includes soft-Deleted — they remain reachable via $filter=status eq 'deleted'.
  • 0 for a leaf. Derived field — not part of $filter / $orderby (not a stored column).

Design notes

  • New repo method count_children_grouped(scope, parent_ids) runs one scope-filtered COUNT ... GROUP BY parent_id for the whole page — no N+1 across rows. Parents with no matching child are absent from the map (callers default to 0).
  • This is deliberately separate from the existing count_children / ChildCountFilter machinery, which is an internal delete-saga guard (allow_all, always counts Provisioning) — left untouched.
  • list_children passes the original barrier-respecting scope into lowering (not the relaxed one used to surface direct self-managed children), so grandchild counts stay scope-filtered.

Files

  • repo: count_children_grouped (trait + reads.rs impl + delegate + fake mock)
  • service: lower_to_tenant / lower_to_tenant_page take scope + fill child_count; all 7 call sites updated
  • sdk / REST: child_count: u32 on Tenant + TenantDto + from_sdk_tenant
  • docs: account-management-v1.yaml Tenant schema (properties + required)

Tests & gates

  • New: count_children_grouped_excludes_provisioning_includes_deleted, count_children_grouped_empty_input_is_empty (repo integration, real SQLite), list_children_reports_direct_child_count_per_child (service); updated DTO wire-shape test.
  • Green: cargo fmt, cargo clippy --all-targets -D warnings (default and --all-features --locked), cargo test (777 lib + integration, 0 failed), cargo dylint --all (custom DDD/GTS lints).

Compatibility

child_count is #[serde(default)] on the SDK Tenant, so existing payloads without the field still deserialize (→ 0).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Tenant API responses now include a child_count field displaying the number of direct child tenants visible to the caller, with soft-deleted children included.
  • Documentation

    • Updated OpenAPI schema to document the new child_count field, noting it is read-only, computed at request time, and unavailable for filtering or sorting operations.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@diffora, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 37 minutes and 41 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses rolling per-developer review limits. Reviews become available again as older review attempts age out of the rolling limit window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7deb97d2-6585-4ddb-958b-5478fddd8826

📥 Commits

Reviewing files that changed from the base of the PR and between 220f0b1 and 25cd58b.

📒 Files selected for processing (13)
  • docs/api/api.json
  • gears/system/account-management/account-management-sdk/src/tenant.rs
  • gears/system/account-management/account-management/src/api/rest/dto.rs
  • gears/system/account-management/account-management/src/api/rest/dto_tests.rs
  • gears/system/account-management/account-management/src/api/rest/handlers/tenants_tests.rs
  • gears/system/account-management/account-management/src/domain/tenant/repo.rs
  • gears/system/account-management/account-management/src/domain/tenant/service/mod.rs
  • gears/system/account-management/account-management/src/domain/tenant/service/service_tests.rs
  • gears/system/account-management/account-management/src/domain/tenant/test_support/repo.rs
  • gears/system/account-management/account-management/src/infra/storage/repo_impl/mod.rs
  • gears/system/account-management/account-management/src/infra/storage/repo_impl/reads.rs
  • gears/system/account-management/account-management/tests/list_children_integration.rs
  • gears/system/account-management/docs/account-management-v1.yaml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch am/list-children-child-count

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.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

@diffora
diffora force-pushed the am/list-children-child-count branch from 98c7c52 to e4e3713 Compare June 23, 2026 18:12
Surface the number of direct children visible to the caller on every
tenant read shape — listChildren page rows and the single-tenant
get/update/lifecycle responses.

- repo: count_children_grouped — one scope-filtered
  `COUNT ... GROUP BY parent_id` per page (no N+1). Excludes the
  AM-internal Provisioning status; includes soft-Deleted children.
  Distinct from the delete-saga count_children guard (allow_all, always
  counts Provisioning), which is left untouched.
- service: lower_to_tenant / lower_to_tenant_page now take the caller
  scope and fill child_count; list_children passes the original
  barrier-respecting scope (not the relaxed one) so a self-managed
  child's own subtree stays scope-filtered and counts to 0.
- sdk/REST: child_count: u32 on Tenant + TenantDto, plus the OpenAPI
  schema and the regenerated docs/api/api.json (make openapi).
- tests: grouped-count repo integration (provisioning excluded, deleted
  included, empty input) + per-child service coverage + dto wire-shape.

Signed-off-by: Diffora <ddiffora@gmail.com>
@diffora
diffora force-pushed the am/list-children-child-count branch from e4e3713 to 25cd58b Compare June 23, 2026 18:15
@diffora diffora closed this Jun 24, 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.

1 participant