Skip to content

Commit 5c6e35f

Browse files
authored
✨ Advance a branch a run already published, when the remote is behind it (#594)
* ✨ Advance a branch a run already published, when the remote is behind it A workflow publishes one branch repeatedly: an iteration commits, pushes, commits again and pushes again. The second push found the destination naming another commit and refused it as a conflict, so a supervised loop could publish its branch exactly once (#588). A destination naming a commit that is anywhere in the ancestry of the one being published is now a performable pre-state. The push itself is unchanged — the same exact `<commit>:<destination>` refspec, which native Git applies only where it fast-forwards, with no force, no lease, no upstream option and nothing local rewritten. Equality still adopts, absence still performs, and anything else is still a conflict. The ancestry is proved inside the already-authenticated, contained object source, out of the objects that source holds, by one local question with two answers. Nothing is fetched to answer it, so an observed commit the source cannot read is an ordinary conflict; a proof that reaches neither answer is a boundary failure rather than a finding about the remote. The retained pre-state gains a third closed shape carrying the predecessor and `relation: "ancestor"`. The two existing shapes are written byte-for-byte as they were, and a record pairing a decision with a pre-state that cannot support it — a relation beside a proven absence, an unknown relation, an undeclared member, an adoption carrying a relation, a performance over an unattested predecessor — still fails closed. `<PullRequest>` now scans the whole successful history rather than refusing at the first older Push for the same branch: the record naming this iteration's commit authorizes wherever it appears, an earlier publication decides only which refusal an unauthorized pull request gets, and an unreadable relevant record still wins. * 🔁 Resume a run that published its branch more than once Two structural corrections to the fast-forward Push, both established by architecture review of 0bb738f. A partial replay of `Push A -> commit B -> Push B` diverged. A Push names its request from the checkout — the branch it is on, and the commit that branch holds — and a replay asked that question after the run had moved on, so the first Push reconstructed B and arrived at A's retained record holding the wrong request. Repeated publication is what this feature is for, so such a run could not be resumed at all. Each completed Push is now reconstructed from the Workspace root its own journal event was appended against — the association the run made when it wrote that event, rather than the frontier the run reached. The historical root is materialized inside a rollback-only savepoint, the checkout family is exported from it, and everything the materialization wrote is discarded on success, failure and cancellation alike: the current root, the retained roots, the metadata and the journal are what they were, and the run stays at B. A position with no retained successful Push is a live attempt and still names its request from the current root. Selecting a root only decides which question is asked. The request it produces still has to be the one that position asked, so a reconstruction naming the wrong moment refuses the replay rather than answering it. Second, a commit is its own ancestor, and `parseGitPushRecord()` accepted `performed` beside `{ remoteCommit: <the commit it published>, relation: "ancestor" }`. Observing the destination at exactly this commit is what adoption is, so that record describes a reconciliation the state machine cannot reach. An attested predecessor is now valid only when it differs from the source. * 🩹 Let the run's last publication of a branch decide, and diverge on purpose Two CI failures, both consequences of the fast-forward change meeting evidence that was written when a branch could only be published once. `admitPushEvidence()` counted exact records, so a run that published this head and then published past it authorized a pull request naming the head it had already replaced. `pull-request-records.test.ts` says otherwise, and it is right: what a pull request is decided against is where the sequence of publications ended. Every relevant record is still read whole and in order — an unreadable one earlier in the sequence still refuses — and the last one decides: this head authorizes, another commit is conflicting, none at all is missing. Tier WFF's refusing remote seeded `refs/heads/publish/1` at `main`'s commit, which `<Git.Switch>` then started the branch from, so what the push observed was its own ancestor and the run now succeeded where WFF11 needs a Git-host effect that established nothing. The seed publishes a second line of history under a name the run does not push to — so the clone carries the objects and the switch does not start there — and the document moves the destination onto it after the clone. The push then observes a commit its own branch does not contain, which is the conflict the case was always describing. The move is written between two `<Repository>` elements rather than inside one: a command runs where the element is written, and the retained checkout is not a host directory to run one in. --------- Co-authored-by: Taras Mankovski <[email protected]>
1 parent e84c0a7 commit 5c6e35f

12 files changed

Lines changed: 1297 additions & 79 deletions

File tree

‎architecture.md‎

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,27 @@ path, so a completed replay reaches no provider and performs no such proof. A
11431143
graph that leaves what the run authenticated is a boundary failure: it publishes
11441144
no outcome, repeats no authored path, and activates fail-stop. It is rejected
11451145
rather than repaired, because editing authored state to make it acceptable would
1146-
publish from state the run wrote on the author's behalf. The Workspace transaction such an effect opens is read-only and is
1146+
publish from state the run wrote on the author's behalf.
1147+
1148+
That same contained source is what decides whether a branch may advance. A
1149+
destination naming another commit is not by itself somebody else's work: a
1150+
supervised run publishes one branch repeatedly, and the ordinary case is a
1151+
remote tip the commit being published was built on top of. So ancestry is proved
1152+
where the objects already are — inside the authenticated source, out of the
1153+
commits it already holds, by one local question whose only answers are ancestry
1154+
and divergence. A proven ancestor other than the commit being published is a
1155+
performable pre-state, published over by the same exact non-force refspec a
1156+
proven absence gets; an equal destination is adopted with nothing performed, and
1157+
is never an attested advance, because a commit is its own ancestor and observing
1158+
the destination at exactly this commit is what adoption is; and compatibility
1159+
that was not proved — a divergent commit, or one the source does not hold — is a
1160+
conflict. Nothing is
1161+
fetched to prove it, because an object retrieved to answer the question would be
1162+
evidence the question created, and a proof that reaches neither of its two
1163+
answers is infrastructure rather than a finding about the remote. The relation,
1164+
not the traversal that found it, is what the record keeps.
1165+
1166+
The Workspace transaction such an effect opens is read-only and is
11471167
closed before the host is observed: no transaction is claimed across the
11481168
Workspace and the external service, and reconciliation rather than a distributed
11491169
transaction is what makes an interrupted attempt reach the host once.
@@ -1300,6 +1320,18 @@ its authority is this run's own matching Push evidence, which no configuration
13001320
grants or withdraws. "Authority ceiling" remains the word for the bound; what an
13011321
operator writes is the list of places this host is allowed to reach.
13021322

1323+
A replayed effect that has to name what it asked for reads the moment it asked
1324+
from. A Push names its request out of the checkout, and a run that publishes one
1325+
branch repeatedly has moved the Workspace on by the time it is resumed — so each
1326+
completed Push is reconstructed from the root its own journal event was appended
1327+
against, which is the association the run made when it wrote that event, rather
1328+
than from the frontier the run reached. That reconstruction is a read: the
1329+
historical root is materialized, exported from, and discarded on every path out,
1330+
leaving the current root, the retained roots, the metadata and the journal
1331+
exactly as they were. It decides only which question is asked, because the
1332+
request it produces still has to be the one that position asked before the
1333+
retained record answers it.
1334+
13031335
An external effect is judged by its retained record rather than by its type. A
13041336
completed Git-host reconciliation record replays without contacting a provider,
13051337
so a fork inherits it and the remote is mutated once; the record keeps the
@@ -3131,8 +3163,8 @@ Status is measured against main.
31313163
| implicit workflow Workspace | retains provider-neutral filesystem, repository and attachment state by run ID | document filesystem built on the #366 stack and Repository/Worktree composition on the #293 stack; process capabilities unbuilt (#218) |
31323164
| `<Repository>` / `<Worktree>` / `<Dir>` composition | names a Git repository and its linked checkouts inside the run-owned Workspace, installs each as contextual working directory, and retains creation identity beside the retained Git bytes | built on the #293 stack, Deno provider only |
31333165
| transactional Git effects (`Git.Switch` / `Git.Add` / `Git.Commit`) | publish local Git mutations with their journal result; the enclosing Repository and the contextual working directory select which retained checkout one runs in, and neither observation carries authority — the observed record is compared with the retained row and the directory with the checkouts that row holds, so a failure of authority, of retained state or of an unrecognized native condition fails the run instead of publishing a result | built on the #294 stack, Deno provider only |
3134-
| `Git.Push` | publishes the selected checkout's exact current named branch and commit to the same branch on the retained Repository's canonical `origin`, reconciled through the shared Git-host state machine rather than through a Workspace transaction: no props and no component result, no force, no upstream mutation and no implicit staging or committing; the durable request and record carry the Repository's filtered identity without its checkout path, and the transport runs in a provider-owned isolated control repository reading the checkout's objects through an object-source attachment whose alternates chain and object tree are proven contained before the first remote observation, aimed at the exact private retained locator | built on the #370 stack, Deno provider only |
3135-
| `<PullRequest>` | upserts one pull request of the selected checkout's current named branch, reconciled through the shared Git-host state machine: a required `title`, an optional positive-integer `number`, an optional `base` defaulting to the Repository's retained initial branch, an optional `draft`, and the rendered content as the body; it renders nothing and returns stable evidence through `as` — the filtered Repository identity, the provider's own stable pull-request identity, number, URL, open state, and the head and base SHAs of the snapshot it finished at. Without a number it creates one pull request for the head/base pair or adopts the compatible one an interrupted attempt left; with a number it brings that exact pull request's title, body, draft state and base to what the request says, records a no-op when they already match, and refuses a number belonging to another repository, opened from another head, or no longer open. It never pushes, never rewrites a head, and never reopens, merges or comments. The run must already hold its own successful `Git.Push` result for that exact Repository identity, head branch, destination ref and commit — proven by a scan that requires the record's natural key, inputs and result to describe one publication — and a missing, conflicting or unreadable one fails locally before the Git host is observed; the first adapter works over `github.com` on REST plus the two GraphQL draft transitions, selected from the private retained locator, credentialed from `GH_TOKEN`, then `GITHUB_TOKEN`, then the machine's own `gh` login, issuing each required mutation at most once per attempt and deciding the outcome by one observation, with the locator, endpoint, credential and payload confined to the per-invocation provider closure | built on the #295 stack, Deno provider only |
3166+
| `Git.Push` | publishes the selected checkout's exact current named branch and commit to the same branch on the retained Repository's canonical `origin`, reconciled through the shared Git-host state machine rather than through a Workspace transaction: no props and no component result, no force, no upstream mutation and no implicit staging or committing; the durable request and record carry the Repository's filtered identity without its checkout path, and the transport runs in a provider-owned isolated control repository reading the checkout's objects through an object-source attachment whose alternates chain and object tree are proven contained before the first remote observation, aimed at the exact private retained locator. A destination proven absent is published to once and one already naming this exact commit is adopted; one naming a distinct commit that same authenticated source proves is in this commit's ancestry is a performable pre-state, published over by the same exact non-force refspec and retained as the predecessor with the attested relation, while a divergent commit and one the source cannot read are both conflicts and nothing is fetched to decide either; a completed Push is reconstructed from the Workspace root its own journal event was appended against, read without publishing it or moving the run's frontier, so a branch published more than once resumes | built on the #370 stack, Deno provider only |
3167+
| `<PullRequest>` | upserts one pull request of the selected checkout's current named branch, reconciled through the shared Git-host state machine: a required `title`, an optional positive-integer `number`, an optional `base` defaulting to the Repository's retained initial branch, an optional `draft`, and the rendered content as the body; it renders nothing and returns stable evidence through `as` — the filtered Repository identity, the provider's own stable pull-request identity, number, URL, open state, and the head and base SHAs of the snapshot it finished at. Without a number it creates one pull request for the head/base pair or adopts the compatible one an interrupted attempt left; with a number it brings that exact pull request's title, body, draft state and base to what the request says, records a no-op when they already match, and refuses a number belonging to another repository, opened from another head, or no longer open. It never pushes, never rewrites a head, and never reopens, merges or comments. The run must already hold its own successful `Git.Push` result for that exact Repository identity, head branch, destination ref and commit — proven by a scan of the whole successful history that requires each relevant record's natural key, inputs and result to describe one publication; a branch is published repeatedly, so the whole history is read in order and the run's last publication of that branch decides — an earlier one behind it is history rather than disagreement, while a last one naming another commit is the branch having moved on; that is conflicting, no relevant record at all is missing, and a relevant record that cannot be read whole is unreadable, each failing locally before the Git host is observed; the first adapter works over `github.com` on REST plus the two GraphQL draft transitions, selected from the private retained locator, credentialed from `GH_TOKEN`, then `GITHUB_TOKEN`, then the machine's own `gh` login, issuing each required mutation at most once per attempt and deciding the outcome by one observation, with the locator, endpoint, credential and payload confined to the per-invocation provider closure | built on the #295 stack, Deno provider only |
31363168
| `<Issue>` | asks one of two questions, decided by its own shape, through a boundary of its own rather than the Git host's. Self-closing with `url` reads that issue and binds `{ url, title, description, tags, assignee }`; paired with `title` upserts and binds exactly `{ url }`, its rendered content being the description. There is no `description` prop. Props are exactly `url`, `title`, optional `tags`, optional `assignee` and — on a read only — optional `provider`; no repository/token/label/milestone/project/comment/close or approval prop. Both forms render nothing. The form is decided before the tracker is read, before any provider is asked and before an `issue_effect` record exists, and that is where a mixed `url`+`title`, a read carrying content or `tags`/`assignee`, an upsert with no content, an upsert naming a `provider`, and an element that is neither are all refused. A read needs no tracker — its URL is the identity; an upsert requires the nearest lexical `<IssueTracker>` and takes its discriminator only from there. The tracker carries a credential-free `url` and an optional `provider`; the URL is canonicalized — a credential, a query and a fragment are refused rather than stripped — and a nested tracker replaces the whole value for its descendants, never merging members, with the enclosing one restored on leaving. It is composition data, not authority: the provider holds an adapter-private ceiling beside its credentials, admitted before it connects, so a target outside it sends nothing. One stable contextual operation, `executablemd.workflow.issue`, with `read(url, options)` and `upsert(issue, options)`; a provider is ordinary middleware around it, matching its own URLs without a discriminator and only its own name with one, independently per member, with no host-side resolution. Once middleware matches it owns the answer — it never delegates afterwards, and nothing catches its refusal to try somebody else — and a request everyone delegated reaches `NoIssueProvider` unchanged. `issue_effect` records an operation discriminator with the normalized request and result; both forms replay without reaching `IssueApi` and therefore without network access; only an upsert derives an idempotency key, from the operation, the canonical target and the run's own effect identity. Retention excludes credentials, endpoints, payloads, provider identities, origin markers and host paths. Observing, adopting, creating once and recovering an interrupted creation are the provider's, because they are knowledge about what a service can prove; title is never identity, and tags are a code-point-sorted set. The Deno workflow host installs configured GitHub middleware and installs none otherwise, so absence of configuration is fail-closed | built on the #296 stack; GitHub middleware, Deno host |
31373169
| workflow lifecycle inspection and control | reads status/list/history without advancing a run, recovering a private copy when a crashed source needs rollback; enforces the executor lock, refuses live cancellation, cancels non-live runs under that lock and deletes retained state | direct read-only inspection and control built on the #367 stack; coordinated recovered inspection built on the #513 stack, Deno provider only |
31383170
| historical authored source | retains an authored durable operation's normalized `SourcePosition` beside its identity, and history parses it or refuses the entry | built on the #367 stack |

‎packages/cli/tests/workflow-fork.test.ts‎

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,26 @@ const EMPTY = ["# Release", "", "Nothing happens here.", ""].join("\n");
132132
* `<Git.Push>` is the shipped external-effect surface, and a completed push
133133
* retains a reconciliation record — the pre-state, the observations, the
134134
* decision and the result — that replays without contacting anything.
135+
*
136+
* `before` is written between the commit and the push, which is where a suite
137+
* arranges what the destination holds by the time the push looks at it. The
138+
* remote has to move *after* the run cloned: a destination that already exists
139+
* when the clone happens is where `<Git.Switch>` starts the branch, so
140+
* whatever it holds is an ancestor of what the run then publishes. It closes
141+
* the Repository around itself, because a command runs where the element is
142+
* written and the checkout is not a host directory to run one in.
135143
*/
136-
function pushing(remote: string, tail: string): string {
144+
function pushing(remote: string, tail: string, before: string[] = []): string {
145+
const repository = '<Repository name="project" url="' + remote + '">';
137146
return [
138-
'<Repository name="project" url="' + remote + '">',
147+
repository,
139148
'<Git.Switch branch="publish/1" />',
140149
'<File path="notes.md">',
141150
"prepared",
142151
"</File>",
143152
'<Git.Add paths="notes.md" />',
144153
'<Git.Commit message="prepare" as="commit" />',
154+
...(before.length === 0 ? [] : ["</Repository>", ...before, repository]),
145155
"<Git.Push />",
146156
"</Repository>",
147157
"",
@@ -152,6 +162,23 @@ function pushing(remote: string, tail: string): string {
152162
].join("\n");
153163
}
154164

165+
/**
166+
* The destination this run's branch does not descend from, put there mid-run.
167+
*
168+
* `refs/heads/diverged` is a second line of history the clone brought along, so
169+
* the commit is readable to the push and provably not in its ancestry — which
170+
* is what makes the refusal a conflict rather than an object nobody could read.
171+
*/
172+
function diverting(remote: string): string[] {
173+
return [
174+
"",
175+
"```bash exec",
176+
`git --git-dir=${remote} update-ref refs/heads/publish/1 refs/heads/diverged`,
177+
"```",
178+
"",
179+
];
180+
}
181+
155182
/** A bare remote with one commit on `main`, and optionally one that refuses pushes. */
156183
function* useRemote(root: string, refusing = false): Operation<string> {
157184
const bare = join(root, refusing ? "refusing.git" : "remote.git");
@@ -170,10 +197,17 @@ function* useRemote(root: string, refusing = false): Operation<string> {
170197
yield* git(root, ["init", "-q", "--bare", "--initial-branch=main", bare]);
171198
yield* git(seed, ["push", "-q", bare, "main"]);
172199
if (refusing) {
173-
// The destination ref already exists, at a commit the run's own branch does
174-
// not descend from. The push observes that and refuses, so what the run
175-
// retains is a Git-host effect that established no completion.
176-
yield* git(seed, ["push", "-q", bare, "main:refs/heads/publish/1"]);
200+
// A second line of history, published under a name the run does not push
201+
// to. A clone copies it along with everything else, so the objects are
202+
// readable inside the run — and `<Git.Switch>` does not start the branch
203+
// there, because it is not the destination's name. The document moves the
204+
// destination onto it mid-run, and the push then observes a commit its own
205+
// branch does not descend from: a Git-host effect that establishes no
206+
// completion.
207+
yield* writeTextFile(join(seed, "which.txt"), "diverged\n");
208+
yield* git(seed, ["add", "-A"]);
209+
yield* git(seed, ["-c", "commit.gpgsign=false", "commit", "-q", "-m", "diverged"]);
210+
yield* git(seed, ["push", "-q", bare, "HEAD:refs/heads/diverged"]);
177211
}
178212
return bare;
179213
}
@@ -747,7 +781,11 @@ describe("Tier WFF — xmd workflow fork", () => {
747781
it("WFF11: a Git-host effect that established nothing is not forkable", function* () {
748782
yield* useFixture({ [DEFINITION]: "# placeholder\n" }, function* (fixture) {
749783
const remote = yield* useRemote(join(fixture.repository, ".."), true);
750-
yield* commit(fixture, { [DEFINITION]: pushing(remote, "echo original") }, "pushing");
784+
yield* commit(
785+
fixture,
786+
{ [DEFINITION]: pushing(remote, "echo original", diverting(remote)) },
787+
"pushing",
788+
);
751789

752790
const started = yield* xmd(fixture, [
753791
"workflow",

0 commit comments

Comments
 (0)