Skip to content

feat: serve latest_version_at in the catalog - #1571

Merged
neuromechanist merged 5 commits into
devfrom
feat/catalog-latest-version-at
Sep 30, 2026
Merged

neuromechanist merged 5 commits into
devfrom
feat/catalog-latest-version-at

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds latest_version_at to the catalog: the created_at of the newest dataset_versions row, as SQLite UTC (YYYY-MM-DD HH:MM:SS, the same form as created_at). It is null when the dataset has no version row.

It is served by the four catalog projections that already serve latest_version: the public list, ?mine=true, the degraded fallback list, and GET /datasets/:id.

Why

The website "Updated" badge reads datasets.updated_at. That column is bumped by any row write: enrichment reindex (admin/doi.ts), finalize (upload.ts), and the DOI callbacks. The 0.10.10 re-enrichment sweep therefore made every swept dataset look freshly updated. Live example: nm000279 was released 2026-09-16 and re-enriched 2026-09-29, and shows 2026-09-29.

latest_version_at moves only when a new version is released, so it is the honest date for that badge. The website consumes it in nemarOrg/website#384.

Changes

  • shared/contract/dataset.ts: latest_version_at: z.string().nullable().optional(), with the regenerated shared/openapi.json (the drift guard compares it byte for byte).
  • src/lib/api/datasets.ts: the CLI-side Dataset type gains the optional field.
  • backend/src/routes/datasets/catalog.ts: one LATEST_VERSION_AT_SQL fragment, used in all four projections. It orders by created_at DESC LIMIT 1, exactly as the latest_version subqueries do. Rows that tie on created_at share the date either way, so the two values cannot disagree (which row a tie names is unchanged by this PR).

Not changed

  • updated_at semantics and every writer that bumps it.
  • The MCP describe_dataset row and output schema. It has its own contract (shared/contract/mcp.ts), and no consumer needs the date there yet.
  • The data-plane reads in data.ts and data-router.ts. The data-plane index already carries the same quantity as latest_published_at (wire key published), so there are now two spellings; aligning them is a separate cleanup.
  • CHANGELOG.md, which is written in per-release PRs. The 0.10.11 entry should mention this API addition.

Compatibility and deploy order

Additive and optional: older consumers ignore it. The website deliberately does not fall back to updated_at (that is the bug), so until this ships to an environment, the website omits "Updated" there. Deploy this to dev before QA of website#384 on staging, and to production before staging is promoted to main on the website.

The value is a zone-less UTC string; new Date("2026-09-16 17:22:05") parses as local time in JavaScript, so consumers must normalize to UTC (the website helper does).

Testing

  • New backend/test/catalog-latest-version-at.test.ts drives the real routes against a real bun:sqlite D1 (no mocks):
    • two versions, with the newer row inserted first, return the newer date;
    • a bare stored version agrees with latest_version;
    • no version row returns null (key present);
    • touching updated_at does not move it;
    • the detail route and the ?mine=true branch serve it;
    • an anonymous deposit still serves it;
    • the degraded fallback list serves it (the public prefix query is made to fail with "no such column" so the real fallback branch runs);
    • list and detail responses still satisfy the shared contract schemas.
      Without the catalog.ts change, 9 of these 10 fail; removing the fragment from the fallback query alone fails exactly the fallback test.
  • test/contract-schemas.test.ts: optional, nullable, string-only.
  • bun run typecheck, biome on the changed files, and bun test backend/test (4360 pass, 0 fail, run twice on the final code). An earlier full run by the author showed 11 failures that did not reproduce in any later run; the tests were not identified, and the log points at network-touching tests such as ORCID and bucket policy.

Review

A Sonnet-model review found no blocking issues. Findings and handling are in the comment below.

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1571

Version: 0.10.11-PR1571.59aaa17
Commit: 59aaa17


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review record

This was a single-pass self-review of the diff through the pr-review-toolkit lenses (code, tests, errors, comments, types, simplification). It was not run with separate reviewer agents.

Lens Finding Resolution
Comments The LATEST_VERSION_AT_SQL doc said the date and latest_version "always agree". Two version rows minted in the same second could in principle be picked in either order (the date is identical either way), so "always" overstated it. Fixed in 3c19879: states the shared ordering and the tie behavior.
Comments The doc did not say where the row's created_at comes from. Fixed in 3c19879: rows are written when the version DOI is minted at publish time; only the admin manifest-regen repair path (datasets-lifecycle.ts) backfills one later, so a repaired dataset shows the repair date.
Tests The contract assertion on list and detail is weak on its own, because the envelope schemas are passthrough. Kept: test/contract-schemas.test.ts separately proves the field is declared (string or null accepted, a number rejected), and the OpenAPI drift guard pins the generated document.
Errors None: the change is a read-only SQL projection, with no new fallbacks, catches or defaults. A dataset with no version row serves an explicit null. No change.
Types latest_version_at is `string null
Simplification The fragment is one constant shared by four projections. The four existing latest_version subqueries were left as they are to keep this diff minimal. No change.

Known limit: a version row that an operator repaired or restored later carries that later date. The normal publish path is unaffected.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review findings and handling (Sonnet-model review of 3c19879)

No blocking issues. All four catalog projections emit the pair with the same ordering, the plan for both subqueries uses idx_dataset_versions_dataset, dataset_versions.created_at is immutable, and the anonymity surface is unaffected.

  • Fallback projection untested. Added a test that forces the public prefix query to fail with "no such column", so the real fallback branch runs and serves the date (and null for an unreleased draft). Removing the fragment from the fallback alone now fails exactly that test.
  • Provenance comment wrong on one write path. The fragment's comment now says the row is recorded at DOI mint on the inline paths, at the manifest-ready callback under the central manifest flow, and by the admin repair path, which stamps the repair time.
  • Test header claimed rows mirror production. Reworded: the rows are modeled on production datasets with rounded dates. Added an anonymous-deposit row and a test that its release date is served.
  • Stale "45-column" and "49-column" comments in catalog.ts are now 46 and 50.
  • PR body wording. Corrected "every projection" (MCP and the data-plane index also carry version data), the tie wording, and the compatibility paragraph (the website has no updated_at fallback by design). Linked website#384 and stated the deploy order.
  • Data-plane index already serves the same quantity as latest_published_at. Noted in the PR body; aligning the names is a separate cleanup.
  • Consumer hazard: the value is zone-less UTC. Noted in the PR body; the website helper normalizes to UTC.
  • Skipped, intentional: unfalsifiable .passthrough() assertions in the contract test (harmless; the number-rejection assertion and the OpenAPI drift guard do discriminate).
  • Skipped, pre-existing: on equal created_at SQLite picks the first-inserted row for both latest_version and latest_version_at. The values cannot disagree, and adding dv.id DESC would change latest_version behavior, so it belongs in its own PR.
  • Skipped, convention: branch is feat/... where .rules/git.md says feature/...; renaming would close and reopen the PR for no functional gain. No per-PR CHANGELOG entry is required (entries land in release PRs).

Tests after the changes: 4360 pass, 0 fail (bun test backend/test, twice); without the catalog.ts change, 9 of the 10 new route tests fail.

@neuromechanist
neuromechanist merged commit 51794fc into dev Sep 30, 2026
21 of 23 checks passed
@neuromechanist
neuromechanist deleted the feat/catalog-latest-version-at branch September 30, 2026 09:32
This was referenced Sep 30, 2026

This branch was previously deployed

1 inactive deployment
npm — 59aaa17b Deployed Sep 30, 2026 by neuromechanist via publish #3008
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