Skip to content

Phase B2b: stage the serving index (#2324) - #2388

Merged
neuromechanist merged 14 commits into
feature/issue-2324-epic-pipeline-progressfrom
feature/issue-2324-b2b-serving-index
Nov 26, 2026
Merged

neuromechanist merged 14 commits into
feature/issue-2324-epic-pipeline-progressfrom
feature/issue-2324-b2b-serving-index

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Phase B2b of #2324: the dispatcher stages the serving index for nemar-ica's archive runs, through the launch specification. The launcher side is nemarOrg/nemar-process#96 (into feature/issue-65-epic-pipeline-progress, nemarOrg/nemar-process#65).

Versioning: nemar.launch-spec.v2 (ADR 0141)

  • The launch specification's root is closed (additionalProperties: false), and the launcher validates against its schema copy and refuses an unknown member as invalid_spec (launcher/nemar_launch/spec.py). A launcher that reads version 1 would refuse a specification carrying serving_index, so the field is a new version, not a v1 addition.
  • Version 2 is version 1 plus one optional member, serving_index: {sha256, size} (size at most 64 MiB, the recipe's own bound), and an open serving_index_response in $defs. Every version 1 document is a version 2 document with the same bytes: the golden vectors and the wire cases are unchanged.
  • The Worker writes the member only for a recipe in RECIPES_KEYING_SERVING_INDEX on the archive input, which runs on Tapis only; no launcher was ever registered with a tenant (nemar-process deploy/tapis/released-versions.json is empty), and a runner is never handed the member.
  • ADR 0141 records it, numbered after checking every remote branch (0139 and 0140 are taken, 0141 is free); it refines ADR 0140 decision 3, and ADR 0140 says so in its body.

What changed

  • Contract (shared/contract/compute-launch.ts, compute-launch.schema.json, compute.ts, compute-state.ts, compute-recipes.ts): the launch member, ServingIndexResponseSchema, SERVING_INDEX_CONTAINER_PATH (/data/serving-index/index.json), a recipe job's serving_index ({sha256, size} or {reason}, refused on a job without a recipe), SERVING_INDEX_ABSENT_REASONS, recipeServingIndexArguments, and the launcher detail serving_index_mismatch under dataset_fetch_failed (the platform's).
  • Dispatch (backend/src/services/serving-index-staging.ts, compute-pipeline.ts): for nemar-ica on bids, before the claim, the Worker reads <id>/zarr/index.json (S3 in production, the NEMAR_ZARR_INDEX_BASE seam outside it) and the tag's commit (tagCommit, the Zarr check's own lookup). It stages the index only when source_commit is exactly the tag's commit; no compare is ever requested, so metadata_only never applies. The exact bytes are kept under serving-index/<sha256>.json in the records bucket (create-only, a key holding other bytes is never overwritten) before the job exists. Every failure is a word recorded in the spec, and the job is dispatched without the index.
  • Arguments: a staged run adds --serving-index /data/serving-index/index.json --source-commit <tag commit> after the archive's own arguments, which already name --dataset-id.
  • Launch (buildLaunch): the recorded {sha256, size} goes into the launch specification; a recorded word does not.
  • Route POST /compute/jobs/:id/serving-index: the bundle route's door (job token, lease for a runner, terminal refused), then a ten-minute presigned GET of the copy the RECORDED specification names (read back by its digest), after a head that checks the size. Every other job gets the door's one refusal.
  • Key (keyStamp): a recorded {sha256, size} is keyed sha256:<hex>, and the arguments must hand that copy (the flag once, at the contract path). A recorded word or no record is keyed none, and the arguments must name no index. Anything else is serving_index_unattested.
  • nemar-ica stays placeholder: true; no path dispatches it.
  • compute-pipeline.ts under routes/admin/ is not touched (B3 has it).

Gates

  • bun run typecheck: clean.
  • bun run lint and Biome over every changed file: clean.
  • Root, targeted: test/compute-serving-index-contract.unit.test.ts, test/compute-contract.unit.test.ts, test/compute-local-launch-contract.unit.test.ts, test/compute-recipes.unit.test.ts, test/contract-schemas.test.ts, test/adr-index.unit.test.ts: 632 pass.
  • Backend, targeted: serving-index-staging (26, new), compute-derivatives, compute-route-inventory, compute-job-callbacks, zarr-source-check, compute-pipeline, compute-pipeline-input, compute-pipeline-verify, compute-runner-jobs, compute-fixture-eligibility, compute-lifecycle-submit, compute-records, tapis-client: 752 pass.
  • No migration, so no migrations:d1-check.
  • Not run: the full bun test (epic to dev only).

