ticket-runner 0.6.5 → 0.6.6

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/src/resume.ts CHANGED
@@ -35,6 +35,9 @@ const stateSchema = z.object({
35
35
  fixUsed: z.boolean(),
36
36
  pullRequest: z.number().int().positive().optional(),
37
37
  title: z.string().optional(),
38
+ body: z.string().optional(),
39
+ problem: z.string().optional(),
40
+ solution: z.string().optional(),
38
41
  rebaseFirst: z.boolean().optional(),
39
42
  runId: z.string(),
40
43
  version: z.string().optional(),
@@ -76,17 +79,21 @@ export function readStateFile(contents: string, ticket: number): StateFile {
76
79
  return { readable: false, ticket, ...(version === undefined ? {} : { version }) };
77
80
  }
78
81
 
79
- // A pull request nobody opened, a title no Stage answered, and a version an
80
- // older pipeline never wrote, are keys that are not there rather than keys
81
- // holding nothing: the rest of the pipeline reads these with the same
82
- // distinction.
83
- const { pullRequest, title, rebaseFirst, version, ...state } = parsed.data;
82
+ // A pull request nobody opened, a title, body, problem or solution no Stage
83
+ // answered, and a version an older pipeline never wrote, are keys that are
84
+ // not there rather than keys holding nothing: the rest of the pipeline reads
85
+ // these with the same distinction.
86
+ const { pullRequest, title, body, problem, solution, rebaseFirst, version, ...state } =
87
+ parsed.data;
84
88
  return {
85
89
  readable: true,
86
90
  state: {
87
91
  ...state,
88
92
  ...(pullRequest === undefined ? {} : { pullRequest }),
89
93
  ...(title === undefined ? {} : { title }),
94
+ ...(body === undefined ? {} : { body }),
95
+ ...(problem === undefined ? {} : { problem }),
96
+ ...(solution === undefined ? {} : { solution }),
90
97
  ...(rebaseFirst === undefined ? {} : { rebaseFirst }),
91
98
  ...(version === undefined ? {} : { version }),
92
99
  },
@@ -117,10 +124,11 @@ function parseJson(contents: string): unknown {
117
124
 
118
125
  /**
119
126
  * The branch of the Target's remote that holds every Ticket's state, one file
120
- * per Ticket, and the transcripts of a handed-off Ticket's Stages beside it,
121
- * under the prefix the pipeline owns (ADR-0004). Named here rather than only in
122
- * the Workspace that writes it, because `ticket-runner remove` deletes it by
123
- * name and the conventions document names it to every human.
127
+ * per Ticket, and the transcripts of a handed-off Ticket's Stages beside it
128
+ * where the Run keeps them on the remote, under the prefix the pipeline owns
129
+ * (ADR-0004). Named here rather than only in the Workspace that writes it,
130
+ * because `ticket-runner remove` deletes it by name and the conventions
131
+ * document names it to every human.
124
132
  */
125
133
  export const STATE_BRANCH = "ticket-runner/state";
126
134
 
package/src/run.ts CHANGED
@@ -2,7 +2,8 @@ import { branchName } from "./branch.js";
2
2
  import { selectFrontier } from "./frontier.js";
3
3
  import { type Refusal, isGuardReason, skipReason } from "./guards.js";
4
4
  import type { RoutedNote } from "./notes.js";
5
- import { type Pipeline, type TicketOutcome, processTicket } from "./orchestrator.js";
5
+ import { type Pipeline, type TicketOutcome, faultOutcome, processTicket } from "./orchestrator.js";
6
+ import { type FaultSide, OutsideFault } from "./outside-fault.js";
6
7
  import { StopSignal, stopLine } from "./stop.js";
7
8
  import { holdsClaim, strandedTickets } from "./stranded.js";
8
9
  import { releaseWords } from "./templates.js";
@@ -34,7 +35,8 @@ export interface RunResult {
34
35
  * A Run that drained the Frontier carries what was left held back; one a
35
36
  * Release stopped carries no candidates, because it ended before it could say
36
37
  * one was held back all Run, and the rate limit carries when it resets, where a
37
- * Stage was told, and a failing base branch the Check it fails and where; one
38
+ * Stage was told, a failing base branch the Check it fails and where, and a
39
+ * fault of GitHub's or the remote's the command and what it printed; one
38
40
  * a human stopped carries the moment it was asked and what it still had in
39
41
  * hand. That is why this is a choice rather than a flag beside
40
42
  * the list: the stops do not report the same things.
@@ -63,6 +65,14 @@ export type RunStop =
63
65
  /** The Check command it failed. */
64
66
  command: string;
65
67
  }
68
+ | {
69
+ /** GitHub, or the git remote, failing on its own side. */
70
+ reason: FaultSide;
71
+ /** The command that failed, on one line. */
72
+ command: string;
73
+ /** The first line it printed. */
74
+ line: string;
75
+ }
66
76
  | {
67
77
  reason: "stopped";
68
78
  /** When the Stop reached the Run, ISO-8601. */
@@ -100,7 +110,9 @@ export type RunStop =
100
110
  * worktree and a doomed Stage to learn what the first one already said. The Lanes still busy finish
101
111
  * what they hold, and the Run reports what stopped it once the last of them
102
112
  * comes back. It does not wait for the limit to reset: a human or an Operator
103
- * starts the next Run, and the summary says when the limit resets.
113
+ * starts the next Run, and the summary says when the limit resets. A hand-off
114
+ * that GitHub or the remote cut short stops it the same way, for the same
115
+ * reason, though its Ticket is reported handed off.
104
116
  *
105
117
  * A Stop is the same shape with a different reason: a human asked for no more
106
118
  * Tickets rather than the subscription, so the Lanes busy at that moment finish
@@ -189,9 +201,10 @@ export async function processRun(
189
201
  /**
190
202
  * Put a Ticket in a Lane, and record what came back when it ends.
191
203
  *
192
- * The line about the Run stopping is logged by the Release that stopped it and
193
- * by no other, even where a later Release outranks it on the last line. The
194
- * Ticket's own release is already logged where it happened; this says the Run
204
+ * The line about the Run stopping is logged by the Release that stopped it,
205
+ * or by the hand-off a fault outside the Ticket cut short, and by no other,
206
+ * even where a later Release outranks it on the last line. The Ticket's own
207
+ * release is already logged where it happened; this says the Run
195
208
  * goes no further, so a transcript shows the Frontier was left alone rather
196
209
  * than found empty, and a Release into a Run that an earlier Release or a
197
210
  * Stop had stopped already claims to have stopped nothing. It leads with the
@@ -206,6 +219,17 @@ export async function processRun(
206
219
  busy.delete(ticket.number);
207
220
  ended += 1;
208
221
  outcomes.push(outcome);
222
+ if (outcome.outcome === "handed-off" && outcome.fault !== undefined) {
223
+ // A hand-off the fault cut short stops the Run as a Release over it
224
+ // would, and outranks nothing that stopped it first.
225
+ if (runStop !== undefined) return;
226
+ const { side, command, line } = outcome.fault;
227
+ runStop = { reason: side, command, line };
228
+ pipeline.log?.(
229
+ `#${outcome.ticket} stopped the Run · ${releaseWords(side, pipeline.credential)}`,
230
+ );
231
+ return;
232
+ }
209
233
  if (outcome.outcome !== "released") return;
210
234
  if (runStop === undefined) {
211
235
  runStop = releaseStop(outcome, pipeline.baseBranch);
@@ -319,7 +343,7 @@ function pollFailure(error: unknown): string {
319
343
 
320
344
  /**
321
345
  * The stop a Release puts on the Run: what released it, when a limit resets,
322
- * and which Check the base branch fails.
346
+ * which Check the base branch fails, and what GitHub or the remote failed.
323
347
  */
324
348
  function releaseStop(
325
349
  outcome: Extract<TicketOutcome, { outcome: "released" }>,
@@ -327,6 +351,9 @@ function releaseStop(
327
351
  ): RunStop {
328
352
  if (outcome.cause === "api-error") return { reason: "api-error" };
329
353
  if (outcome.cause === "out-of-budget") return { reason: "out-of-budget" };
354
+ if ((outcome.cause === "github" || outcome.cause === "remote") && outcome.fault !== undefined) {
355
+ return { reason: outcome.cause, ...outcome.fault };
356
+ }
330
357
  if (outcome.failingBase !== undefined) {
331
358
  return { reason: "failing-base", baseBranch, ...outcome.failingBase };
332
359
  }
@@ -344,7 +371,8 @@ function releaseStop(
344
371
  * rate limit outranks an API failure, which says nothing of when the next Run
345
372
  * can start, and a limit nobody was told the end of is outranked by one a
346
373
  * Stage was told. A failing base branch and a Stop stay whatever comes after
347
- * them, and so does an API budget, and a limit already told when it resets.
374
+ * them, and so does an API budget, a limit already told when it resets, and a
375
+ * fault of GitHub's or the remote's.
348
376
  */
349
377
  function outranks(
350
378
  outcome: Extract<TicketOutcome, { outcome: "released" }>,
@@ -425,6 +453,10 @@ async function nobodysToTake(pipeline: Pipeline, ticket: number): Promise<Skippe
425
453
  * hand-off writes are outside that net: a tracker that goes down mid-Ticket
426
454
  * would otherwise take the whole Run with it. The Ticket is reported as handed
427
455
  * off — which, without the label, is what a human will find on the board.
456
+ *
457
+ * Unless GitHub or the remote failed on its own side, before the claim or in
458
+ * it: that is a fault outside the Ticket, reported released so the Run claims
459
+ * no more, and the Ticket is left as far as the claim got, for the next Run.
428
460
  */
429
461
  async function take(pipeline: Pipeline, ticket: Taken): Promise<TicketOutcome> {
430
462
  // Handed to the Ticket rather than read off its outcome, because there is no
@@ -434,6 +466,16 @@ async function take(pipeline: Pipeline, ticket: Taken): Promise<TicketOutcome> {
434
466
  try {
435
467
  return await processTicket(pipeline, ticket.number, notes);
436
468
  } catch (error) {
469
+ if (error instanceof OutsideFault) {
470
+ pipeline.log?.(`#${ticket.number} stopped at setup · ${error.message}`);
471
+ return faultOutcome(
472
+ { number: ticket.number, title: ticket.title },
473
+ ticket.branch,
474
+ "setup",
475
+ error,
476
+ notes,
477
+ );
478
+ }
437
479
  const failure = (error as Error).message;
438
480
  pipeline.log?.(`#${ticket.number} failed outside the hand-off path: ${failure}`);
439
481
  return {
package/src/start.ts CHANGED
@@ -20,6 +20,7 @@ import { conventionsWarning, newerVersionLine } from "./staleness.js";
20
20
  import { type StopSource, StopSignal, listenForStop } from "./stop.js";
21
21
  import { startupMessages } from "./startup.js";
22
22
  import { runSummary } from "./templates.js";
23
+ import { resolveTranscriptHome } from "./transcript-home.js";
23
24
 
24
25
  /**
25
26
  * Everything between the arguments and the work: the two refusals a Run can
@@ -175,7 +176,7 @@ export async function startRun(given: StartOptions): Promise<number> {
175
176
  const stopping = new StopSignal();
176
177
  const deafen = listenForStop(stopping, options.signals);
177
178
  try {
178
- return await execute(options, { credential, host, baseBranch }, log, stopping);
179
+ return await execute(options, { credential, baseBranch, host }, log, stopping);
179
180
  } finally {
180
181
  // The lock goes first: SIGTERM between the two is a kill again, and a kill
181
182
  // that leaves the lock behind costs the next Run a stale holder to reclaim,
@@ -196,9 +197,9 @@ async function execute(
196
197
  options: StartOptions,
197
198
  {
198
199
  credential,
199
- host,
200
200
  baseBranch,
201
- }: { credential: Credential; host: HostKind; baseBranch: string },
201
+ host,
202
+ }: { credential: Credential; baseBranch: string; host: HostKind },
202
203
  print: (line: string) => void,
203
204
  stopping: StopSignal,
204
205
  ): Promise<number> {
@@ -230,6 +231,9 @@ async function execute(
230
231
  // Once per Run: only a Target that is the pipeline's own repository
231
232
  // has a checkout that is the pipeline, and every Stage is told which it is in.
232
233
  const selfHosted = await isPipelineRepository(tracker, options.repository);
234
+ // Once per Run as well: whether the Target is public is read here and no
235
+ // later, so every hand-off of the Run keeps its transcripts in one place.
236
+ const transcriptHome = await resolveTranscriptHome({ config, tracker, host });
233
237
 
234
238
  const pipeline: Pipeline = {
235
239
  tracker,
@@ -239,7 +243,6 @@ async function execute(
239
243
  repoRoot,
240
244
  runId,
241
245
  version,
242
- host,
243
246
  credential,
244
247
  billing: emptyBilling(),
245
248
  baseBranch,
@@ -254,12 +257,17 @@ async function execute(
254
257
  // branch run it at their merge-base once between them.
255
258
  baseChecks: new BaseBranchChecks(),
256
259
  selfHosted,
260
+ transcriptHome: transcriptHome.home,
257
261
  log,
258
262
  };
259
263
 
260
264
  const startedAt = Date.now();
261
265
  log(opening(runId, work, config.lanes));
262
266
  if (newer !== undefined) log(newer);
267
+ if (transcriptHome.said !== undefined) log(transcriptHome.said);
268
+ // Before the first claim, on any Host: a shallow clone refuses every move of
269
+ // its base branch a rebase needs, and would hand off each Ticket there.
270
+ if (await workspace.unshallow()) log("the clone was shallow, so its full history was fetched");
263
271
  const summary = (outcomes: TicketOutcome[], stop: RunStop) =>
264
272
  runSummary({
265
273
  version,