Skip to content

Phase A7: Tenant reconcile, observer and reporting - #2055

Merged
neuromechanist merged 38 commits into
feature/issue-2005-epic-compute-corefrom
feature/issue-2012-phase7-tenant-reconcile-observer-and-reporting
Nov 6, 2026
Merged

neuromechanist merged 38 commits into
feature/issue-2005-epic-compute-corefrom
feature/issue-2012-phase7-tenant-reconcile-observer-and-reporting

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Migration 0118_compute_observer.sql: observer runs, queue snapshots, sacct rows, legal holds, five sweep-bookkeeping columns on compute_jobs, and the partial indexes the rotations use. Migration 0130_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 pool holder_ref and ledger actor_user_id).
  • Tenant sweep (sweepTenantJobs, live on the 30-minute tick, week in the daily block, exact production only, and only while COMPUTE_ENABLED is 1): 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 pool tenant any job that skipped the reservation. A failed listing changes nothing.
  • Observer: POST /admin/compute/observer-runs mints a one-hour token (<run id>.<HMAC>, domain tag compute-observer); POST /compute/observer checks 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 through settleFinal, flagging mismatch beyond the policy tolerance and still settling.
  • Reporting and holds, routes and nemar admin compute jobs ... commands: list, record (by NEMAR id, Tapis uuid or Slurm id; --identity/--spec owner-only, reasoned, audited through readRecordObject), report, access-report (and --csv), hold, release-hold, holds, access-reports (failed rows by fixed word), requeue-access-report --confirmed-not-recorded (owner only), and observer mint.
  • Retention sweep (runComputeRetentionSweep, daily, exact production): deletes due records/ and logs/ honoring job and account holds, counts any refusal as locked and 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.
  • A5 open points: the two terminal repair lists, the orphan list and the cancel list rotate; a second orphan is logged and flagged; a terminal row with an unreadable Tapis record is settled without it; advance carries 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.
  • ADR 0118 amendment of 2026-11-05 and implementation notes section 12.

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.
  • The wider compute set (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 check on src, shared, backend/src: no error in a touched file (the errors it reports are in zenodo.ts and doi-orcid-discovery.ts, which this branch does not touch). Full bun test: not run.
  • Local end to end: 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 to finished, provisional charge, ACCESS stand-in told once, an observer post finalizing within tolerance, then record <slurm id> by the real CLI against a Bun.serve of 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 as scheduled() 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-check and typecheck clean; 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.

Guard Mutation Failing test
Tolerance decides flag_mismatch tolerance test always true compute-observer: beyond-tolerance case, tolerance unit, repriced case
A spent token is refused at the door do not check run status in authorizeObserverRun compute-observer: refusal before the body is read
One ingest per token drop status = 'issued' from the claim compute-observer: two posts racing
Unreserved charge only to a partner pool drop holder_kind = 'partner' compute-ledger-unreserved
Tag binds the submit race ignore tags compute-sweep: bound case, duplicate case
A sweep row is the sweep's own drop flag_unreserved = 0 from BOUND_ROWS_SQL compute-sweep
Row written before the cancel cancel first compute-sweep: unrecordable job is not cancelled
A failed listing changes nothing carry on after a failed listing compute-sweep: week pass with Tapis down
Sweep acts only with compute on drop computeEnabled compute-sweep, compute-source-scan
Repair list rotates order by age again compute-lifecycle-rotation
Orphan list rotates do not stamp the orphan row compute-lifecycle-rotation
Cancel list rotates order by request time only compute-lifecycle-rotation
Unreadable terminal row settled retry for ever compute-lifecycle-rotation (two cases)
Staging carries out a cancel remove the early driveCancel in advanceComputeJob compute-lifecycle-rotation
Second orphan not silent drop the log and flag compute-lifecycle-rotation
Hold read by the candidate query drop the term compute-retention
Hold read again before delete drop the second read compute-retention (hold placed after the list)
Hold term of the reducing statement drop it compute-retention
A live job is never touched list every state compute-retention
Any refusal is locked count only a refusal naming a lock compute-retention
A locked job goes behind do not stamp the job compute-retention (21 locked jobs)
A job is locked once count per stage compute-retention
A hold never keeps a result hold keeps a result compute-retention
A flagged job keeps its logs drop the flag terms compute-retention
Anonymise only a deleted account drop the deleted-user term of the trigger compute-retention (both engines)
Anonymise changes no amount drop the totals terms compute-retention (both engines)
Actor is only ever the token allow NULL compute-retention (both engines)
Nothing else about an entry changes drop the column terms compute-retention (both engines)
Re-queue needs the acknowledgement drop the check compute-reporting-routes; CLI: admin-compute-jobs-cli
Hold placement is owner-only drop the owner term of the statement compute-retention
Re-queue only touches a failed row drop state = 'failed' compute-reporting-routes
Views show no identity add an email to the job view compute-reporting-routes
A person counts once count rows as users compute-reporting-routes
Unreserved leaves the ACCESS report drop the flag term compute-reporting-routes
CLI reads identity only with a reason drop the reason check admin-compute-jobs-cli
Failed ACCESS rows surface do not list them compute-sweep
Retention is wired do not call it cron-sweep-wiring
Never cancel a job a row bound since the snapshot (K1) skip the check of the row's uuid compute-sweep: bound after snapshot, conflicting insert
A NEMAR tag is trusted on the service identity only (K8) trust the tag on any owner compute-sweep
Only a 409 is over (K6) treat every rejected as over compute-sweep
Only real closes count (K9, finished counter; the give-up counter is covered by the next row) count every close compute-sweep
Only a real give-up counts always count the give-up compute-sweep: a give-up another run closed first, and a second run over a closed row, count once in all
A refused owner of the re-queue is not_owner classify by role alone compute-reporting-routes
Age from the last good read (K10) age from creation compute-sweep (two cases)
A job first seen RUNNING is finalized later (K2) keep the first row compute-observer
The state is the first word (T3) match the whole state compute-observer
A run whose store failed is re-postable (K7) leave the run spent compute-observer
A cut-off prefix is incomplete (K3) report it complete compute-retention (two cases)
A programming error is not a lock, an overdue lock alarms (K4) catch everything as a lock compute-retention (three cases)
A capped stage counts its backlog (K5) do not count compute-retention
Open-hold-only actors leave the window (K12) list every actor compute-retention
A refused owner is not_owner (K11) classify by role alone compute-retention
Per-node pricing (T4) do not divide the row's CPUs by its nodes (mutated and run: a multi-node allocation is priced per node fails) compute-observer
List order and paging (T2) read a sixth page; drop the orderBy check compute-sweep, tapis-client
The modes the cron passes (T5) daily call with live cron-sweep-wiring
Owner before body (T8) remove requireOwner from the read route compute-reporting-routes
0130 pool trigger only raises (T10) add an UPDATE to its body compute-ledger (two cases)
Anonymizing update changes nothing else (T1) drop any one of 23 terms of the two triggers compute-retention, each killed

Two 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-retention and the route-table pin by admin-route-inventory), and the record read, where readRecordObject also 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 charge entry (no hold)". The table refuses a charge that closes no hold (compute_ledger_closes_its_hold, migration 0114), and a job nobody reserved has none, so the entry is an overrun of the partner pool tenant counted against the people budget. It is one statement (unreservedChargeStatements, commit Charge unreserved use to a partner pool); a charge kind with no hold would need a migration of the ledger's triggers. The row's flag_overrun is 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 an adjust entry if it is warranted.

  • The sweep reads computeEnabled (the issue says it runs "only when computeEnabled"). The phase A5 source scan allowed that switch in one gating place and now names sweepTenantJobs too (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 driveCancel and advanceComputeJob, 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.

  • listJobs in backend/src/services/tapis/client.ts (a phase A4 file) gained an optional orderBy (validated as a field and a direction, sent as orderBy=created(desc) by the sweep). Its spelling is unverified against a real tenant; tapis-client.test.ts pins 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 on compute_pools (0114 and 0130) and requires 0130's one trigger to be BEFORE UPDATE with a body that only raises, with no write in it.

  • TENANT_GIVE_UP_DAYS (7): a followed unreserved row is closed, flagged mismatch and 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, flagged mismatch) 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_at is 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 in routes/admin/compute.ts; the helpers of that file (refuse, requireOwner, readJson, invalidBody, fail, the sentences) are exported for it.

  • Retention treats a TypeError, RangeError, ReferenceError or SyntaxError thrown by a bucket delete as 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 a created job gets one retry before submit_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 record output 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.

  • D1: the unreserved usage entry is an overrun on the tenant partner pool, counted against the people budget (the table refuses a charge that closes no hold).
  • D2: POST /admin/compute/observer-runs stays 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.
  • D3: migration 0130 keeps the account link (compute_gateway_users.account_id) and the gw_ pseudonym for ever, and the 0115 triggers refuse change and delete. This is recorded in ADR 0118 as well.
  • D4: TENANT_GIVE_UP_DAYS stays at 7 days; a followed unreserved row closes with nothing charged.
  • D5: the 30-minute tick stays equal to the default reservationWaitMinutes (30), so a created job gets one retry before submit_timeout.

Residual risks and not verified

  • Tapis: the order of 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.
  • R2: the text and class of a real lock refusal are unrecorded. A TypeError, RangeError, ReferenceError or SyntaxError thrown by delete is a failed stage, and any other throw counts as locked with its class kept and an alarm when the lock is overdue (more than a day past retention_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 whose delete throws for named keys.
  • The observer's real export was not seen; shapes and bounds are the issue's. A sweep run handles at most 25 unbound jobs, five pages of 1,000 listed, and 150 observer settlements per pass; the rest wait for the next run and are reported at error level.
  • An administrator's ledger idempotency key embeds the actor's number (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.
  • Subrequest cost of the daily sweeps is estimated, not measured.

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.
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR2055

Version: 0.10.28-PR2055.56a0c08
Commit: 56a0c08


🤖 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
neuromechanist merged commit e6ca96f into feature/issue-2005-epic-compute-core Nov 6, 2026
17 of 19 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-2012-phase7-tenant-reconcile-observer-and-reporting branch November 6, 2026 18:25

This branch was previously deployed

1 inactive deployment
npm — 56a0c08f Deployed Nov 6, 2026 by neuromechanist via publish #4255
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