Mutation testing

Each mutation applied alone, the targeted tests run, the file restored (script kept in the session scratchpad).

# Mutation Killed by
CLI-01 staging accepts an index of any commit serving-index-staging.test.ts
CLI-02 staging takes checkZarrSource's metadata_only allowance serving-index-staging.test.ts
CLI-03 staging reads the index past 64 MiB serving-index-staging.test.ts
CLI-04 the kept copy keeps whatever bytes are at the key serving-index-staging.test.ts
CLI-05 staged although the copy was not kept serving-index-staging.test.ts
CLI-06 the job hands --serving-index although none was staged serving-index-staging.test.ts
CLI-07 the job records no serving_index serving-index-staging.test.ts
CLI-08 buildLaunch drops the staged index serving-index-staging.test.ts
CLI-09 the route signs the copy without the head and size check serving-index-staging.test.ts
CLI-10 the route signs for a job with no staged index serving-index-staging.test.ts
CLI-11 keyStamp keys a staged run none compute-derivatives.test.ts
CLI-12 keyStamp ignores the path the run was handed compute-derivatives.test.ts
CLI-13 keyStamp accepts the flag twice compute-derivatives.test.ts
CLI-14 keyStamp keys a staged digest the arguments never hand the run compute-derivatives.test.ts
CLI-15 keyStamp keys none a run that names an index none was staged for compute-derivatives.test.ts
CLI-16 a job that is not a recipe's may carry serving_index root contract tests (compute-serving-index-contract, compute-contract)
CLI-17 zod drops the 64 MiB bound on the launch member root contract tests (compute-serving-index-contract, compute-contract)
CLI-18 the JSON Schema drops the 64 MiB bound root contract tests (compute-serving-index-contract, compute-contract)
CLI-19 serving_index_mismatch is the submitter's root contract tests (compute-serving-index-contract, compute-contract)
CLI-20 the arguments omit --source-commit root contract tests (compute-serving-index-contract, compute-contract), serving-index-staging.test.ts

Deviations from the design

  • The design says the Worker reads the index "from R2"; the serving index is in the S3 data bucket (getZarrIndex reads it there), so the Worker reads it from S3, through a new getZarrIndexResponse that returns the exact bytes.
  • The bytes are kept content-addressed (serving-index/<sha256>.json) in the records bucket rather than under the job's own records/<id>/ prefix: the job id exists only inside createJob, and writing first means no specification ever names bytes that are not kept. Per-job retention does not delete these copies (see the question below).

Questions for the owner

  1. Retention of the kept copies. Settled: kept, no sweep (ADR 0141).
  2. A transient read failure. Settled by the owner: a fault defers for up to 24 hours (round 1 below).
  3. Provenance. Settled: left as is; the binding is indirect (ADR 0141).

