Repository navigation
Phase A3: Job records and the results and records buckets - #2035
Merged
neuromechanist merged 12 commits intoNov 4, 2026
Conversation
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR2035Version: 🤖 Updated on each push. |
Contributor
Author
|
Review triage, driver, 2026-11-04. Round 1 was a two-reviewer Sonnet panel (contract and types; tests, errors and maintainability); this phase has no Opus checkpoint. Every accepted finding is fixed on this branch and was re-verified against its test; about 50 mutations of the new guards were killed. Deferred or open, with the reason:
|
neuromechanist
merged commit Nov 4, 2026
c2bb527
into
feature/issue-2005-epic-compute-core
19 checks passed
neuromechanist
deleted the
feature/issue-2008-phase3-job-records-and-the-results-and
branch
November 4, 2026 19:34
This was referenced Nov 4, 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 A3 of the compute program (#2008), part of epic #2005. It adds the job index, the two private R2 buckets and the one function that makes a job and its hold. Nothing submits to Tapis yet.
What changed
0115_compute_jobs.sql:compute_jobs(one index row per job, account id and fixed words only, no foreign key, no identity column; every state, source, kind and pool is an enumerated CHECK that a test compares withshared/compute-state.ts;failure_code,failure_detail,cancel_reasonandpartitionare checked by shape so a later epic's word needs no rebuild;state = 'failed'if and only if a failure code is set; a partial unique index on(account_id, idempotency_key), a partial index over the live states and one on(account_id, created_at)) andcompute_gateway_users(the ACCESS pseudonym,gw_and 20 base32 characters, never rotated and never removed).launch_spec_digestis not added: that is phase A5's migration 0116.backend/src/services/compute-jobs.ts:createJobmakes the job and its hold in ONE batch (the ledger's hold with the person's live-job limit as a guard read inside the same statement, then the pseudonym'sINSERT OR IGNORE, then the job INSERT, the last two gated onEXISTSof the hold row), so a refused hold leaves no job, no ledger entry, no pseudonym and no object in either bucket. It validates before any hold exists, returns the existing job for a replayed(account, key)and refuses the same key for another request, and writes the records after the commit.backend/src/services/compute-records.ts: the records layout (records/<id>/identity.json,spec.json,submitted/...,bundle-manifest.json,result-manifest.json,provenance.json,result.json;logs/<id>/...;incoming/<id>/...),writeIdentitySnapshot,writeSpec,presignIncomingUploads,finalizeBundle,finalizeSubmittedFiles,presignBundleReadandreadRecordObject(owner-only, reasoned, audited before any byte is read).spec_digestis the SHA-256 of the exact bytes ofrecords/<id>/spec.json, made once before the INSERT and written after the commit.backend/src/services/compute-s3.ts: the aws4fetch signer against R2's S3 interface (path style, regionauto):computeS3,presignPut,presignGet,copyObject. The endpoint isglobalThis.NEMAR_COMPUTE_S3_URLwhen set, else theCOMPUTE_R2_S3_ENDPOINTsecret;S3_ENDPOINT_URLis never read. A key is encoded segment by segment and judged by the contract'sCOMPUTE_PATH_RE, not byassertValidS3Key, soa..b.csvand100%.txtround-trip. An expiry above seven days is refused.backend/wrangler-sccn.tomlandtypes/bindings.ts:COMPUTE_RECORDSandCOMPUTE_RESULTSin[[r2_buckets]]and[[env.dev.r2_buckets]]with the four existing bucket names, both*_BUCKET_NAMEvariables in[vars]and[env.dev.vars], and the three Worker secret names in the comment block (no value, no endpoint). The two switches are not added.compute-ledger.ts: the part ofplaceHoldthat names why a hold was refused is now the exportedholdRefusalReason, socreateJobcan ask after its own batch refused without taking a second hold. No behaviour change.compute-s3.test.ts, a verifying S3 stand-in over the same Miniflare R2 buckets (helpers/compute-s3-standin.ts), a harness, seeding helpers and a D1 wrapper whose statements take a round trip on both sides. A test of A2's migration that listed everycompute_%trigger is scoped to its own three tables. ADR 0118 gets an amendment andimplementation-notes.mda section 8.Gates
bun test backend/test/compute-jobs-migration.test.ts backend/test/compute-jobs.test.ts backend/test/compute-records.test.ts backend/test/compute-buckets-config.test.ts: 272 pass, 0 fail (4 files, 2533 expect calls); withcompute-s3.test.ts325 pass, 0 failbun run migrations:d1-check:All migrations applied on real D1. Catalog matches bun:sqlite (186 objects, 53 tables). OK.(117 migrations, 0115 included, run once after the round 1 migration edits)bun run typecheck: passesbunx biome check src shared backend/src: only the 5 known baseline errors in untouchedzenodo.tsanddoi-orcid-discovery.ts, none in a changed filebun test: not run, by the owner's rule that it runs only at epic to dev. Targeted neighbours instead (21 files, 1262 tests, 0 failures): the six A2 ledger and policy suites, the suites that readwrangler-sccn.toml(S3 override fence, Neurobagel scan, switch pins, email and retention vars),migrations.test.ts,datasets-column-budget.test.ts, the compute contract and state tests and the A3 files.Every test was proved to fail by mutating the line it guards, one perturbation at a time, including the three in the issue: removing the
EXISTSterm of the job INSERT (the refused-hold cases then see a job), writing the records before the batch (they then see an object, and the ordering test sees no committed job), and taking the bundle key from the caller. The others: the live-job limit read before the batch instead of inside the hold's statement (caught only once the race tests took a round trip on both sides of each statement), an ungated pseudonym insert, a replay that ignores the digest, a replay that does not finish the records, the audit row after the bucket was touched, an audit failure that does not refuse, a reason minimum of 3, an audit row not gated on the owner role, no archive size check, no decoding layer in the traversal check, one layer only, the partner cap,finalizeBundlecopying before the job is read, copying again on a replay, overwriting an existing destination, no key encoding in the signer, an assertValidS3Key-like predicate, the checksum header not signed, a 200 error body ignored, the expiry cap,S3_ENDPOINT_URLhonoured, the global ignored, and eleven mutations of the migration and the toml.Round 1 fixes
idisTEXT PRIMARY KEY NOT NULL(SQLite let a NULL id in and the CHECK passed on NULL), the pseudonym table's key isINT NOT NULL PRIMARY KEY(not a rowid alias, so a NULL account is refused and not numbered), the header claim about NULL is now true and says which columns are NOT NULL and why, and a BEFORE INSERT triggercompute_gateway_users_keeps_firstignores an insert whose account or pseudonym is already stored, soINSERT OR REPLACEandREPLACE INTO(which delete without firing the delete trigger on D1) are a no-op. The header says what the three triggers do and do not cover, and a catalog test says the jobs have none and the pseudonyms exactly three.createJobtakes{ source: "partner", holdBody }, the exact text sent, reads the nine small fields of a hold from it (strict schema, at most 8 KiB, the partition tables and the owner's ceilings apply), skips the specification schema,launchSpecFitsand the bundle checks, andspec_digestis the SHA-256 of those exact bytes, which are alsospec.json. About 110 non-test lines, consistent with Phase D4: Partner reservation and report contract #2025 (the body there is{ app_id, app_version, kind, partition, nodes, cores, memory_mb, gpus, minutes }). A person's or pipeline's job is unchanged.presignIncomingUploads,finalizeSubmittedFilesand an owner's read of a submitted file now ask well-formed text and the 1,024-byte limit of both keys a path becomes (incoming/andrecords/.../submitted/) before signing, and answerinvalid_specnamingfiles.<i>.path(orinvalid_record);submittedPathProblemitself is not tightened, so a bundle manifest path keeps the 512-character rule.submittedPathProblemnow decodes leniently, per run of valid escapes, so one stray%no longer switches the encoded-traversal check off.bundle_too_largewhatever the owner's limits say.ComputeJobRow.stateisComputeState,UPLOAD_STATESisreadonly ComputeState[], and the private duplicate ofRECORDS_WRITTEN_SQLis gone.NEMAR_COMPUTE_S3_URLglobal. The docblock, ADR amendment item 2, the notes and the test header now say the copy waits for the job's row, which exists only if its hold does; the arithmetic is "about 39,470 outputs".filePathProblemsurvives because the records key is the longer prefix and its check implies the incoming one (kept on purpose, with a comment); and forcing the presign archive's outer clamp off survived becausecheckFilesclamps again, so I dropped the outer clamp.Decisions and deviations, for the reviewer
ENCRYPTION_KEY. The issue says both (the migration bullet says random and stored because a derivation changes if the key rotates; thecompute-jobs.tsbullet says derive it), and the design page says random and stored, so I followed the design and the migration bullet. ADR 0118 amendment item 4 records it.maxFiles(it is a contract the launcher's repository also holds);outputsBodyLimitBytes(maxFiles)derives the cap from the owner'smaxFiles(at least 1 MiB, at most 64 MiB,8 KiB + maxFiles x 1,700 bytesbetween). The launcher's own 1 MiB cap is the tighter bound today, so a job with more than about 8,000 ordinary outputs still failstoo_many_outputsat the launcher until its cap is raised, which is the launcher's change. Nothing calls the helper yet; Phase A5: Job lifecycle, webhooks, settlement and results #2010's route will.CopyObjectand a Worker invocation may make at most 1,000 subrequests. The cap shadows the owner'sbundleLimits.maxFileswith the same refusal word (bundle_too_many_files), so the partner contract and the design's section 6 must say 500. The file sizes are read from one listing before anything is copied.createJobalso refusesbundle_too_largebefore the hold (the owner's limit, never more than the 5 GiB one copy takes), throwsidempotency_conflictfor a key reused for another request, and answerscompute_disabledwhen the records binding is absent; a partner batch job is marked written byfinalizeSubmittedFiles, not bycreateJob;presignIncomingUploadstakes an optionalnowthat only a test sets.recordsWritten: truemeansspec.jsonandidentity.jsonlanded, not that the job is ready to submit: that isjob.records_written_at.x-amz-checksum-sha256header is signed with an INCOMING PUT when the caller declares a digest (the issue body); it is deferred only for output PUTs (Phase A5: Job lifecycle, webhooks, settlement and results #2010). Real R2's acceptance of the signed header on a presigned PUT is unverified (the stand-in enforces what S3 documents, and a real R2 may not enforce it or may refuse it); if real R2 refuses it, the fix is to dropsha256HexinpresignIncomingUploads. The size read back through the binding is the boundfinalizeBundlerelies on.complete, the job token's validity,declared.json) belong to Phase A5: Job lifecycle, webhooks, settlement and results #2010 and are not built here. The stateuploadingis not written: every edge aftercreatedis phase A5's.Not run, would check
bun test(epic to dev CI): this change adds a migration, bindings and a toml block that many suites read, so one full run is the way to see an unforeseen reader.CopyObject, path canonicalisation and an expiry of seven days have only been exercised against Miniflare and the verifying stand-in; one real presigned PUT and one copy in the dev bucket would settle them. The create-only conditional write (onlyIf: { etagDoesNotMatch: "*" }) is tested on Miniflare with a bucket whoseheadalways answers nothing (a stale view): a different specification is refused as a conflict and the stored bytes stay, and an existing identity snapshot is kept; whether real R2 honoursetagDoesNotMatch: "*"on a put is not proved, and the lock is the real guard.