Keep the project where main is when a regenerated-skill landing goes wrong, and keep a first push idempotent after it
Before adoption: this commit came in with the history the project adopted, so no landing records it.
- packages/project/src/project.ts: a follow-up that fails is now judged by where main stands (`unlanded`). Still at the landing it follows: nothing landed, so that landing stands and the failure is logged, as before. Moved on (the push went through and the Lander's answer was lost), or unreadable: the call fails and commits nothing, so the project's landed SHA never falls behind main, and the same call run again finds both commits by request id (principle 8). Before, the failure was swallowed in every case, which recorded the landing while main stood one commit further and left every later landing `StaleBase`. - `followUp` is split into its guards, `landFollowUp` (generate, compose, land, record) and `unlanded`; behaviour on the happy path is unchanged. - `recordFirstPush` with the same head again answers `{ landed }` once the follow-up moved the landed SHA past it: the adoption (the one landing with no parent) is still the first push. Before, the replay was refused `DirectPush`. - apps/cli/src/local/check.ts: the stale note says the copy differs from what main's config gives, names the landing it says it came from, and gives both causes (an older config or a hand edit); it no longer claims the config changed when the copy was edited by hand. stale.ts's header now matches `isStale`: a skill copy without frontmatter is stale. - Tests added: apps/platform/test/generated.test.ts plays a mishap on the next follow-up's land through a wrapped isomorphic-git Lander: a busy repo leaves the landing standing with main on it; a lost answer fails the call, and the call run again lands nothing new and records the `gen-<landed>` commit. The first-push test records the same first push again. packages/project/test/generated.test.ts holds the credit order's middle branch (a deciding author without `Decided-by`; a planted bug that drops it now fails) and drops a test that restated `generatedRequestId`. apps/cli/test/local/stale.test.ts adds a hand-edited skill copy. Each new assertion was red before its fix.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+304 added−83 removed
- tests:+177 added−24 removed
- other:+127 added−59 removed
Provenance
- Commit
caf329b- Tree
a20e8b6- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
a30d422
6 files changed+304 added−83 removed
modified:apps/cli/src/local/check.ts+9 added-6 removed
125 unmodified lines126 Effect.fail(new Reported())127 )128 );129 130-/** What a stale copy is told: which file, the landing it names, and how to get a current one. */130+/**131+ * What a stale copy is told: which file, the landing it names, why it can132+ * differ (an older config or a hand edit; the copy alone can't say which),133+ * and how to get a current one.134+ */135 const staleNote = ({ landed, path }: StaleCopy) =>132- `${path} is out of date: ${Option.match(landed, {133- onNone: () => "it is not what main's config gives",134- onSome: (sha) =>135- `it was generated at ${sha}, and main's config now gives other text`,136- })}. The platform regenerates it whenever the config changes; pull main for the current copy instead of editing it.`;136+ `${path} differs from what main's config gives${Option.match(landed, {137+ onNone: () => "",138+ onSome: (sha) => ` (it says it was generated at ${sha})`,139+ })}: it was generated for an older config, or edited by hand. The platform regenerates it whenever the config changes; pull main for the current copy instead of editing it.`;140 141 /** The stale copies as `--json` lists them: absent when there are none. */142 const staleField = (stale: readonly StaleCopy[]) =>143 Array.match(stale, {535 unmodified linesmodified:apps/cli/src/local/stale.ts+5 added-4 removed
5 unmodified lines678910111210111213141516173 unmodified lines2122232424252627282957 unmodified lines5 unmodified lines * on disk. The platform lands them again whenever the config changes what * they say, so a copy that differs was generated for an older config, or * was edited by hand; `<cli> check` warns about each one and lists it. * * Read only: nothing here writes a file. A file that is missing, or one the * platform does not manage (a skill with no frontmatter of ours, an * AGENTS.md with no block), is no copy, and never stale. * Read only: nothing here writes a file. A missing file is no copy, and * never stale; nor is an AGENTS.md with no block, whose text is all the * project's own. A skill copy without the platform's frontmatter is stale: * its path is the platform's, so the frontmatter was taken off (`isStale`). */import { agentsBlock, upsertAgentsBlock } from "@repo/agent-kit/agents-block";import { isStale } from "@repo/agent-kit/generated-file";import { projectSkill } from "@repo/agent-kit/project-skill";3 unmodified lines
/** A generated file on disk that is not what main's policy gives, and the landing its copy names. */export interface StaleCopy { readonly path: string; /** The landing the copy says it came from; none for the AGENTS.md block, which names none. */ /** The landing the copy says it came from; none for the AGENTS.md block, which names none, and for a skill copy without frontmatter. */ readonly landed: Option.Option<LandedSha>;}
const agentsFile = "AGENTS.md";57 unmodified linesmodified:apps/cli/test/local/stale.test.ts+39 added-3 removed
111 unmodified lines112 expect(printed.envelope).toMatchObject({113 data: { stale: [{ landed: older, path: skill }] },114 ok: true,115 });116- expect(printed.err).toContain(`${skill} is out of date`);116+ expect(printed.err).toContain(117+ `${skill} differs from what main's config gives`118+ );119 expect(printed.err).toContain(older);120 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))121 );122 123 it.live(124+ "notes a contribute skill edited by hand since it was generated, naming the landing it came from",125+ () =>126+ Effect.gen(function* () {127+ const repo = yield* cleanRepo;128+ const policy = yield* policyAtMain(repo);129+130+ const [copy] = yield* projectSkill({131+ landed: older,132+ policy,133+ project: name,134+ });135+136+ yield* writeFile(137+ repo,138+ skill,139+ `${copy?.content ?? ""}\nOne more rule of our own.\n`140+ );141+142+ const printed = yield* checked(repo.root);143+144+ expect(printed.envelope).toMatchObject({145+ data: { stale: [{ landed: older, path: skill }] },146+ ok: true,147+ });148+ expect(printed.err).toContain(149+ `${skill} differs from what main's config gives (it says it was generated at ${older})`150+ );151+ expect(printed.err).toContain("edited by hand");152+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))153+ );154+155+ it.live(156 "notes an AGENTS.md block that is not the one main's policy gives",157 () =>158 Effect.gen(function* () {159 const repo = yield* cleanRepo;16 unmodified lines176 expect(printed.envelope).toMatchObject({177 data: { stale: [{ path: "AGENTS.md" }] },178 ok: true,179 });146- expect(printed.err).toContain("AGENTS.md");180+ expect(printed.err).toContain(181+ "AGENTS.md differs from what main's config gives"182+ );183 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))184 );185 186 it.live("says nothing of copies generated from main's policy", () =>37 unmodified lines224 },225 ok: true,226 v: 1,227 });192- expect(printed.err).not.toContain("out of date");228+ expect(printed.err).not.toContain("differs from");229 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))230 );231 });modified:apps/platform/test/generated.test.ts+125 added-12 removed
36 unmodified lines37 RequestId,38 TreeSha,39 } from "@repo/protocol/ids";40 import { Person } from "@repo/protocol/principal";41+import { RepoBusy, VerifierBlocked } from "@repo/protocol/refusal";42 import { RulesEvaluator } from "@repo/rules/rules-evaluator";43 import { advanceTo } from "@repo/testkit/clock";44 import { gitClient } from "@repo/testkit/git-client";45 import type { Files } from "@repo/testkit/git-client";46 import { aProject } from "@repo/testkit/scenarios";46-import { Context, Effect, Layer, Option, Schema } from "effect";47+import { Context, Effect, Exit, Layer, Option, Ref, Schema } from "effect";48 49 import { ProjectSkillGenerator } from "../src/workflows/generated.ts";50 51 const scenario = aProject();87 unmodified lines139 );140 })141 );142 143+/**144+ * What goes wrong with the next follow-up's land, once: nothing, a busy145+ * repo before anything is pushed, or a push that went through and whose146+ * answer was lost on the way back (a Lander call that timed out after it).147+ */148+type Mishap = "none" | "busy" | "lost";149+150+class Mishaps extends Context.Service<151+ Mishaps,152+ { readonly next: (mishap: Mishap) => Effect.Effect<void> }153+>()("test/Mishaps") {}154+155+/** W2's isomorphic-git Lander, with the next follow-up's mishap played on its land. */156+const mishapLander = Layer.effectContext(157+ Effect.gen(function* () {158+ const real = Context.get(yield* Layer.build(LanderIsogit), Lander);159+ const next = yield* Ref.make<Mishap>("none");160+161+ const land: Lander["Service"]["land"] = (job) =>162+ Effect.gen(function* () {163+ const mishap = job.requestId.startsWith("gen-")164+ ? yield* Ref.getAndSet(next, "none")165+ : "none";166+167+ if (mishap === "busy") {168+ return yield* new RepoBusy({});169+ }170+171+ const landed = yield* real.land(job);172+173+ return mishap === "lost" ? yield* new VerifierBlocked({}) : landed;174+ });175+176+ return Context.make(Lander, Lander.of({ ...real, land })).pipe(177+ Context.add(Mishaps, { next: (mishap) => Ref.set(next, mishap) })178+ );179+ })180+);181+182 /** Commits made the way git would make them, pushed to a repo's `main`. */183 class Pusher extends Context.Service<184 Pusher,185 {40 unmodified lines226 ).pipe(227 Layer.provideMerge(228 Layer.mergeAll(AnswerRunsInline, AlarmsMemory, ProjectionMemory, rules)229 ),190- Layer.provideMerge(Layer.merge(LanderIsogit, checker)),230+ Layer.provideMerge(Layer.merge(mishapLander, checker)),231 Layer.provideMerge(RepoHostMemory)232 );233 234 /** Where canonical `main` stands. */90 unmodified lines325 326 return { api, first };327 });328 289-/** alice lands a change of her own from her working fork: `files` on top of `base`. */329+/** alice's own change from her working fork, `files` on top of `base`, made ready to land. */330 const aliceLands = (base: LandedSha, files: Files, requestId: string) =>331 Effect.gen(function* () {332 const api = yield* Projects.use((each) => each.get(project)).pipe(333 Effect.orDie22 unmodified lines356 message: "Change the project",357 requestId: RequestId.make(requestId),358 };359 320- return {321- receipt: yield* api.land(alice, request).pipe(Effect.orDie),322- replay: () => api.land(alice, request).pipe(Effect.orDie),323- };360+ return { api, land: () => api.land(alice, request).pipe(Effect.orDie) };361 });362 363 const landedSha = (outcome: Outcome) =>364 Outcome.guards.Landed(outcome) ? Option.some(outcome.sha) : Option.none();2 unmodified lines367 it.effect(368 "follows the first push with a landing of the generated files alone, credited to the initializer",369 () =>370 Effect.gen(function* () {334- const { first } = yield* firstPushed;371+ const { api, first } = yield* firstPushed;372 const tip = yield* mainTip;373 374 expect(yield* followUpAt(tip)).toStrictEqual({375 author: authorLine(platformHandle),14 unmodified lines390 );391 expect(yield* textAt(tip, skill)).toStrictEqual(392 yield* textAt(tip, claudeSkill)393 );394+395+ // The same first push recorded again is still the project's first push.396+ expect(397+ yield* Effect.exit(api.recordFirstPush(alice, first))398+ ).toStrictEqual(Exit.succeed({ landed: first }));399+ expect(yield* mainTip).toBe(tip);400 }).pipe(Effect.provide(world))401 );402 403 it.effect(9 unmodified lines413 yield* filesAt(generatedOnce, withUnit),414 "land-alice-unit-lane"415 );416 374- const landed = Option.getOrThrow(landedSha(changed.receipt.outcome));417+ const landed = Option.getOrThrow(418+ landedSha((yield* changed.land()).outcome)419+ );420+421 const tip = yield* mainTip;422 423 expect(yield* changedBy(landed)).toStrictEqual([runFile]);424 expect(yield* followUpAt(tip)).toStrictEqual({7 unmodified lines432 expect(Option.getOrElse(yield* textAt(tip, skill), () => "")).toContain(433 "bun run test"434 );435 390- const replayed = yield* changed.replay();436+ const replayed = yield* changed.land();437 438 expect(landedSha(replayed.outcome)).toStrictEqual(Option.some(landed));439 expect(yield* mainTip).toBe(tip);440 }).pipe(Effect.provide(world))20 unmodified lines461 ),462 "land-alice-parse"463 );464 419- expect(yield* mainTip).toStrictEqual(420- Option.getOrThrow(landedSha(changed.receipt.outcome))465+ const landed = landedSha((yield* changed.land()).outcome);466+467+ expect(Option.some(yield* mainTip)).toStrictEqual(landed);468+ }).pipe(Effect.provide(world))469+ );470+471+ it.effect(472+ "leaves the landing it follows standing when the follow-up could not land",473+ () =>474+ Effect.gen(function* () {475+ yield* firstPushed;476+477+ const generatedOnce = yield* mainTip;478+479+ const changed = yield* aliceLands(480+ generatedOnce,481+ yield* filesAt(generatedOnce, withUnit),482+ "land-alice-unit-lane"483 );484+485+ yield* Mishaps.use((each) => each.next("busy"));486+487+ const landed = landedSha((yield* changed.land()).outcome);488+489+ expect(Option.some(yield* mainTip)).toStrictEqual(landed);490+ expect(yield* changedBy(Option.getOrThrow(landed))).toStrictEqual([491+ runFile,492+ ]);493 }).pipe(Effect.provide(world))494 );495+496+ it.effect(497+ "fails the call when the follow-up reached main but its answer was lost, and the call run again records both landings",498+ () =>499+ Effect.gen(function* () {500+ yield* firstPushed;501+502+ const generatedOnce = yield* mainTip;503+504+ const changed = yield* aliceLands(505+ generatedOnce,506+ yield* filesAt(generatedOnce, withUnit),507+ "land-alice-unit-lane"508+ );509+510+ yield* Mishaps.use((each) => each.next("lost"));511+512+ const lost = yield* Effect.exit(changed.land());513+ const tip = yield* mainTip;514+ const followed = yield* followUpAt(tip);515+ const again = yield* changed.land();516+517+ expect({518+ followed: followed.requestId,519+ lost: Exit.isFailure(lost),520+ main: yield* mainTip,521+ }).toStrictEqual({522+ followed: `gen-${followed.parent}`,523+ lost: true,524+ main: tip,525+ });526+ expect(landedSha(again.outcome)).toStrictEqual(527+ Option.some(followed.parent)528+ );529+530+ const recorded = yield* changed.api531+ .landing(alice, tip)532+ .pipe(Effect.orDie);533+534+ expect(recorded.landing.requestId).toBe(`gen-${followed.parent}`);535+ }).pipe(Effect.provide(world))536+ );537 });modified:packages/project/src/project.ts+113 added-49 removed
1519 unmodified lines1520 Effect.orDie1521 );1522 1523 /**1524- * After a call moved the landed SHA (the first adoption, an answer, a1525- * decider's own landing, an ask opened, a vouch): the platform's own1526- * landing of the regenerated contribute skill and AGENTS.md block on1527- * top, when the policy read at the new landed SHA changes what they say1528- * (spec D12, W4 410). It never joins the landing that changed the config1529- * ("land only the checked tree"): its files are composed onto main and1530- * landed through the Lander, a compare-and-swap push of `main` then the1531- * mirror, as every platform landing is, under the project's lock, with1532- * the request id `gen-<landed>`, so a replay finds its commit. It is1533- * recorded in the same commit as the landing it follows. It is1534- * bookkeeping: one that cannot land is logged, and the landing it follows1535- * stands; the next landing that changes the config writes the files1536- * again.1524+ * The platform's own landing of the regenerated files on top of1525+ * `landed`, recorded with the landing it follows: the files composed1526+ * onto main and landed through the Lander, a compare-and-swap push of1527+ * `main` then the mirror, as every platform landing is, with the request1528+ * id `gen-<landed>`, so a replay finds its commit.1529 */1538- const followUp = (h: Hydrated, writes: Writes, now: DateTime.Utc) =>1530+ const landFollowUp = (input: {1531+ readonly h: Hydrated;1532+ readonly landed: LandedSha;1533+ readonly landing: LandingView;1534+ readonly now: DateTime.Utc;1535+ /** The policy read at `landed`, encoded as the row holds it. */1536+ readonly policy: Exclude<ProjectRow["policy"], undefined>;1537+ readonly row: ProjectRow;1538+ readonly writes: Writes;1539+ }) =>1540 Effect.gen(function* () {1540- const row = writes.project.get("row");1541- const landed = row?.landed;1541+ const { h, landed, landing, now, row, writes } = input;1542 1543- if (1544- row?.policy === undefined ||1545- landed === undefined ||1546- row.policyAt !== landed ||1547- Option.exists(h.project, (before) => before.landed === landed)1548- ) {1549- return;1550- }1551-1552- const requestId = generatedRequestId(landed);1553- const landing = writes.landings.find(({ sha }) => sha === landed);1554-1555- const followed = [...h.landings, ...writes.landings].some(1556- (each) => each.requestId === requestId1557- );1558-1559- if (landing === undefined || followed) {1560- return;1561- }1562-1543 const made = yield* generatedFollowUp(1544 {1565- after: yield* Effect.orDie(decodePolicy(row.policy)),1545+ after: yield* Effect.orDie(decodePolicy(input.policy)),1546 before: h.policy,1547 initializer: row.initializer,1548 landing,1549 project: name,5 unmodified lines1555 if (Option.isNone(made)) {1556 return;1557 }1558 1579- const { author, credits, message } = made.value;1559+ const { author, credits, message, requestId } = made.value;1560 1561 const files = Array.map(made.value.files, ({ content, path }) => ({1562 content,1563 path: RepoPath.make(path),29 unmodified lines1593 writes.events.push(1594 ProjectEventInput.Landed({ at: now, landing: view })1595 );1596 writes.project.set("row", moved);1617- }).pipe(1618- Effect.catchCause((cause) =>1619- Cause.hasInterruptsOnly(cause)1620- ? Effect.interrupt1621- : Effect.logWarning(1622- "the regenerated contribute skill and AGENTS.md block did not land",1623- cause1624- )1625- )1626- );1597+ });1598 1599 /**1600+ * A follow-up that did not land. When canonical `main` still stands at1601+ * `landed`, nothing of it reached main: the landing it follows stands,1602+ * and the failure is logged. When main moved on (the push went through1603+ * and the Lander's answer was lost), or where it stands can't be read,1604+ * the call fails and commits nothing, so the project's landed SHA never1605+ * falls behind main: the same call run again finds both commits by their1606+ * request ids.1607+ */1608+ const unlanded = <E>(landed: LandedSha, cause: Cause.Cause<E>) =>1609+ Effect.gen(function* () {1610+ const refs = yield* Effect.option(host.refs(repo));1611+1612+ if (Option.exists(refs, (all) => all.get(mainRef) === landed)) {1613+ return yield* Effect.logWarning(1614+ "the regenerated contribute skill and AGENTS.md block did not land",1615+ cause1616+ );1617+ }1618+1619+ yield* Effect.logError(1620+ `main moved past ${landed} while the regenerated files landed: the call records nothing, so it can run again`,1621+ cause1622+ );1623+1624+ return yield* Effect.orDie(Effect.failCause(cause));1625+ });1626+1627+ /**1628+ * After a call moved the landed SHA (the first adoption, an answer, a1629+ * decider's own landing, an ask opened, a vouch): the platform's own1630+ * landing of the regenerated contribute skill and AGENTS.md block on1631+ * top, when the policy read at the new landed SHA changes what they say1632+ * (spec D12, W4 410). It never joins the landing that changed the config1633+ * ("land only the checked tree"), and it is recorded in the same commit1634+ * as the landing it follows, under the project's lock. It is1635+ * bookkeeping: one that cannot land is logged, and the landing it follows1636+ * stands; the next landing that changes the config writes the files1637+ * again (`unlanded`).1638+ */1639+ const followUp = (h: Hydrated, writes: Writes, now: DateTime.Utc) =>1640+ Effect.gen(function* () {1641+ const row = writes.project.get("row");1642+ const landed = row?.landed;1643+ const policy = row?.policy;1644+1645+ if (1646+ row === undefined ||1647+ policy === undefined ||1648+ landed === undefined ||1649+ row.policyAt !== landed ||1650+ Option.exists(h.project, (before) => before.landed === landed)1651+ ) {1652+ return;1653+ }1654+1655+ const requestId = generatedRequestId(landed);1656+ const landing = writes.landings.find(({ sha }) => sha === landed);1657+1658+ const followed = [...h.landings, ...writes.landings].some(1659+ (each) => each.requestId === requestId1660+ );1661+1662+ if (landing === undefined || followed) {1663+ return;1664+ }1665+1666+ yield* landFollowUp({1667+ h,1668+ landed,1669+ landing,1670+ now,1671+ policy,1672+ row,1673+ writes,1674+ }).pipe(1675+ Effect.catchCause((cause) =>1676+ Cause.hasInterruptsOnly(cause)1677+ ? Effect.interrupt1678+ : unlanded(landed, cause)1679+ )1680+ );1681+ });1682+1683+ /**1684 * One call that writes (`writeLocked`), with the generated follow-up of1685 * any landing the body recorded, in the same commit.1686 */1687 const write = <A, E>(612 unmodified lines2300 }2301 2302 const landed = LandedSha.make(head);2303 2304+ // The same first push again: still the project's adoption (the one2305+ // landing with no parent), whatever the platform landed on top of2306+ // it since, such as the regenerated contribute skill.2307 if (row.state === "live") {2308+ const adopted = h.landings.some(2309+ ({ parent, sha }) => sha === landed && parent === undefined2310+ );2311+2250- return row.landed === landed ? { landed } : yield* refused;2312+ return row.landed === landed || adopted2313+ ? { landed }2314+ : yield* refused;2315 }2316 2317 writes.landings.push(adoption(row.initializer, landed, now));2318 writes.project.set(1128 unmodified linesmodified:packages/project/test/generated.test.ts+13 added-9 removed
6 unmodified lines7 import { aProject } from "@repo/testkit/scenarios";8 import { DateTime, Effect, Option, Schema } from "effect";9 10 import { platformHandle } from "../src/attention/effects.ts";11-import { generatedFollowUp, generatedRequestId } from "../src/generated.ts";11+import { generatedFollowUp } from "../src/generated.ts";12 import type { Generate } from "../src/generated.ts";13 14 const scenario = aProject({ deciders: ["alice", "dora"], people: ["bob"] });15 280 unmodified lines296 { handle: dora, role: "Decided-by" },297 ],298 };299 300+ const doraLands: LandingView = {301+ ...aliceLands,302+ author: dora,303+ credits: [{ handle: dora, role: "Signed-off-by" }],304+ };305+306 const bobAlone: LandingView = {307 ...aliceLands,308 author: bob,309 credits: [{ handle: bob, role: "Signed-off-by" }],310 };311 312 expect({307- bob: yield* creditOf(bobAlone),308- dora: yield* creditOf(decidedByDora),313+ decidedBy: yield* creditOf(decidedByDora),314+ deciderAuthor: yield* creditOf(doraLands),315+ neither: yield* creditOf(bobAlone),316 }).toStrictEqual({310- bob: Option.some([{ handle: alice, role: "Decided-by" }]),311- dora: Option.some([{ handle: dora, role: "Decided-by" }]),317+ decidedBy: Option.some([{ handle: dora, role: "Decided-by" }]),318+ deciderAuthor: Option.some([{ handle: dora, role: "Decided-by" }]),319+ neither: Option.some([{ handle: alice, role: "Decided-by" }]),320 });321 })322 );315-316- it("names its request for the landing it follows", () => {317- expect(generatedRequestId(landed)).toBe(`gen-${landed}`);318- });323 });