Skip to content

Phase 6a: upstream re-pull record and state machine - #1936

Merged
neuromechanist merged 8 commits into
feature/issue-1046-epic-upstream-freshnessfrom
feature/issue-1912-phase6a-repull-record
Oct 24, 2026
Merged

neuromechanist merged 8 commits into
feature/issue-1046-epic-upstream-freshnessfrom
feature/issue-1912-phase6a-repull-record

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Adds the durable record of an upstream re-pull (ADR 0111): migration 0105_upstream_repulls.sql, the pure state machine in shared/repull-state.ts, backend/src/services/upstream-repull.ts and the admin routes under /admin/repulls. A re-pull is one row per dataset, tag and attempt, with a partial unique index that allows one non-terminal row per dataset and CHECKs that make impossible states unwritable (gates_clear, complete, terminal_at). Transitions are compare-and-set on the previous status, refuse a stale from, keep the branch, PR number and patch identity once set, and refuse abandoned, superseded and patch_declined while a merge claim is held. Creating a record writes lineage (source_version, basis) on a NULL/NULL row only when lineage_recordable is true, counts a held merge claim as blocking a new attempt, refuses anonymous datasets, and refuses every non-xx write unless the environment is exactly production. The staleness report now shows an open re-pull as in progress ahead of a parked import. No mail is sent from any new route.

Phase 6a of epic #1046, part of #1912 (which stays open until 6g). No behavior changes for existing flows; nothing creates a record yet.

What is in it

  • backend/src/db/migrations/0105_upstream_repulls.sql, shared/repull-state.ts, test/repull-state.unit.test.ts; publication-review-migration.test.ts bounded so a later table cannot break its "0098 objects" check.
  • backend/src/services/upstream-repull.ts, backend/src/routes/admin/upstream-repulls.ts, registration in routes/admin/index.ts, the cascade delete in deletion.ts, the route inventory pin (total 162).
  • backend/src/services/upstream-status.ts and shared/upstream-staleness.ts: the in-progress hook.
  • ADR 0111 amendment slice for 6a, reading UNIQUE(dataset_id, to_tag) as per attempt so an abandoned tag can be retried.

Test plan

  • 13 targeted files: 351 pass, 0 fail; full bun test ran before the last edits with only the website parity failure (stale sibling checkout) and two failures fixed afterward.
  • bun run typecheck and bun run lint clean; migration 0105 exercised on Miniflare D1 in process (CHECKs, partial index, json_patch, create, lineage write, audit and transitions).
  • Single-line mutants applied across migration, state module, service and hook; one survivor, equivalent.
  • migrations:d1-check (wrangler) was not run; meta.last_row_id and changes() inside D1 batches have no production check.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1936

Version: 0.10.24-PR1936.5d18f74
Commit: 5d18f74


🤖 Updated on each push.

Migration 0105 records one row per re-pull attempt, with stage
invariants as CHECKs and a partial unique index for one open row per
dataset. shared/repull-state.ts holds the states, the only allowed
edges and the columns each edge may write.

Tested on bun:sqlite and Miniflare D1; every edge pair asserted.
Adds the /admin/repulls routes (create, list, get, transition) and the
service behind them: environment fence (exactly production lifts it),
anonymity, withdrawn and import-in-flight refusals, version facts from
D1, one open record per dataset, attempts, lineage at create through
the one writer of that word, and compare-and-set transitions that take
only the allowed edge and the columns it names.

The delete cascade removes the records. No route sends mail.

Tested on bun:sqlite and Miniflare D1; a source scan pins the lineage
writer.
The staleness report left a mirror being re-pulled unclassified beyond
its import state. A non-terminal upstream_repulls row now makes the
mirror in_progress and keeps it out of the OpenNeuro comparison.

Tested on the route (SQLite and Miniflare D1) and the pure classifier.
Migration 0105 (unreleased) gains revision, a unique index on
(dataset_id, to_tag) for rows holding a merge sha, and the
patch_released tag CHECK. The state module gains the self-edges that
record a claim to merge, the locked count and a planned error.
Tested on SQLite and Miniflare D1.
Transitions compare-and-set on status and revision. A merge claim is
recordable and blocks head moves and closes. Any unreconciled merge
blocks the dataset (merge-unreconciled). The lineage write matches v
spellings and reports lineage_rows. Blank errors are refused, forward
edges clear last_error, refusals carry a code, the create race is
retried once, and a source scan pins that no mail is imported.
Tested; mutations killed.
The Worker stamps the claim time; a request cannot carry it. The two
claim columns are paired by a CHECK. A failed row that was merged and
tagged no longer blocks the dataset. Dead gates-not-set branch removed,
a deleted row answers 404, test names corrected. Tested.
@neuromechanist
neuromechanist force-pushed the feature/issue-1912-phase6a-repull-record branch from ac8f49e to 5d18f74 Compare October 24, 2026 15:43
@neuromechanist
neuromechanist merged commit 07752a4 into feature/issue-1046-epic-upstream-freshness Oct 24, 2026
14 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-1912-phase6a-repull-record branch October 24, 2026 16:18

This branch was previously deployed

1 inactive deployment
npm — 5d18f745 Deployed Oct 24, 2026 by neuromechanist via publish #3896
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