Skip to content

Phase: availability report never creates main - #1672

Merged
neuromechanist merged 14 commits into
feature/issue-1671-epic-bru-upload-fixesfrom
feature/issue-1643-availability-no-main
Oct 8, 2026
Merged

neuromechanist merged 14 commits into
feature/issue-1671-epic-bru-upload-fixesfrom
feature/issue-1643-availability-no-main

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The availability-report sweep commits .nemar/availability-report.json to main through the GitHub Contents API.
On a repository that was created but never pushed, that PUT created main as an unrelated root commit and broke every later nemar dataset upload (nm000358).
The report now refuses when main does not exist, the check runs before any S3 work, and the sweep only selects datasets that have a version (issue #1643).

The first commit is the contributor's original fix (PR #1655, bruAristimunha), preserved with authorship.
The commits on top are review refinements:

  • the branch check runs before the S3 listing and manifest walk, and is bounded: one interactive attempt that never sleeps, so rate-limit pressure becomes a per-row error instead of a stalled sweep
  • the lookup is classified instead of guessed: a 404 on the ref is followed by a repository probe (200 means main is absent; 404 means the repository is not visible to NEMAR and is reported as a distinct fault, not as a depositor-side 409); a 409 counts as "empty repository" only when its body says so; a 2xx must carry object.sha; every other status throws and leaves the row unstamped
  • the 409 "Git Repository is empty." shape is confirmed against api.github.com (two empty public repositories, 2026-10-07; it is not in GitHub's reference documentation)
  • a route-level test proves the guard: with main absent there are zero PUTs and zero S3 requests, with main present exactly one PUT whose committed body is decoded and checked, and one ordered event log pins GitHub first, S3 second, PUT last
  • six fault cases (403, 401, junk 2xx, 500, non-empty 409, invisible repository) each run as the single-dataset route, the sweep and a direct call
  • verifyDatasetVersionS3 and the report's manifest read accept S3_ENDPOINT_URL through testS3EndpointOverride(env), which returns it only outside production; a config-guard test asserts no wrangler [vars] block declares it
  • branch refs are encoded per path segment so #, ? and % in a name cannot change the URL (GitHub accepts release/1.0 and release%2F1.0 alike, so this is hardening, not a fix for slash branches)
  • branchExists and getMainBranchSha share one ref fetch and one response validator; getMainBranchSha keeps its retry-on-404
  • the has-a-version predicate is exported once as datasetHasVersionSql("d" | "datasets") and used by the archive retry sweep and the availability candidacy, with a test that pins both
  • the sweep's per-dataset error entries gain a status marker (409 refused, 500 fault, 400 and 404 the dataset's own state), AvailabilityReportError keeps its cause, and 5xx are logged on the single-dataset route
  • descriptions of the sweep's scope are corrected (it covers non-sandbox datasets that have a version and no report yet; the cron cap is 30, not 10; three GitHub calls per candidate)

Part of epic #1671. Supersedes #1655 (contributor PR retargeted to the epic branch). Issue: #1643.

Behavior to know about

  • Imports blocklisted before any version exists (no_source, identifier_scrub_refused) no longer get a report carrying blocklist_reason; the reason stays in D1. This follows from restricting the sweep to versioned datasets.
  • A refused row stays unstamped and keeps one of the 30 LIMIT slots on every pass. A test pins this as a known limitation so changing it is a deliberate decision.
  • The order of failures on the single-dataset route is now 404, 400 (no repository), 400 (bad repository name), 500 (authentication or lookup fault), 409 (no main), then S3.

Test plan

  • bun run typecheck (root and backend), biome check on the 16 changed files
  • 20 backend test files, 496 pass, 0 fail; a wider run of 26 backend files that import the changed modules, 619 pass, 0 fail; 3 root test files, 32 pass, 0 fail
  • Mutation checks, one at a time and restored byte-identical: branch guard deleted fails 9; S3 walk moved before the guard fails 17; interactive policy reverted fails 4; no object.sha check fails 5; any 409 treated as empty fails 4; repository probe not distinct fails 4; seam fence removed fails 1 at each of the two sites; S3_ENDPOINT_URL added to a wrangler vars block fails 1; lookup fault reported as 409 fails 18; version predicate dropped fails 1
  • Live tier (api-test, integration-dev): backend changes reach the dev worker only when the epic merges to dev
  • A real empty nemarDatasets repository has not been exercised (only public empty repositories and stand-ins)

Follow-ups (not in this PR)

  • guard the single writer createOrUpdateFile, or move writers to commitFilesAsTree, which cannot create a branch
  • other unguarded writers (commitEnrichmentWithBidsignore, routes/admin/doi.ts:1171, enrich-dataset.ts:1090)
  • an excluded_unversioned count in the sweep response
  • a read-only audit of existing parentless main commits on dataset repositories
  • stamp or skip a permanently refused row so it stops holding a LIMIT slot
  • the sweep route answers HTTP 200 even when every entry in errors failed
  • convert data-integrity-sweep-route and imports-verify-route to the S3_ENDPOINT_URL seam

bruAristimunha and others added 9 commits October 7, 2026 15:39
The availability-report sweep commits .nemar/availability-report.json to
main through the Contents API. On a dataset that was created but whose
upload had not pushed yet, that PUT created main as an unrelated ROOT
commit. nm000358 (created 2026-10-06 14:55Z, report commit 4ba0a7b at
03:00Z): every later 'nemar dataset upload' attempt failed at 'Pushing
metadata to GitHub' with '[rejected] adjusted/main(unlocked) -> main (fetch
first)', and the adjusted branch cannot be auto-rebased, so the upload Job
failed after 12 attempts and needed a manual merge.

- writeAvailabilityReport checks that main exists (new branchExists: 404 or
  GitHub's 409 'Git Repository is empty' mean no) and refuses with 409
  instead of creating it.
- The sweep's candidates now require a version (a version DOI or a
  dataset_versions row), like ARCHIVE_RETRY_SWEEP_QUERY: a never-versioned
  dataset has nothing to report, and a row the pass cannot complete must not
  hold one of its LIMIT slots forever.
- Test seeds that model reportable datasets now carry a version.
branchExists sent encodeURIComponent(branch) as one component, so release/1.0 became release%2F1.0 and read as absent. It and getMainBranchSha now share one ref request that encodes per segment; 404 retry stays a per-caller choice. Tested against a local GitHub stand-in.
verifyDatasetVersionS3 and the availability report's manifest read built their S3 origin from the literal AWS host, so neither could be driven by a local server. They now pass env.S3_ENDPOINT_URL like the data plane and admin routes do. Unset in every deployment, so no production behavior changes.
The branch check ran after verifyDatasetVersionS3 (a paginated LIST plus manifest walk, up to 30 times per sweep) for rows that were then refused. The GitHub target and the main check now come first on the write path. The 409 message also covers a repository that is invisible to NEMAR, which GitHub reports as the same 404. Route-level tests drive the single-dataset and sweep routes against local GitHub and S3 stand-ins and assert zero PUTs and zero S3 requests when main is absent or the repository is empty, and exactly one PUT when main exists.
The version DOI or dataset_versions row rule was hand-copied from ARCHIVE_RETRY_SWEEP_QUERY into the availability-report sweep. It is now exported once as datasetHasVersionSql from archive-retry.ts and both queries build from it. A test pins that they share it; the candidacy tests keep pinning the behavior.
branchExists slept inside a sweep row under rate-limit pressure (about 60 s per row), treated every 404 as 'no branch', trusted any 2xx, and treated any 409 as an empty repository. It now makes one interactive attempt (never sleeps), probes the repository on a 404 and throws when it is not visible, requires object.sha on a 2xx, and accepts a 409 only when the message says the repository is empty. getMainBranchSha shares the sha check and keeps its retry on 404. Tests cover each case against a local GitHub stand-in, including the retry behavior of getMainBranchSha.
S3_ENDPOINT_URL is now honored only in a recognized non-production environment (testS3EndpointOverride), at the integrity check and the report's manifest read, which now builds its options from getS3Config. A guard test asserts no wrangler vars block declares it. A failed or untrustworthy main lookup (auth, rate limit, 5xx, a repository not visible to NEMAR) is wrapped as a 500 with its cause, logged on the single-dataset route, and distinct from the 409 refusal; sweep error entries gain a status. One REPORT_BRANCH constant names the branch for the guard and the write, and datasetHasVersionSql takes only the two aliases in use.
Route-level tests for the availability report now share one ordered event log across the GitHub and S3 stand-ins. They cover: 403, 401, junk 2xx, 500, non-empty 409 and a repository not visible to NEMAR as 500s with a cause and zero PUTs and zero S3 requests; the 409 refusals with their status marker; the order lookup, S3 walk, PUT; the PUT body (dataset, version, completeness, message, no sha); the token on every GitHub call; the moved 400 and 500 checks; a version-less dataset as a non-candidate; the known LIMIT-slot starvation of a refused row; and that S3_ENDPOINT_URL is ignored in production.
The CLI help, the cron comment and three test headers described the sweep as covering every managed dataset, capped at 10, with sibling routes having no S3 seam. It covers every non-sandbox dataset with a version and no report, AVAILABILITY_REPORT_SWEEP_MAX is 30 (the cron passes no limit), and listObjectPages and verifyDatasetVersionS3 honor S3_ENDPOINT_URL outside production.
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1672

Version: 0.10.15-PR1672.7fd1c01
Commit: 7fd1c01


🤖 Updated on each push.

verifyDatasetVersionS3 and the availability report's manifest read built the same fenced S3 options in two places, one of them layered over getS3Config's unfenced endpoint. versionReadS3Options is now the one builder; behavior is unchanged.
The write-target block of writeAvailabilityReport (the 400 checks, auth, and the never-create-main guard with its 409) is now resolveReportTarget. Messages, statuses and the order (guard before any S3 work) are unchanged.
Check the 404 first, then any other failure, then release the body once, instead of an early return that cancelled the body separately. Behavior is unchanged.
The LIMIT-slot behavior of a refused row is documented on AVAILABILITY_REPORT_SWEEP_BASE_WHERE; the cron comment, the route doc, the remaining doc and the test point to it. The createOrUpdateFile docblock keeps the warning and the fact that only the availability report guards it, without naming callers, and the fetchBranchRef docblock no longer restates the call sites.
The refusal and fault cases share expectRouteRefusal and expectSweepRefusal; stand-in ref states derive from one answers record; the branch-exists stand-in drops its hit counter and special repository; the rejection helper is shared. New tests pin that the single-dataset route logs a 5xx and only a 5xx. All six faults still run as route, sweep and cause tests.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review record

One pass of the PR review toolkit (Sonnet agents): code review, test analysis, silent-failure hunt, comment analysis, then a propose-only simplifier. No critical findings. Every finding below was fixed unless it is listed under "Not done". Tip at the time of writing: 7fd1c017.

Important

  • Rate-limit sleeps inside every sweep row (code review, silent-failure hunt; measured at about 60 s per call): branchExists is now one interactive attempt that never sleeps, so a drained bucket is an immediate per-row error.
  • A 404 for a repository NEMAR cannot see was reported as "main absent" with a 409: on a 404 only, the repository itself is probed; 200 means the branch is absent, 404 is a distinct "not visible to NEMAR" fault (500), and the 409 text is now exact.
  • A 2xx with a junk body read as "main exists" (would allow the root-commit PUT): a 2xx must carry object.sha, validated by a helper shared with getMainBranchSha.
  • A 409 was matched on status alone: it counts as "empty repository" only when the body says so. The shape (409 {"message":"Git Repository is empty."}) was confirmed against api.github.com on two empty public repositories; it is not in GitHub's reference documentation.
  • Test gaps: the committed report body was never inspected, no route-level test for a ref lookup failing with something other than 404 or 409, the Authorization header was never asserted, a version-less dataset was covered only at SQL level, and getMainBranchSha's retry-on-404 was unpinned. All added; six fault cases (403, 401, junk 2xx, 500, non-empty 409, invisible repository) run as route, sweep and direct call.
  • The S3_ENDPOINT_URL seam could apply in production: it is fenced to non-production by one builder (versionReadS3Options) used at both read sites, and a config-guard test asserts no wrangler vars block declares it.
  • Comments that were false: the "release%2F1.0 names no ref" story (real GitHub accepts both spellings; per-segment encoding stays as hardening for #, ?, %), the nm000358 incident timeline, "same rule as resolveCurrentVersion" (stricter for an unparseable DOI), sweep scope descriptions ("every managed dataset", "2 API calls", cron cap "10" versus 30), and stale sibling test headers.

Suggestions and nice-to-have (all applied)

  • Cause kept on AvailabilityReportError, 5xx logged on the single-dataset route (with tests), an additive status marker on sweep error entries, one REPORT_BRANCH constant, datasetHasVersionSql narrowed to "d" | "datasets", the body of a 404 cancelled, getS3Config reuse, and a test that pins GitHub first, S3 second, PUT last in one ordered event log.
  • Simplifier: shared refusal helpers and a record-derived stand-in state in the tests, resolveReportTarget extracted, assertRepositoryVisible flattened, the refused-row limitation stated once. The optional proposal to run the sweep and cause tests against one fault instead of six was declined on purpose.

Verification

  • Typecheck (root and backend) and Biome on the changed files are clean; 20 backend test files, 496 pass, 0 fail; a wider 26-file run, 620 pass; 3 root files, 32 pass.
  • 26 mutations applied one at a time and restored byte-identical, every one caught (for example: branch guard deleted fails 7, S3 walk before the guard fails 17, interactive policy reverted fails 4, no object.sha check fails 5, fence removed at any of the three sites fails 1 or more, lookup fault reported as 409 fails 19).

Not done (tracked follow-ups)

  • guard the single writer createOrUpdateFile, or move writers to commitFilesAsTree, which cannot create a branch
  • other unguarded writers (commitEnrichmentWithBidsignore, routes/admin/doi.ts:1171, enrich-dataset.ts:1090)
  • an excluded_unversioned count in the sweep response (imports blocklisted before any version exists no longer get a report carrying blocklist_reason)
  • a read-only audit of existing parentless main commits on dataset repositories
  • stamp or skip a permanently refused row so it stops holding a LIMIT slot (pinned by a test as a known limitation)
  • the sweep route answers HTTP 200 even when every entry in errors failed
  • convert data-integrity-sweep-route and imports-verify-route to the S3_ENDPOINT_URL seam

@neuromechanist
neuromechanist merged commit 7e4017a into feature/issue-1671-epic-bru-upload-fixes Oct 8, 2026
14 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-1643-availability-no-main branch October 8, 2026 00:02
@neuromechanist neuromechanist changed the title Phase: availability report never creates main (#1643) Phase: availability report never creates main Oct 8, 2026

This branch was previously deployed

1 inactive deployment
npm — 7fd1c017 Deployed Oct 7, 2026 by neuromechanist via publish #3227
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.

2 participants