Repository navigation
Phase B2: quality view route and serving-index key (#2324) - #2383
Merged
neuromechanist merged 17 commits intoNov 26, 2026
Merged
neuromechanist merged 17 commits into
neuromechanist merged 17 commits into
Conversation
A recipe that reads the serving index on the archive input (nemar-ica) gets a version 2 derivative key whose ninth line is serving_index (none, or the index file's SHA-256), so runs with and without an index, or with different indexes, never collide. Every other key stays version 1 byte for byte. A run handed --serving-index is not keyed until the dispatcher stages the index (serving_index_unattested). Migration 0153 keeps the field on the row; ADR 0138 records the decision. Tested: contract-derivatives (vectors computed in Python and Bun), compute-derivatives (nemar-ica keying, skip word, column CHECK).
The Worker cannot run Ajv, which compiles schemas with new Function. schema-check.ts interprets the draft 2020-12 keywords the vendored neuroschema schemas use and throws when a set is built over any keyword it does not implement. Held to python-jsonschema's kinds-verdicts (all 244 cases of the schemas dataQuality reaches) and to Ajv over the verdict, preset and kind corpora and over 50,000 one-edit mutations. Tested: test/schema-check-contract.unit.test.ts.
recordQualityEntry now honors the I-JSON reader's unsafe-integer flag over the whole record (integer_unsafe) and refuses a plugin view whose plugin the recipe version does not run at its quality checkpoint (view_unknown_plugin), the two points the B1 review left to B2. It also returns the dataset and recording the record says it is of. Tested: quality-documents-contract (113 pass).
Migration 0152: dataset_quality_epochs, a table of its own (datasets is near D1's column cap), advanced by a trigger on every real change of visibility, status, anonymous, first_published_at, withdrawn_at or ezid_status. The quality route keys its edge cache by it. Tested: migrations:d1-check (144 migrations on local D1, catalog matches bun:sqlite), datasets-column-budget.
GET /<id>/quality/v1/<recipe>/record/<recording> serves a recording's dataQuality document from the recipe's current public derivative (CURRENT_PUBLIC_DERIVATIVE_SQL), and .../file/<key>/<sha256>/<recording> one file a validated view declares. The dataset gate (active, public, unconcealed, first published, unwithdrawn, untombstoned) and the derivative are read in one D1 statement before the edge cache, which is keyed by the dataset's epoch and the derivative key. The record is checked whole against the vendored neuroschema schemas through schema-check.ts, plus recording scope and the record's own identity; a file is re-hashed before it is served. Refusals are fixed words, no-store, never cached. Tested: quality-route (47 pass, real D1 and Miniflare R2, the P7 fixture), quality-route-contract, quality-documents-contract.
Kills the three mutants that survived the first round: the served file's size check (its log reason), one digest declared as two files of one format, and dependentSchemas in the schema checker. Tested: quality-route (48 pass), schema-check-contract (254 pass).
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR2383Version: 🤖 Updated on each push. |
3 tasks
ADR 0138 is taken on dev and 0139 on open branches. The ADR index tolerates both gaps until they land. Tested: adr-index, contract-derivatives.
The Python harness now computes every derivative_key vector (version 1 and the version 2 key of ADR 0140) and refuses every refused one, so the cross-language claim is tested in CI where uv is available. Tested: contract-derivatives-python with NEMAR_REQUIRE_SCRUB_TOOLS=1 (117 pass).
Migration 0152 keeps NOT NULL only: its one writer is a trigger inside every update of a gate column, which must never be refused for the sake of a cache. Tested: migrations:d1-check, quality-route.
CURRENT_QUALITY_DOCUMENTS_SQL now joins the dataset through QUALITY_DATASET_GATE_SQL (moved to quality-documents.ts), so a tombstoned or never-published dataset shows no dataQuality on metadata.json or the page bundle. Tested: metadata-json-quality (tombstoned and never-published cases), quality-documents.
compute_derivatives.quality_plugins (migration 0153) records the recipe version's quality plugins when the row is keyed; the route checks plugin view sources against it, so a derivative of a recipe version the registry has moved past is still served, and a row without the list serves nothing. The record answer's ETag is now the SHA-256 of the body. Tested: quality-route (older version, catalog and published; stored list decides; null list refused; body ETag), compute-derivatives.
purgeCacheTags and purgeQualityCache in services/cloudflare.ts purge Cache-Tag nemar-dq-<id> after the D1 write of a visibility flip to private (unpublish, withdraw), a withdrawal stamp and a concealment: best effort, logged, never blocking. The browser and shared-cache residual of up to 300 s is documented in routes/quality.ts. Tested: quality-cache-purge, review-auto-require-paths (purge after the row is private; a refused purge keeps the flip), unpublish, withdraw, anonymity suites.
Tested: not applicable (documentation).
withdrawDataset flips the row private through applyDatasetVisibility, which purges the tag after the write. The second, explicit purge after the withdrawal stamp was redundant and untested (mutant B2R-07 survived), so it is removed. Tested: withdraw, withdraw-route, review-auto-require-paths, quality-cache-purge.
postPurge aborts a request after PURGE_TIMEOUT_MS, so a purge API that never answers cannot stall an unpublish; the failure is logged as cache_purge_failed. Tested: review-auto-require-paths (a never-answering stand-in: the flip finishes, the row is private, the failure is logged).
The Workers Cache API strips Cache-Tag from what it stores; the route sets it again on a hit. Tested: quality-route with a cache stand-in that strips the header.
Migration 0153 sets quality_plugins = '[]' on existing nemar-floor rows, which run no plugin at any version; other recipes' earlier rows stay null, as the comment says why. Tested: quality-route (migration replayed on rows written before 0153), migrations:d1-check.
neuromechanist
merged commit Nov 26, 2026
ddb1822
into
feature/issue-2324-epic-pipeline-progress
25 of 27 checks passed
This was referenced Nov 26, 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.
Part of #2324 (phase B2 of the live quality views, ADR 0137 decisions 6 and 7). Takes the backend items of #2341 that B1 left: the view route, the derivative key, and the registry comment.
What changed
backend/src/routes/quality.ts, mounted inroutes/data.tsbefore the version routes; paths, words and bounds inshared/contract/quality-route.ts):GET /<id>/quality/v1/<recipe>/record/<recording>: the recording'sdataQualitydocument (level: record) from the recipe's current public derivative, with the derivative's key and dataset version and each view'snemar.view-digest.v1.GET /<id>/quality/v1/<recipe>/file/<key>/<sha256>/<recording>: one file a validated view of that recording declares.relativeLocationnaming a recording, key and digest 64 hex) before any read; then ONE D1 statement with the dataset gate (active, public,anonymous = 0, first published, not withdrawn, not tombstoned; the pipeline eligibility's own terms) and the derivative bound by the row,CURRENT_PUBLIC_DERIVATIVE_SQLreused; then the edge cache keyed by the dataset's epoch and the derivative key; then the record (at most 512 KiB) checked whole; then the file, re-hashed.quality_not_found). A public key that has expired answersviews_expired(410).Cache-Control: public, max-age=300,Cache-Tag: nemar-dq-<id>,ETag= SHA-256. Every refusal isno-storeand never cached. Unlisted formats areapplication/octet-streamattachments; every file carriesnosniffand an RFC 6266filename*.backend/src/services/quality-views.ts):{level: "record", recipes: {<recipe>: entry}}against the vendored neuroschema 0.6.0dataQuality, which reachesview.schema.jsonand every kind, content and transform schema. Plus recording scope only, one digest = one file, and the record's own dataset and recording must be the ones asked for (record_elsewhere).shared/contract/schema-check.ts: the Worker cannot run Ajv (new Function), so this interprets the vendored JSON Schema (draft 2020-12 subset the bundle uses) and throws at build time on any keyword it does not implement. Held to python-jsonschema's kinds-verdicts (all 244 cases of the schemasdataQualityreaches) and to Ajv over the verdict, preset and kind corpora plus more than 50,000 one-edit mutations.recordQualityEntry): the reader's unsafe-integer flag is honored over the whole record (integer_unsafe), and a plugin view's plugin must be one the recipe version runs at itsqualitycheckpoint (view_unknown_plugin).dataset_quality_epochs: a table of its own (datasetsis near D1's column cap), advanced by a trigger on every real change ofvisibility,status,anonymous,first_published_at,withdrawn_atorezid_status.RECIPES_KEYING_SERVING_INDEX: nemar-ica) gets a version 2 key,nemar.derivative-key.v2, the eight version 1 lines plusserving_index(none, orsha256:and the index file's digest). Every other key is version 1, byte for byte. A run whose spec names--serving-indexis not keyed (serving_index_unattested) until the dispatcher stages the index and records its digest.compute_derivatives.serving_indexkeeps the field soderivative.jsonwrites the key text again.placeholdersince it entered the registry (Phase A6: First-party pipeline dispatch #2054), and no path dispatches a placeholder, so no nemar-ica stamp has succeeded or been keyed.shared/compute-recipes.ts: 17 files per recording, about 1,470 recordings atmaxFiles25,000); nothing left to change.compute-derivatives.tsISOLATION comment names the one reading route. CHANGELOG (Unreleased, Added).Not done: dispatch staging (stopped, as briefed)
Staging
<zarr base>/<id>/zarr/index.jsonfor an archive nemar-ica job needs infrastructure beyond the backend's dispatch code.The launch spec,
nemar.launch-spec.v1, is shared byte for byte with the launcher in nemar-process.It stages only the code bundle (through a Worker route with the job token) and the datasets (from the data plane).
It has no field for an extra staged file, and the job's network fence admits no host.
So the backend cannot pass
--serving-indexfor a file that exists on the node.Nothing was invented.
--serving-indexis not passed, and a run that names it is not keyed (see ADR 0140), so a later staging change cannot collide with today's keys.See owner question 1.
Tests
Real D1 (bun:sqlite with every migration) and Miniflare R2, using the P7 product from
test/fixtures/quality/ica-views:backend/test/quality-route.test.ts(48): each gate term (private, archived, deleted, withdrawn, tombstoned, never published, annm099998-shaped anonymous deposit, and anonymity alone with the 0085 trigger dropped); canary, copying, failed, expired (views_expired), supersededcatalogand supersededpublishedrows; newest bystored_atand the tie rule; one dataset's key under another;record_elsewhere; an invalid full declaration (empty caption, spectrumoverlap1); an unsafe integer; a foreign plugin source; reserved scope; a record over 512 KiB; one digest declared as two files; undeclared digests (including the record's and_ica.json's); digest and size mismatch; a missing object; path traversal and non-recording paths; malformed keys and digests; cache before gate, the epoch in the key, refusals never cached, and the derivative key in the cache key; and migration 0152's trigger.backend/test/compute-derivatives.test.ts: nemar-ica keyednoneunder v2 (row, key andderivative.jsonkey text);--serving-indexin either form is unkeyable; the floor stays v1; the 0153 CHECK (including the Zarr input).test/contract-derivatives.unit.test.ts: new vectors (computed in Python and in Bun) and refusals; four distinct keys for no field,none, index A and index B.test/schema-check-contract.unit.test.ts,test/quality-route-contract.unit.test.ts,test/quality-documents-contract.unit.test.ts.Gates
bun run typecheck,bun run lint, andbiome checkon every touched file: clean.bun run migrations:d1-check: 144 migrations replayed on local real D1; the catalog matches bun:sqlite.contract-derivatives,quality-documents-contract,quality-route-contract,schema-check-contract,compute-recipes,adr-index,view-digest-contract,contract-neuroschema,contract-schemas,plugin-manifest-contract).quality-route,quality-documents,metadata-json-*,compute-derivatives,compute-quality-documents-migration,datasets-column-budget,anonymity-projection,data-route-manifest-stream,landing-payload-archive,page-bundle-*,compute-pipeline,compute-progress-reconcile).bun test. It is the epic-to-devgate and takes about 80 minutes.Mutation table
Each mutation was applied alone, the named suites were run, and the file was restored.
git statuswas clean after the run.52 mutations, all killed. In round 1, B2-15, B2-25 and B2-39 survived. The tests were strengthened in 7006e6f "Pin size, one-digest and dependentSchemas checks", and those three were then killed in round 2.
activepublicnot_anonymousfirst_publishednot_withdrawnnot_tombstonedDeviations from the plan
dataset-read-access.ts, are not built. A private dataset answers 404.schema-check.ts), not by a hand-written zod view mirror. It is held to jsonschema's verdicts and to Ajv instead.dataset_quality_epochs), not in adatasetscolumn, because of the column budget. Its trigger covers all six gate columns, not only visibility and status.nemar.derivative-key.v2, with ADR 0140, because ADR 0123's Consequences require a new format name and a new ADR for any change to the key. The "no index" value is the wordnone, matching the contract's existingLOCATIONS_NONE, rather than a literalnull._servingunmixing.tsvis served inline as TSV.view-digest-contracttest, not again inquality-route-contract.shared/openapi.json. No capture script either: the fixtures come from B1's copy at a nemar-process pin.recording_path_invalidis 400, andrecord_unreadableandview_data_corruptare 502. Every refusal isno-store.Owner and lead rulings (review of 2026-11-25)
qualityplugins.none: kept. The Python replay of the key vectors now runs in CI.Next: B2b (dispatch staging of the serving index)
serving_index: {sha256, size}tonemar.launch-spec.v1. This is a shared schema change in nemar-cli and nemar-process.<zarr base>/<id>/zarr/index.json. It stages the index only when the index'ssource_commitis exactly the dispatched tag commit, never undermetadata_only. Otherwise it stages none, and the run declares no view of the serving copy.--serving-index,--dataset-idand--source-commit.keyStampkeysserving_index sha256:<digest>from the spec, never from the record.serving_index_unattestedthen applies only to a run that names--serving-indexwithout a recorded digest.Review fixes (round 1)
Important: older recipe versions. Migration 0153 adds
compute_derivatives.quality_plugins: the recipe version'squalityplugins as a JSON array, recorded when the row is keyed. The route checks plugin view sources against the stored list. A row with a null list (made before the migration; no nemar-ica row exists) serves nothing and logsquality_plugins_unknown. Route tests cover a catalog and a published derivative at an older version, the stored list deciding, and a null list.Cache-Tag purge.
purgeCacheTagsandpurgeQualityCacheinservices/cloudflare.tspurgenemar-dq-<id>:markAnonymous).Purging is best effort: a failure is logged as
cache_purge_failedand never blocks the write.An explicit second purge on the withdrawal stamp was redundant and untested (mutant B2R-07 survived), so it was removed.
The residual is documented in
routes/quality.ts: a copy in a browser, or in a shared cache outside Cloudflare, can be served for up to 300 seconds.0152: the table has only
NOT NULL, so the trigger can never refuse an update to a gate column. A test covers a dataset id of an odd shape.ETag: a strong ETag, the SHA-256 of the response body's bytes.
Gate mismatch:
QUALITY_DATASET_GATE_SQLmoved toquality-documents.ts, and B1'sCURRENT_QUALITY_DOCUMENTS_SQLnow uses it. Tests onmetadata.jsonand the page bundle cover a tombstoned dataset and a never-published one.feature/issue-2188-review-inputs(0152); the lead renumbers at epic-to-devif needed.test/contract-derivatives-python.unit.test.tsnow computes everyderivative_keyvector (v1 and v2) and every refused one in Python.Mutations for the fixes, each applied alone and the file restored:
Gates after the fixes:
bun run typecheckandbun run lint: clean.bun run migrations:d1-check: 144 migrations on local D1; the catalog matches bun:sqlite.quality-cache-purge,review-auto-require-paths,unpublish,visibility,withdraw,withdraw-route,anonymity*,publish-withdrawandfleet-visibility-route.bun test.Review fixes (round 2)
postPurgeaborts each request after 5 s (PURGE_TIMEOUT_MS,AbortSignal.timeout).A test with a purge stand-in that never answers shows the flip finishes, the row is private, and
cache_purge_failedis logged.Handing the purge to
executionCtx.waitUntilis not done:applyDatasetVisibilityandmarkAnonymousare services with no execution context, and threading one through every caller is a wider change.Cache-Tagis set again on a cache hit, because the Workers Cache API strips it. Tested with a cache stand-in that strips the header the same way.quality_plugins = '[]'on existingnemar-floorrows, which run no plugin at any version.Other recipes' earlier rows stay null: their plugins depend on the version, and a guess could admit a view the run never wrote. No nemar-ica row exists.
Tested by replaying 0153 over rows written before it;
migrations:d1-checkpasses.Cache-TagGates after round 2:
typecheckandlint: clean.migrations:d1-check: OK.Tripwire for the epic-to-dev merge
test/adr-index.unit.test.tstolerates gaps 0138 and 0139. When dev, which holds ADR 0138 (rootless Podman), is merged into the epic, remove 0138 fromTOLERATED_GAPSand its comment. Remove 0139 too once that ADR lands. Migration 0152 may also need renumbering then (it collides withfeature/issue-2188-review-inputs).No remote environment was touched. Nothing was deployed, and no dev or production D1 or R2 was read or written.
Agentic AI tools were used.