Repository navigation
Phase D4: Partner reservation and report contract - #2077
Merged
neuromechanist merged 43 commits intoNov 7, 2026
Merged
neuromechanist merged 43 commits into
neuromechanist merged 43 commits into
Conversation
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.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR2077Version: 🤖 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
merged commit Nov 7, 2026
e0685a2
into
feature/issue-2021-epic-compute-users
25 of 27 checks passed
This was referenced Nov 7, 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.
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
0134_compute_partner.sql(only what was absent): the tablecompute_idempotency_keys(scopeclient:<id>), the columnspartner_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 withcompute.reservethroughoidcBearer, audience checked (decision below).shared/contract/compute-partner.ts(closed refusal enum, sentences, open responses) andcompute-partner-request.ts(strict requests, listed inSTRICT_BY_DESIGN).createJobfor 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.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 byfinishMismatch: cancelled at Tapis, the hold released, what ran anoverrunof the partner pooltenant, 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; verifiespendingrows; carries outmismatchrows. 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) andPOST /admin/compute/jobs/:id/move-charge: twoadjustentries in one batch that name no budget.Names found in the merged Epic A code (read before writing)
Hold builder
holdStatements/HOLD_INSERT_SQLwithHoldGuard(took the client predicates as it stood: no second hold path, no change to it);createJob(extended for a partner job withcaps,idempotency,requireActiveAccess); release statementsreleaseStatements/computeReleaseStatements(partner reservations are left alone by the cascade, unchanged); the tenant sweepsweepTenantJobs/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 iscreated, notheld.Decisions
API_BASE_URL), else 403wrong_audience; the read routes still do not (ADR 0119, D2 item 4).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.overrunon 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.compute-ledger-budget.test.tshas the row. No ambiguity found that needed the conservative fallback.Gates
bun run lint,bunx tsc --noEmitandbunx tsc --noEmit -p backendclean,bun run migrations:d1-checkOK (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
shareJobmodels the arrangement. The owner confirms it inpolicy.partner.tapisVisibilityConfirmed; until then holds are 503partner_not_enabledand the reaper never releases on an empty search.subitself is assumed (tapisUsernameForSub, one place).--gpus=Nscheduler 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).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.ts11,test/admin-compute-move-charge-cli.test.ts7, 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)
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).createJobcase was added, then 1).finalizeSubmittedFileswithout its verified gate (killed in compute-records, 1), a withdrawn binding that clears every cancel (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)
POST /compute/holdspartner_not_enabled(the contract is closed until the owner confirms); the 201 answer carriesstate; a repeat after the hold ended is 409hold_released/hold_cancelled;expires_atis the time stored when the hold was madePOST /compute/jobs/:id/reporttapis_job_unreadable(new; NEMAR may not read the job, nothing bound);report_mismatchgains the wordunverifiable; a refused reservation's repeat afterhold_endedis 409hold_cancelled; the Tapis id is 1 to 64 letters, digits and-(a dot is 400invalid_spec); a second, differentfileslist after the first accepted is 400invalid_spec(files)DELETE /compute/holds/:idPOST /admin/compute/jobs/:id/move-chargeconfirm_unproven_owner; 409owner_not_proven; the answer gainsattributed_account_idandowner_proven; CLI--confirm-unproven-ownerPolicy:
partner = { tapisVisibilityConfirmed, execSystemId? }(optional, absent means off; a confirmed block names the execution system). Migration 0134 (unreleased, edited in place) gainspartner_expires_atandpartner_files_digestand astateterm on the unverified index.Findings and the test that kills each
pendingfor evertapis_job_unreadable, binds nothing; unavailable bindspending; two hours unreadable is refused asunverifiable, cancelled blind, released, charged to the partner, warn logcompute-partner-unverifiable.test.ts(3 tests)--gpus=Nwithin the hold), execution system pinned, observer caps the person at the hold, excess is the partner's overrun, flagged and auditedcompute-partner-unverifiable.test.ts,compute-partner-final.test.tslogs_not_availableunlessverifiedcompute-partner-logs.test.tscheckReport, window; removed before the slice; backlog-awarecompute-hold-reaper.test.ts(5 tests)createJobcompute-partner-holds.test.ts(race injected at the exact statement)policy.partnerconfirmation; holds 503 until set; reaper keeps the hold, warnscompute-partner-holds.test.ts,compute-hold-reaper.test.tscompute-partner-{unverifiable,holds,report,files,move-charge,migration},compute-hold-reaperHostile-partner checklist (extended)
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 ...unverifiedremoved (the planner picks that index anyway; the open-list one is killed and both plans are pinned); the sweep's owner term (redundant withcheckReport, 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 backendandbun run migrations:d1-checkclean on the final head.Second review round (Opus delta review of the first round)
parameterSetis a JSON string in the Jobs specificationschedulerArgsOfparses a string under a 262,144-character bound and still reads the object; the stand-in serves the string by defaultcompute-partner-scheduler.test.ts(and every partner happy path now covers the string)policy.partner.allowedSchedulerArgs(exact strings, never--gpus/--gres); owner reads ONE real record before turning the confirmation oncompute-partner-allowed-args.test.tsunverifiableon one bad readpartner_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 wordcompute-partner-unverifiable.test.ts(probe A and the cancel-failed-first case included)invalid_responseboundpending; a refused cancel pinned the slotunavailable, else 422tapis_job_unreadable; a cancel refused with 400/403/404 ends the row with the whole hold on the partner and a warn linecompute-partner-unverifiable.test.tscompute-partner-unverifiable.test.tscompute-hold-reaper.test.ts(probes C and D)partner_reservations_openunless--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 offcompute-partner-switch.test.ts,admin-compute-cli.test.tscompute-hold-reaper.test.tscompute-partner-final.test.tsNew words: admin
partner_reservations_open(409); policypartner.allowedSchedulerArgs; flag/auditcompute.partner.recovered. Migration 0134 (unreleased) gainspartner_read_failuresandpartner_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.