Skip to content

id: per-account quotas — ownership resolution at the guest-burn charge path (#1067) - #12739

Merged
dezren39 merged 2 commits into
mainfrom
felix/1067-per-account-quotas
Nov 23, 2026
Merged

dezren39 merged 2 commits into
mainfrom
felix/1067-per-account-quotas

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Refs #1067 — the per-account quotas slice of F12.10, on the ownership model Drewry decided 2026-11-22 (decision note on #1067). Design: doc/2026-11-23_design_id1067-account-quotas.md.

What lands

Ownership resolution at the charge path (new id-worlds::account_charge):

  • resolve_charge_account implements the decided precedence: an explicit admin registry entry wins; a world configured for creator-principal charging charges its recorded creator; otherwise the calling account pays. A call carrying no caller identity at this layer charges the world's own charge key as its account bucket — visible in the counters, never silently charged to a different account.
  • WorldAccountRegistry is the (b) store: a JSON config mapping ({ "worlds": { "<id>": { "account": ..., "mode": ... } } }), runtime configuration in the RuntimeLimits idiom — installed once by the serve path (install_shared, first install wins), no admin UI. A malformed file is an error, not an empty registry.
  • Fail-visible (a): creator mode with no recorded creator is a typed ChargeResolutionError::CreatorNotRecorded. At the funnel the call does not run, no permit is taken, nothing is charged, a tracing::warn! names the world and reason, and the error propagates as the call's error. No world records a creator yet, so the mode is inert until a creation record lands — by design, and loudly rather than silently if configured early.

Per-account enforcement (guest_burn, beside slice 2's process-wide budget):

  • acquire_charged(key, account, allowance) admits against both the process-wide bound and an optional per-account concurrency bound. Queue-never-refuse preserved; grant eligibility is per waiter, so one account at its bound queues only its own calls (no cross-account head-of-line blocking, no deadlock — every admitted call is fuel-bounded).
  • Grant order: least attained service by account, then by key, then arrival (within one account this reduces to slice 2's order). Charges settle by actual fuel at both levels; an unsettled permit charges its allowance at both levels.
  • snapshot() gains per-account counters and the configured bound. The pre-account acquire() delegates with the key as its own account, so existing callers/budgets are behaviour-identical when no account bound is configured.
  • Configuration follows the RuntimeLimits pattern: guest_burn_per_account_concurrency / --world-guest-burn-per-account-concurrency, 0 = no per-account bound (the default — an unconfigured hub runs exactly slice-2 admission). restore_program applies it to the shared budget and installs the shared registry on every restored guest.

Wiring boundary, stated plainly: the funnel sees participant ids, not accounts — no caller principal reaches WorldInstance through the actor today, and no world records a creator. This slice wires everything downstream of that threading (resolution, enforcement, counters, the instance setter surface mirroring set_charge_key/set_burn_budget); session→actor caller threading is the remaining plumbing, named on #1067.

Evidence (laptop, under fleet-build-lock)

  • Fail-before: the new guest_burn tests spliced onto pristine origin/main fail to compile with 10 errors naming the missing surface (acquire_charged, new_with_account_bound, snapshot accounts, max_concurrent_per_account).
  • Pass-after: cargo test -p id-worlds --features sandbox --lib -- guest_burn account_charge sandbox:: — 57 passed, 0 failed, including all 14 new tests: resolution (registry wins / creator / caller / caller-less bucket / creator-less error / registry JSON), budget (per-account isolation, per-account fair grant order, settle-by-actual-fuel, bound clamping), and instance wiring (registry account charged; creator-less guest fails visibly and charges nothing).
  • cargo test -p id-caps --lib — 179 passed. cargo check -p id-cli clean; cargo test -p id-cli --lib — 743 passed, 1 failed: test_command_lists_cover_all_clap_subcommands ("README CLI Commands table omits walk"), which fails identically on pristine main (743/1 there too) — pre-existing fallout from the id walk landing, not this change.
  • Module-reach check passes; the slice is rustfmt-clean. No new dependencies.

Exit shape — not claimed

This slice does not claim #1067's exit criterion. The fuel_spin_isolation ratio gap is attributed in BASELINES.md to scheduler contention around the burn path (spawn/shutdown churn, the blocking round trip), which a per-account concurrency bound does not govern. What this slice changes: per-account fairness is now real at the funnel — one account's worlds can no longer hold the whole burn pool at once, grant priority has an account axis, and every burn is attributed to an account under the decided ownership model. Remaining on #1067: the hub scheduler, slow-client back-pressure, caller-principal threading to the funnel, and the persistent-spinner profile variant named in BASELINES.md.


Proof this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

felix and others added 2 commits November 23, 2026 00:07
…e path (#1067)

World→account ownership as decided 2026-11-22: calling account by
default, admin registry and creator principal as per-world options,
precedence registry > creator configuration > caller.

- account_charge (new, id-worlds): ChargeMode, WorldChargeConfig,
  WorldAccountRegistry (JSON config store, shared install), and the
  pure resolve_charge_account. Creator mode with no recorded
  creator is a typed error, never a silent caller fallback.
- guest_burn: per-account concurrency bound beside the process-wide
  one (queue-never-refuse, per-waiter eligibility so one account's
  bound queues only its own calls), grant order by account attained
  service then key, per-account counters in the snapshot, charges
  settling by actual fuel at both levels. acquire() delegates with
  the key as its own account, so pre-account callers are unchanged.
- sandbox: WorldInstance resolves the charge account before
  admission; a resolution failure fails the call visibly (logged,
  nothing charged). Composition setters mirror set_charge_key /
  set_burn_budget.
- world_store restore_program installs the shared registry and
  applies RuntimeLimits::guest_burn_per_account_concurrency
  (--world-guest-burn-per-account-concurrency; 0 = no bound).

Design: doc/2026-11-23_design_id1067-account-quotas.md
@dezren39
dezren39 requested a review from a team as a code owner November 23, 2026 00:39
@coderabbitai

coderabbitai Bot commented Nov 23, 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 16 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: c07497a1-cf6c-4a08-adc4-4e82dd92861e
Commits

Reviewing files that changed from the base of the PR and between ed259e4 and 7668819.

Files selected for processing: 8

  • doc/2026-11-23_design_id1067-account-quotas.md
  • pkgs/id/crates/id-caps/src/world_limits.rs
  • pkgs/id/crates/id-cli/src/cli/world.rs
  • pkgs/id/crates/id-worlds/src/account_charge.rs
  • pkgs/id/crates/id-worlds/src/guest_burn.rs
  • pkgs/id/crates/id-worlds/src/lib.rs
  • pkgs/id/crates/id-worlds/src/sandbox.rs
  • pkgs/id/crates/id-worlds/src/world_store.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

@dezren39

Copy link
Copy Markdown
Member Author

Verification addendum from the lane: clippy could not be run to a verdict on the laptop venue. Three configurations (broker-pooled target dir; fresh target dir with the profile cargo; fresh target dir with the rustup-pinned 1.99.1 toolchain end-to-end) all fail in dependency crates with E0514 ("found crate iroh_base/serde/tracing compiled by an incompatible version of rustc") before any workspace crate is checked — the laptop carries both a nix-profile rustc 1.99.0 and the rustup pin 1.99.1, and some build step mixes them. The failure is identical on code this PR does not touch and pre-dates the change; cargo test/cargo check on the same venue are green (see the PR body). The canonical gate is just check in the nix dev shell at review.

@dezren39
dezren39 merged commit b9b9436 into main Nov 23, 2026
2 checks passed
@dezren39
dezren39 deleted the felix/1067-per-account-quotas branch November 23, 2026 00:49
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