@chernabog/recipes 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/flows/epic.ts CHANGED
@@ -4,7 +4,9 @@
4
4
  // branch of the one task it builds on. Tasks that don't build on each other
5
5
  // run at once. A stack is only pull requests whose base is the branch of the
6
6
  // one below: no rebase, no force-push. Between rounds the run keeps one
7
- // status comment on the epic, and parks until a layer's pull request changes;
7
+ // status comment on the epic, and parks until a layer's pull request changes,
8
+ // recording that it waits, with what it knows, on the epic's record, so the
9
+ // run that takes the epic up then carries on from there;
8
10
  // each layer's review, changes and conflicts are the review, address-review,
9
11
  // re-review and resolve-conflicts flows' to do. When a layer's head moves, as
10
12
  // a fix pushed on it does, the run carries the change up its stack: it merges
@@ -28,7 +30,7 @@
28
30
 
29
31
  import {
30
32
  activity,
31
- awaitSignal,
33
+ Blocks,
32
34
  Claims,
33
35
  defineFlow,
34
36
  Epic,
@@ -37,6 +39,7 @@ import {
37
39
  GitHub,
38
40
  Implement,
39
41
  Lanes,
42
+ Phases,
40
43
  Plan,
41
44
  PullRequest,
42
45
  Repo,
@@ -46,6 +49,7 @@ import {
46
49
  Run,
47
50
  Settings,
48
51
  Stack,
52
+ StatusLabels,
49
53
  Worktree,
50
54
  } from "@chernabog/sdk";
51
55
  import * as Effect from "effect/Effect";
@@ -55,10 +59,6 @@ import * as Schema from "effect/Schema";
55
59
  // Tasks implemented at once, unless the flow's atOnce setting says otherwise.
56
60
  const AT_ONCE = 2;
57
61
 
58
- // How long the run parks before it looks at the epic again with no signal,
59
- // for what changes no layer: a person's task closed, say.
60
- const LOOK_AGAIN_AFTER = "1 day";
61
-
62
62
  // What config.yaml may set for this flow alone, under flows.<name>.settings.
63
63
  const Own = Schema.Struct({
64
64
  atOnce: Schema.optionalKey(
@@ -112,7 +112,7 @@ const queuedAs = (ships: boolean) =>
112
112
  // Lets the task's claim go once its attempt ends with a person, as a step of
113
113
  // the attempt's own, so a later attempt lets it go again.
114
114
  const releaseTask = (issue: number, id: string) =>
115
- activity(`release-claim#${id}`, Claims.release(Claims.issue(issue)));
115
+ activity(`release-claim#${id}`, StatusLabels.release(Claims.issue(issue)));
116
116
 
117
117
  // Where a stacked task's pull request goes once its work is done, as the step
118
118
  // `task-base#<id>`: its base, or, when the layer below merged while the task
@@ -272,13 +272,31 @@ const implementTask = (
272
272
 
273
273
  pullRequest = Option.some(opened.number);
274
274
 
275
- yield* Implement.waitForCi(
275
+ // A lane can't park on its own: CI still pending ends it, recorded on
276
+ // the task's own record, and a later round, or the run that takes the
277
+ // parked epic up, takes the task up once CI settles (Epic.takeUpCi).
278
+ const left = yield* Implement.waitForCiLeaving(
276
279
  opened.number,
277
280
  worktree,
278
281
  { ...session, branch, base: openedOn },
279
282
  { id },
280
283
  );
281
284
 
285
+ if (Option.isSome(left)) {
286
+ yield* Epic.leftOnCi(
287
+ {
288
+ issue,
289
+ pullRequest: opened.number,
290
+ lane: id,
291
+ branch,
292
+ base: openedOn,
293
+ },
294
+ left.value,
295
+ );
296
+
297
+ return `#${issue}: waits on CI for #${opened.number}`;
298
+ }
299
+
282
300
  return yield* Implement.handOff(issue, opened, outcome, { needsReview: true, id });
283
301
  }).pipe(
284
302
  Effect.catchTags({
@@ -304,8 +322,8 @@ const implementTask = (
304
322
  // What the run reads of a stacked layer before it carries the layers below up
305
323
  // to it, as the step `stack-base-<round>#<pull request>`: the branch it is
306
324
  // built on and that branch's head, none once it is gone, and whether a person
307
- // has the layer. The saved head is the layer's recorded base, so a replay
308
- // compares as the run first did.
325
+ // has the layer, by its pull request's record. The saved head is the layer's
326
+ // recorded base, so a replay compares as the run first did.
309
327
  const StackBase = Schema.Struct({
310
328
  base: Schema.String,
311
329
  baseSha: Schema.Option(Schema.String),
@@ -317,13 +335,12 @@ const readBase = (round: number, pullRequest: number) =>
317
335
  `stack-base-${round}#${pullRequest}`,
318
336
  Effect.gen(function* () {
319
337
  const github = yield* GitHub;
320
- const labelNames = yield* Settings.labels;
321
338
  const pull = yield* github.pullRequest(pullRequest);
322
339
 
323
340
  return {
324
341
  base: pull.baseRef,
325
342
  baseSha: yield* github.branchSha(pull.baseRef),
326
- withPerson: pull.labels.includes(labelNames.needsHuman),
343
+ withPerson: yield* Phases.withPerson(Phases.pullRequestItem(pullRequest)),
327
344
  };
328
345
  }).pipe(
329
346
  // A pull request gone under the run leaves nothing to bring up to date.
@@ -359,33 +376,32 @@ const refreshWorktree = (branch: string, key: string, attempt: number) =>
359
376
  Schema.String,
360
377
  );
361
378
 
362
- // Hands a layer whose refresh needs a person to one: labelled auto:needs-human,
363
- // with the reason. Keyed by the refresh, so a later one goes to a person too.
364
- const refreshToPerson = (pullRequest: number, key: string, reason: string) =>
365
- activity(
366
- `needs-human#refresh-${key}`,
367
- Effect.gen(function* () {
368
- const github = yield* GitHub;
369
- const labelNames = yield* Settings.labels;
370
- yield* github.addLabel(pullRequest, labelNames.needsHuman);
371
- yield* github.comment(
372
- pullRequest,
373
- `Chernabog stopped bringing this layer up to date with its base and needs a person: ${reason}`,
374
- );
375
- }),
376
- ).pipe(Effect.as(`#${pullRequest}: ${reason}`));
377
-
378
379
  // What one refresh did: whether the layer was carried, whether it pushed,
379
- // and whether it went to a person.
380
- type Carried = { readonly carried: boolean; readonly pushed: boolean; readonly toPerson: boolean };
380
+ // whether it went to a person, and the CI it left pending, whose review waits
381
+ // for it to settle.
382
+ type Carried = {
383
+ readonly carried: boolean;
384
+ readonly pushed: boolean;
385
+ readonly toPerson: boolean;
386
+ readonly left: Option.Option<Epic.PendingRefresh>;
387
+ };
381
388
 
382
389
  // Brings one layer up to date with its base at `baseSha` (Stack.refreshLayer):
383
390
  // merges it in, adjusts the layer when the base changed what it builds on,
384
391
  // pushes and waits for CI. `lower`, once the layer below has merged, is its
385
392
  // pull request, so a squash of it is reconciled rather than merged again. One that needs a person is handed to one, and
386
- // reads as not carried, so the layers above it wait. Every step is keyed by
393
+ // reads as not carried, so the layers above it wait. CI still pending ends
394
+ // the refresh (audit W7), which records what it left on the layer's pull
395
+ // request (Epic.leaveRefresh) and carries it. Every step is keyed by
387
396
  // the pull request, the base's sha and, after a hand-back, the attempt, so the
388
397
  // refresh after one runs again rather than replaying the outcome it saved.
398
+ const notCarried: Carried = {
399
+ carried: false,
400
+ pushed: false,
401
+ toPerson: false,
402
+ left: Option.none(),
403
+ };
404
+
389
405
  const refresh = (
390
406
  layer: Epic.Layer,
391
407
  pullRequest: number,
@@ -402,24 +418,42 @@ const refresh = (
402
418
  const key = `${pullRequest}-${baseSha.slice(0, 12)}${again}`;
403
419
 
404
420
  const toPerson = (reason: string) =>
405
- refreshToPerson(pullRequest, key, reason).pipe(
406
- Effect.as<Carried>({ carried: false, pushed: false, toPerson: true }),
421
+ Stack.refreshToPerson(pullRequest, key, reason).pipe(
422
+ Effect.as<Carried>({ carried: false, pushed: false, toPerson: true, left: Option.none() }),
407
423
  );
408
424
 
409
425
  return Effect.gen(function* () {
410
426
  const branch = Claims.branchFor(layer.number);
411
427
  const worktree = yield* refreshWorktree(branch, key, attempt);
412
428
 
429
+ const below = Option.match(lower, {
430
+ onNone: () => ({}),
431
+ onSome: (on) => ({ lower: on }),
432
+ });
433
+
434
+ const which = { layer: layer.number, pullRequest, baseSha, ...below };
435
+
413
436
  const refreshed = yield* Stack.refreshLayer(worktree, {
414
437
  pullRequest,
415
438
  branch,
416
439
  base,
417
440
  baseSha,
418
441
  attempt,
419
- ...Option.match(lower, { onNone: () => ({}), onSome: (below) => ({ lower: below }) }),
442
+ ...below,
443
+ leave: true,
420
444
  });
421
445
 
422
- return { carried: true, pushed: !refreshed.upToDate, toPerson: false } satisfies Carried;
446
+ const left = yield* Option.match(refreshed.left, {
447
+ onNone: () => Effect.succeedNone,
448
+ onSome: (found) => Effect.asSome(Epic.leaveRefresh(`refresh-ci-record-${key}`, which, found)),
449
+ });
450
+
451
+ return {
452
+ carried: true,
453
+ pushed: !refreshed.upToDate,
454
+ toPerson: false,
455
+ left,
456
+ } satisfies Carried;
423
457
  }).pipe(
424
458
  Effect.catchTags({
425
459
  NeedsHuman: (needsHuman) => toPerson(needsHuman.reason),
@@ -428,9 +462,8 @@ const refresh = (
428
462
  PushRejected: (rejected) => toPerson(rejected.message),
429
463
  CiTimedOut: (timedOut) => toPerson(timedOut.message),
430
464
  // A layer closed or gone under the run has nothing above it to carry.
431
- PullRequestClosed: () =>
432
- Effect.succeed<Carried>({ carried: false, pushed: false, toPerson: false }),
433
- NotFound: () => Effect.succeed<Carried>({ carried: false, pushed: false, toPerson: false }),
465
+ PullRequestClosed: () => Effect.succeed<Carried>(notCarried),
466
+ NotFound: () => Effect.succeed<Carried>(notCarried),
434
467
  }),
435
468
  );
436
469
  };
@@ -468,33 +501,102 @@ const stackedLayers = (progress: Epic.Progress) => {
468
501
  // them, by pull request: the base head it last brought each layer up to, its
469
502
  // refresh attempt, the layers whose refresh it handed to a person, the layer
470
503
  // below each was last seen stacked on, and the layers it has brought up to
471
- // date with that one's merge. Rebuilt from the rounds' saved results
472
- // whenever the run resumes.
504
+ // date with that one's merge, and the refreshes left on pending CI, as this
505
+ // round reads their records. Rebuilt from the rounds' saved results whenever
506
+ // the run resumes.
473
507
  type Upkeep = {
474
508
  readonly attempts: Map<number, number>;
475
509
  readonly recorded: Map<number, string>;
476
510
  readonly withPerson: Set<number>;
477
511
  readonly below: Map<number, number>;
478
512
  readonly caughtUp: Set<number>;
513
+ // Refreshes left on their pull request's pending CI, by their records:
514
+ // never kept in the epic's own.
515
+ readonly ci: Array<Epic.PendingRefresh>;
479
516
  };
480
517
 
518
+ // The upkeep a run parked with kept, or a fresh one.
519
+ const upkeepFrom = (kept: Option.Option<Epic.LayerKeep>): Upkeep =>
520
+ Option.match(kept, {
521
+ onNone: () => ({
522
+ attempts: new Map(),
523
+ recorded: new Map(),
524
+ withPerson: new Set(),
525
+ below: new Map(),
526
+ caughtUp: new Set(),
527
+ ci: [],
528
+ }),
529
+ onSome: (found) => ({
530
+ attempts: new Map(found.attempts),
531
+ recorded: new Map(found.recorded),
532
+ // This run's own: the pull request's record says who has it.
533
+ withPerson: new Set(),
534
+ below: new Map(found.below),
535
+ caughtUp: new Set(found.caughtUp),
536
+ ci: [],
537
+ }),
538
+ });
539
+
540
+ // The upkeep as the epic's waiting record keeps it: the refreshes left on
541
+ // pending CI, and who has a layer, are on their pull requests' records.
542
+ const keptOf = (upkeep: Upkeep): Epic.LayerKeep => ({
543
+ attempts: [...upkeep.attempts],
544
+ recorded: [...upkeep.recorded],
545
+ below: [...upkeep.below],
546
+ caughtUp: [...upkeep.caughtUp],
547
+ });
548
+
549
+ // Takes up the refreshes left on pending CI whose CI has settled, or run
550
+ // past ciTimeout (Epic.takeUpRefreshes), into `upkeep`: one green and
551
+ // reviewed is carried, as a refresh that waited would have been, and one
552
+ // that went to a person waits for them. Whether it took any up.
553
+ const settleRefreshes = (round: number, epic: number, upkeep: Upkeep) =>
554
+ Effect.gen(function* () {
555
+ const settled = yield* Epic.takeUpRefreshes(round, epic);
556
+ upkeep.ci.splice(0, upkeep.ci.length, ...settled.pending);
557
+
558
+ // One that caught up with the merge of the layer below, or with its base.
559
+ for (const carried of settled.carried) {
560
+ Option.match(Option.fromUndefinedOr(carried.lower), {
561
+ onNone: () => upkeep.recorded.set(carried.pullRequest, carried.baseSha),
562
+ onSome: () => upkeep.caughtUp.add(carried.pullRequest),
563
+ });
564
+ }
565
+
566
+ for (const pullRequest of settled.withPerson) {
567
+ upkeep.withPerson.add(pullRequest);
568
+ }
569
+
570
+ return settled.taken;
571
+ });
572
+
573
+ // Whether a layer waits this round: the one below it waits, or its own
574
+ // refresh waits on CI.
575
+ const heldBack = (layer: Epic.Layer, waiting: ReadonlySet<number>, upkeep: Upkeep) =>
576
+ Option.exists(Option.fromUndefinedOr(layer.stackedOn), (below) => waiting.has(below)) ||
577
+ upkeep.ci.some((left) => left.pullRequest === layer.pullRequest);
578
+
481
579
  // Carries each layer's change up its stack, bottom to top: a layer whose base
482
580
  // branch's head is not the one it was last brought up to is refreshed, then
483
581
  // the one above it reads its own base, now moved too. A layer a person has,
484
582
  // or whose refresh went to one, waits, and so do the layers above it; the
485
583
  // rest of the epic carries on. A layer the run handed to a person and that
486
584
  // no longer carries auto:needs-human is handed back: its next refresh is a
487
- // new attempt. Whether anything was pushed.
488
- const carryUp = (round: number, progress: Epic.Progress, upkeep: Upkeep) =>
585
+ // new attempt. A refresh whose CI is still pending ends there (audit W7): the
586
+ // layer and those above it wait, and its review waits too, until a round
587
+ // takes it up once CI settles, first thing (settleRefreshes). Whether
588
+ // anything was pushed, or taken up.
589
+ const carryUp = (round: number, epic: number, progress: Epic.Progress, upkeep: Upkeep) =>
489
590
  Effect.gen(function* () {
490
591
  const { attempts, recorded, withPerson } = upkeep;
491
592
  const waiting = new Set<number>();
492
- let pushed = false;
593
+ // A refresh left on pending CI that has settled is taken up first.
594
+ let pushed = yield* settleRefreshes(round, epic, upkeep);
493
595
 
494
596
  for (const layer of stackedLayers(progress)) {
495
597
  const pullRequest = layer.pullRequest ?? 0;
496
598
 
497
- if (Option.exists(Option.fromUndefinedOr(layer.stackedOn), (below) => waiting.has(below))) {
599
+ if (heldBack(layer, waiting, upkeep)) {
498
600
  waiting.add(layer.number);
499
601
  continue;
500
602
  }
@@ -528,6 +630,14 @@ const carryUp = (round: number, progress: Epic.Progress, upkeep: Upkeep) =>
528
630
  continue;
529
631
  }
530
632
 
633
+ // Its CI still pending: the layers above wait, and a later round takes it up.
634
+ if (Option.isSome(refreshed.left)) {
635
+ upkeep.ci.push(refreshed.left.value);
636
+ waiting.add(layer.number);
637
+ pushed = true;
638
+ continue;
639
+ }
640
+
531
641
  recorded.set(pullRequest, baseSha);
532
642
  pushed = pushed || refreshed.pushed;
533
643
  }
@@ -537,7 +647,7 @@ const carryUp = (round: number, progress: Epic.Progress, upkeep: Upkeep) =>
537
647
 
538
648
  // What the run reads of a layer before it lands it, as the step
539
649
  // `land-read-<round>#<pull request>`: the branch it is on, whether it ships,
540
- // whether a person has it, and where it lands: the branch the layer below
650
+ // whether a person has it, by its record, and where it lands: the branch the layer below
541
651
  // merged into once that one has, the flow's integration base otherwise, and
542
652
  // that branch's head.
543
653
  const Landing = Schema.Struct({
@@ -564,7 +674,7 @@ const readLanding = (round: number, pullRequest: number, lower: Option.Option<nu
564
674
  return {
565
675
  base: pull.baseRef,
566
676
  ships: PullRequest.ships(pull, labelNames),
567
- withPerson: pull.labels.includes(labelNames.needsHuman),
677
+ withPerson: yield* Phases.withPerson(Phases.pullRequestItem(pullRequest)),
568
678
  target,
569
679
  targetSha: yield* github.branchSha(target),
570
680
  };
@@ -670,6 +780,13 @@ const catchUp = (
670
780
  upkeep.withPerson.add(pullRequest);
671
781
  }
672
782
 
783
+ // Its CI still pending: it may merge once a later round takes it up.
784
+ for (const left of Option.toArray(refreshed.left)) {
785
+ upkeep.ci.push(left);
786
+
787
+ return { moved: true, mayMerge: false };
788
+ }
789
+
673
790
  if (refreshed.carried) {
674
791
  upkeep.caughtUp.add(pullRequest);
675
792
  }
@@ -702,7 +819,11 @@ const landLayer = (
702
819
  upkeep: Upkeep,
703
820
  ) =>
704
821
  Effect.gen(function* () {
705
- if (stillStacked(layer, progress, upkeep)) {
822
+ // Still stacked, or its refresh waits on CI.
823
+ if (
824
+ stillStacked(layer, progress, upkeep) ||
825
+ upkeep.ci.some((left) => left.pullRequest === pullRequest)
826
+ ) {
706
827
  return false;
707
828
  }
708
829
 
@@ -796,6 +917,34 @@ const declareLane = (
796
917
  ),
797
918
  ]);
798
919
 
920
+ // A task the run attempted that reads as something other than ready since,
921
+ // or whose attempt ended with a person, is handed back: it may start again.
922
+ const noteHandedBack = (
923
+ progress: Epic.Progress,
924
+ attempts: ReadonlyMap<number, number>,
925
+ handedBack: Set<number>,
926
+ withPerson: Set<number>,
927
+ ) => {
928
+ for (const layer of progress.layers) {
929
+ if (attempts.has(layer.number) && (layer.state !== "ready" || withPerson.has(layer.number))) {
930
+ handedBack.add(layer.number);
931
+ withPerson.delete(layer.number);
932
+ }
933
+ }
934
+ };
935
+
936
+ // Takes up the tasks whose lanes left on pending CI once it has settled, by
937
+ // the tasks' own records (Epic.takeUpCi); those that went to a person count
938
+ // as ended with one.
939
+ const takeUpTasks = (round: number, epic: number, concurrency: number, withPerson: Set<number>) =>
940
+ Effect.tap(Epic.takeUpCi(round, epic, concurrency), (tasksCi) =>
941
+ Effect.sync(() => {
942
+ for (const issue of tasksCi.withPerson) {
943
+ withPerson.add(issue);
944
+ }
945
+ }),
946
+ );
947
+
799
948
  // Round after round: read where the epic stands, write its status comment,
800
949
  // carry each moved layer's change up its stack, land the layers that ship
801
950
  // and may, start every ready task, and
@@ -805,24 +954,33 @@ const declareLane = (
805
954
  // or a hand-off has; one still ready after its attempt, as one another run
806
955
  // holds, waits. An attempt that ended with a person counts as read so: a
807
956
  // round runs only once every task started with it ends, so a person may hand
808
- // the task back before any round reads it with them (#249). The counts are
809
- // rebuilt from the rounds' saved results whenever the run resumes.
810
- const workThrough = (epic: number, ships: boolean, concurrency: number) =>
957
+ // the task back before any round reads it with them (#249). A run ends at its
958
+ // park (ADR 0021, decision 4); the next takes the epic up with what the
959
+ // parked one kept in its waiting record (`resumed`).
960
+ const workThrough = (
961
+ epic: number,
962
+ ships: boolean,
963
+ concurrency: number,
964
+ resumed: Option.Option<Epic.Waiting>,
965
+ ) =>
811
966
  Effect.gen(function* () {
812
- const attempts = new Map<number, number>();
813
- const handedBack = new Set<number>();
814
- // Tasks whose attempt ended with a person.
967
+ const kept = Option.match(resumed, {
968
+ onNone: (): Epic.TaskKeep => ({ attempts: [], handedBack: [] }),
969
+ onSome: (parked) => parked.tasks,
970
+ });
971
+
972
+ const attempts = new Map(kept.attempts);
973
+ const handedBack = new Set(kept.handedBack);
974
+ // Tasks whose attempt in this run ended with a person: a round reads each
975
+ // as handed back before the run parks, so the waiting record never keeps
976
+ // it; who has a task is its own record (with-person).
815
977
  const withPerson = new Set<number>();
816
978
  // The sub-issues each task waited on, as the rounds read them.
817
979
  const waitedOn = new Map<number, Set<number>>();
818
980
 
819
- const upkeep: Upkeep = {
820
- attempts: new Map(),
821
- recorded: new Map(),
822
- withPerson: new Set(),
823
- below: new Map(),
824
- caughtUp: new Set(),
825
- };
981
+ const upkeep = upkeepFrom(
982
+ Option.flatMap(resumed, (parked) => Option.fromUndefinedOr(parked.layers)),
983
+ );
826
984
 
827
985
  for (let round = 1; ; round++) {
828
986
  const progress = yield* Epic.progress(epic, round);
@@ -830,11 +988,13 @@ const workThrough = (epic: number, ships: boolean, concurrency: number) =>
830
988
  noteWaits(progress, waitedOn);
831
989
 
832
990
  if (Epic.finished(progress)) {
991
+ yield* Epic.recordFinished(epic, round);
992
+
833
993
  return `#${epic}: every task is closed`;
834
994
  }
835
995
 
836
996
  // A refresh moved layers' heads: read the epic again before going on.
837
- if (yield* carryUp(round, progress, upkeep)) {
997
+ if (yield* carryUp(round, epic, progress, upkeep)) {
838
998
  continue;
839
999
  }
840
1000
 
@@ -843,16 +1003,16 @@ const workThrough = (epic: number, ships: boolean, concurrency: number) =>
843
1003
  continue;
844
1004
  }
845
1005
 
846
- for (const layer of progress.layers) {
847
- if (
848
- attempts.has(layer.number) &&
849
- (layer.state !== "ready" || withPerson.has(layer.number))
850
- ) {
851
- handedBack.add(layer.number);
852
- withPerson.delete(layer.number);
853
- }
1006
+ // A task left on pending CI whose CI has settled, or run out of time,
1007
+ // is taken up: then read the epic again.
1008
+ const tasksCi = yield* takeUpTasks(round, epic, concurrency, withPerson);
1009
+
1010
+ if (tasksCi.taken) {
1011
+ continue;
854
1012
  }
855
1013
 
1014
+ noteHandedBack(progress, attempts, handedBack, withPerson);
1015
+
856
1016
  const ready = Epic.startable(progress).filter(
857
1017
  (task) => !attempts.has(task.number) || handedBack.has(task.number),
858
1018
  );
@@ -881,9 +1041,16 @@ const workThrough = (epic: number, ships: boolean, concurrency: number) =>
881
1041
  continue;
882
1042
  }
883
1043
 
884
- yield* awaitSignal([Epic.LAYER_CHANGED], {
885
- id: `epic-${round}`,
886
- timeout: LOOK_AGAIN_AFTER,
1044
+ // The epic's waiting record keeps what the run knows, so the run that
1045
+ // takes the epic up once a layer changes, as one always does once this
1046
+ // one ends at its park, carries on from here.
1047
+ yield* Epic.park(epic, round, {
1048
+ fingerprint: progress.fingerprint,
1049
+ tasks: {
1050
+ attempts: [...attempts],
1051
+ handedBack: [...handedBack],
1052
+ },
1053
+ layers: keptOf(upkeep),
887
1054
  });
888
1055
  }
889
1056
  });
@@ -904,7 +1071,7 @@ const settings = Schema.Struct({
904
1071
  });
905
1072
 
906
1073
  const flow = defineFlow({
907
- trigger: Epic.queued.pipe(reportAs("trigger")),
1074
+ trigger: Epic.queued.pipe(Blocks.checked("epic.queued"), reportAs("trigger")),
908
1075
  gate: Implement.gate,
909
1076
  concurrency: 1,
910
1077
  labels: Effect.map(Settings.declaredLabels, (set) => [
@@ -927,16 +1094,20 @@ const flow = defineFlow({
927
1094
 
928
1095
  // However the run ends, its claim on the epic goes, and the engine lets
929
1096
  // its tasks' claims go too; a run parked between rounds keeps them.
930
- return yield* workThrough(epic, ships, concurrency).pipe(Claims.releasing(Claims.epic(epic)));
1097
+ return yield* workThrough(epic, ships, concurrency, Epic.resuming(item)).pipe(
1098
+ StatusLabels.releasing(Claims.epic(epic)),
1099
+ );
931
1100
  }),
932
1101
  });
933
1102
 
934
1103
  // The GitHub events that can change what its trigger finds, so it wakes in CI
935
- // rather than only on the schedule: an issue labelled auto:epic, and what moves
1104
+ // rather than only on the schedule: an issue labelled auto:epic, what moves
936
1105
  // an epic's layers (a task closed or relabelled, a push to, review of or merge
937
- // of a layer's pull request). Its trigger reads the epic's phase, so a phase
938
- // event wakes it too.
1106
+ // of a layer's pull request), and a finished CI run, which settles a task's
1107
+ // or a layer's CI the run left pending, which the task's or the layer's pull
1108
+ // request's own record names. Its trigger reads the epic's phase, and its
1109
+ // tasks' and layers' waits on CI, so a phase event wakes it too.
939
1110
  export default Events.declare(flow, {
940
- events: [Events.issueLabelled, ...Events.layerChanged],
1111
+ events: [Events.issueLabelled, ...Events.layerChanged, Events.ciRunCompleted],
941
1112
  readsPhases: true,
942
1113
  });
@@ -19,6 +19,7 @@ import {
19
19
  Review,
20
20
  Settings,
21
21
  Skip,
22
+ StatusLabels,
22
23
  type WorkItem,
23
24
  } from "@chernabog/sdk";
24
25
  import * as Effect from "effect/Effect";
@@ -73,7 +74,7 @@ const workflow = (item: WorkItem) =>
73
74
 
74
75
  // However the run ends, its claim on the issue goes; the branch and any
75
76
  // pull request stay.
76
- return yield* work(issue).pipe(Claims.releasing(Claims.issue(issue)));
77
+ return yield* work(issue).pipe(StatusLabels.releasing(Claims.issue(issue)));
77
78
  }).pipe(
78
79
  // An issue deleted or transferred under the run leaves nothing to do.
79
80
  Effect.catchTag("NotFound", (gone) => Effect.fail(new Skip({ reason: gone.message }))),