Skip to content
Myr

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.

authored by oscabriel · committed by oscabriel · parent a30d422 · Browse files · 6 files+304 added−83 removed
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

6 files+304 added−83 removed

modified:apps/cli/src/local/check.ts+9 added-6 removed
125 unmodified lines
126 Effect.fail(new Reported())127 )128 );129130/** 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 */135const 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.`;140141/** The stale copies as `--json` lists them: absent when there are none. */142const staleField = (stale: readonly StaleCopy[]) =>143 Array.match(stale, {
535 unmodified lines
modified:apps/cli/src/local/stale.ts+5 added-4 removed
modified:apps/cli/test/local/stale.test.ts+39 added-3 removed
111 unmodified lines
112 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 );122123 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);129130 const [copy] = yield* projectSkill({131 landed: older,132 policy,133 project: name,134 });135136 yield* writeFile(137 repo,138 skill,139 `${copy?.content ?? ""}\nOne more rule of our own.\n`140 );141142 const printed = yield* checked(repo.root);143144 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 );154155 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 lines
176 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 );185186 it.live("says nothing of copies generated from main's policy", () =>
37 unmodified lines
224 },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 lines
37 RequestId,38 TreeSha,39} from "@repo/protocol/ids";40import { Person } from "@repo/protocol/principal";41import { RepoBusy, VerifierBlocked } from "@repo/protocol/refusal";42import { RulesEvaluator } from "@repo/rules/rules-evaluator";43import { advanceTo } from "@repo/testkit/clock";44import { gitClient } from "@repo/testkit/git-client";45import type { Files } from "@repo/testkit/git-client";46import { aProject } from "@repo/testkit/scenarios";46import { Context, Effect, Layer, Option, Schema } from "effect";47import { Context, Effect, Exit, Layer, Option, Ref, Schema } from "effect";4849import { ProjectSkillGenerator } from "../src/workflows/generated.ts";5051const scenario = aProject();
87 unmodified lines
139 );140 })141);142143/**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 */148type Mishap = "none" | "busy" | "lost";149150class Mishaps extends Context.Service<151 Mishaps,152 { readonly next: (mishap: Mishap) => Effect.Effect<void> }153>()("test/Mishaps") {}154155/** W2's isomorphic-git Lander, with the next follow-up's mishap played on its land. */156const 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");160161 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";166167 if (mishap === "busy") {168 return yield* new RepoBusy({});169 }170171 const landed = yield* real.land(job);172173 return mishap === "lost" ? yield* new VerifierBlocked({}) : landed;174 });175176 return Context.make(Lander, Lander.of({ ...real, land })).pipe(177 Context.add(Mishaps, { next: (mishap) => Ref.set(next, mishap) })178 );179 })180);181182/** Commits made the way git would make them, pushed to a repo's `main`. */183class Pusher extends Context.Service<184 Pusher,185 {
40 unmodified lines
226).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);233234/** Where canonical `main` stands. */
90 unmodified lines
325326 return { api, first };327});328289/** 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. */330const aliceLands = (base: LandedSha, files: Files, requestId: string) =>331 Effect.gen(function* () {332 const api = yield* Projects.use((each) => each.get(project)).pipe(333 Effect.orDie
22 unmodified lines
356 message: "Change the project",357 requestId: RequestId.make(requestId),358 };359320 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 });362363const landedSha = (outcome: Outcome) =>364 Outcome.guards.Landed(outcome) ? Option.some(outcome.sha) : Option.none();
2 unmodified lines
367 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;373374 expect(yield* followUpAt(tip)).toStrictEqual({375 author: authorLine(platformHandle),
14 unmodified lines
390 );391 expect(yield* textAt(tip, skill)).toStrictEqual(392 yield* textAt(tip, claudeSkill)393 );394395 // 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 );402403 it.effect(
9 unmodified lines
413 yield* filesAt(generatedOnce, withUnit),414 "land-alice-unit-lane"415 );416374 const landed = Option.getOrThrow(landedSha(changed.receipt.outcome));417 const landed = Option.getOrThrow(418 landedSha((yield* changed.land()).outcome)419 );420421 const tip = yield* mainTip;422423 expect(yield* changedBy(landed)).toStrictEqual([runFile]);424 expect(yield* followUpAt(tip)).toStrictEqual({
7 unmodified lines
432 expect(Option.getOrElse(yield* textAt(tip, skill), () => "")).toContain(433 "bun run test"434 );435390 const replayed = yield* changed.replay();436 const replayed = yield* changed.land();437438 expect(landedSha(replayed.outcome)).toStrictEqual(Option.some(landed));439 expect(yield* mainTip).toBe(tip);440 }).pipe(Effect.provide(world))
20 unmodified lines
461 ),462 "land-alice-parse"463 );464419 expect(yield* mainTip).toStrictEqual(420 Option.getOrThrow(landedSha(changed.receipt.outcome))465 const landed = landedSha((yield* changed.land()).outcome);466467 expect(Option.some(yield* mainTip)).toStrictEqual(landed);468 }).pipe(Effect.provide(world))469 );470471 it.effect(472 "leaves the landing it follows standing when the follow-up could not land",473 () =>474 Effect.gen(function* () {475 yield* firstPushed;476477 const generatedOnce = yield* mainTip;478479 const changed = yield* aliceLands(480 generatedOnce,481 yield* filesAt(generatedOnce, withUnit),482 "land-alice-unit-lane"483 );484485 yield* Mishaps.use((each) => each.next("busy"));486487 const landed = landedSha((yield* changed.land()).outcome);488489 expect(Option.some(yield* mainTip)).toStrictEqual(landed);490 expect(yield* changedBy(Option.getOrThrow(landed))).toStrictEqual([491 runFile,492 ]);493 }).pipe(Effect.provide(world))494 );495496 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;501502 const generatedOnce = yield* mainTip;503504 const changed = yield* aliceLands(505 generatedOnce,506 yield* filesAt(generatedOnce, withUnit),507 "land-alice-unit-lane"508 );509510 yield* Mishaps.use((each) => each.next("lost"));511512 const lost = yield* Effect.exit(changed.land());513 const tip = yield* mainTip;514 const followed = yield* followUpAt(tip);515 const again = yield* changed.land();516517 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 );529530 const recorded = yield* changed.api531 .landing(alice, tip)532 .pipe(Effect.orDie);533534 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 lines
1520 Effect.orDie1521 );15221523 /**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;15421543 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 }15511552 const requestId = generatedRequestId(landed);1553 const landing = writes.landings.find(({ sha }) => sha === landed);15541555 const followed = [...h.landings, ...writes.landings].some(1556 (each) => each.requestId === requestId1557 );15581559 if (landing === undefined || followed) {1560 return;1561 }15621543 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 lines
1555 if (Option.isNone(made)) {1556 return;1557 }15581579 const { author, credits, message } = made.value;1559 const { author, credits, message, requestId } = made.value;15601561 const files = Array.map(made.value.files, ({ content, path }) => ({1562 content,1563 path: RepoPath.make(path),
29 unmodified lines
1593 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 });15981599 /**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));16111612 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 }16181619 yield* Effect.logError(1620 `main moved past ${landed} while the regenerated files landed: the call records nothing, so it can run again`,1621 cause1622 );16231624 return yield* Effect.orDie(Effect.failCause(cause));1625 });16261627 /**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;16441645 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 }16541655 const requestId = generatedRequestId(landed);1656 const landing = writes.landings.find(({ sha }) => sha === landed);16571658 const followed = [...h.landings, ...writes.landings].some(1659 (each) => each.requestId === requestId1660 );16611662 if (landing === undefined || followed) {1663 return;1664 }16651666 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 });16821683 /**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 lines
2300 }23012302 const landed = LandedSha.make(head);23032304 // 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 );23112250 return row.landed === landed ? { landed } : yield* refused;2312 return row.landed === landed || adopted2313 ? { landed }2314 : yield* refused;2315 }23162317 writes.landings.push(adoption(row.initializer, landed, now));2318 writes.project.set(
1128 unmodified lines
modified:packages/project/test/generated.test.ts+13 added-9 removed
6 unmodified lines
7import { aProject } from "@repo/testkit/scenarios";8import { DateTime, Effect, Option, Schema } from "effect";910import { platformHandle } from "../src/attention/effects.ts";11import { generatedFollowUp, generatedRequestId } from "../src/generated.ts";11import { generatedFollowUp } from "../src/generated.ts";12import type { Generate } from "../src/generated.ts";1314const scenario = aProject({ deciders: ["alice", "dora"], people: ["bob"] });15
280 unmodified lines
296 { handle: dora, role: "Decided-by" },297 ],298 };299300 const doraLands: LandingView = {301 ...aliceLands,302 author: dora,303 credits: [{ handle: dora, role: "Signed-off-by" }],304 };305306 const bobAlone: LandingView = {307 ...aliceLands,308 author: bob,309 credits: [{ handle: bob, role: "Signed-off-by" }],310 };311312 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 );315316 it("names its request for the landing it follows", () => {317 expect(generatedRequestId(landed)).toBe(`gen-${landed}`);318 });323});