Skip to content

Phase D3a: Compute job submission, server half - #2073

Merged
neuromechanist merged 16 commits into
feature/issue-2021-epic-compute-usersfrom
feature/issue-2024-compute-submit-server
Nov 7, 2026
Merged

neuromechanist merged 16 commits into
feature/issue-2021-epic-compute-usersfrom
feature/issue-2024-compute-submit-server

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

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) and shared/contract/compute-submit.ts (request, open responses, header names, bounds, COMPUTE_SUBMIT_SENTENCES); words and statuses are in shared/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 403 origin_not_allowed; an OpenID Connect token is refused 401)

Every response is Cache-Control: no-store. Every refusal is { error: <sentence>, code: <word> } plus field for invalid_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 same 404 job_not_found on every route below.

  • POST /compute/jobs, body { spec, manifest? }, optional header Idempotency-Key (8 to 128 of A-Za-z0-9._:-). spec is JobSpecSchema (its name is part of it and is recorded in spec.json; there is no name column). manifest is { files: [{ path, size, sha256 }] } and is required exactly when spec.bundle is present. 201 { job_id, state, tag, name, upload?, replayed? }: bundle job state: "uploading" with upload; 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). tag is nemar_job:<id>. Replay: header Idempotent-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: false means the records are written and the tick submits it (state stays uploading).
  • GET /compute/jobs/:id/logs: 200 text/plain; charset=utf-8, X-Content-Type-Options: nosniff, the FIRST 1 MiB of tapisjob.out, header X-Nemar-Truncated: true when cut. 404 logs_not_available before the job started or when it wrote none; 503 storage_unavailable when Tapis cannot be reached.
  • GET /compute/jobs/:id/results[?after=<last path>] and POST /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 the notice). 409 bad_state if the job is not finished and verified; 410 results_expired once retention.resultsDays (30 by default) has passed since the job ended, or once the objects are gone; 400 invalid_spec field after for a cursor that is not a safe path.
  • POST /compute/jobs/:id/cancel (exists; changed): 200 { ok, state, outcome, cancelled }. cancelled: true for cancel_requested and already_cancelled; a job that had finished or failed is 200 { state: <unchanged>, outcome: "already_ended", cancelled: false } (it was 409 bad_state).

