Repository navigation
Phase D3a: Compute job submission, server half - #2073
Merged
neuromechanist merged 16 commits intoNov 7, 2026
Merged
neuromechanist merged 16 commits into
neuromechanist merged 16 commits into
Conversation
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR2073Version: 🤖 Updated on each push. |
neuromechanist
merged commit Nov 7, 2026
35e8536
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 D3a of epic #2021 (issue #2024): the SERVER half of user job submission. The CLI half (
nemar compute submit|logs|results|cancel, header parsing, packing, the secret scan,--wait) is phase D3b, built against the two contract files below after this merges.The wire is snake_case JSON. Contract files for the CLI and website#496:
shared/contract/compute-bundle.ts(caps,checkBundleManifest, manifest schema) andshared/contract/compute-submit.ts(request, open responses, header names, bounds,COMPUTE_SUBMIT_SENTENCES); words and statuses are inshared/compute-state.ts(COMPUTE_REFUSAL_STATUS). ADR 0118 has the amendment of 2026-11-06 (#2024); implementation notes section 14.Routes (all need a CLI key or the session cookie; a cookie write needs a NEMAR
Origin, else 403origin_not_allowed; an OpenID Connect token is refused 401)Every response is
Cache-Control: no-store. Every refusal is{ error: <sentence>, code: <word> }plusfieldforinvalid_spec(a field name of the request, never a value). A job that is not the caller's, an absent job and a malformed id are the same404 job_not_foundon every route below.POST /compute/jobs, body{ spec, manifest? }, optional headerIdempotency-Key(8 to 128 ofA-Za-z0-9._:-).specisJobSpecSchema(itsnameis part of it and is recorded inspec.json; there is no name column).manifestis{ files: [{ path, size, sha256 }] }and is required exactly whenspec.bundleis present.201 { job_id, state, tag, name, upload?, replayed? }: bundle jobstate: "uploading"withupload; image job (no bundle)state: "submitted", or"created"if it could not be sent just now (compute off, Tapis down; the 30-minute tick sends it).tagisnemar_job:<id>. Replay: headerIdempotent-Replayed: true,replayed: true.POST /compute/jobs/:id/finalize, body the manifest{ files: [...] }(no body is needed for a job already past the upload).200 { job_id, state, name?, submitted, replayed }.submitted: falsemeans the records are written and the tick submits it (state staysuploading).GET /compute/jobs/:id/logs:200 text/plain; charset=utf-8,X-Content-Type-Options: nosniff, the FIRST 1 MiB oftapisjob.out, headerX-Nemar-Truncated: truewhen cut.404 logs_not_availablebefore the job started or when it wrote none;503 storage_unavailablewhen Tapis cannot be reached.GET /compute/jobs/:id/results[?after=<last path>]andPOST /compute/jobs/:id/results/renew[?after=](the same links, made again):200 { expires_at, files: [{ path, size, sha256, url }], total, truncated, next_after, bearer_links: true, notice }, at most 1,000 files a page. Links are seven-day presigned GETs and BEARER links (anyone holding one can download that file until it expires; print thenotice).409 bad_stateif the job is not finished and verified;410 results_expiredonceretention.resultsDays(30 by default) has passed since the job ended, or once the objects are gone;400 invalid_specfieldafterfor a cursor that is not a safe path.POST /compute/jobs/:id/cancel(exists; changed):200 { ok, state, outcome, cancelled }.cancelled: trueforcancel_requestedandalready_cancelled; a job that had finished or failed is200 { state: <unchanged>, outcome: "already_ended", cancelled: false }(it was409 bad_state).Refusal order of
POST /compute/jobs(the first failing check is the answer; a refusal writes nothing and returns no address)403 no_compute_access(none, requested, denied, revoked, deleted) or403 suspended. Read from the account, and again inside the hold's own statement (requireActiveAccess), so a grant that ends between the two cannot be spent; the pools' freeze is the second line.Idempotency-Keyshape:400 invalid_specfieldIdempotency-Key.400 invalid_spec(or413 invalid_specover 2.4 MB) with fieldspec.<path>,manifest.<path>orbody; a recipe (spec.recipe), a dataset version with no data-plane tag (spec.datasets.<i>.version), a specification over the 64 KiB launch bound, a manifest without a bundle or a bundle without a manifest (manifest).422 idempotency_conflict.422 runtime_unavailable(matlab; orpythonwhile NEMAR's runtime image is not set),422 registry_not_allowed(the owner'sregistrieslist, empty by default, matches the image path by whole segments).422 partition_not_offered, then422 over_job_limit.409 over_concurrency(live jobs against the owner's limit).400 invalid_spec(manifest.files.<i>.path|size|sha256, a traversal even percent-encoded),413 bundle_too_many_files,413 bundle_too_large(a file over the file cap, the running total over the total cap, the archive over the total cap),422 entry_not_in_bundle.422 dataset_not_eligible(one answer for private, anonymous, unpublished, withdrawn, tombstoned, sandbox, fixture, versionless or absent),404 version_not_found,422 version_untagged,422 too_many_files(over 38,000 manifest entries). Only the pipelines' EEG-only term is set aside for a person.403 no_compute_access/suspendedagain,409 insufficient_balance(sentence: the balance is used up, contact an administrator; no refund is promised),409 over_concurrency,409 platform_budget_exhausted.New words and statuses:
version_not_found404,version_untagged422,too_many_files422,entry_not_in_bundle422,bundle_incomplete409,idempotency_conflict422,logs_not_available404,upload_expired409,storage_unavailable503.upload_expiredis also the failure code of a released upload (the submitter's, not the platform's). The issue'simage_digest_requiredis not a word (a tag-only image isinvalid_speconspec.image);image_not_allowedisregistry_not_allowed.Caps (
shared/contract/compute-bundle.ts, the owner'sbundleLimitsdefault to the same numbers and a test holds them equal)BUNDLE_MAX_TOTAL_BYTES100 MiB (the archive file; the sum of the files inside is held to it too),BUNDLE_MAX_FILES2,000,BUNDLE_MAX_FILE_BYTES25 MiB,BUNDLE_PATH_MAX240, archive namebundle.tar.gz, request body boundBUNDLE_BODY_MAX_BYTES.checkBundleManifest(files, limits?, entry?)is the one rule (shape, path, duplicate, count, sizes, then entry); the Worker calls it with the owner's limits and then the records bucket's percent-encoding traversal rule. The Worker enforces the OWNER's limits; if the owner raises them a CLI built earlier keeps refusing at the constants (the safe direction).The upload (what the CLI does)
uploadis{ url, method: "PUT", headers, expires_at, size }.PUT urlwith exactlyheaders(the signedx-amz-checksum-sha256, base64 of the archive's SHA-256) andContent-Length: size; the body is the archive bytes. The key is fixed (incoming/<id>/bundle.tar.gz, records bucket); the address works for one hour (X-Amz-Expires=3600,expires_at) and for that object only; it is issued only after the hold commits and only to the owner. The archive's length is also SIGNED into the address (content-lengthinX-Amz-SignedHeaders, not returned inheaders: the client setsContent-Lengthitself), and the declared size is enforced again at finalize by a HEAD: an absent, short or long object is409 bundle_incompleteand nothing is copied; a LARGER object is deleted, a shorter one is left. Not verified against the real store: whether R2 enforces the signed checksum or the signed length on a presigned PUT (the stand-in does both).An expired address is refused by the store (403). While the job is still
uploading(inside its hour from creation), repeating the request with the sameIdempotency-Keyreturns the same job with a FRESH address. The window is judged on the spot: a repeat or afinalizeafter the hour ends the job asupload_expired(hold released) whether or not the release has run; the repeat returns that failed job with no address andfinalizeis409 upload_expired: submit again with a new key. Afinalizeinside the hour (minute 45, say) succeeds and is never a platform failure: the reservation wait runs from the finalize, not from the creation.Finalize contract
Owner only. A job past the upload is returned unchanged (
200,replayed: true).failed/cancelledis409 upload_expired(released) or409 bad_state; a recorded cancel is409 bad_state. Otherwise the manifest body is judged (same words as submit, with the job'sentry), then HEAD (bundle_incomplete), then ONE server-side copy torecords/<id>/submitted/bundle.tar.gzandrecords/<id>/bundle-manifest.json(archive{sha256, size}and each file's{path, size, sha256}), then the job is submitted. Per-file digests are the packer's claim, recorded and never re-checked; the archive digest is verified by the launcher on the node, not by the Worker.Other changes
(account_id, idempotency_key)withspec_digestas the request hash (scopeuser:<id>): NO migration is added and0133is unused. Phase D4 needs its own table forclient:<id>(no account to key by). Migrations0131/0132untouched;migrations:d1-checkpasses.runUploadExpiryCron(production only, on the 30-minute tick, not inDEV_CRON_ALLOWLIST, self-fenced, no switch read, ten rows a tick): fails anuploadingjob with unwritten records after one hour, hold released, nothing charged. Listed incron-sweep-wiring.test.tsandcron-dev-safety.test.ts. The 30-minute backstop no longer takes such a row andsubmitComputeJobrefuses it asrecords_not_written(the reservation wait would have failed itsubmit_timeout, a platform failure, inside the upload hour).compute-source-scanunchanged). With compute off a submission takes its hold and waits; past the reservation wait it failssubmit_timeout, hold released (tested).resolveRunis exported and takes the terms to set aside (PERSON_EXCEPT_TERMS= the EEG term only), so a person and a pipeline cannot disagree about eligibility. This also makes ADR 0118 decision 13's premise true for a person's job.finalizeBundlerecords each file'ssha256when given.ResultLinkgainedsha256(additive;POST /linkscarries it too).test/account-copy-parity.test.tsis unaffected.Tests (all targeted; nothing run in a full suite)
cd backend && bun test ./test/<file>.test.tsper file:compute-jobs-submit51,compute-jobs-race5,compute-jobs-finalize17,compute-jobs-person-routes20,cron-sweep-wiring214,cron-dev-safety79,compute-route-inventory8,oidc-token-allowlist7,compute-results-routes17 (its cancel-of-an-ended-job case changed to the new 200),compute-source-scan4, plus the neighbourscompute-jobs,compute-records,compute-lifecycle,compute-lifecycle-submit,compute-pipeline*,compute-end-callers,compute-e2e,compute-full-pathall green. Root:compute-state.unit59,compute-submit-contract.unit25,compute-admin-contract.unit37,api-export-surface.unit14,help-tiers.unit12.bun run typecheck,bun run lintandbun run migrations:d1-checkpass on this head.Mutation runs (each reverted; 29 mutants, all killed after two weak tests were strengthened): reordered runtime/ceiling, dropped the route's access read, dropped the hold's access guard, dropped
requireActiveAccess, skipped the dataset gate, skipped the HEAD size check, ignored the request hash on replay, restored the 409 cancel, doubled the log cap, dropped the retention clock, let any account own a job, droppedcookieOriginGuard, let the reservation wait end an upload, let the tick take unfinished uploads, released a finalized job, skipped the release, omittedsha256, allowed every registry, dropped the percent-encoding path rule, widened or droppedPERSON_EXCEPT_TERMS, allowedsuspended, skipped the submit after finalize, removed the hold gate of the job insert, droppedno-store, dropped the concurrency read, logged the job name, unwired the cron, accepted an OIDC token on submit. The issue's "presign before the hold" mutant cannot be written literally:presignIncomingUploadsreads the job row, which exists only with its hold, so the race suite pins the nearest regressions (the job insert's hold gate, no address or id in the loser's answer, no object in either bucket).Not done / for the owner
Not verified: R2's enforcement of the signed checksum on a presigned PUT; every Tapis and S3 shape is from published specifications (no response recorded from a real service). The gated design page (
admin/design/compute-gateway, section 7) still needs the route shapes above; the docs repository is not touched here. Open questions: (1) whether a person's job should be allowed on a non-EEG dataset (done here; one constant to change), (2) whetherfinalizeshould keep the manifest from submit instead of taking it again (done as taking it again, so the Worker stores nothing between the calls), (3) whethertagshould mean something other than the Tapis job tag.Review round (commits after 0de7bf5)
I1 reservation wait measured from the finalize for a bundle job, finalize/repeat after the window end the job on the spot as
upload_expired; I2 CORS allowsIdempotency-Keyand exposesX-Nemar-Truncated,Idempotent-Replayed; M1 the ending statement bindsrecords_written_at IS NULL(?17; the tenant sweep's other caller binds 0); M2 window judged at repeat and finalize; M3 a 503 after the hold carriesjob_idand a note; M4 solved at the root: a bundle job is BORNuploadingin the hold's batch, so nocreatedbundle job exists to strand (no widening of the release); M5 content-length signed into the presigned PUT (stand-in verifier now signs it when listed), larger incoming object deleted at finalize, per-person incoming byte cap recorded as open; M6 concurrency tests (parallel finalizes, same-key parallel submits); M7 and the renew/no-store lines in the ADR; Low:canonicalJobSpecsortsenvbefore the digest. Re-run counts: compute-jobs-submit 55, -race 6, -finalize 25, -person-routes 20, -cors 3 (new), cron-sweep-wiring 214, cron-dev-safety 79, route-inventory 8, oidc-token-allowlist 7, results-routes 17, source-scan 4, compute-jobs 120, compute-lifecycle 121, compute-lifecycle-submit 35, compute-records 86, compute-e2e 3, compute-sweep 43; root compute-state.unit 59, compute-submit-contract.unit 25, compute-admin-contract.unit 37, api-export-surface.unit 14, help-tiers.unit 12. Lint, both typechecks andmigrations:d1-checkpass.