Skip to content

Tenant-wide ceiling on live jobs, checked at acceptance (P2) - #2126

Merged
neuromechanist merged 13 commits into
devfrom
feature/tenant-ceiling
Nov 11, 2026
Merged

neuromechanist merged 13 commits into
devfrom
feature/tenant-ceiling

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Refs #2121 (phase P2: the tenant-wide ceiling on live jobs, checked when a job is accepted). No queue (P3), no migration.

What is added

  • Policy key tenant { maxLiveJobs, reserved { people, pipelines, partner } } (optional, strict; the schema refuses floors that add up to more than the ceiling, so PUT /admin/compute/policy does). TENANT_POLICY_DEFAULT = ceiling 20, floors 8 / 2 / 0, the same object DEFAULT_COMPUTE_POLICY.tenant carries; a stored policy without the key falls back to it, never to "unlimited".
  • services/compute-tenant.ts: TENANT_COUNTS_SQL, tenantGuard(class, tenant), tenantFacts, tenantClassOf (by source word: cli/web people, pipeline pipelines, partner partner, swept rows and orphans other).
  • createJob adds the tenant guard for EVERY source, after the class cap. The rule, in the hold's own statement: occupied + 1 + SUM over other classes of max(0, floor - occupied) <= ceiling. Occupancy is every live row plus one slot per row (live or not) that records an orphaned platform job.
  • New refusal word platform_busy (409), worded last (each guard is asked again in order after the refused hold, so the class cap wins over the tenant). It stops a pipeline run (STOPS_A_RUN) and ends the daily dispatcher's whole run (ENDS_THE_RUN); the admin route sentence is "NEMAR's share of the cluster is full right now; try again shortly."
  • GET /admin/compute/status gains tenant and the attention count tenant_over_ceiling; nemar admin compute status prints Tenant: occupied/ceiling (people a, pipelines b, partner c, other d); the policy help documents the key. The live tenant sweep adds tenant_live=<n> occupied=<n>/<ceiling> to its line and warns when tenant_live exceeds the ceiling.
  • ADR 0118 amendment of 2026-11-10 and a CHANGELOG sentence folded into the compute bullet.

Defaults and what they do

With the defaults the pipelines can burst to 12 (their own caps are 8 CPU + 4 GPU) only while nothing else occupies a slot, and people to 18. Runs and dry runs are clamped to the tenant room (room.tenant_left, limited_by: tenant). The floors are unconditional.

Tests

New backend/test/compute-tenant-ceiling.test.ts (36 tests). Every guard case runs on BOTH engines (bun:sqlite and Miniflare D1): two and six requests racing for the last slots, a mixed crowd under a floor, a floor unconditional, a ceiling of 0, a floor equal to the ceiling, classes independent, a created job counting, web and cli one class, the orphan term, the plan on both engines (live leg through a partial index, the orphan leg the one scan), the stored-policy-without-the-key fallback. Route level (real admin router and Tapis stand-in): (a) a CPU eligible run over a full ceiling makes 0 jobs, takes no hold, stops with platform_busy and the stamp is refused (with a control one slot higher that dispatches); the cron stops with the word; PUT refuses floors above the ceiling; the status route; the default 12-burst. Sweep, status CLI, contract and state unit tests updated.

Mutation checks (one line each, restored): no guard (dev behavior): (a) and 14+ others fail (dispatched 5 instead of 0); <= to <: race, floor and edge cases fail; floor term zeroed: floor and independence cases fail; orphan term off: orphan case and the plan pin fail; fallback made unlimited: the three fallback tests fail.

Targeted runs: all backend/test/compute* files plus admin-credential-cascade (1599 pass, 0 fail), the compute CLI suites, adr-index, changelog-format, contract/state units and contract-schemas; bun run typecheck, bun run lint clean. No migration, so migrations:d1-check was not run.

Existing tests changed (the default ceiling is real)

Three suites made more live jobs than the default admits, so each lifts the ceiling for itself, with a comment: compute-jobs on Miniflare D1 (never reset), compute-pipeline-dispatch ("never more than one tick's bound", 13 live jobs), compute-access-reporter (30 live jobs). One CLI run showed four pool grant timeouts under machine load (5 s); they pass alone.

Not verified / limits

  • Not run: the full bun test (epic-to-dev), and the remaining root CLI suites.
  • The orphan term has no index (it would need a migration), so every hold pays one scan of compute_jobs; pinned by the plan test and written in the ADR.
  • The counts are NEMAR's own view; the warning in the sweep is how occupancy NEMAR did not admit shows.
  • A Worker rolled back to a build from before this reads a stored policy with the tenant key as unreadable (strict reader, fails closed): write a policy without the key first.
  • I did not add the optional room.tenant_left to a run response.