Refusal order of POST /compute/jobs (the first failing check is the answer; a refusal writes nothing and returns no address)

  1. compute access: 403 no_compute_access (none, requested, denied, revoked, deleted) or 403 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.
  2. the Idempotency-Key shape: 400 invalid_spec field Idempotency-Key.
  3. the body: 400 invalid_spec (or 413 invalid_spec over 2.4 MB) with field spec.<path>, manifest.<path> or body; 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).
  4. a repeated key: the same specification is that job again (nothing below is asked); another is 422 idempotency_conflict.
  5. runtime and mode: 422 runtime_unavailable (matlab; or python while NEMAR's runtime image is not set), 422 registry_not_allowed (the owner's registries list, empty by default, matches the image path by whole segments).
  6. 422 partition_not_offered, then 422 over_job_limit.
  7. 409 over_concurrency (live jobs against the owner's limit).
  8. the bundle: 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.
  9. datasets, in order, through the pipelines' own gate: 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.
  10. the hold: 403 no_compute_access/suspended again, 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_found 404, version_untagged 422, too_many_files 422, entry_not_in_bundle 422, bundle_incomplete 409, idempotency_conflict 422, logs_not_available 404, upload_expired 409, storage_unavailable 503. upload_expired is also the failure code of a released upload (the submitter's, not the platform's). The issue's image_digest_required is not a word (a tag-only image is invalid_spec on spec.image); image_not_allowed is registry_not_allowed.

Caps (shared/contract/compute-bundle.ts, the owner's bundleLimits default to the same numbers and a test holds them equal)

BUNDLE_MAX_TOTAL_BYTES 100 MiB (the archive file; the sum of the files inside is held to it too), BUNDLE_MAX_FILES 2,000, BUNDLE_MAX_FILE_BYTES 25 MiB, BUNDLE_PATH_MAX 240, archive name bundle.tar.gz, request body bound BUNDLE_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)

upload is { url, method: "PUT", headers, expires_at, size }. PUT url with exactly headers (the signed x-amz-checksum-sha256, base64 of the archive's SHA-256) and Content-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-length in X-Amz-SignedHeaders, not returned in headers: the client sets Content-Length itself), and the declared size is enforced again at finalize by a HEAD: an absent, short or long object is 409 bundle_incomplete and 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 same Idempotency-Key returns the same job with a FRESH address. The window is judged on the spot: a repeat or a finalize after the hour ends the job as upload_expired (hold released) whether or not the release has run; the repeat returns that failed job with no address and finalize is 409 upload_expired: submit again with a new key. A finalize inside 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/cancelled is 409 upload_expired (released) or 409 bad_state; a recorded cancel is 409 bad_state. Otherwise the manifest body is judged (same words as submit, with the job's entry), then HEAD (bundle_incomplete), then ONE server-side copy to records/<id>/submitted/bundle.tar.gz and records/<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

  • Idempotency uses Epic A's (account_id, idempotency_key) with spec_digest as the request hash (scope user:<id>): NO migration is added and 0133 is unused. Phase D4 needs its own table for client:<id> (no account to key by). Migrations 0131/0132 untouched; migrations:d1-check passes.
  • runUploadExpiryCron (production only, on the 30-minute tick, not in DEV_CRON_ALLOWLIST, self-fenced, no switch read, ten rows a tick): fails an uploading job with unwritten records after one hour, hold released, nothing charged. Listed in cron-sweep-wiring.test.ts and cron-dev-safety.test.ts. The 30-minute backstop no longer takes such a row and submitComputeJob refuses it as records_not_written (the reservation wait would have failed it submit_timeout, a platform failure, inside the upload hour).
  • The compute switch is not read by any new code (compute-source-scan unchanged). With compute off a submission takes its hold and waits; past the reservation wait it fails submit_timeout, hold released (tested).
  • resolveRun is 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.
  • finalizeBundle records each file's sha256 when given. ResultLink gained sha256 (additive; POST /links carries it too).
  • No account-copy keys added; test/account-copy-parity.test.ts is unaffected.

Tests (all targeted; nothing run in a full suite)

cd backend && bun test ./test/<file>.test.ts per file: compute-jobs-submit 51, compute-jobs-race 5, compute-jobs-finalize 17, compute-jobs-person-routes 20, cron-sweep-wiring 214, cron-dev-safety 79, compute-route-inventory 8, oidc-token-allowlist 7, compute-results-routes 17 (its cancel-of-an-ended-job case changed to the new 200), compute-source-scan 4, plus the neighbours compute-jobs, compute-records, compute-lifecycle, compute-lifecycle-submit, compute-pipeline*, compute-end-callers, compute-e2e, compute-full-path all green. Root: compute-state.unit 59, compute-submit-contract.unit 25, compute-admin-contract.unit 37, api-export-surface.unit 14, help-tiers.unit 12. bun run typecheck, bun run lint and bun run migrations:d1-check pass 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, dropped cookieOriginGuard, let the reservation wait end an upload, let the tick take unfinished uploads, released a finalized job, skipped the release, omitted sha256, allowed every registry, dropped the percent-encoding path rule, widened or dropped PERSON_EXCEPT_TERMS, allowed suspended, skipped the submit after finalize, removed the hold gate of the job insert, dropped no-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: presignIncomingUploads reads 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) whether finalize should keep the manifest from submit instead of taking it again (done as taking it again, so the Worker stores nothing between the calls), (3) whether tag should 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 allows Idempotency-Key and exposes X-Nemar-Truncated, Idempotent-Replayed; M1 the ending statement binds records_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 carries job_id and a note; M4 solved at the root: a bundle job is BORN uploading in the hold's batch, so no created bundle 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: canonicalJobSpec sorts env before 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 and migrations:d1-check pass.

@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@PR2073

Version: 0.10.28-PR2073.6de842f
Commit: 6de842f


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit 35e8536 into feature/issue-2021-epic-compute-users Nov 7, 2026
25 of 27 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-2024-compute-submit-server branch November 7, 2026 09:24

This branch was previously deployed

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