Repository navigation
Phase A7: Tenant reconcile, observer and reporting - #2055
Merged
Conversation
Migration 0118 (observer runs, queue snapshots, sacct rows, legal holds, sweep bookkeeping columns and indexes) and the shared words the later commits use. Tested with the suites that follow; the migration is also run by migrations:d1-check on real D1.
An overrun entry on the tenant partner pool with the people budget, once per job, never to a person. Tested: ledger-unreserved suite against the real triggers.
The two terminal repair lists, the orphan list and the cancel list rotate by last examination; a second orphan is logged; an unreadable terminal row is settled without its record; advance carries out a recorded cancel on staging. Tested: rotation suite, with mutations.
Per-run observer token and ingest with final settlement against Expanse figures; admin reporting, legal holds, ACCESS report re-queue and the observer mint route. Tested: observer, reporting route and contract suites, inventories.
Lists the tenant, binds the submit race, cancels duplicates, and indexes, cancels and charges jobs that skipped the reservation. Tested: sweep suite against the Tapis stand-in, source scan.
Deletes due records and logs honouring holds, counts any refusal as locked, reconciles results, and anonymises a deleted account's pools and ledger actors (migration 0130). Tested: retention suite on both SQL engines, with mutations.
Tick and daily production-only calls. Tested: cron wiring suite.
jobs list, record, report, access-report, hold, release-hold, holds, access-reports, requeue-access-report, observer mint. Tested: CLI suite against the real routes.
Pipeline run to observer-settled record, an account revoked mid-run, and an unreserved job, with the real CLI leg. Tested.
Amendment of 2026-11-05 and implementation notes section 12.
Test failed before the change (a 400 was silent), passes after.
Test failed before the change (a stranger tag got the job cancelled unrecorded), passes after.
Two tests failed before the change (bound-after-snapshot and conflicting insert), pass after.
Test failed before the change, passes after.
Two tests failed before the change, pass after.
Test failed before the change, passes after.
Test failed before the change, passes after.
New test; it fails when the division by nodes is removed.
Two tests failed before the change, pass after.
Two tests failed before the change, pass after.
Four tests failed before the change, pass after.
Two tests failed before the change, pass after.
Test failed before the change, passes after.
Test failed before the change, passes after.
The route already ran requireOwner as middleware before the handler; this test pins it and fails if the middleware is removed.
New tests; they fail when the regex check or the page bound is removed.
New test; it fails when the daily call is made with live.
New assertion; it fails when the stamp sets flag_overrun.
Test cleanups; the new assertion fails if available is not -2000.
Comment only; the scan test passes unchanged.
The A2 guard now names the two migrations and requires the one new trigger to be BEFORE UPDATE with a raise-only body.
Each column of a pool and of a ledger entry changed alone beside the anonymisation is refused; 23 single-term mutations are each killed. The trigger also pins created_at and updated_at of a pool now.
Comments, strings, the ADR amendment and the notes; identifiers and file names kept. Tested: retention, ledger and state suites pass.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR2055Version: 🤖 Updated on each push. |
New test; it fails when the counter always counts.
The branches were already single-counted (a race-bound job is not in the snapshot set); the new test passes before and after and locks it.
New test; it fails when the re-queue classifies by role alone.
Docs only; ADR index test passes.
neuromechanist
merged commit Nov 6, 2026
e6ca96f
into
feature/issue-2005-epic-compute-core
17 of 19 checks passed
neuromechanist
deleted the
feature/issue-2012-phase7-tenant-reconcile-observer-and-reporting
branch
November 6, 2026 18:25
8 of 9 tasks
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.
Implements #2012 (phase A7 of epic #2005): the tenant sweep, the observer and final settlement, admin reporting and legal holds, the retention sweep, the anonymizing update the A2 amendment assigned to this phase, the A5 and A8 open points, and the epic's end-to-end proof.
What changed
0118_compute_observer.sql: observer runs, queue snapshots, sacct rows, legal holds, five sweep-bookkeeping columns oncompute_jobs, and the partial indexes the rotations use. Migration0130_compute_anonymise.sql(numbered 0130, because 0114 to 0119 are used and 0120 to 0129 are reserved): the one exception to the pools' and the ledger's immutability (a deleted account's poolholder_refand ledgeractor_user_id).sweepTenantJobs,liveon the 30-minute tick,weekin the daily block, exact production only, and only whileCOMPUTE_ENABLEDis1): binds the submit race by tag, cancels a duplicate under a row's tag without indexing it, and indexes, cancels and charges to the partner pooltenantany job that skipped the reservation. A failed listing changes nothing.POST /admin/compute/observer-runsmints a one-hour token (<run id>.<HMAC>, domain tagcompute-observer);POST /compute/observerchecks it before reading a byte, answers one refusal for every bad token, bounds the body (1 MiB, 5,000 rows), spends the run with one conditional UPDATE, stores the rows and settles ended jobs to Expanse's figure throughsettleFinal, flaggingmismatchbeyond the policy tolerance and still settling.nemar admin compute jobs ...commands:list,record(by NEMAR id, Tapis uuid or Slurm id;--identity/--specowner-only, reasoned, audited throughreadRecordObject),report,access-report(and--csv),hold,release-hold,holds,access-reports(failed rows by fixed word),requeue-access-report --confirmed-not-recorded(owner only), andobserver mint.runComputeRetentionSweep, daily, exact production): deletes duerecords/andlogs/honoring job and account holds, counts any refusal aslockedand retries tomorrow, reconciles results (late), reduces the index row to anonymous counts, anonymizes a deleted account's pools and actors, and writes one audit row of counts.advancecarries out a recorded cancel on staging. A8 amendment: failed ACCESS reports are listed by word, surfaced in the week sweep's log line, and re-queued only by the owner on an explicit acknowledgement.Tests run (targeted only; the A7 files are run in batches, not in one process, because together they hit the known Miniflare platform-proxy failure)
bun test backend/test/compute-e2e.test.ts backend/test/compute-observer.test.ts backend/test/compute-sweep.test.ts backend/test/compute-retention.test.ts backend/test/cron-sweep-wiring.test.ts test/admin-compute-jobs-cli.test.ts test/admin-route-inventory.unit.test.ts: 321 pass, 0 fail.backend/test/compute-*.test.ts,cron-sweep-wiring,admin-credential-cascade,test/compute-*.test.ts,test/admin-compute-*.test.ts, the route inventory, the API export surface, the help tiers): 2410 pass, 0 fail, 62 files. New suites:compute-ledger-unreserved,compute-lifecycle-rotation,compute-reporting-routes.bun run migrations:d1-check: 122 migrations on real D1, catalog matches bun:sqlite.bun run typecheck: clean.bun run biome checkonsrc,shared,backend/src: no error in a touched file (the errors it reports are inzenodo.tsanddoi-orcid-discovery.ts, which this branch does not touch). Fullbun test: not run.backend/test/compute-e2e.test.ts, whose leg 1 is the issue's list in order (fund the pipelines pool,pipeline run, hold present, submit seen by the Tapis stand-in, the launcher declares and uploads through the outputs routes, a webhook hint then a cron tick tofinished, provisional charge, ACCESS stand-in told once, an observer post finalizing within tolerance, thenrecord <slurm id>by the real CLI against aBun.serveof the real routers); leg 2 revokes a second account mid-run (account_ended, frozen pool, Tapis cancel after the sweep); leg 3 is an unreserved job charged to the tenant pool. The environment is the in-process Worker with real D1 (bun:sqlite with every migration), Miniflare R2, and real HTTP stand-ins for Tapis, the S3 interface and ACCESS; the production-only crons are called asscheduled()calls them.Fix round 1: tests after the review
Batches after fix round 1: tenant sweep and rotation 42 pass; observer and reporting routes 53; retention, ledger and unreserved ledger 103; cron wiring, source scan, route inventory and Tapis client 394; end to end 3; CLI, admin inventory, admin contract, state, API surface 140; lifecycle, submit, money and release cascade 174. All 0 fail.
migrations:d1-checkandtypecheckclean; no biome error in a touched file.Mutation table
Each mutation was applied alone, the named test failed, and the code was restored. None is committed.
flag_mismatchcompute-observer: beyond-tolerance case, tolerance unit, repriced caseauthorizeObserverRuncompute-observer: refusal before the body is readstatus = 'issued'from the claimcompute-observer: two posts racingholder_kind = 'partner'compute-ledger-unreservedcompute-sweep: bound case, duplicate caseflag_unreserved = 0fromBOUND_ROWS_SQLcompute-sweepcompute-sweep: unrecordable job is not cancelledcompute-sweep: week pass with Tapis downcomputeEnabledcompute-sweep,compute-source-scancompute-lifecycle-rotationcompute-lifecycle-rotationcompute-lifecycle-rotationcompute-lifecycle-rotation(two cases)driveCancelinadvanceComputeJobcompute-lifecycle-rotationcompute-lifecycle-rotationcompute-retentioncompute-retention(hold placed after the list)compute-retentioncompute-retentionlockedcompute-retentioncompute-retention(21 locked jobs)lockedoncecompute-retentioncompute-retentioncompute-retentioncompute-retention(both engines)compute-retention(both engines)compute-retention(both engines)compute-retention(both engines)compute-reporting-routes; CLI:admin-compute-jobs-clicompute-retentionstate = 'failed'compute-reporting-routescompute-reporting-routescompute-reporting-routescompute-reporting-routesadmin-compute-jobs-clicompute-sweepcron-sweep-wiringcompute-sweep: bound after snapshot, conflicting insertcompute-sweepover(K6)rejectedas overcompute-sweepcompute-sweepcompute-sweep:a give-up another run closed first, and a second run over a closed row, count once in allnot_ownercompute-reporting-routescompute-sweep(two cases)compute-observercompute-observercompute-observercompute-retention(two cases)compute-retention(three cases)compute-retentioncompute-retentionnot_owner(K11)compute-retentiona multi-node allocation is priced per nodefails)compute-observercompute-sweep,tapis-clientlivecron-sweep-wiringrequireOwnerfrom the read routecompute-reporting-routescompute-ledger(two cases)compute-retention, each killedTwo guards are layered, so removing one layer alone changes nothing a test can see unless the layers are pinned separately: hold placement (the statement refuses a non-owner as well as the middleware; the statement mutation is caught by
compute-retentionand the route-table pin byadmin-route-inventory), and the record read, wherereadRecordObjectalso refuses a non-owner, so the middleware's removal is caught by the route-table pin and by the owner-before-body test (compute-reporting-routes, T8).Deviations from the issue
The issue says the tenant sweep writes "a
chargeentry (no hold)". The table refuses achargethat closes no hold (compute_ledger_closes_its_hold, migration 0114), and a job nobody reserved has none, so the entry is anoverrunof the partner pooltenantcounted against thepeoplebudget. It is one statement (unreservedChargeStatements, commitCharge unreserved use to a partner pool); achargekind with no hold would need a migration of the ledger's triggers. The row'sflag_overrunis not set for it. Driver to confirm.For the same reason
settleFinal(which corrects a hold's charge) cannot correct an unreserved job. The observer matches and lists such a row by its Slurm id; an administrator moves the charge by anadjustentry if it is warranted.The sweep reads
computeEnabled(the issue says it runs "only whencomputeEnabled"). The phase A5 source scan allowed that switch in one gating place and now namessweepTenantJobstoo (compute-source-scan.test.ts).Migration 0130 for the anonymizing update is a second migration (the A2 amendment asks for its own); it is numbered 0130 (0114 to 0119 are used and 0120 to 0129 are reserved).
An unreserved job's index row is the sweep's own: it is excluded from the tick's generic lists and refused by
driveCancelandadvanceComputeJob, so the lifecycle never verifies results a foreign job never uploaded.A flagged job keeps its logs until its records go (design section 9), so the early logs stage applies to unflagged, unheld jobs only.
The 1 MiB body bound and the 5,000 row bound are both kept; the longest row is 231 bytes, so 1 MiB admits about 4,500 of them.
listJobsinbackend/src/services/tapis/client.ts(a phase A4 file) gained an optionalorderBy(validated as a field and a direction, sent asorderBy=created(desc)by the sweep). Its spelling is unverified against a real tenant;tapis-client.test.tspins the regex and the query string.The A2 guard in
compute-ledger.test.ts("a pool's totals are written only by a ledger entry") is narrowed, not loosened: it now names the two migrations that create a trigger oncompute_pools(0114 and 0130) and requires 0130's one trigger to beBEFORE UPDATEwith a body that only raises, with no write in it.TENANT_GIVE_UP_DAYS(7): a followed unreserved row is closed, flaggedmismatchand charged nothing when Tapis no longer has the job (not_found), or when no read has found it for 7 days. The 7 days are counted from the last GOOD read (tapis_synced_at, refreshed by a good read of a live row), so one transient 5xx on an old row does not close it. This differs from phase A5's repair of a terminal row, which settles without the Tapis record (released unless something shows the job ran, flaggedmismatch) 7 days after the job ended, and is then corrected by the observer's final settlement; an unreserved row has no hold and no final settlement, so nothing corrects it. See the owner decisions below.compute_sacct_rows.applied_atis a column the issue's table did not list. It records that a row was applied to the ledger or judged not to apply, so a row that can never settle is not tried for ever.The reporting routes, the legal-hold routes, the ACCESS report routes and the observer mint route live in a new file,
backend/src/routes/admin/compute-reporting.ts, not inroutes/admin/compute.ts; the helpers of that file (refuse,requireOwner,readJson,invalidBody,fail, the sentences) are exported for it.Retention treats a
TypeError,RangeError,ReferenceErrororSyntaxErrorthrown by a bucketdeleteas a failed stage, not as a lock; every other throw is a lock whatever its text, with the first class kept in the log line.One A5 open point is not changed: the 30-minute tick equals the default
reservationWaitMinutes(30), so acreatedjob gets one retry beforesubmit_timeout. It is the owner's policy value (the contract is frozen); at 60 or more a job gets two. Recorded in the ADR amendment.The CLI parse of
recordoutput is passthrough, per the A1 amendment. The design page in the docs repository and the owner runbook for the observer token are not edited here (the issue's "When merged" step is the driver's).Owner decisions (approved 2026-11-06)
The owner approved all five as they stand in the code.
overrunon the tenant partner pool, counted against thepeoplebudget (the table refuses achargethat closes no hold).POST /admin/compute/observer-runsstays admin-level, as the issue says. Accepted risk: an administrator who mints a token can post a charged amount that settles a pool without owner authority.compute_gateway_users.account_id) and thegw_pseudonym for ever, and the 0115 triggers refuse change and delete. This is recorded in ADR 0118 as well.TENANT_GIVE_UP_DAYSstays at 7 days; a followed unreserved row closes with nothing charged.reservationWaitMinutes(30), so acreatedjob gets one retry beforesubmit_timeout.Residual risks and not verified
GET /v3/jobs/list(orderBy=created(desc)is asked for, its spelling is unverified), whether the tenant credential lists more than its own and shared jobs (the sweep finds what the service identity can list; the issue's fallback is that NEMAR is the only submitter), and the stand-in's responses were not recorded from a real tenant.TypeError,RangeError,ReferenceErrororSyntaxErrorthrown bydeleteis a failed stage, and any other throw counts aslockedwith its class kept and an alarm when the lock is overdue (more than a day pastretention_until). If R2 raised a lock refusal as one of those four classes, it would show as a failed stage, not as a silent lock. Miniflare does not enforce a lock, so the retention tests use one wrapper around the real bucket whosedeletethrows for named keys.grant:<actor>:<key>) and is kept when the actor is anonymized, because rewriting a key changes the identity a replay is judged by; the number is internal and the audit log holds it too.