For the third-party epic (#2116)

That branch rewrites the same guards block of createJob: whoever merges dev into it must keep the tenant guard and the pipeline guard (and the guardRefusal ordering).

Review round

Review fixes are listed per item in the comment below (head b27fbee4). P2 is not in 0.10.33; this PR merges into dev after the release PR, and its changelog sentence sits in the Unreleased compute bullet, ready to move.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR2126

Version: 0.10.34-PR2126.a44b850
Commit: a44b850


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review fixes pushed (head b27fbee4, origin/dev merged; the one CHANGELOG conflict kept both sides, the tenant sentences last in the compute bullet).

  • I1 TENANT_COUNTS_SQL now counts every row that records an orphan (orphan_tapis_uuid IS NOT NULL, no state filter), so a live row with a duplicate platform job holds two slots. Tests on both engines: terminal row with an orphan (1), live row with a duplicate (2, and nothing else admitted), terminal row without one (0). "Never too few" is reworded in the code and the ADR (a platform job nothing recorded, or a second orphan of one row, is not counted).
  • M1 room.tenant_left and limited_by: tenant (order: limit, per_invocation, daily_cap, live_cap, tenant, first on a tie); a run is clamped to tenant_left and stops with platform_busy; a dry run of a named dataset reports blocked: platform_busy after over_concurrency. tenantRoom is the guard's own arithmetic (test: a class has room exactly when its next job is admitted). Both engines: ceiling 3 full gives room 0, limited_by: tenant, blocked named dataset, and the live run agrees (dispatched 0, stopped_by: platform_busy); two slots more gives a preview of 2 and a live run of 2; a tie goes to limit. CLI room line and help updated. Consequence: an eligible run is now stopped by the clamp before it claims a stamp; the hold's guard still refuses a named dataset or a racing run, and that path ends the stamp refused (tested).
  • M2 reworded at all five places and the test comments.
  • M3 ADR and CHANGELOG qualified; policy help gains the sentence.
  • M4 createJob re-reads the idempotency key before wording a refusal. Both engines: three concurrent requests with one key at the last slot give one job and two replays of the same job, one hold.
  • M5 ENDS_THE_RUN exported, membership unit-tested, cron test asserts recipes.length (1). Note: the membership test asserts over_concurrency and daily_cap_reached are NOT in the set (they are pool-scoped and handled by refusedPools); they never were.
  • M6 policy_unreadable attention count (always present, 1 when the strict reader throws); the tenant block is then absent; the CLI prints it with what it means. Other errors are no longer swallowed. Tests: route, CLI, and createJob throws ComputePolicyUnreadable and writes nothing on both engines.
  • M7, M8, M9, S1, S3, S4 ADR text; the M7 launcher answer is stated as verified in code (503 policy_unavailable at the route, compute_disabled from the service's own read). S2 comment fixed (readTenantSlots runs before the loop).
  • Owner's answer on floors: ADR item 1 now says a floor protects a class from the other classes and admits nothing over the ceiling.
  • Three more existing tests lift the tenant ceiling for themselves (caps (f), the rotation test with 11 orphan-carrying live jobs).

Mutations (hand, restored): orphan term off fails 6 tests; old non-live-only orphan rule fails the duplicate test on both engines; platform_busy out of ENDS_THE_RUN fails the membership test; key replay removed fails the replay test on both engines; clamp without the tenant fails 3 (a, dry run on both engines); guard <= to < fails the race tests on both engines.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Round-2 fixes pushed (head 0876150f). e5743a4c: test/compute-admin-contract.unit.test.ts now expects tenant last in COMPUTE_PIPELINE_LIMITED_BY and parses a room carrying tenant_left (and refuses a string one); the file is 39/39, with contract-schemas, compute-state, compute-contract, changelog-format and adr-index also green (632 pass in all), and no other test pins the list. 0876150f (docs only): the compute-tenant.ts docblock and ADR 0118 now name the second live-orphan case (a live row with a cancel pending whose Tapis job turned up later is recorded by bindTapisJob as both tapis_uuid and orphan, so one job counts twice until cancelOrphan succeeds or the row ends; one slot, errs high, shows in cancel_pending_failed after an hour), and the ADR gains the sentence that each live orphan cuts the pipelines' 12 by one and the four slots to the cluster's 24 do not help them, so a stray orphan or two leaves the daily run unchanged unless more than about 2 pipeline jobs from earlier days are still live. Verified in code: BIND_ORPHAN_UUID_SQL sets tapis_uuid when null, then recordOrphan sets the orphan.

@neuromechanist
neuromechanist merged commit bbe29d8 into dev Nov 11, 2026
27 checks passed
@neuromechanist
neuromechanist deleted the feature/tenant-ceiling branch November 11, 2026 21:01

This branch was previously deployed

1 inactive deployment
npm — a44b8507 Deployed Nov 11, 2026 by neuromechanist via publish #4402
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