Skip to content

Phase D4: Partner reservation and report contract - #2077

Merged
neuromechanist merged 43 commits into
feature/issue-2021-epic-compute-usersfrom
feature/issue-2025-compute-partner
Nov 7, 2026
Merged

neuromechanist merged 43 commits into
feature/issue-2021-epic-compute-usersfrom
feature/issue-2025-compute-partner

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Phase D4 of Epic D (#2021), issue #2025: the partner reservation and report contract. A partner site (treated as potentially hostile) reserves compute time for a signed-in person, reports the Tapis job it launched and releases a reservation; NEMAR holds it to one Tapis job per reservation, verified by NEMAR's own read-back, with a cancel, an overrun charge and an admin flag on any mismatch.

What changed

  • Migration 0134_compute_partner.sql (only what was absent): the table compute_idempotency_keys (scope client:<id>), the columns partner_state, partner_flag, partner_verified_at, and three partial indexes. The unique index on the bound Tapis uuid already exists (compute_jobs.tapis_uuid UNIQUE, 0115), as do the orphan slot, the rotation stamp, the cancel intent and the four flags.
  • POST /compute/holds, POST /compute/jobs/:id/report, DELETE /compute/holds/:id (routes/compute/partner.ts), one credential: an access token for a person with compute.reserve through oidcBearer, audience checked (decision below). shared/contract/compute-partner.ts (closed refusal enum, sentences, open responses) and compute-partner-request.ts (strict requests, listed in STRICT_BY_DESIGN).
  • The reservation is one conditional insert (createJob for a partner job): the person's access, the balances, the person's live-job limit, the client's open-reservation cap and its UTC-day cap are all in the hold's WHERE, and the idempotency claim is in the same batch.
  • The report binds a uuid with one conditional UPDATE and NEMAR reads the job back (compute-report-verify.ts): owner, application and version, queue, nodes, cores, minutes, memory and the price of the record's resources against the hold. A match is one batch (verified, submitted) then NEMAR's webhook; a mismatch is recorded as intent (flag word, cancel intent, one audit row) and carried out by finishMismatch: cancelled at Tapis, the hold released, what ran an overrun of the partner pool tenant, never the person's. No Tapis call is inside a batch; nothing is released on a Tapis error.
  • reapExpiredHolds(env) on the 30-minute tick, production only, 25 rows of each of three lists: it searches Tapis by the tag before releasing; verifies pending rows; carries out mismatch rows. The tenant sweep leaves a sole, matching, owner-agreeing partner job under a live reservation to its report (see the review round).
  • nemar admin compute move-charge <job> --to <account id> (owner only) and POST /admin/compute/jobs/:id/move-charge: two adjust entries in one batch that name no budget.
  • ADR 0118 and 0119 addenda and implementation notes section 16.

Names found in the merged Epic A code (read before writing)

Hold builder holdStatements/HOLD_INSERT_SQL with HoldGuard (took the client predicates as it stood: no second hold path, no change to it); createJob (extended for a partner job with caps, idempotency, requireActiveAccess); release statements releaseStatements/computeReleaseStatements (partner reservations are left alone by the cascade, unchanged); the tenant sweep sweepTenantJobs/handleUnbound/unreservedChargeStatements (reused, not duplicated; one deferral added); bindTapisJob/adopt (not used for a partner: they bind without verification); finalizeSubmittedFiles/presignIncomingUploads (wired now); provisionalCharge, lostSettlement, suMilliFor (formula unchanged); ABANDONED_UPLOADS_SQL (partner jobs excluded as before). The real state word is created, not held.

Decisions

  • Audience: the write routes require the token's audience to name this API (same origin as API_BASE_URL), else 403 wrong_audience; the read routes still do not (ADR 0119, D2 item 4).
  • Client caps: the owner's policy clients[<client id>] is the source, closed by default (an unlisted client has no reservations); the client's own record caps are a second ceiling (smaller stands). No new column or command.
  • A mismatch is charged to the partner pool and the hold is released, not an overrun on the person's pool as the issue's wording read: the issue's acceptance criterion and decision 5 say no path charges a person for a job NEMAR has not verified.
  • Move of a charge: owner-only (raising a person's charge is the owner's under the interim rule). Accounting: both halves name no budget, so the people budget is counted once; tests assert the invariants and the operations table of compute-ledger-budget.test.ts has the row. No ambiguity found that needed the conservative fallback.

Gates

bun run lint, bunx tsc --noEmit and bunx tsc --noEmit -p backend clean, bun run migrations:d1-check OK (243 objects). Targeted tests by file (backend one file at a time): see the final comment for counts and the mutation list. Not run, would check: the full suite, because it is the epic gate.

Not verified, and owner items

  • Whether the tenant credential can search by tag and read another owner's job. The stand-in's shareJob models the arrangement. The owner confirms it in policy.partner.tapisVisibilityConfirmed; until then holds are 503 partner_not_enabled and the reaper never releases on an empty search.
  • The Tapis username the partner gives a person (design question 13): the OIDC sub itself is assumed (tapisUsernameForSub, one place).
  • The GPU count of a partner job is read from its --gpus=N scheduler option (allowlisted) and the final charge to the person is capped at the hold; whether Expanse reports what the option asked for is the observer's evidence (see the review round).
  • R2's enforcement of a signed content length on a presigned PUT; no cap on a partner's bytes in incoming/ beyond the owner's file limits and the pinned first list; the OpenAPI document covers the catalog only.

Test results (targeted, by file; backend files one at a time from backend/)

compute-partner-migration 10, compute-partner-credentials 13, compute-partner-holds 23, compute-partner-report 37, compute-partner-release 9, compute-partner-move-charge 12, compute-hold-reaper 21, compute-route-inventory 9, oidc-token-allowlist 8, cron-sweep-wiring 220, cron-dev-safety 88, compute-ledger-budget 32, compute-records 87, root test/compute-partner-e2e.test.ts 11, test/admin-compute-move-charge-cli.test.ts 7, admin-route-inventory 6, compute-state 59, contract-schemas 63, compute-admin-contract 38; and a sweep of 162 other backend and root compute, OIDC, cron and admin files with 0 failures. No test file was skipped.

Mutations (one expression replaced, one test file run, restored; the test file named is the one that killed it)

  • move-charge: name the budget on the person's side (1 failed), drop flag_unreserved = 1 (survived until a reserved-job case was added, then 1), drop the second half's EXISTS (9), drop the target status term (1).
  • credentials: drop the client binding (1), the person binding (1), the audience check (1), let a key through (1), drop the scope (1), treat a cookie as no credential (1).
  • holds: drop the client open guard (3), the daily guard (3), the idempotency claim from the batch (8), the daily guard counting only live holds (1), split the cap check from the insert (1), drop the access guard from the hold (survived until a direct createJob case was added, then 1).
  • report: skip the Tapis cancel (13), charge the person for a mismatch (11), drop the owner check (5), settle files before verification (1), drop the price check (survived until a memory-priced case was added, then 1), drop the unique-bind mapping (survived the concurrent case, killed by a trigger that plays the competing bind, 1), drop the NEMAR-identity guard in both places (1; each term alone also 1; the report route's guard alone survives by design because the verifier re-checks it), finalizeSubmittedFiles without its verified gate (killed in compute-records, 1), a withdrawn binding that clears every cancel (1).
  • release: drop the bound check (1), the statement's own no-Tapis-job term (survived until a stale-row case was added, then 1).
  • reaper: release on a search error (2), on an unreadable job (1), with Tapis not configured (1), adopt one of several (1), drop the age term (1), drop the cancel-intent branch (2), skip the cancelled-reservation refusal (2), drop the sweep deferral (1), count an accounted uuid (2), run outside production (1).

Reviewers: this is the most security-sensitive phase of the epic; the two lenses asked for are atomicity and races (createJob's batch, the bind, the release and the report race, the move) and what a hostile partner can do (compute-report-verify.ts, compute-partner.ts, the sweep deferral).

Review round (one round, atomic commits on this branch)

Two independent reviews (adversarial, atomicity) found two critical and several important faults. Each is fixed with a test that kills it (mutation-checked); the ADR text (0118 items 17 to 24, 0119) is in step.

Routes and refusal words (what changed in the contract)

Route Words added or changed
POST /compute/holds 503 partner_not_enabled (the contract is closed until the owner confirms); the 201 answer carries state; a repeat after the hold ended is 409 hold_released / hold_cancelled; expires_at is the time stored when the hold was made
POST /compute/jobs/:id/report 422 tapis_job_unreadable (new; NEMAR may not read the job, nothing bound); report_mismatch gains the word unverifiable; a refused reservation's repeat after hold_ended is 409 hold_cancelled; the Tapis id is 1 to 64 letters, digits and - (a dot is 400 invalid_spec); a second, different files list after the first accepted is 400 invalid_spec (files)
DELETE /compute/holds/:id unchanged
POST /admin/compute/jobs/:id/move-charge body gains confirm_unproven_owner; 409 owner_not_proven; the answer gains attributed_account_id and owner_proven; CLI --confirm-unproven-owner

Policy: partner = { tapisVisibilityConfirmed, execSystemId? } (optional, absent means off; a confirmed block names the execution system). Migration 0134 (unreleased, edited in place) gains partner_expires_at and partner_files_digest and a state term on the unverified index.

Findings and the test that kills each

Finding Fix Killing test
C1 unreadable report bound pending for ever 403 is tapis_job_unreadable, binds nothing; unavailable binds pending; two hours unreadable is refused as unverifiable, cancelled blind, released, charged to the partner, warn log compute-partner-unverifiable.test.ts (3 tests)
C2 person charged for resources NEMAR never saw scheduler options allowlisted (--gpus=N within the hold), execution system pinned, observer caps the person at the hold, excess is the partner's overrun, flagged and audited compute-partner-unverifiable.test.ts, compute-partner-final.test.ts
I1 (Opus) logs of a refused job readable logs_not_available unless verified compute-partner-logs.test.ts
I2 (Opus) sweep shelter starves the slots sole tag holder, owner, checkReport, window; removed before the slice; backlog-aware compute-hold-reaper.test.ts (5 tests)
I1 (Sonnet) same-key loser refused the key is asked again before a refusal is named, in the route and in createJob compute-partner-holds.test.ts (race injected at the exact statement)
I2 (Sonnet) empty search proves nothing policy.partner confirmation; holds 503 until set; reaper keeps the hold, warns compute-partner-holds.test.ts, compute-hold-reaper.test.ts
M1/M2/M3/M4/M5/M7 (Opus), M1 to M7 (Sonnet), minors see ADR 0118 items 17 to 23 compute-partner-{unverifiable,holds,report,files,move-charge,migration}, compute-hold-reaper

Hostile-partner checklist (extended)

  • C1: a job NEMAR cannot read cannot pin a hold or run unbilled; it is refused, cancelled and charged to the partner.
  • C2: no resource the partner chooses (GPUs, memory, exclusivity, execution system) can raise what a person pays above their hold.
  • I1: a person cannot be made to read another owner's output through a refused report.
  • I2: a partner cannot starve the sweep's slots by tagging jobs, or keep a hold open by adding tagged jobs under another owner; an unconfirmed tenant never produces a release.
  • Also: a corrected retry under the same key works; a replay is never answered as live after the end; a charge moved to an account the job was not attributed to is the owner's recorded word.

Mutation results of the round

43 mutations in the first pass: 35 killed, 8 survived. Three of the survivors got a test and are now killed (a refused job's records stamp; the two same-key race guards, with the race injected at the exact statement). The other five are equivalent or redundant by design: >= vs > on the UTC-day start (the bound is a date string, and a timestamp on that day compares greater either way); INDEXED BY ...unverified removed (the planner picks that index anyway; the open-list one is killed and both plans are pinned); the sweep's owner term (redundant with checkReport, which refuses a different owner); and the pin statement and the early digest check of a files list, each alone (two layers; both removed together are killed). Added later and killed: the two files-pin layers together, and an ACCESS report row added for a refused job.

Tests run (targeted; "not run": the full suite, which is the epic gate)

Backend one file at a time: compute-partner-credentials 13, -holds 31, -report 37, -release 9, -unverifiable 14, -final 2, -logs 2, -files 4, -move-charge 15, -migration 13, compute-hold-reaper 30, compute-ledger-budget 32, compute-records 87, compute-observer 51, compute-sweep 43, compute-status-route 24, compute-e2e 3, compute-policy-routes 21, compute-read-jobs 13, compute-route-inventory 9, compute-source-scan 4, cron-sweep-log 8, cron-sweep-wiring 220, oidc-token-allowlist 8, compute-lifecycle 121 and the other compute-lifecycle/ledger/jobs files (0 failures). Root: compute-partner-e2e 11, admin-compute-move-charge-cli 8, admin-compute-jobs-cli 30, admin-compute-cli 27, admin-route-inventory 6, compute-admin-contract 38, contract-schemas 63, compute-state 59. bun run lint, bunx tsc --noEmit, bunx tsc --noEmit -p backend and bun run migrations:d1-check clean on the final head.

Second review round (Opus delta review of the first round)

Item Fix Killing test
1 critical: parameterSet is a JSON string in the Jobs specification schedulerArgsOf parses a string under a 262,144-character bound and still reads the object; the stand-in serves the string by default compute-partner-scheduler.test.ts (and every partner happy path now covers the string)
2 options Tapis merges in (account, profile) policy.partner.allowedSchedulerArgs (exact strings, never --gpus/--gres); owner reads ONE real record before turning the confirmation on compute-partner-allowed-args.test.ts
3 unverifiable on one bad read three failed reads on separate ticks spanning two hours, counted on the row (partner_read_failures, partner_first_failed_at); a refusal that can be read later and matches is verified again, not cancelled; one that does not match gets its real word compute-partner-unverifiable.test.ts (probe A and the cancel-failed-first case included)
4 invalid_response bound pending; a refused cancel pinned the slot pending only for unavailable, else 422 tapis_job_unreadable; a cancel refused with 400/403/404 ends the row with the whole hold on the partner and a warn line compute-partner-unverifiable.test.ts
5 unread job charged the minimum the whole hold, to the partner compute-partner-unverifiable.test.ts
6 shelter counted every job under the tag owner, not over, not accounted, exactly one; the reaper's ambiguity ignores an ended first attempt compute-hold-reaper.test.ts (probes C and D)
7 switch off froze everything a policy write that drops the confirmation with partner reservations open is 409 partner_reservations_open unless --force-partner-off (says how many are frozen); unconfirmed, a reservation a day past expiry whose person ended or cancelled is released with no Tapis call; a repeat of a hold replays when the contract is off compute-partner-switch.test.ts, admin-compute-cli.test.ts
8 shelter read budget evaluated lazily while the slice fills, stops when full compute-hold-reaper.test.ts
9 routine tolerance and the provisional cap the flag word and audit row need a difference beyond the owner's tolerance; the provisional settlement is capped at the hold too, the rest on the partner (one shared helper); the final stamp reads the person's pool; a job with no Slurm id and no final is charged by its provisional settlement alone, never above the hold compute-partner-final.test.ts
10 docs migration header, ADR 0118 items 25 to 33, implementation notes, staging note (the development Worker's partner policy stays unconfirmed and it holds no production tenant credentials) docs only

New words: admin partner_reservations_open (409); policy partner.allowedSchedulerArgs; flag/audit compute.partner.recovered. Migration 0134 (unreleased) gains partner_read_failures and partner_first_failed_at.

Mutations of the round: 45 distinct mutants, 44 killed (three needed a pattern or test fixed first); the one survivor is by design: the excess entry's after-stamp gate only guards a second writer of the same figure, which the entry's once-per-job key already makes idempotent. Targeted tests are run by file as in the first round; the full suite is not run.

Adds policy.partner (visibility confirmation, execution system), the words tapis_job_unreadable, partner_not_enabled and unverifiable, the hold's state, the Tapis id the table keeps, and the columns partner_expires_at and partner_files_digest. Contract and schema tests pass; behavior follows in the next commits.
A job NEMAR may not read binds nothing and one unreadable for two hours is refused as unverifiable; scheduler options and the execution system are checked; a request claims its key only after its cheap checks; a refused job owes no ACCESS report and no log copy; a same-key request that lost a race is answered with the winner; the contract is closed until the owner confirms. Tests: unverifiable, holds, report, release, e2e (mutation-checked).
The reaper uses the stored expiry and named indexes, never releases on an empty search until the owner confirms, counts only the reservation owner's jobs toward ambiguity and prunes old idempotency keys. The sweep shelters only a sole, matching, owner-agreeing job and removes it before its slice, with a backlog-aware window. Tests: hold-reaper, migration (plans pinned).
The observer charges the person at most the hold; the excess is an overrun of the partner pool, flagged and audited once. Test: compute-partner-final (mutation-checked).
The logs route answers logs_not_available for a partner row that is not verified. Test: compute-partner-logs.
The store's SHA-256 is compared with the declared one where it is returned, a copy refused because a concurrent report wrote the destination counts as copied, and the manifest comment is corrected. Test: compute-partner-files.
Moving a charge to an account the job was not attributed to needs --confirm-unproven-owner; the audit row and the answer say whether the owner was proven; success is judged by changes > 0. Tests: move-charge, ledger-budget, CLI.
ADR 0118 items 17 to 24, the ADR 0119 words and implementation-notes section 16. Documentation only.
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR2077

Version: 0.10.28-PR2077.51bd8a5
Commit: 51bd8a5


🤖 Updated on each push.

The Jobs specification types parameterSet as a JSON string; the accessor parses it under a size bound and still reads the object form. The Tapis stand-in now serves the string by default. Tests: compute-partner-scheduler (mutation-checked); tapis-client and partner suites pass.
policy.partner.allowedSchedulerArgs lists exact option strings accepted besides at most one --gpus=N within the hold; GPU options cannot be listed. Test: compute-partner-allowed-args (mutation-checked).
A bound job is refused as unverifiable after three failed reads on separate ticks spanning two hours, counted on the row; a refusal that can be read later and matches is verified again instead of cancelled. A report binds pending only for an unavailable Tapis. A cancel Tapis definitively refuses ends the row, and an unread job is charged the whole hold to the partner. Tests: compute-partner-unverifiable, migration (mutation-checked).
The sweep's tag search keeps only jobs the reservation's Tapis user owns that are not over and not accounted, and the reaper ignores an ended first attempt when a live retry exists. Tests: compute-hold-reaper (mutation-checked).
A policy write that drops the partner confirmation while partner reservations are open is refused unless --force-partner-off, which says how many are frozen. While it is off, a reservation a day past expiry whose person ended or cancelled is released without a search, and a repeat of a hold's key still replays. Tests: compute-partner-switch, admin-compute-cli (mutation-checked).
The shelter is evaluated while the run's slice fills and stops reading when it is full, instead of reading up to 100 candidates before every slice. Test: compute-hold-reaper (mutation-checked).
The provisional settlement charges the person at most the hold and puts the rest on the partner through one shared helper, which the final settlement uses too; the flag word and audit row need a difference beyond the owner's tolerance, and the final stamp reads the person's pool only. A job with no Slurm id and no final is charged to the person by its provisional settlement alone, never above the hold. Tests: compute-partner-final (mutation-checked).
Migration 0134 header (seven columns, all flag words, the 7-day prune), ADR 0118 items 25 to 33, implementation notes, and the staging note that the development Worker's partner policy stays unconfirmed. Documentation and comments only.
Its header claims integration but the workflow routes by file name or marker, and the file holds no marker; the .integration.test.ts suffix is the convention for such suites. Tested: ci-tier-routing and the renamed suite pass.
The api/compute module gained moveComputeCharge in phase D4; it is added to the module pin and the post-split additions. Tested: api-export-surface and ci-tier-routing pass.
@neuromechanist
neuromechanist merged commit e0685a2 into feature/issue-2021-epic-compute-users Nov 7, 2026
25 of 27 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-2025-compute-partner branch November 7, 2026 13:41

This branch was previously deployed

1 inactive deployment
npm — 51bd8a59 Deployed Nov 7, 2026 by neuromechanist via publish #4326
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