Repository navigation
Apply the pipelines' live and daily caps to every dispatch path - #2122
Merged
Merged
Conversation
Live cap guards the hold; daily cap, live cap and a 10 per invocation bound clamp eligible runs. Tested on real SQLite; refs #2121
Tested against the real routes; refs #2121
Docs only; refs #2121
The cron passes its room to dispatchEligible, so the day's count is scanned once per tick. CRON_DISPATCH_PER_TICK is the contract bound. Targeted tests pass; refs #2121
Race, cap 0, pool independence, created counts, plan check on both engines; mutation-checked. Refs #2121
Docs only; refs #2121
Contributor
Author
|
Review round 2, pushed as c491124, d0392d8, 900bd36. Targeted tests, typecheck and lint pass.
Also in the PR body: the merge note for #2116. |
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR2122Version: 🤖 Updated on each push. |
This was referenced Nov 11, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #2121 (phase P1). Goes on
dev; no migration, no queue, no switch added.What was wrong
POST /admin/compute/pipeline/run(--eligible --limit N, N up to 100) calleddispatchEligible, which created pipeline jobs with no live guard and no daily guard and stopped only on a refusal such as an empty pool.The daily dispatcher applied
pipelines.maxLiveJobsandpipelines.dailyJobCaponly as reads before dispatching, so an admin run racing the cron could exceed them.The comment on
COMPUTE_PIPELINE_RUN_LIMIT_MAX("the policy's daily cap is the real ceiling") was false.Design
createJobaddsPIPELINE_LIVE_JOBS_GUARD_SQLto the hold's own statement forsource = 'pipeline', the patternLIVE_JOBS_GUARD_SQLuses for a person: pipeline jobs live in the pool (literal live states,createdincluded) must be fewer thanpolicy.pipelines.maxLiveJobs[pool].A refusal reads back as the existing
over_concurrency(guard_refused), so the documented order of refusals is unchanged and a refused hold still writes no job, ledger row or pseudonym.Pipeline jobs may have a null account (
compute-jobs.test.tscreates them), whichaccount_id = ?would never count, and the cron's existing read counted every pipeline job regardless of account.One shared statement (
PIPELINE_LIVE_JOBS_SQL) is both the guard and the read, so the room read equals the room enforced.Without the account term the planner does not use
compute_jobs_live; it scanscompute_jobs_examined, which is partial on the same live-state list, so the scan is over live rows only (a test pins this: partial live index, never the table).dispatchPipelineJobintocreateJob, as the third-party branch does withCLIENT_DAY_GUARD_SQL;PIPELINE_JOBS_TODAY_SQLis a full scan ofcompute_jobsthat would then run inside every pipeline hold's write, and an account-bound count or a new index needs an account bind or a migration; an atomic daily guard belongs in P2 beside the tenant-ceiling guard).pipelineRoom(db, policy, pool) -> { daily_left, live_left }(moved intocompute-pipeline.ts, used by the cron, the admin route and the dry run).dispatchEligibletriesmin(limit, COMPUTE_PIPELINE_RUN_PER_INVOCATION = 10, daily_left, live_left)for every actor, and stops withdaily_cap_reached(new, 409, declared inCOMPUTE_PIPELINE_ONLY_REFUSAL_STATUS) orover_concurrencywhen a cap, not the requested number, ended the run or the room is 0.The per-invocation bound is not a refusal (
stopped_bynull,room.limited_by = per_invocation).over_concurrency, stamprefused, no ledger row) and counted by, not refused by, the daily cap (comment says the owner may rule otherwise).room { daily_left, live_left, limited_by }(limit | per_invocation | daily_cap | live_cap, first on a tie), on live eligible runs and dry runs; the dry run trimswould_dispatchto it and reportsblocked: over_concurrencyfor a named dataset on a full pool.COMPUTE_PIPELINE_RUN_LIMIT_MAXfixed; route sentence forover_concurrencyis now "NEMAR's pipelines already have as many live jobs as the owner allows."; CLI help and print updated; ADR 0118 addendum dated 2026-11-10; CHANGELOG### Fixedunder Unreleased.Tests (real SQLite with every migration, real admin router, the Tapis stand-in; no mocks)
New
backend/test/compute-pipeline-caps.test.ts(12 tests): (a) limit 100 over 20 datasets with cpu cap 3 makes exactly 3 live jobs, 3 holds, 3 stamps, none refused, stopsover_concurrency,room.live_left3; (b) admin run vs cron viaPromise.allonroundTripD1(a round trip each side of every statement) for one slot, same dataset and different datasets, plus ten concurrent named datasets for three slots; (c) daily cap 2 with one job today dispatches 1 thendaily_cap_reached, and a named dataset counts toward it without being refused; (d) named dataset on a full pool is 409over_concurrency, stamprefused, ledger and job counts unchanged; (e) dry run reports the room and trims; (f) 25 datasets with room for all dispatch 10; the cron still dispatches only what the live cap allows.Also: CLI tests (
test/admin-compute-pipeline-cli.test.ts: help, live print, dry-run print, per-invocation print, named dataset exit 1), the contract unit test (new word, new schema, bound), and the plan check for the guard statement incompute-jobs-migration.test.ts.On unmodified
devthe new file fails 11 of 12 (the 12th is the cron regression test, which passes on both).Mutation checks (one line broken by hand, restored each time):
< ?to< ? + 1000No existing test's expectation changed.
Passing: the new file,
compute-pipeline*(compute-pipeline, dispatch, queue, routes, eligibility, verify, stamps-migration),compute-jobs,compute-jobs-migration,compute-ledger-race,compute-route-inventory,compute-switches-flag,compute-source-scan,compute-jobs-admin-routes,cron-sweep-wiring, the fouradmin-compute-*-clisuites,adr-index,changelog-format, the compute contract and state unit tests;bun run typecheck,bun run lint.Not verified
bun testwas not run (targeted tests only, per the repo rule).roundTripD1; the guard itself is now also raced on Miniflare D1 incompute-jobs.test.ts(second review round)..context/decisions/README.mdindex line for 0118 left as is (the index test does not require a change).Merge note for the third-party epic (#2116, on hold)
That branch rewrites the same
guardsblock increateJob. Whoever mergesdevinto it must keep the pipeline branch of the guard (source === "pipeline"); the crowd test and test (d) incompute-pipeline-caps.test.tsfail if it is dropped.Second round (review fixes)
Daily-cap rationale corrected; tick bound tied to the contract constant; both-engine guard tests (race, cap 0, pool independence, created counts, plan check on both engines); the day's count scanned once per tick and once per admin run or dry run; CHANGELOG folded into the compute bullet under Added.