@operad-io/dev 0.0.1 → 0.1.1

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/dev.schema.json CHANGED
@@ -300,6 +300,11 @@
300
300
  "exclusiveMinimum": 0,
301
301
  "default": 1800
302
302
  },
303
+ "stallSecs": {
304
+ "description": "How long a gate command, or an integration key command, may write nothing before dev stops its process group, in seconds. A stalled command fails the check with reason \"stall\" and goes to the worker; it is not rerun and is not a \"not the code\" wait. Unset turns the limit off.",
305
+ "type": "number",
306
+ "exclusiveMinimum": 0
307
+ },
303
308
  "places": {
304
309
  "description": "The most checks of this repository that run at once, on top of the home's limit. A check waits, without a time limit, for a place of the home and one of the repository. Unset means the repository has no limit of its own.",
305
310
  "type": "integer",
@@ -422,27 +427,51 @@
422
427
  "additionalProperties": false
423
428
  },
424
429
  "fallback": {
425
- "description": "A second harness step and arguments used when the primary reviewer is unavailable.",
426
- "type": "object",
427
- "properties": {
428
- "use": {
429
- "description": "The harness step that reviews when the primary is unavailable.",
430
- "type": "string",
431
- "minLength": 1
430
+ "description": "A second harness step and arguments used when the primary reviewer is unavailable or does not write the report, or a list of them tried in order until one writes the report.",
431
+ "oneOf": [
432
+ {
433
+ "type": "object",
434
+ "properties": {
435
+ "use": {
436
+ "description": "The harness step that reviews when the primary is unavailable.",
437
+ "type": "string",
438
+ "minLength": 1
439
+ },
440
+ "args": {
441
+ "description": "Arguments the fallback harness step passes to its command.",
442
+ "type": "array",
443
+ "items": {
444
+ "type": "string"
445
+ },
446
+ "default": []
447
+ }
448
+ },
449
+ "required": ["use"],
450
+ "additionalProperties": false
432
451
  },
433
- "args": {
434
- "description": "Arguments the fallback harness step passes to its command.",
452
+ {
435
453
  "type": "array",
454
+ "minItems": 1,
436
455
  "items": {
437
- "type": "string"
438
- },
439
- "default": []
456
+ "type": "object",
457
+ "properties": {
458
+ "use": {
459
+ "type": "string",
460
+ "minLength": 1
461
+ },
462
+ "args": {
463
+ "type": "array",
464
+ "items": {
465
+ "type": "string"
466
+ },
467
+ "default": []
468
+ }
469
+ },
470
+ "required": ["use"],
471
+ "additionalProperties": false
472
+ }
440
473
  }
441
- },
442
- "required": [
443
- "use"
444
- ],
445
- "additionalProperties": false
474
+ ]
446
475
  },
447
476
  "timeoutSecs": {
448
477
  "description": "The longest a review may run, in seconds.",
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@operad-io/dev",
3
- "version": "0.0.1",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
7
7
  },
8
8
  "dependencies": {
9
- "@operad-io/chat": "0.0.1",
10
- "@operad-io/engine": "0.0.1",
11
- "@operad-io/pool": "0.0.1",
12
- "@operad-io/review-grading": "0.0.1"
9
+ "@operad-io/chat": "0.1.1",
10
+ "@operad-io/engine": "0.1.1",
11
+ "@operad-io/pool": "0.1.1",
12
+ "@operad-io/review-grading": "0.1.1"
13
13
  },
14
14
  "devDependencies": {
15
- "@operad-io/shell": "0.0.1"
15
+ "@operad-io/shell": "0.1.1"
16
16
  },
17
- "description": "operad: the dev plugin, plans and tasks on a repository (in development)",
17
+ "description": "operad: the dev plugin, plans and tasks on a repository",
18
18
  "repository": {
19
19
  "type": "git",
20
20
  "url": "git+https://github.com/operad-io/operad.git",
package/src/actions.ts CHANGED
@@ -443,7 +443,10 @@ export const actions: readonly ActionTypeDefinition[] = [
443
443
  why: planWhy("cancel"),
444
444
  settled: planSettled("cancel"),
445
445
  async run(ctx) {
446
- await cancelPlan(ctx.store, ctx.object.id, { runs: ctx.runs });
446
+ await cancelPlan(ctx.store, ctx.object.id, {
447
+ runs: ctx.runs,
448
+ home: ctx.home,
449
+ });
447
450
  },
448
451
  },
449
452
  {
@@ -459,7 +462,11 @@ export const actions: readonly ActionTypeDefinition[] = [
459
462
  why: taskWhy("cancel"),
460
463
  settled: taskSettled("cancel"),
461
464
  async run(ctx) {
462
- await cancelTask(ctx.store, ctx.object.id, { runs: ctx.runs });
465
+ const cancelled = await cancelTask(ctx.store, ctx.object.id, {
466
+ runs: ctx.runs,
467
+ home: ctx.home,
468
+ });
469
+ return cancelled.alreadyMerged;
463
470
  },
464
471
  },
465
472
  {
package/src/chat.ts CHANGED
@@ -22,7 +22,7 @@ import { isRegistered, prepareWorktree, workBranch, worktreePath } from "./steps
22
22
  /**
23
23
  * The harnesses a repository chat offers, in order: the ones that can stop a
24
24
  * tool call before it starts, so the main clone stays read-only
25
- * (`operad-conversation.md` decisions 13 and 14). radian is not one.
25
+ * (ADR 0028 D2, D3). radian is not one.
26
26
  */
27
27
  export const CHAT_HARNESSES = ["claude", "pi"] as const;
28
28
 
package/src/gate.ts CHANGED
@@ -38,6 +38,7 @@ import {
38
38
  type DevSettings,
39
39
  type FixLevel,
40
40
  type ReviewerFallback,
41
+ reviewerFallbacks,
41
42
  type ReviewerSettings,
42
43
  } from "./settings.ts";
43
44
  import { reviewWaitKind } from "./waits.ts";
@@ -303,13 +304,20 @@ export async function runVerify(
303
304
  run: () =>
304
305
  runCheckCommands(
305
306
  runStep,
306
- { cwd: path, timeoutSecs: context.settings.gate.commandTimeoutSecs },
307
+ {
308
+ cwd: path,
309
+ timeoutSecs: context.settings.gate.commandTimeoutSecs,
310
+ ...(context.settings.gate.stallSecs === undefined
311
+ ? {}
312
+ : { stallSecs: context.settings.gate.stallSecs }),
313
+ },
307
314
  commands,
308
315
  stepOptions(ctx, path),
309
316
  rerun,
310
317
  checkPlaces(ctx, context.repository, context.settings.gate.places, context.taskKey),
311
318
  ),
312
319
  limit: context.settings.check.loadLimit,
320
+ flakyLimit: context.settings.check.flakyLoadLimit,
313
321
  signal: ctx.signal,
314
322
  log: (text) => ctx.logger.write(text),
315
323
  });
@@ -365,6 +373,7 @@ export async function runVerify(
365
373
  run: ctx.runId,
366
374
  commands: commands.map((line) => (typeof line === "string" ? line : line.run)),
367
375
  ...(command === undefined ? {} : { command }),
376
+ ...(typeof outcomeData.reason === "string" ? { reason: outcomeData.reason } : {}),
368
377
  ...(log === undefined ? {} : { log }),
369
378
  ...(message === undefined ? {} : { message }),
370
379
  ...(lineNumber === undefined ? {} : { lineNumber }),
@@ -1511,6 +1520,8 @@ function replayReview(
1511
1520
  interface ReviewAction {
1512
1521
  readonly role: ReviewRunRole;
1513
1522
  readonly reason: ReviewRunReason;
1523
+ /** The entry of the fallback list a fallback run uses. */
1524
+ readonly fallbackIndex?: number;
1514
1525
  }
1515
1526
 
1516
1527
  type ReviewNext =
@@ -1522,42 +1533,72 @@ type ReviewNext =
1522
1533
  | "out-of-time"
1523
1534
  | "failed";
1524
1535
 
1536
+ /** Whether two runs used the same reviewer: the primary, or the same fallback. */
1537
+ function sameRunner(a: ReviewRunRecord, b: ReviewRunRecord): boolean {
1538
+ return (
1539
+ a.role === b.role &&
1540
+ (a.role === "primary" || (a.fallbackIndex ?? 0) === (b.fallbackIndex ?? 0))
1541
+ );
1542
+ }
1543
+
1544
+ /** The same run again: same role and, for a fallback, the same list entry. */
1545
+ function retryOf(last: ReviewRunRecord): ReviewAction {
1546
+ return last.role === "fallback"
1547
+ ? { role: "fallback", reason: "retry", fallbackIndex: last.fallbackIndex ?? 0 }
1548
+ : { role: "primary", reason: "retry" };
1549
+ }
1550
+
1525
1551
  /**
1526
1552
  * What the next run of a review round is. A report ends the round; an
1527
1553
  * unavailable primary goes to the fallback once; a timeout is retried once on
1528
1554
  * the same model; an invalid report is retried once. Every other state ends
1529
1555
  * the round for a person or for a wait.
1530
1556
  */
1531
- function nextReviewAction(
1557
+ export function nextReviewAction(
1532
1558
  runs: readonly ReviewRunRecord[],
1533
- fallback: ReviewerFallback | undefined,
1559
+ fallback: ReviewerFallback | readonly ReviewerFallback[] | undefined,
1534
1560
  ): ReviewNext {
1535
1561
  const last = runs[runs.length - 1];
1536
1562
  if (last === undefined) return { role: "primary", reason: "initial" };
1563
+ const list = reviewerFallbacks(fallback);
1564
+ // The list got shorter after this run (dev.json changed): there is no entry
1565
+ // to retry or follow, so the round ends for a person.
1566
+ if (
1567
+ last.outcome !== "report" &&
1568
+ last.role === "fallback" &&
1569
+ (last.fallbackIndex ?? 0) >= list.length
1570
+ ) {
1571
+ return "failed";
1572
+ }
1573
+ // The fallback after the last run: the first one when the primary ran last
1574
+ // and no fallback has run in this round (a later primary failure waits
1575
+ // instead of trying them again), the next one after a fallback's failure.
1576
+ const nextFallback = (): ReviewAction | undefined => {
1577
+ const index =
1578
+ last.role === "primary"
1579
+ ? runs.some((run) => run.role === "fallback")
1580
+ ? list.length
1581
+ : 0
1582
+ : (last.fallbackIndex ?? 0) + 1;
1583
+ return index < list.length
1584
+ ? { role: "fallback", reason: "fallback", fallbackIndex: index }
1585
+ : undefined;
1586
+ };
1537
1587
  switch (last.outcome) {
1538
1588
  case "report":
1539
1589
  return "done";
1540
1590
  case "unavailable":
1541
- // A round uses its fallback exactly once, even when it runs again after
1542
- // `retryAt`: a later primary failure waits instead of trying it again.
1543
- if (
1544
- last.role === "primary" &&
1545
- fallback !== undefined &&
1546
- !runs.some((run) => run.role === "fallback")
1547
- ) {
1548
- return { role: "fallback", reason: "fallback" };
1549
- }
1550
- return "wait-unavailable";
1591
+ return nextFallback() ?? "wait-unavailable";
1551
1592
  case "timed_out": {
1552
1593
  const before = runs[runs.length - 2];
1553
1594
  if (
1554
1595
  before !== undefined &&
1555
1596
  before.outcome === "timed_out" &&
1556
- before.role === last.role
1597
+ sameRunner(before, last)
1557
1598
  ) {
1558
- return "wait-timed-out";
1599
+ return (last.role === "fallback" ? nextFallback() : undefined) ?? "wait-timed-out";
1559
1600
  }
1560
- return { role: last.role, reason: "retry" };
1601
+ return retryOf(last);
1561
1602
  }
1562
1603
  case "invalid":
1563
1604
  case "no_report": {
@@ -1565,20 +1606,23 @@ function nextReviewAction(
1565
1606
  if (
1566
1607
  before !== undefined &&
1567
1608
  (before.outcome === "invalid" || before.outcome === "no_report") &&
1568
- before.role === last.role
1609
+ sameRunner(before, last)
1569
1610
  ) {
1570
- return "failed";
1611
+ return (last.role === "fallback" ? nextFallback() : undefined) ?? "failed";
1571
1612
  }
1572
- return { role: last.role, reason: "retry" };
1613
+ return retryOf(last);
1573
1614
  }
1574
1615
  case "failed":
1575
- return "failed";
1616
+ return (last.role === "fallback" ? nextFallback() : undefined) ?? "failed";
1576
1617
  }
1577
1618
  }
1578
1619
 
1579
1620
  /** One run in words a person can read. */
1580
1621
  function runPhrase(run: ReviewRunRecord): string {
1581
- const who = run.role === "fallback" ? `fallback ${run.model}` : run.model;
1622
+ // A later list entry is named by its place, as the settings name it, so two
1623
+ // entries with one model and different arguments read apart.
1624
+ const place = (run.fallbackIndex ?? 0) > 0 ? `[${run.fallbackIndex}]` : "";
1625
+ const who = run.role === "fallback" ? `fallback${place} ${run.model}` : run.model;
1582
1626
  switch (run.outcome) {
1583
1627
  case "report":
1584
1628
  return `${who} reviewed`;
@@ -1851,7 +1895,9 @@ export async function runReview(
1851
1895
  // A report from the fallback harness ran with the fallback's harness and
1852
1896
  // arguments; only the limits carried over from the round.
1853
1897
  const lastRun = recorded.runs?.[recorded.runs.length - 1];
1854
- const fallback = context.settings.reviewer.fallback;
1898
+ const fallback = reviewerFallbacks(context.settings.reviewer.fallback)[
1899
+ lastRun?.fallbackIndex ?? 0
1900
+ ];
1855
1901
  if (used !== undefined && lastRun?.role === "fallback" && fallback !== undefined) {
1856
1902
  used = {
1857
1903
  ...used,
@@ -2268,18 +2314,22 @@ export async function runReview(
2268
2314
  const resume =
2269
2315
  pendingReview !== undefined &&
2270
2316
  pendingReview.role === action.role &&
2271
- pendingReview.reason === action.reason
2317
+ pendingReview.reason === action.reason &&
2318
+ (pendingReview.fallbackIndex ?? 0) === (action.fallbackIndex ?? 0)
2272
2319
  ? pendingReview
2273
2320
  : undefined;
2274
2321
  pendingReview = undefined;
2275
- const use =
2276
- resume?.use ??
2277
- (action.role === "fallback"
2278
- ? settings.fallback?.use ?? roundSettings.use
2279
- : roundSettings.use);
2322
+ const chosen =
2323
+ action.role === "fallback"
2324
+ ? reviewerFallbacks(settings.fallback)[action.fallbackIndex ?? 0]
2325
+ : undefined;
2326
+ const use = resume?.use ?? chosen?.use ?? roundSettings.use;
2280
2327
  const args =
2281
- resume?.args ??
2282
- (action.role === "fallback" ? settings.fallback?.args ?? [] : roundArgs);
2328
+ resume?.args ?? (action.role === "fallback" ? chosen?.args ?? [] : roundArgs);
2329
+ const fallbackFields =
2330
+ action.fallbackIndex === undefined
2331
+ ? {}
2332
+ : { fallbackIndex: action.fallbackIndex };
2283
2333
  const model = resume?.model ?? modelOf(use, args);
2284
2334
  // One path per call: the calls before it in this round are the try number,
2285
2335
  // so a stale report of an earlier call is never read and never removed.
@@ -2338,6 +2388,7 @@ export async function runReview(
2338
2388
  args,
2339
2389
  model,
2340
2390
  reason: action.reason,
2391
+ ...fallbackFields,
2341
2392
  run: ctx.runId,
2342
2393
  report: reportPath,
2343
2394
  },
@@ -2418,6 +2469,7 @@ export async function runReview(
2418
2469
  args,
2419
2470
  model,
2420
2471
  reason: action.reason,
2472
+ ...fallbackFields,
2421
2473
  outcome: "report",
2422
2474
  run: ctx.runId,
2423
2475
  findings,
@@ -2433,6 +2485,7 @@ export async function runReview(
2433
2485
  args,
2434
2486
  model,
2435
2487
  reason: action.reason,
2488
+ ...fallbackFields,
2436
2489
  outcome: call.outcome,
2437
2490
  run: ctx.runId,
2438
2491
  ...(call.message.length === 0 ? {} : { message: call.message }),
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /** The dev plugin: repositories, plans, tasks and their commands and views. */
2
2
 
3
+ import pkg from "../package.json" with { type: "json" };
3
4
  import { definePlugin } from "@operad-io/engine";
4
5
  import { PLAN_FILTERS, REPO_FILTERS, TASK_FILTERS } from "./model.ts";
5
6
  import devFlow from "../flows/dev.flow.ts";
@@ -25,7 +26,7 @@ export function createDevPlugin() {
25
26
  return definePlugin({
26
27
  name: "dev",
27
28
  kind: "domain",
28
- version: "0.0.0",
29
+ version: pkg.version,
29
30
  objects: [
30
31
  {
31
32
  name: "repo",
package/src/integrate.ts CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  updateMainClone,
26
26
  type CommandRunner,
27
27
  type MainCloneOutcome,
28
+ type PrepareMarker,
28
29
  } from "./mainclone.ts";
29
30
  import { runCheckSteadily } from "./notcode.ts";
30
31
  import { runCheckCommands } from "./rerun.ts";
@@ -71,6 +72,11 @@ export const integrateTestHooks: {
71
72
  turnTaken?: ((task: string) => Promise<void> | void) | undefined;
72
73
  /** Awaited by a batch's leader once it has claimed the tasks queued behind it. */
73
74
  claimed?: ((followers: readonly string[]) => Promise<void> | void) | undefined;
75
+ /**
76
+ * Awaited under the queue's land lock between the leader's last check and
77
+ * its push. A test holds the push to make a cancel race it.
78
+ */
79
+ beforePush?: ((candidate: string) => Promise<void> | void) | undefined;
74
80
  /** How a task waits for its turn before it looks again. */
75
81
  wait?: ((ms: number) => Promise<void>) | undefined;
76
82
  } = {};
@@ -83,6 +89,7 @@ export async function followMain(
83
89
  lines: [],
84
90
  run: async () => ({ ok: true, out: "" }),
85
91
  },
92
+ marker?: PrepareMarker | undefined,
86
93
  ): Promise<MainCloneOutcome> {
87
94
  return updateMainClone(
88
95
  repository.path,
@@ -90,6 +97,7 @@ export async function followMain(
90
97
  sha,
91
98
  prepare.lines,
92
99
  integrateTestHooks.runCommand ?? prepare.run,
100
+ marker,
93
101
  );
94
102
  }
95
103
 
@@ -358,6 +366,22 @@ export async function runIntegrate(
358
366
  let flakyReason: string | undefined;
359
367
  /** The other tasks this task was merged with in one batch. */
360
368
  let batchWith: readonly string[] = [];
369
+ /** Saves that this merge's prepare is due before the clone moves, and done after. */
370
+ const prepareMarker = (record: IntegrationRecord): PrepareMarker => ({
371
+ due: record.prepareDue === true,
372
+ save: async (due) => {
373
+ const pending: IntegrationRecord = {
374
+ ...record,
375
+ result: "pending",
376
+ prepareDue: due,
377
+ };
378
+ return (
379
+ (await writeIntegration(ctx, context, task, attempt, pending, {
380
+ integrating: true,
381
+ })) !== undefined
382
+ );
383
+ },
384
+ });
361
385
  const recordMerged = async (
362
386
  record: IntegrationRecord,
363
387
  sha: string,
@@ -371,10 +395,15 @@ export async function runIntegrate(
371
395
  settings.mainBranch,
372
396
  cloneSha,
373
397
  { lines: settings.prepare, run: mainCloneRunner(ctx, settings) },
398
+ prepareMarker(record),
374
399
  );
375
400
  integrateTestHooks.at?.("clone-followed");
376
401
  const cloneChange = mainCloneChange(clone);
377
- const withClone: IntegrationRecord = { ...record, mainClone: { ...clone } };
402
+ const withClone: IntegrationRecord = {
403
+ ...record,
404
+ prepareDue: false,
405
+ mainClone: { ...clone },
406
+ };
378
407
  if (
379
408
  (await writeIntegration(ctx, context, task, attempt, withClone, {
380
409
  phase: "merged",
@@ -446,10 +475,12 @@ export async function runIntegrate(
446
475
  settings.mainBranch,
447
476
  typeof previous.batchHead === "string" ? previous.batchHead : previous.candidate,
448
477
  { lines: settings.prepare, run: mainCloneRunner(ctx, settings) },
478
+ prepareMarker(record),
449
479
  );
450
480
  const cloneChange = mainCloneChange(clone);
451
481
  const withClone: IntegrationRecord = {
452
482
  ...record,
483
+ prepareDue: false,
453
484
  mainClone: { ...clone },
454
485
  };
455
486
  if (
@@ -586,7 +617,12 @@ export async function runIntegrate(
586
617
  run: () =>
587
618
  runCheckCommands(
588
619
  runStep,
589
- { cwd: gate },
620
+ {
621
+ cwd: gate,
622
+ ...(settings.gate.stallSecs === undefined
623
+ ? {}
624
+ : { stallSecs: settings.gate.stallSecs }),
625
+ },
590
626
  keyCommands,
591
627
  stepOptions(ctx, gate),
592
628
  settings.check.rerun,
@@ -599,6 +635,7 @@ export async function runIntegrate(
599
635
  ),
600
636
  ),
601
637
  limit: settings.check.loadLimit,
638
+ flakyLimit: settings.check.flakyLoadLimit,
602
639
  signal: ctx.signal,
603
640
  log: (text) => ctx.logger.write(text),
604
641
  });
@@ -703,11 +740,18 @@ export async function runIntegrate(
703
740
  return merged;
704
741
  };
705
742
  // A claimed task that left (cancelled) is not merged: one by one instead.
706
- // Checked last, so the window between this and the push is as short as it can be.
707
- if (queue.stillQueued(followers).length !== followers.length) return undefined;
708
- queue.publish(result);
709
- const push = git(gate, ["push", settings.remote, `HEAD:refs/heads/${settings.mainBranch}`]);
710
- if (push.ok) {
743
+ // The check and the push share the queue's land lock with a withdrawal,
744
+ // so a cancel either comes before the check or after the push.
745
+ const landed = await queue.landWhenStillQueued(followers, result, async () => {
746
+ await integrateTestHooks.beforePush?.(batchHead);
747
+ return git(gate, [
748
+ "push",
749
+ settings.remote,
750
+ `HEAD:refs/heads/${settings.mainBranch}`,
751
+ ]).ok;
752
+ });
753
+ if (landed === "withdrawn") return undefined;
754
+ if (landed === "pushed") {
711
755
  integrateTestHooks.afterPush?.(batchHead);
712
756
  return land({});
713
757
  }
@@ -920,7 +964,12 @@ export async function runIntegrate(
920
964
  run: () =>
921
965
  runCheckCommands(
922
966
  runStep,
923
- { cwd: gate },
967
+ {
968
+ cwd: gate,
969
+ ...(settings.gate.stallSecs === undefined
970
+ ? {}
971
+ : { stallSecs: settings.gate.stallSecs }),
972
+ },
924
973
  keyCommands,
925
974
  stepOptions(ctx, gate),
926
975
  settings.check.rerun,
@@ -933,6 +982,7 @@ export async function runIntegrate(
933
982
  ),
934
983
  ),
935
984
  limit: settings.check.loadLimit,
985
+ flakyLimit: settings.check.flakyLoadLimit,
936
986
  signal: ctx.signal,
937
987
  log: (text) => ctx.logger.write(text),
938
988
  });
@@ -1106,7 +1156,7 @@ export async function runIntegrate(
1106
1156
  `main moved ${MAX_INTEGRATION_ROUNDS} times while the candidate was built; ${lastError}`,
1107
1157
  );
1108
1158
  } finally {
1109
- queue.leave();
1159
+ await queue.leave();
1110
1160
  }
1111
1161
  }
1112
1162