Repository navigation
fix(op): the gate's ledger write survives a CI checkout, and says so when it does not (#2301, #2303) - #2309
Conversation
…when it does not (#2301, #2303) Three failures of one mechanism, all found by the first real execution of a generated Op pipeline on GitLab CE 17.11 (INTENTIUS/choudoufu#1026). The gate records its pending fact as a commit on `chant/lifecycle`; every guard on both sides had only ever read generated YAML, so nothing had exercised what that commit needs from the checkout it runs in. A CI checkout differs from a developer's in two ways, and the gate depended on both without saying so. **No committer identity (#2301).** GitLab CI, GitHub Actions and Forgejo Actions all clone without `user.email` or `user.name`, and `git commit-tree` refuses rather than inventing one. `writeBlobToPath` now supplies chant's own — `chant <chant@localhost>` — through `git -c` on that one invocation, and only when `git var GIT_COMMITTER_IDENT` says the checkout cannot name a committer itself. A configured identity is never overridden, so every existing caller's commits are byte-identical; nothing is written into the repository's config either way. `CHANT_LIFECYCLE_COMMITTER_NAME` / `_EMAIL` repoint it at a bot account a project controls. This is in core's one git-plumbing path rather than in the three generated dialects, so github and forgejo — untested for this, and named in the issue as needing to be — are fixed by the same change as gitlab, and a project that generated its pipeline before this needs no regeneration. **No error text at all (#2301, the half the issue says matters more).** The symptom was an apply that printed `Op "live-apply" failed after 43.8s` and nothing else: no error line, no failing step, exit 1. Two causes, one inside the other. `runGateStep` was the only step kind that could throw instead of returning a record — `runStep` has always turned an activity's throw into a failing `StepRecord` carrying the message, and the gate did not — so a git failure unwound the phase loop with no record of itself. Then `runOpLocally`'s catch, which unpacks `PhaseFailure` and `GateStop` and nothing else, built an `OpRunFailure` from the records it had and never referenced `err` again. Since `renderHuman` prints text only from records, the cause reached nobody. Both are closed. A gate that cannot be decided is now a failing step like any other, and any error the catch does not recognise becomes a synthetic failing record carrying its message, with the original on `OpRunFailure.cause` for a programmatic caller. The compensation loop had the same swallow one level down and gets the same treatment. This is deliberately general: the gate is where it was found, not the only thing it hid — anything thrown between the phases was equally invisible. The component driver's parallel path was checked and already re-throws what it does not recognise, so it needed nothing. `writeBlobToPath`'s own failures now name what was being written and where (`cannot write _gates/live-apply.jsonl on the chant/lifecycle branch: ...`), because `git commit-tree failed: <stderr>` does not say that the thing that failed was chant recording a fact on its own branch. `runtimes/local.ts` also declared no `onLedgerError`, so a run-ledger append dying for the identical reason was caught and dropped; it warns now. **No ledger branch (#2303).** A GitLab CI checkout fetches the pipeline's own ref at depth 20 and nothing else, so `chant/lifecycle` is absent — and an absent branch reads exactly like an empty ledger, which is to say like nothing having been approved. A retried job therefore recorded a *second* pending fact and gated again; two runs of one commit produced two pending records with different expiries. `GIT_DEPTH: 0` does not fix it, because GitLab fetches refspecs rather than all branches. The read is what has to be right, so `gitGateLedgerPort.read` fetches the branch before reading it. `fetchLifecycleStatus` distinguishes the four outcomes a boolean could not: `fetched`, `no-remote` (a single-machine project, where local is authoritative by construction), `absent` (the remote answered and has no such branch — a real empty ledger, and a first gate must not be refused), and `unreachable` / `diverged`, which is where `LifecycleLedgerUnreadableError` refuses by name rather than guessing. That refusal is the issue's stated minimum, and it is only useful because of the paragraph above: thrown from inside gate evaluation, it would have been swallowed too. **`chant approve` force-writing the branch (#2303, the serious one).** `writeBlobToPath` builds its commit from `readTree`, which on a checkout with no local `chant/lifecycle` returns an empty tree and a null tip. The append therefore parented on nothing and wrote a tree holding only the line it had just produced — a new root commit replacing the branch instead of extending it. The `update-ref` CAS did not catch it, because the assertion it makes ("the ref does not exist") was perfectly true locally. An operator cloning, approving and pushing turned a branch holding the pending record into a branch holding only the resolution: silent history loss on the branch both READMEs call the approval of record. `recordGateApproval` and `--expire` now call `requireLifecycleLedgerWritable` first. Fetching is the fix — with real history in the checkout the append parents on it and the pending fact survives — and the guard refuses outright on divergence, which the read path tolerates and a write must not, since appending across a fork drops one side either way. Proof is in `packages/core/src/op/gate.test.ts`, new, against real git: a bare remote, an authoring clone, and a `--single-branch` clone standing in for the CI checkout, which is the closest local equivalent of GitLab's refspec fetch. Every assertion was shown red by a deliberate tamper first. Reverting the identity args reproduces the reported `fatal: no email was given` inside the new "cannot write ... on the chant/lifecycle branch" wrapper; reverting both halves of the swallow reproduces the reported output exactly, three lines ending in a bare failure; reverting the read guard records a second pending fact at a different expiry; reverting the write guard leaves the pending record gone (`expected [] to have a length of 1`). No egress-catalogue change: `chant run` and `chant approve` already reach the git remote (`pushLifecycle`), and the catalogue's shell-out list scopes the offline phases, which these are not. Part of #2289. Closes #2301. Closes #2303. Claude-Session: https://claude.ai/code/session_01Ba8bBNoVmfrpiVKnwYLBzM Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`lint-docs-sentences.mjs` gates em-dash density per file, and the new "What the gate needs from a CI checkout" section pushed guide/ops.mdx from 23 to 26 against a baseline of 23. Parentheses for the committer-identity aside and a colon for the absent-branch clause carry the same meaning without the dashes. Claude-Session: https://claude.ai/code/session_01Ba8bBNoVmfrpiVKnwYLBzM Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…2303) Four defects from the adversarial review of #2309. The first is a data-loss path this PR's own first pass opened, and it is reproduced end to end against real git. **A diverged local ledger was read as authoritative, then force-pushed over the remote.** `requireLifecycleLedgerReadable` fetched, then returned early on `if (hadLocal)`, which swallowed `diverged` as well as `unreachable`. The docstring justified it with "it has real history to read", which is only true when the local branch *is* the remote's history. On a fork, the gate read a ledger missing every remote approval, recorded a second pending fact, and pushed it. The push was unprotected. A rejected non-fast-forward fetch still updates `refs/remotes/<remote>/chant/lifecycle` opportunistically in a full clone (verified on git 2.50.1: the `! [rejected]` line comes with `* [new branch] chant/lifecycle -> origin/chant/lifecycle`), so `getRemoteLifecycleBranchSha` read the tip the failed fetch had just learned and `--force-with-lease` matched. A remote holding a pending fact and an `e2e-operator` approval ended up holding neither. Divergence now always refuses, for readers and writers alike, and the two guards are one function: keeping them separate is what let the read path drift laxer than the write path. `unreachable` still refuses only when there is no local history, which is the case indistinguishable from an empty ledger; refusing it with history present would strand every offline run for no gain, since the lease fails safely on its own there. Distinguishing a fork from a branch that is merely *ahead* is what makes that rule safe to apply. git reports "non-fast-forward" for both, and "ahead" is the ordinary state right after an append whose push has not landed — the state a retry exists to repair. `fetchLifecycleStatus` resolves the remote tip into a scratch ref and asks `merge-base --is-ancestor`, so `ahead` and `diverged` are separate outcomes. **The identity fallback turned a loud failure into a silent branch fabrication.** Every ledger writer reaches `writeBlobToPath`, which on a checkout with no local `chant/lifecycle` builds a tree from an empty read and commits it with no parent: a root commit that replaces the branch. `updateRefCAS` cannot catch it, because "the ref does not exist" is true locally. Until #2301 the damage was capped by accident, in that `commit-tree` died for want of a committer before it could happen. Supplying an identity removed that accident, on every writer that reaches here without a ledger — a run record on an Op with no gate at all, a snapshot, a release, a build manifest — and since GitLab runners reuse `/builds/<project>` across jobs, the next job carried the fork into the gate. The guard now runs inside `writeBlobToPath`, at the one seam they all pass through, and only when the branch is absent, so an extend still costs no fetch and a genuinely first write still creates the branch. **`chant operator` never got #2301's fix.** It renders its own events rather than going through `renderHuman`, passed no `onLedgerError`, and reported a fixed `Op "x" failed — see its ledger record for step-level detail` while `err.result.records` and `err.cause` sat unread. It pointed the reader at an artifact that a failed ledger append means is missing. It now names the failing steps, falls back to `cause`, and reports a dropped ledger append as its own tick failure. **Locale and remote selection.** Both strings `fetchLifecycleStatus` matches are in git's translation catalogs, so under a distro git with NLS and a non-C `LANG` a project's genuine first gate would fall through to `unreachable` and be refused. Every git invocation parsed by its output is pinned with `LC_ALL=C` and a cleared `LANGUAGE`, which needed an `env` option on the runtime adapter's `spawn` (merged over the parent environment, not replacing it). A non-zero exit from `git remote` is no longer read as "no remote configured", since a git that failed to answer is not evidence that a project is single-machine. `origin` is preferred over whichever remote name sorts first, so a repo with a `backup` remote does not fetch the ledger from it. **Two smaller corrections.** The identity fallback is per-field now: `git var GIT_COMMITTER_IDENT` fails if either half is missing, so filling in both overwrote a configured `user.name` in a checkout that had a name but no email, which is not what this file's own doc comment and ops.mdx promise. And both `chant approve` write sites used `pushLifecycle().catch(() => undefined)` and then printed unconditional success, so a rejected push read as a completed approval; they warn and mark the line local-only now, keeping exit 0 because the local append is still a correct local fact. `git.test.ts`'s "concurrent write rejected" test asserted the *old* behaviour: that operator B's fork was caught by the lease at push time. A write that has to be caught by a lease is the bug, so it is now two tests — B appends to A's history and both snapshots survive, and a genuinely stale lease still throws. Every new assertion was shown red by a deliberate tamper. Restoring the `hadLocal` early return makes the gate record a second pending fact against a fork and moves the remote tip off the approval; disabling the write guard leaves the fabricated branch with no trace of the pending fact; restoring the operator's fixed string, the all-or-nothing identity, and the push swallow each fail their own assertion. Part of #2289. Closes #2301. Closes #2303. Claude-Session: https://claude.ai/code/session_01Ba8bBNoVmfrpiVKnwYLBzM Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Review defects addressed in 785f3c5. The critical one was real and I reproduced it end to end before fixing it. 1 (critical) — diverged ledger read as authoritative, then force-pushedConfirmed exactly as described. Standalone repro against git 2.50.1, full clone: The approval is gone. (Note the opportunistic remote-tracking update needs a full clone's default refspec; in a Fix. Divergence now always refuses, and the two guards are collapsed into one Making that rule safe required separating two states git reports identically. "non-fast-forward" covers both a fork and a branch merely ahead — and "ahead" is the ordinary state right after an append whose push has not landed, exactly what a retry repairs. Added the missing assertion you flagged: and then, with that assertion relaxed so execution continues, destroying the remote: 2 (high) — identity fallback fabricating a branchCorrect, and it contradicted my claim 4. The guard now lives inside Red, on a run-ledger append for an Op with no gate at all: 3 (medium) —
|
| Gate | Result |
|---|---|
| core typecheck | clean |
npx tsx scripts/typecheck.ts |
31 known failures, no regressions |
just lint |
0 errors (2 pre-existing warnings, untouched file) |
just docs-check |
passes |
node scripts/lint-docs-sentences.mjs |
4084 gated finding(s), no regressions |
vitest packages/core |
390 files, 6330 passed |
vitest test/ + all lexicons |
793 files, 9768 passed, 30 skipped |
…ead of resolving quietly (#2310) (#2336) gate.ts:71's `appendPending` still did `await pushLifecycle(opts).catch(() => undefined)` after #2309 fixed the same swallow at the two `chant approve` write sites in `../cli/handlers/operator.ts`. #2309's author left it on purpose, reasoning that a pending fact reaching only the local branch is still a correct local answer, and that changing it would alter gated-run exit semantics. That reasoning holds for the exit code and does not hold for the report. A `chant run` that stops at a gate is right to end `gated` whether or not its push landed: the append to `chant/lifecycle` always succeeds locally (#2309's fetch-before-append), and there is nothing wrong with the local fact to fail the run over. But a rejected push means the pending record exists only in this checkout, and an operator working from a clone of the remote cannot see a fact they cannot see to approve it. Before this, the run gave no hint that this was why `chant approve` found nothing to resolve — exactly `chant approve`'s pre-#2309 bug, one caller over. The decision here is: still exit 3, still gate, and now say so. `gate.ts`'s `GateLedgerPort.appendPending` returns `{ record, pushed, pushWarning? }` instead of the bare `PendingGateRecord`, mirroring the shape `operator.ts`'s `reportedPush` (#2309 review) already reports through. `evaluateGate`'s `GateCheck` carries `pushed`/`pushWarning` alongside the pending fact, present only when this call's own append is what ran — `recorded: false` (a standing pending fact from an earlier run) has nothing new to report. From there it threads through both executors exactly the way #2301 threaded a gate's failure onto `OpRunResult`/`DriverComponentResult`: `GateStop` in both `local-executor.ts` and `components/driver.ts` carries `pushed`/`pushWarning`, `runOpLocally`/`runComponentDeploy` land them as `gatePushed`/`gatePushWarning` on the result, and `cli-support.ts`'s `RunComponentsResult.gated` and `run.ts` carry them the rest of the way to `chant run`'s human render, `--json`, and the `GITHUB_STEP_SUMMARY`/ `CHANT_GATE_SUMMARY` block `chant run` already writes for a gated run (the step summary is the surface an operator working from a different checkout actually opens, so it is where this mattered most). Audited every other `pushLifecycle` caller for the same swallow: - `activities/converge.ts:435` (`convergeTick`'s ledger append) has the identical `.catch(() => undefined)` idiom. Left alone here: it is a different ledger (the converge tick log, not the gate ledger) with a much softer consequence (an informational log line missing a remote, not an approval nobody can see), and reporting it would mean extending `ConvergeTickResult`/`ConvergeOp`'s outcome attributes, which is its own change. Worth its own issue. - `lifecycle/snapshot.ts:302` and `cli/handlers/lifecycle.ts:531` let a rejection propagate/already report `pushed` — no swallow. - `cli/handlers/components.ts:133`, `components/manifest-persistence.ts:139` and `components/auto-release.ts:192` all catch a *rejected* push (a real `StaleLifecycleBranchError`) and report failure correctly; only the "no remote configured" `false` return goes unremarked in favor of a reported success, a smaller and pre-existing gap, not the swallow #2310 is about. Every new assertion was shown red by reverting `gate.ts`'s fix back to `await pushLifecycle(opts).catch(() => undefined); return { record, pushed: true };` and rerunning `gate.test.ts`: FAIL packages/core/src/op/gate.test.ts > op/gate — a CI checkout that never fetched the ledger (#2303) > a project with no remote is local-only and is never refused AssertionError: expected true to be false // Object.is equality 507| expect(check.pushed).toBe(false); FAIL packages/core/src/op/gate.test.ts > op/gate — a rejected ledger push is reported, not swallowed (#2310) > gitGateLedgerPort's appendPending reports pushed:false and the rejection reason AssertionError: expected true to be false // Object.is equality 574| expect(third.pushed).toBe(false); The second test reproduces the actual race against real git: two clones of one bare remote, the second fetches and appends on top of the first's push, then the first appends its own fact on the tip it still knows and pushes against a lease the remote has since moved past — the same `StaleLifecycleBranchError` a concurrent `chant approve` can hit. Restored the fix, both green. New/extended coverage: `gate.test.ts` (the rejection above, plus `evaluateGate`'s propagation from a stub port, plus the existing no-remote test extended to assert `pushed`/`pushWarning`), `local-executor.test.ts` and `driver.test.ts` (a rejected push still ends the run/component `gated` and lands `gatePushed`/`gatePushWarning` on the result), `local-output.test.ts` (`renderHuman`/`renderJson` show the warning), `gate-summary.test.ts` (the CI step-summary markdown block). Docs: `docs/cli/run.mdx` gains a paragraph on the append/push split and what a rejected push means for the run and its `--json`/step-summary output, answering the issue's "say which in the docs" for the decision made here (report, don't retry, don't fail). Gates: `npx tsc --noEmit -p packages/core/tsconfig.json` clean. `npx tsx scripts/typecheck.ts`: 31 known/0 new. `just lint`: 2 pre-existing warnings in an unrelated file (packages/core/src/meta/publish-metadata.test.ts), 0 errors. `just docs-check`: 20 tutorial, 52 how-to, 58 reference, 34 explanation, clean. `node scripts/lint-docs-sentences.mjs`: 4084 baselined, no regressions. Targeted: `npx vitest run packages/core/src/op/gate.test.ts packages/core/src/op/local-executor.test.ts packages/core/src/op/local-output.test.ts packages/core/src/op/gate-summary.test.ts packages/core/src/components/driver.test.ts packages/core/src/components/cli-support.test.ts packages/core/src/lifecycle/git.test.ts packages/core/src/cli/handlers/operator.test.ts packages/core/src/cli/handlers/run.test.ts` — 304 passed. Full `npx vitest run packages/core` — 390 files, 6350 passed. Closes #2310. Claude-Session: https://claude.ai/code/session_01Ba8bBNoVmfrpiVKnwYLBzM Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Three failures of one mechanism — the gate's commit on
chant/lifecycle— all found by the first real execution of a generated Op pipeline on GitLab CE 17.11 (INTENTIUS/choudoufu#1026).Why one PR
These were assigned as two issues and are delivered as one PR, because they do not separate cleanly:
packages/core/src/lifecycle/git.tsandpackages/core/src/op/gate.ts— a CI checkout has no git identity, so the gate's pending write fails with no error text at all #2301 in the write, approve then re-run does not close the gate in CI, andchant approvewithout the ledger ref force-writes the branch, discarding the pending fact #2303 in the read, sharingwriteBlobToPath.chant approvewithout the ledger ref force-writes the branch, discarding the pending fact #2303's stated minimum is "refuse with a message naming the missing ref". That refusal is thrown from inside gate evaluation — which is exactly what a CI checkout has no git identity, so the gate's pending write fails with no error text at all #2301 deliverable 2 found was being swallowed. Landing approve then re-run does not close the gate in CI, andchant approvewithout the ledger ref force-writes the branch, discarding the pending fact #2303 alone would add a refusal that prints nothing.packages/core/src/op/gate.test.ts).#2301 — the write fails with no error text at all
Deliverable 1, the identity. CI checkouts on all three forges clone without
user.emailoruser.name, andgit commit-treerefuses rather than inventing one.writeBlobToPathnow supplies chant's own —chant <chant@localhost>— throughgit -con that one invocation, and only whengit var GIT_COMMITTER_IDENTsays the checkout cannot name a committer itself. A configured identity is never overridden, so existing commits are byte-identical; nothing is written into the repository's config.CHANT_LIFECYCLE_COMMITTER_NAME/_EMAILrepoint it at a project's own bot account.This sits in core's single git-plumbing path rather than in the three generated dialects, so github and forgejo — named in the issue as untested and needing to be — are fixed by the same change as gitlab, and a project that generated its pipeline before this needs no regeneration.
Deliverable 2, the silence. This turned out to be a general error-swallowing bug in the Op executor, not something local to the gate. Two causes, one inside the other:
runGateStepwas the only step kind that could throw instead of returning a record.runStephas always turned an activity's throw into a failingStepRecordcarrying the message ("Never throws — returns a record"); the gate did not, so a git failure unwound the phase loop leaving no record of itself.runOpLocally's catch unpacksPhaseFailureandGateStopand nothing else. Every other error was used to build anOpRunFailureand then never referenced again —errwas dead after that line. SincerenderHumanprints text only from records, the cause reached nobody.Both are closed. A gate that cannot be decided is a failing step like any other; any error the catch does not recognise becomes a synthetic failing record carrying its message, with the original on
OpRunFailure.cause. The compensation loop had the same swallow one level down and gets the same treatment. Anything thrown between the phases was equally invisible — the gate is where this was found, not the only thing it hid. The component driver's parallel path was checked and already re-throws what it does not recognise, so it needed no change.Also:
writeBlobToPath's failures now name what was being written and where, andruntimes/local.tsdeclared noonLedgerError, so a run-ledger append dying for the identical reason was caught and dropped. It warns now.#2303 — approve-then-re-run, and the force-write
Finding 1. A GitLab CI checkout has no
chant/lifecycle, and an absent branch reads exactly like an empty ledger. A retried job recorded a second pending fact and gated again.gitGateLedgerPort.readnow fetches the branch first.fetchLifecycleStatusdistinguishes the four outcomes a boolean could not —fetched,no-remote(single-machine, local is authoritative),absent(a real empty ledger; a first gate must not be refused), andunreachable/diverged, whereLifecycleLedgerUnreadableErrorrefuses by name rather than guessing.Finding 2, the serious one.
writeBlobToPathbuilds its commit fromreadTree, which on a checkout with no local branch returns an empty tree and a null tip — so the append parented on nothing and wrote a new root commit replacing the branch. Theupdate-refCAS did not catch it, because the assertion it makes ("the ref does not exist") was perfectly true locally.recordGateApprovaland--expirenow callrequireLifecycleLedgerWritablefirst; with real history in the checkout the append parents on it, and the guard refuses outright on divergence.Proof
packages/core/src/op/gate.test.tsis new and runs against real git: a bare remote, an authoring clone, and a--single-branchclone standing in for the CI checkout (the closest local equivalent of GitLab's refspec fetch). Every assertion was shown red by a deliberate tamper before it went green.#2301, identity — reverting
identityArgsfrom thecommit-treeinvocation:#2301, the error naming — reverting
ledgerWriteErrorto the bare${stage} failed: ${stderr}:#2301, the swallow — reverting
runGateStep's catch:and with the outer backstop reverted as well, the rendered output is the reported symptom exactly — a completed step, then a bare failure line, and no cause:
Compare the issue's report:
#2303 finding 1 — reverting the
requireLifecycleLedgerReadablecall ingitGateLedgerPort.read. The approve-then-re-run loop does not close:and the unreachable ledger is read as empty, recording a second pending fact at a different expiry — the reported behaviour:
#2303 finding 2 — emptying
requireLifecycleLedgerWritable. The pending fact is discarded:Gates
npx tsc --noEmit -p packages/core/tsconfig.jsonnpx tsx scripts/typecheck.ts31 known failure(s), no regressions— baseline unchangedjust lintjust docs-check20 tutorial, 52 how-to, 58 reference, 34 explanationpackages/coretest/+ github/gitlab/forgejo lexiconsNo egress-catalogue change:
chant runandchant approvealready reach the git remote throughpushLifecycle, andOFFLINE_SHELL_OUTSscopes the offline phases, which these are not. The egress guard was run and is green.Part of #2289. Closes #2301. Closes #2303.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Ba8bBNoVmfrpiVKnwYLBzM