Repository navigation
Phase 6c: prepare a re-pull through prepared - #1948
Merged
neuromechanist merged 23 commits intoOct 25, 2026
Merged
neuromechanist merged 23 commits into
neuromechanist merged 23 commits into
Conversation
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1948Version: 🤖 Updated on each push. |
Move the two NEMAR API reads the plan starts from (the dataset row and its version rows) out of the plan command into src/lib/repull/execute/catalog.ts, so execution can re-read them before it re-plans. No behavior change; test/repull-plan-cli.test.ts passes (23 tests).
Execution reads the reviewed plan file, proves its body hashes to the stated digest, refuses a plan made by another planner, against another API or from other remotes, refuses an anonymous dataset, and plans again from live sources: the live preflight and executable decide, never the file's. A main moved only by .nemar/** other than the privacy ledger rebases; anything else, a moved git-annex branch included, is plan-stale. A recording whose key NEMAR marks dead refuses, since the plan pins no version to scrub it from. The planner gains collect: the bytes of every computed target recorded by blob id, so execution never rebuilds a standard edit; the digest does not move. nemar-s3's remote.log reading is exported for execution's upload. Tested: repull-compare-plans.unit.test.ts (new) and repull-plan.test.ts (a collect test added), 61 pass.
A working clone of NEMAR's main at depth 2 at the base, git-annex initialized with no special remote enabled and no background gc. Every path the plan writes or deletes is written from where the plan says (upstream's blob, fetched by id when missing; bytes the planner computed; a pinned object read at its version and proved by its key; the merged description) and staged by its exact id, never through git add; .nemar/metadata.json's IsIdenticalTo names the new snapshot. The materialized index is then committed locally, after a check that nothing outside the scrub's scope changed; that commit is never pushed. Tested with the integration suite added in the run commit (repull-execute-prepare.test.ts).
The importer's own scrub on the delta paths and the provenance files only: annexed recordings read at the version the plan pinned (a key NEMAR holds is not read again), dates set, a repull-scrubbed ledger line at the record's time under a fixed actor. Upstream's location log is recorded first for each copied recording NEMAR's branch never knew, so a key the scrub re-keys can be retired and marked dead. Git-held data the policy annexes is then annexed and uploaded with the same upload, and the import's closing check runs over the copy keys. Tested with the integration suite added in the run commit (repull-execute-prepare.test.ts).
git commit-tree of the prepared index onto the base: one parent, the fixed identity, the record's created_at as both dates, a body of counts and the Upstream-Snapshot and Repull-Plan trailers last. Before it is accepted the tree must be the plan's targets with the scrub's changes only, no replaced key named, every named key held, copied or uploaded here, and the copy manifest a subset of the plan's copy keys; after it, no scrubbed original is reachable. The work branch and the local git-annex branch are saved as a 0600 bundle with the base as prerequisite, and restored only when it delivers the recorded commit. Tested: repull-synthesize.unit.test.ts (new, 12 pass); the rest with the run commit's suite.
executeRepull, the library entry the execute command will call: prove and re-plan the reviewed plan, POST /admin/repulls (or find the open record of the same plan), then prepare and move planned to prepared with the commit, its tree, the copy manifest's digest and counts. A prepared record is left as it is when its working clone holds its commit, restored from the checkpoint otherwise, or prepared again and required to reproduce the recorded tree and commit; a base moved by .nemar/** only is prepared again there. A failure records why on the record. Adds the /admin/repulls API client and pins its exports; makeRepullApp mounts the real /admin/repulls routes; the fixture gains an xx id, an S3 stand-in holding upstream's pinned versions under newer ones, a flagged added EDF, an identifier sidecar and a CRLF sidecar. Tested: repull-execute-prepare.test.ts (new, 30 pass), api-export-surface, repull-plan-cli; full bun test 19745 pass, 2 fail unrelated (website parity against the sibling checkout; a users-search test that passes alone).
Append the Phase 6c slice, dated 2026-10-24: execution on the administrator's machine, the plan proved by its digest and its preflight recomputed, the narrow reading of the .nemar/** rule, the dead-recording refusal, the preparation (exact-id staging, the local materialization commit, the scope with the provenance files, upstream's location log adopted for copied recordings), the synthesized commit and its checks, deterministic re-preparation and the checkpoint, and what only stand-ins answered. Docs only.
The synthesis no longer exempts .nemar/** and .github/**: every path there must be NEMAR's side as it was, .nemar/metadata.json what the NEMAR-owned edit wrote, and the privacy ledger the base's text plus exactly one repull-scrubbed line when the scrub changed something (none otherwise; an edited line, a removal or a second line refuses). Modes are checked too: a path kept is kept with its mode, an in-place scrub change keeps the mode, and every annexed entry the re-pull writes is a symlink. The reachability comment now says it holds within the clone's depth. Tested: repull-synthesize.unit.test.ts, 17 pass (6 new), each rule mutated and caught.
A dead key N.0.0 would name at a recording path must be re-keyed by the scrub from upstream's bytes, and the plan pins only the keys it copies, so the plan itself now refuses it (dead-recording-unpinned) and a reviewer sees it; execution's late refusal of the same is removed, as the live plan is then not executable. The fixture gains movedScrubbedEdf (only a recording is dead), and the options the execution suite uses (bomNemarMetadata, symlinkB, nestedGitattributesB). Tested: repull-plan.test.ts -t dead, 3 pass (1 new); the refusal mutated off and caught.
A prepared self-edge sent with no error now clears the stored error, as an edge into another open status does: it records the whole stage again, so the step it repeats succeeded (CLEARING_SELF_EDGES in shared/repull-state.ts). Every other repeat, and an edge into a terminal status, keeps the error, and an error sent on the self-edge still goes through ADR 0051's rule. Execution uses it when a prepared row is shown to hold its facts again. Tested: upstream-repulls-route.test.ts, 108 pass (two 6a tests moved to a pr_open repeat, one new); both directions mutated and caught.
materializeDelta returns each NEMAR-owned edit it left, by its status, so the run can say and count them rather than leave them silently; .nemar/metadata.json is read as the planner reads it, a byte-order mark set aside and kept. Tested with the execution suite (a BOM-prefixed file and an unparseable one), in the test commit below.
ImportScrubRefused keeps whether upstream stopped serving its bytes (upstreamInaccessible, now a readonly field), and execution's ExecuteRefused carries it as retryable through the conversion. The scrub-delta comment states the provenance rule by content and that an in-scope scans table has every dated row set; the remote name is the one S3_REMOTE_NAME constant. Tested with the execution suite (a pinned version upstream dropped), in the test commit below; the pass-through mutated off and caught.
Execution goes on only when the dataset row says anonymous is exactly 0: 1 is anonymous-dataset as before, and an absent or unreadable field is anonymity-unknown, since unknown is never clean. Tested with the execution suite (a catalog row without the field), in the test commit below; the check mutated to === 1 and caught.
Every git and git-annex call of an execution, the planner's included, runs with GIT_CONFIG_GLOBAL=/dev/null and GIT_CONFIG_NOSYSTEM=1, and the work clone is made with annex.addunlocked=false, core.autocrlf=false, core.hooksPath, core.attributesFile and core.excludesFile set to /dev/null and no background gc. The clone refuses a git-annex branch that is not the plan's (plan-stale). One execution per plan holds a pid lock beside its directory (execution-locked; a dead holder's lock is taken over). A prepared row shown to hold its facts again sends the prepared self-edge, which clears a stale error; the clone and checkpoint say in fixed words why they were not used; a failure that cannot be recorded is said; NEMAR-owned edits left are said and counted; the row keeps the scrub's unread and unproven counts (new count keys); the final cleanup never replaces the real refusal, and a refusal in S0 leaves no empty directory. Comments: only a prepared row resumes from disk; S0 writes nothing to the API, pushes or uploads; the execute command is not built yet. Tested with the execution suite, in the test commit below.
The execution suite now asserts: the commit changes exactly the plan's paths, the NEMAR-owned edit and, after a scrub, the ledger and provenance files; origin refs equal before and after; private modes up to repull/; the scrub's unread counts and the owned-edit counts; a rerun uploads and writes nothing; a stale error cleared; a manifest digest not reproduced; a prepared row rebased onto a moved main; a hostile global git config and XDG attributes giving the identical commit; the plan lock both ways; the git-annex pin; the closing header check's wiring; a pinned version upstream dropped (retryable, recorded, and said when the record cannot be written); a wrong destination prefix; until-not-built; anonymity unknown; a BOM and an unparseable metadata file; a dead recording; the CRLF, 100755, symlink and nested .gitattributes targets. repull-materialize.unit.test.ts pins isWritablePath. Tested: 47 + 2 pass; the repull set, the scrub suite and the export pin 591 pass.
The Phase 6c slice, still last and dated 2026-10-24, now records: only a prepared row resumes from disk; the plan lock and the config isolation; the refusal order as built; anonymity exactly 0; a moved main with no differing path is plan-stale, and the clone pins the git-annex branch; the dead-recording refusal now in the plan; the pre-scrub commit's unscrubbed blobs kept in the private clone until the pull request opens; scans tables in scope fully dated; the adopted upstream holders the pushing slice must handle; the NEMAR-owned, ledger and mode rules of the synthesis; reachability within the clone's depth; the stale-error clearing and the meaning of delta_paths. Two sentences of the first Phase 6 slice carry dated annotations for the prepared self-edge. Docs only.
The pid file is written in a private sibling directory that is then renamed onto the lock's path, which fails while a lock is there, so no lock is seen without its pid; a lock whose pid cannot be read is taken for a live one. A crashed holder's lock is moved aside and taken over only if what was moved is still that holder's; the release removes only this process's own lock. The refusal names the lock's path and says to remove it when no execution runs (pid reuse after a crash). Tested in the test commit below: an empty pid in a fresh lock is never taken over, a live and a dead holder, the release guard.
Every error the preparation records now begins [prepare:<code>], and a prepared row shown to hold its facts again sends the clearing self-edge only when its stored error begins so; an error a later step recorded is left as it is. The CLEARING_SELF_EDGES comment says the same. Tested in the test commit below, both directions.
withIsolatedGit keeps a depth: the outermost call saves the user's GIT_CONFIG_GLOBAL and GIT_CONFIG_NOSYSTEM and only the last to finish restores them, so overlapping executions in one process cannot leave the isolated values behind. Tested in the test commit below (repull-workdir.unit.test.ts).
ExecuteRefused.retryable had no reader: dropped, with the readonly the importer's ImportScrubRefused gained for it. A scrub refusal keeps the scrub's message as it is, which begins with the [openneuro-upstream-inaccessible] marker when upstream stopped serving a pinned object; that text is what the Worker matches. Tested in the test commit below (the message begins with the marker).
A plan whose dataset has no row is refused as dataset-missing, before the anonymity check, which would otherwise call it anonymity-unknown. Tested in the test commit below.
repull-execute-prepare.test.ts: a lock with an empty pid in a fresh directory is refused and left as it was, the refusal naming the lock's path; an error a later step recorded is not cleared by a preparation that holds; a dropped pinned version's refusal begins with the upstream marker; a missing dataset row is dataset-missing. repull-workdir.unit.test.ts (new): overlapping isolations restore only at the last, a throwing call restores, the lock's release removes only its own lock. Tested: the 6c suites and the repull route suites, 377 pass before the two lock unit tests; each fix mutated and caught.
The Phase 6c slice of ADR 0111 now says how the lock is made atomically and what its refusal names, that a missing dataset row is dataset-missing, that a scrub refusal's [openneuro-upstream-inaccessible] marker text is the contract for a failure that may pass later, and that execution clears only an error that begins [prepare:; the dated annotation on the first slice's last_error sentence says the same. Docs only.
neuromechanist
force-pushed
the
feature/issue-1912-phase6c-prepare
branch
from
October 25, 2026 02:34
bfa8f21 to
124d176
Compare
neuromechanist
merged commit Oct 25, 2026
119bd82
into
feature/issue-1046-epic-upstream-freshness
20 checks passed
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.
Summary
Prepares a re-pull on the administrator's machine, through the
preparedstate and no further (ADR 0111). The code re-verifies a saved plan against live sources (digest, reachability, subset rule, anonymity), builds a working clone with a checkpoint, materializes the upstream delta by exact blob id (so a CRLF blob is never changed), scrubs the delta with the provenance files always in scope and pinned upstream reads, and synthesizes one deterministic commit carrying both re-pull trailers. The ledger actor is fixed so re-preparing gives the same commit. A thin API client talks to the/admin/repullsrecord routes. Nothing here copies to S3, pushes, opens a pull request, merges or sends mail; those are the next phases.Phase 6c of epic #1046, part of #1912 (which stays open until 6g). It builds on the merged record (6a), the shared seams (6b) and the screen and cap (6e).
What is in it
src/lib/repull/execute/:catalog.ts,verify-plan.ts,body.ts,workdir.ts,materialize.ts,scrub-delta.ts,synthesize.ts,run.ts;src/lib/api/repull.ts; small edits toplan.ts,overlay.ts,edits.ts,commands/admin-repull.ts(acollectwrite and exports).test/repull-execute-prepare.test.ts(real git and git-annex, real routers over bun:sqlite,awsagainst the S3 stand-in),repull-synthesize.unit.test.ts,repull-compare-plans.unit.test.ts.Deviations from the plan (the code wins, the safer direction each time)
git add; the materialized index gets a local commit before the scrub so the importer's index removal accepts an overwritten annex symlink; upstream's holders are recorded for copied recordings NEMAR never knew (this puts upstream presence lines into the local git-annex branch that 6d pushes); a new refusaldead-recording-unpinned(the plan pins no version for dead recordings); clones setgc.auto=0and removal is strict; the checkpoint bundle uses prerequisites for shallow clones.Test plan
bun testran once: 19745 pass, 242 skip, 2 fail, both unrelated (website parity against a stale sibling checkout; one admin-users-search test that passes alone). Typecheck and Biome clean. About 25 single-line mutants applied, all killed.aws s3 syncand listing against the real bucket, the GitHub pulls listing, depth-2 clone and fetch-by-sha on GitHub,--no-autoenableagainst production'sremote.log, that OpenNeuro's location logs exist for newly added keys, bundle restore on a large shallow git-annex branch.