Skip to content

Epic #896: platform hardening + website↔CLI/backend contract - #943

Merged
neuromechanist merged 8 commits into
devfrom
feature/issue-896-epic-arch-hardening
Jul 7, 2026
Merged

neuromechanist merged 8 commits into
devfrom
feature/issue-896-epic-arch-hardening

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Arch-review follow-ups (2026-07). Six phases, each individually reviewed (sonnet) + merged to this epic branch.

Phases

  1. Phase 1: Release/deploy safety — serialize deploy-backend + gate on tests #897 deploy safety (PR Phase 1: serialize + gate backend deploys (#897) #934) — concurrency group + a test-gate job serialize prod deploys and gate them on tests (prod was double-deploying ungated). Review caught that the gate was a no-op (custom if: drops the implicit needs-success gate) — fixed.
  2. S3 upload of files >5 GB fails silently: buildS3RemoteArgs omits partsize (git-annex single-part PUT hits S3 5 GB cap) #886 S3 >5 GB partsize (PR Phase 2: S3 partsize for >5GB uploads (#886) #935) — partsize=1GiB so large recordings upload via multipart instead of failing EntityTooLarge; git-annex stdout surfaced on copy failure.
  3. Phase 3: Website↔CLI/backend contract foundation (shared types + canonical formats + CI contract test) #898 contract foundation (PR Phase 3: shared wire-contract foundation (#898) #938) — shared/contract/ Zod schemas (extraction-ready for @nemar/contract) + vendored neuroschema v0.3.0 bundle with ajv conformance + a live CI contract test. Follow-up Productize the wire contract: @nemar/contract npm pkg + OpenAPI + website adoption #937 (publish pkg + OpenAPI).
  4. Phase 4: Fix known contract drift — file_size (#895), getCurrentUser, /datasets/:id parity (#864) #899 drift fixes (PR Phase 4: fix contract drift (getCurrentUser, version prefix) (#899) #939) — getCurrentUser unwraps {user,token}.user; catalog latest_version canonicalized to vX.Y.Z. Companion: website#145 (vv1.0.0 coerce), zarr queue: normalize version comparison (bare vs vX.Y.Z) nemarDatasets/.github#61 (zarr-queue re-drain guard).
  5. Phase 5: DOI version-mint reconciliation (orphaned reserved DOIs) #900 DOI reconcile (PR Phase 5: DOI version-mint reconciliation (#900) #940) — complete a reserved DOI on already-exists (never resurrect a tombstone); day-rotated backstop cron sweep.
  6. Phase 6: Data-plane + credential hardening — zarr rate limit + STS prefix-scoping #901 zarr rate-limit (PR Phase 6: rate-limit the zarr data plane (#901) #942) — the highest-volume path is now rate-limited (data-plane bucket incl. the /zarrproxy shape; 429 keeps CORS). STS ListBucket prefix-scoping split to STS per-session ListBucket over-scoping (cross-dataset key enumeration) #941.

Operational items for after dev→main (owner)

Follow-ups filed

#936 (backend lint in CI), #937 (@nemar/contract pkg + OpenAPI), #941 (STS prefix-scoping).

Closes #896, #897, #886, #898, #899, #900. (#901 partial — STS half is #941.)

* Serialize + gate backend deploys on tests

Epic #896 Phase 1 (#897). Prod was double-deployed ungated: the dev->main
merge commit and the auto-tag strip commit both match backend/** and fired
migrate+deploy to production in parallel, racing tests.
- concurrency group deploy-backend-${{ github.ref }} (cancel-in-progress:false)
  serializes deploys per ref; the two release commits now deploy sequentially.
- new test-gate job (typecheck + lint + pure unit tests, mirroring test.yml's
  required tier); both deploy jobs needs: it, so a red build can't deploy.
- post-deploy release-tag drift notice (git tag vs deployed commit).

* Fix: explicit test-gate.result check blocks deploy

Review found the gate was a no-op: deploy jobs have a custom if: (env
check), which drops GitHub Actions' implicit needs-success gate, so a
FAILED test-gate would not block the deploy. Add explicit
needs.test-gate.result == 'success' to both deploy jobs.
* Add S3 partsize so >5GB files upload (multipart)

Epic #896 Phase 2 (#886). git-annex uploads of any data file >5 GB (common
for raw iEEG/EEG) failed with a generic 'Failed to copy to remote'.
- buildS3RemoteArgs now emits partsize (default DEFAULT_S3_PARTSIZE=1GiB,
  per-remote configurable via S3RemoteConfig.partsize) so git-annex uses
  multipart PUT instead of a single-part PUT that S3 caps at 5 GB
  (400 EntityTooLarge). Applies to existing remotes on next enableremote.
- extractCopyError surfaces git-annex STDOUT on copy failure (the S3 error
  lands on stdout, not stderr), so users see the real cause not a generic msg.
- buildS3RemoteArgs/DEFAULT_S3_PARTSIZE/extractCopyError exported for unit
  tests; export-surface pin updated (INTERNAL_WIRING) in the same commit.

* Address #886 review: cap copy-error output length

extractCopyError's relevant-lines branch was unbounded; a many-file copy
failure (generic fail/error matches) could surface hundreds of lines to
the CLI. Cap to the last 20 with an omitted-count note, matching the
bounded-subprocess-error convention (github.ts, import-openneuro.ts).
Added a >20-line test case.
* Add shared wire-contract foundation (Zod + neuroschema)

Epic #896 Phase 3 (#898). Foundation only; drift FIXES land in #899.
- shared/contract/ (zero-dep-beyond-zod, extraction-ready for @nemar/contract):
  version.ts (canonical toVersionTag/versionTagSchema), user.ts (the {user,
  token} /users/me envelope), dataset.ts (catalog/detail/search + neuroschema-
  conformant dataset schema; NEUROSCHEMA_VERSION single source).
- data-router.ts single-sources toVersionTag + NEUROSCHEMA_VERSION from the
  contract (re-exports toVersionTag so routes/data.ts is unaffected).
- CLI request<T> gains an optional Zod schema param: validates the response and
  fails loud on drift instead of silently casting (the getCurrentUser class).
- neuroschema conformance ENFORCED: vendored self-contained v0.3.0 bundle
  (build-vendor.mjs, 20 schemas) + ajv 2020-12 conformance test.
- CI contract test (contract-live, TEST_API_URL-gated) validates live catalog/
  detail/search/users-me against the Zod schemas; data-plane metadata against
  the neuroschema bundle (warn-only until #899 fixes drift).
- Tests: contract-schemas (10), contract-neuroschema (5). ajv added as devdep.

* Address #898 review: fix schema/wire mismatches

- CRITICAL: searchHitSchema keyed on dataset_id, but /datasets/search
  aliases d.dataset_id AS id and has no latest_version -> would have failed
  integration-dev CI on any non-empty search. Rewrote to the real SearchResult
  shape (id required, nullable raw columns, score/snippet). Added fixture tests.
- catalogItemSchema.id made optional (?mine=true branch omits the alias).
- datasetDetailSchema overrides file_size/modalities/tasks/authors/license to
  nullable (detail query is raw d.*, no COALESCE, unlike the list query).
- data-plane neuroschema live check is now fully warn-only (recording_modality
  can be [] pre-classification); #899 flips to hard-fail after the drift fix.
…939)

* Fix contract drift: getCurrentUser + version prefix

Epic #896 Phase 4 (#899). Applies the #898 contract to the known drift.
- getCurrentUser() unwraps the {user, token} envelope (.user) and validates
  against userMeResponseSchema. It previously declared flat UserInfo and read
  the envelope top level, so every field was undefined at runtime -- silently
  writing undefined over stored account config on 'auth status --refresh' and
  disabling the upload ORCID auto-match. Consumers coerce nullable username/
  github_username -> undefined for config.
- Catalog latest_version is emitted in the canonical vX.Y.Z tag form
  (withCanonicalLatestVersion) at the list/fallback/detail responses, matching
  the data plane + what hallu-sync's archives/<v>.zip URLs need. Fixes the
  website vv1.0.0 double-prefix (website PR nemarOrg/website#145 coerces too).
- file_size (#895): the compute is already annex-aware (getDatasetS3Stats sums
  real S3 object sizes); the ~36B symptom is stale legacy folded rows -> fixed
  by an operational reindex backfill at finalize, no code change.
- /datasets/:id parity (#864) is backend-complete (#853); website backfillSearchHit
  removal tracked separately.

* Address #899 review: strict version test + cleanup

- Live contract test now asserts the RAW catalog latest_version is the
  canonical tag via the non-coercing strictVersionTagSchema, so a dropped
  withCanonicalLatestVersion call site fails CI (the coercing envelope schema
  couldn't catch that).
- Added a getCurrentUser() live-integration test that calls the function and
  asserts flat access (config dir is isolated by setup.ts).
- Removed the now-dead UserInfo interface and a redundant cast at the detail
  return.
- Cross-repo: nemarDatasets/.github#61 normalizes the Hallu zarr-queue version
  comparison so #899's tagged latest_version doesn't re-drain the queue.
* Complete reserved version DOIs (mint reconcile)

Epic #896 Phase 5 (#900). In createEzidVersionDoi, if createIdentifier
(reserved) succeeded but a prior attempt crashed before makePublic, the
retry hit the 'already exists' branch and returned the still-reserved
identifier early -- a permanent, non-resolving DOI recorded as the
dataset's latest version.
- Core fix: on 'already exists', fetch the identifier and inspect status.
  Only return early when it's already public; when still reserved, fall
  through to makePublic to finish the transition.
- Backstop: reconcileReservedVersionDois daily cron sweep (mirrors
  archiveRetrySweep) checks the most-recently-updated datasets carrying an
  EZID version DOI, and completes any still stuck reserved. No new D1 column
  (avoids a migration-number clash with the paused #923 epic's 0057).
- Pure helper tests (version/shoulder parsing). Full backend unit green.

* Address #900 review: rotation coverage + tombstone guard

- Reconcile sweep now day-rotates over ALL version-DOI datasets
  (rotationOffset) instead of ORDER BY updated_at DESC LIMIT 25. A stuck
  reserved DOI is exactly the row that stops being updated, so the recency
  window could permanently starve it under unrelated churn; rotation
  guarantees full coverage within ceil(total/batch) days.
- classifyExistingVersionDoi() makes the already-exists branch explicit:
  public->return, reserved->complete, anything else (unavailable/tombstone)
  ->throw, so a deliberately-tombstoned DOI is never silently resurrected.
- Dropped the redundant, silently-swallowing getDatasetsToken gate
  (per-row resolveEzidAuth already guards missing secrets).
- Pure tests for classifyExistingVersionDoi + rotationOffset coverage.
* Rate-limit the zarr data plane

Epic #896 Phase 6 (#901), zarr half. zarr.nemar.org's host fork dispatched
straight to zarrDataRoutes, bypassing the api middleware stack and its rate
limiter -- the highest-request-volume data-plane path ran unthrottled.
- __selectBucket routes /<id>/zarr/* to the generous data-plane IP bucket
  (same DATA_MAX_REQUESTS as data.nemar.org), so a runaway viewer/scraper is
  bounded while a real reader runs unthrottled.
- zarrDataRoutes applies the rateLimiter middleware (skipping OPTIONS so a 429
  never strips a CORS preflight's headers).
- The STS ListBucket prefix-scoping half of #901 is tracked as a follow-up
  (941); it needs live git-annex validation (HeadBucket == ListBucket).

* Address #901 review: /zarrproxy bucket + 429 CORS

- ZARR_PATH_RE now matches the /zarrproxy/<id>/zarr/* shape too. Hono's
  app.route('/zarrproxy', ...) PREPENDS the prefix (doesn't strip it), so
  c.req.path keeps /zarrproxy — reachable at api.nemar.org (prod) and the
  workers.dev fallback. The old anchor missed it, OVER-throttling real zarr
  viewers to 500 instead of 10000. Corrected the misleading comment; added
  /zarrproxy path cases to the bucket test (the gap that let it through).
- The rate-limiter 429 on the zarr host now carries the zarr CORS headers,
  so a throttled browser viewer reads the 429 + retry_after instead of an
  opaque cross-origin failure.
- Shared data-ip bucket with data.nemar.org is per the issue's spec (10000/
  60s is generous); flagged by review, kept deliberately.
The #899 strict latest_version assertion validates the DEPLOYED dev backend,
which lags this PR until the epic merges+deploys (pre-#899 it serves bare
'1.0.0'). A hard assert would red integration-dev during the very PR that
ships the fix. Make it warn-only (same warn->hard path as the neuroschema
check); flip to hard in #937 once #899 is live on dev. Wiring stays
unit-guarded by catalog-version-normalize.test.ts.
@github-actions

github-actions Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR943

Version: 0.8.76-PR943.a8f95d5
Commit: a8f95d5


🤖 Updated on each push.

Cross-phase interaction (#897 test-gate x #898 new file): the CI tier
classifier greps the whole test file for testRequest|TEST_API_URL|runCli(,
and contract-schemas.test.ts (a PURE test) mentioned TEST_API_URL in a
comment -- so it was silently routed out of BOTH unit-pure (required for dev)
and #897's deploy test-gate. A schema regression would not have blocked a
deploy through the very gate #897 built. Reword the comment to drop the
literal token (verified: narrowing the grep instead reclassifies 6 other
files, too risky). Also refresh a stale #899->#937 warn-only comment.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Cross-phase integration review (sonnet) — addressed in a8f95d5

Reviewed the COMBINED epic diff for phase interactions (each phase was already individually reviewed).

All 6 phases + these finalize fixes on the epic branch. Merging once CI is green.

This branch was previously deployed

1 inactive deployment
npm — a8f95d50 Deployed Jul 7, 2026 by neuromechanist via publish #1709
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