Review fixes (round 1)

  1. test/compute-state.unit.test.ts: serving_index_mismatch is under dataset_fetch_failed.platform in TABLE.
  2. An unusable index never fails the run. The Worker checks the index as the recipe does before it stages it: strict JSON (readIJson: UTF-8, no byte order mark, no repeated member name) and zarr_input.validate_document's shape (stores, store_count, each store's path, zarr and groups, each group's name, modality, rate, n_channels, n_samples, with the recipe's bounds). One that fails is index_unusable and the run goes ahead at once without it. The recipe side is in B2b: fetch and bind the staged serving index (#65) nemar-process#96: an index it cannot use skips the views of the serving copy with serving_index_unusable instead of exiting 2, so serving_index_unusable joins VIEWS_SKIPPED_NEMAR_PROCESS_WORDS. Residual: a whole number written as 3.0 is a JSON float in Python and an integer in JavaScript, so the Worker accepts it where the recipe would not; the recipe then skips with its own word.
  3. Copy faults have their own lines: [serving-index] copy_conflict sha256=<hex> for foreign bytes at the content address, and [serving-index] copy_put_failed error=<class> for a store throw; neither shares the generic stage_threw line.
  4. Owner ruling: a fault defers.
    • On github_unreadable, index_unreadable (an S3 throw included), token_mint_failed, no_github_credentials or index_not_stored, the run is not dispatched. servingIndexForRun writes a refused stamp with serving_index_deferred, the stamp states that already exist (a refused stamp holds no slot, never counts toward the cooldown or the cap, and is left out of the grid), and the dispatch answers zarr_source_unverifiable (503) with the fault's word and the stamp (superseded in round 2 by its own word, serving_index_deferred). No migration.
    • Later passes try again. Once the oldest deferral of the run (the deferred stamps newer than the tuple's newest stamp of any other kind) is 24 hours old, a fault dispatches without the index and the specification records the fault's word.
    • no_index, source_commit_differs, tag_absent, index_too_large, index_unusable and index_commit_unusable run at once without the index.
    • 403: getZarrIndex's sweep relies on 403 meaning absent, so that is left alone; the staging reader getZarrIndexResponse is its own, and there a 403 now throws and is index_unreadable, a fault.
    • The refusal word is the existing zarr_source_unverifiable rather than a new one, so shared/contract/compute-admin.ts (which B3 changes) is untouched.
  5. ADR 0141 decision 3 is amended to say this; it now also notes that serving-index/ is outside the records' lock and retention rules (no sweep; a future sweep must never remove a copy a live job names) and that provenance.json binds the index indirectly through launch_spec_digest.

Before nemar-ica's placeholder is lifted

  • A dispatch-level test on nm099999 is required: nemar-ica is a placeholder, so no test reaches dispatchPipelineJob past the placeholder gate. The deferral's mapping is tested through servingIndexRefusal, but the one call-site line (if (refusal !== null) return refusal;) survives mutation until that test exists (CLI-37 below).
  • The first Tapis app version registered for nemar-ica must be built from a launcher that reads nemar.launch-spec.v2.

Gates after the fixes

  • bun run typecheck, bun run lint, Biome over every changed file: clean.
  • Root, targeted (adds test/compute-state.unit.test.ts and test/quality-documents-contract.unit.test.ts): 804 pass across 8 files.
  • Backend, targeted (adds compute-pipeline-grid, compute-pipeline-queue, compute-pipeline-dispatch): 896 pass across 16 files; serving-index-staging is 66.
  • No migration. Not run: the full bun test.

Mutations of the new checks

# Mutation Killed by
CLI-21 a fault runs at once serving-index-staging.test.ts
CLI-22 every word defers serving-index-staging.test.ts
CLI-23 a fault defers for ever serving-index-staging.test.ts
CLI-24 the wait is measured from the newest deferral serving-index-staging.test.ts
CLI-25 an earlier run's deferrals count serving-index-staging.test.ts
CLI-26 the wait is 20 hours serving-index-staging.test.ts
CLI-27 a 403 from S3 is an absent index serving-index-staging.test.ts
CLI-29 the shape is not checked serving-index-staging.test.ts
CLI-30 a repeated member name is accepted serving-index-staging.test.ts
CLI-31 a rate of zero is accepted serving-index-staging.test.ts
CLI-32 a dot segment is accepted serving-index-staging.test.ts
CLI-33 the sample bound is dropped serving-index-staging.test.ts
CLI-34 a conflict logs the put failure's line serving-index-staging.test.ts
CLI-35 a store throw logs no class name serving-index-staging.test.ts
CLI-28 a byte order mark is accepted serving-index-staging.test.ts
CLI-36 the dispatch runs through a deferral serving-index-staging.test.ts
CLI-37 the dispatch drops the refusal it was given SURVIVED

Review fixes (round 2)

The epic base is merged in (a merge, not a rebase), with B3's and B3b's shared/contract/compute-admin.ts; only CHANGELOG.md conflicted.

  1. A truly absent index no longer waits 24 hours. The Worker's S3 credentials lack s3:ListBucket, so a missing object answers 403. getZarrIndexResponse now hands a 403 back as "forbidden", and staging reads the dataset row with ZARR_COPY_SQL (moved beside the rule): a copy that is not ready, or has no store, is no_index and runs at once; a ready copy with stores is a fault (index_unreadable) and defers. The index seam applies the same rule. Tested both ways through a stand-in that answers 403, for four row states.
    • Alternative, the owner's: grant the Worker's S3 credentials s3:ListBucket on the Zarr prefix; S3 then answers 404 for a missing object, and the row is no longer needed to tell the two apart. Not done here: it is an infrastructure change.
  2. The call site narrows by type: if (decided.kind !== "run") return servingIndexRefusal(decided, datasetId, tag);, then decided.servingIndex. servingIndexRefusal takes only the two non-run decisions. Dropping the line, or only its return, is a bun run typecheck error (Property 'servingIndex' does not exist on type 'ServingIndexDecision'), checked by hand: CLI-37 is killed by the compiler.
  3. serving_index_deferred (503) is its own word: in PipelineRefusal, COMPUTE_PIPELINE_ONLY_REFUSAL_STATUS and the route's sentences. The sentence says the serving index could not be staged because of a temporary fault, that the run is deferred, not failed, that its stamp records the deferral, and that 24 hours after the first deferral the run goes ahead without the index; the answer carries runs_without_index_after (ISO 8601), the time it goes ahead. PIPELINE_RUN_STATUS_SQL is unchanged (a refused stamp still reads failed there); the sentence states that the stamp is a deferral. B3's admin quality route answers a deferred stamp run_not_succeeded.
    • Website: W9 must take the new word serving_index_deferred and the field runs_without_index_after; the website drift tests pin these word lists.
  4. Docs. servingIndexShapeOk's docstring names the one difference from the recipe: an integer-valued float such as 3.0 is accepted by the Worker and refused by the recipe, which then skips the views. ADR 0141 no longer calls the provenance binding complete: launch_spec_digest binds the digest the launcher was handed, not proof that the file was checked. It also records the 403 rule and the word.
  5. Boundary test at exactly 1,440 minutes (deferred at 1,439, runs at 1,440). The age is now whole seconds divided by 60 (strftime('%s')), so the boundary is exact; with julianday it was a fraction past 1,440 and R2-04 survived.

Gates after round 2

  • bun run typecheck, bun run lint, Biome over every changed file: clean.
  • Root, targeted (adds compute-admin-contract, admin-compute-pipeline-cli, admin-route-inventory, api-export-surface): 953 pass across 12 files.
  • Backend, targeted (adds compute-pipeline-routes, quality-admin-route): 966 pass across 18 files; serving-index-staging is 74.
  • No migration. Not run: the full bun test.

Mutations, round 2

# Mutation Killed by
R2-01 every 403 is a fault serving-index-staging
R2-02 every 403 is an absent index serving-index-staging
R2-03 a ready copy with no store defers serving-index-staging
R2-04 the wait ends after, not at, 1,440 minutes serving-index-staging
R2-05 a deferral answers zarr_source_unverifiable serving-index-staging
R2-06 runs_without_index_after always 24 hours from now serving-index-staging
R2-07 the call site drops the narrowing line, or its return bun run typecheck

CLI-21 to CLI-35 were run again on the new code and all are killed (CLI-24 against the new age SQL); CLI-27, CLI-36 and CLI-37 are superseded by R2-01, R2-02, R2-05 and R2-07.

Agentic AI tools were used.

Adds serving_index to nemar.launch-spec.v2 and to a recipe job's spec, the serving index response, the container path and serving_index_mismatch. Tested: contract unit tests.
nemar-ica's archive job is handed the index only when its source_commit is the tag's; the copy is kept by digest before the job exists. Tested later with the route.
POST /compute/jobs/:id/serving-index signs the copy the recorded spec names. Tested: serving-index-staging, route inventory.
Tested: compute-derivatives.
Not tested: prose only.
Tested: compute-state (59 pass).
index_unusable for an index the recipe would refuse (readIJson plus validate_document's shape); copy_conflict and copy_put_failed lines; a 403 from S3 is a fault. Tested: serving-index-staging.
A fault leaves a refused serving_index_deferred stamp and answers zarr_source_unverifiable; after 24 hours the run goes without the index. Tested: serving-index-staging (66 pass).
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR2388

Version: 0.10.40-PR2388.fd154d9
Commit: fd154d9


🤖 Updated on each push.

…-progress' into feature/issue-2324-b2b-serving-index

# Conflicts:
#	CHANGELOG.md
A 403 is an absent index unless the row's copy is ready with stores; a deferral answers serving_index_deferred (503) with runs_without_index_after; the age is whole minutes, the call site narrows by type. Tested: serving-index-staging (74), backend targeted (966).
Over 50,000 documents judged twice exceed bun's 5 s default on a loaded runner; the corpus keeps its size. Tested: schema-check-contract.
@neuromechanist
neuromechanist merged commit 39e2ee3 into feature/issue-2324-epic-pipeline-progress Nov 26, 2026
25 of 27 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-2324-b2b-serving-index branch November 26, 2026 03:05

This branch was previously deployed

1 inactive deployment
npm — fd154d9d Deployed Nov 26, 2026 by neuromechanist via publish #4950
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