@futurelastic/colab-handbook 1.17.0-rc.2 → 1.17.0-rc.3

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/package.json CHANGED
@@ -33,5 +33,5 @@
33
33
  "engines": {
34
34
  "node": ">=18"
35
35
  },
36
- "version": "1.17.0-rc.2"
36
+ "version": "1.17.0-rc.3"
37
37
  }
package/tools/colab CHANGED
@@ -11106,6 +11106,9 @@ It never waits: each call reads the remote, takes ONE step and exits —
11106
11106
  One batch per base: a batch at this base carrying OTHER members is waited on (exit 3) while its run
11107
11107
  is pending or green, but a declined one — its combined run red — is deleted and the batch you asked
11108
11108
  for is built in its place, so the survivors of a decline can batch without landing serially first (#391).
11109
+ A call that goes serial on trunk CI not green gives up on its members, so it deletes every batch at
11110
+ trunk's tip whose members it ALL names (its run cancelled if still going) — nobody would ever land
11111
+ it, and it would hold this base for every later call; a batch also carrying another member stays (#656).
11109
11112
  The batch also holds the trunk LANE (#581): while a ship-batch/<trunk-sha7> ref at trunk's tip has its
11110
11113
  combined run in flight — or green within ${shipBatch.LANE_GRACE_SEC / 60}m, so its lander can land it — a serial
11111
11114
  \`colab ship --branch\` into trunk pauses with exit 3 (⏸ BATCH-IN-FLIGHT; its --dry --json row
@@ -15322,12 +15325,55 @@ function cmdShipBatch(opts) {
15322
15325
  const gh = isGhUsable(repoAbs);
15323
15326
  if (!gh) throw new UserError(`gh not usable (${ghUnusableWhy(repoAbs)}) — a batch cannot read its combined run`);
15324
15327
 
15328
+ // #415: every write on the resume path goes through here or shipBatchLand — under --dry, neither writes.
15329
+ const deleteRef = (ref) => {
15330
+ if (opts.dry) { print(` [dry] would delete ${remote}/${ref}`); return true; }
15331
+ const d = git.git(['push', remote, '--delete', ref], repoAbs);
15332
+ if (!d.ok) warn(`could not delete ${remote}/${ref}: ${git.gitFailureLine(d.stderr)} — delete it by hand`);
15333
+ return d.ok;
15334
+ };
15335
+ // A ref nothing can land any more may still have its run going: cancel it rather than let it finish.
15336
+ const cancelRuns = (ref, sha) => {
15337
+ for (const r of (git.ghRunsForRef(repoAbs, ref, sha) || []).filter((x) => x.status !== 'completed' && x.databaseId)) {
15338
+ if (opts.dry) { print(` [dry] would cancel run ${r.databaseId} on ${ref}`); continue; }
15339
+ const cx = git.ghRunCancel(repoAbs, r.databaseId);
15340
+ if (!cx.ok) warn(`could not cancel run ${r.databaseId} on ${ref} — it will finish on a ref that is gone`);
15341
+ }
15342
+ };
15343
+
15325
15344
  // ---- (b) trunk CI, read with NO doors: the cure/grant doors apply per member, never to a batch ----
15326
15345
  const tci = shipCiCheck(repoAbs, gh, trunk, trunk, null, null);
15327
15346
  const trunkCi = tci.ok ? 'green' : (tci.class === SELF_CLEARING ? 'pending' : 'red');
15328
15347
  if (trunkCi === 'red') {
15348
+ // #656: going serial here gives up on these members, so a ref this command staged for them on an
15349
+ // earlier call is landed by nobody — and it would read "in flight" to the next --batch at this base
15350
+ // and to every serial door, until trunk moved (which the lock itself was preventing). Delete each
15351
+ // ref rooted at trunk's tip whose members are ALL named here; one that also carries another
15352
+ // caller's member stays (#581). Still fails closed: nothing lands, the members go serial.
15353
+ releaseGivenUpBatches();
15329
15354
  return serial(`trunk CI not green (${tci.detail}) — a batch never passes the cure/grant doors; each member meets them on its own`);
15330
15355
  }
15356
+ function releaseGivenUpBatches() {
15357
+ const ls = git.git(['ls-remote', remote, `refs/heads/${trunk}`, 'refs/heads/ship-batch/*'], repoAbs);
15358
+ if (!ls.ok) { warn(`could not read ${remote}'s ship-batch refs — a batch staged for ${members.join(', ')} (if any) stays; delete it by hand`); return; }
15359
+ const rows = ls.stdout.split('\n').map((l) => l.split('\t')).filter(([sha, ref]) => sha && ref).map(([sha, ref]) => [sha.trim(), ref.trim()]);
15360
+ const tip = ((rows.find(([, ref]) => ref === `refs/heads/${trunk}`) || [])[0]) || '';
15361
+ const refs = rows.map(([sha, ref]) => ({ sha, parsed: shipBatch.parseBatchRef(ref) })).filter((x) => x.parsed);
15362
+ if (!tip || !refs.length) return;
15363
+ const chains = shipBatch.batchChains({ refs: refs.map((x) => ({ ref: x.parsed.ref, base7: x.parsed.base7, sha: x.sha })), trunkNow: tip });
15364
+ const rooted = refs.filter((x) => chains.get(x.parsed.ref).rooted).map((x) => {
15365
+ // Each ref's OWN members: its trailers name it (a chain child's commits sit above its parent's).
15366
+ const lg = git.git(['log', '--format=%B%x00', `${tip}..${x.sha}`], repoAbs);
15367
+ const own = shipBatch.parseMemberTrailers(lg.ok ? lg.stdout.split('\0') : []).filter((m) => m.ref === x.parsed.ref).reverse();
15368
+ return { ref: x.parsed.ref, sha: x.sha, members: own.map((m) => m.branch) };
15369
+ });
15370
+ for (const ref of shipBatch.givenUpRefs({ refs: rooted, members })) {
15371
+ const b = rooted.find((x) => x.ref === ref);
15372
+ print(` ${ref} carries ${b.members.join(', ')} — every one going serial now, so nothing would ever land it; ${opts.dry ? 'would delete it [DRY RUN]' : 'deleting it'} (#656)`);
15373
+ cancelRuns(ref, b.sha);
15374
+ deleteRef(ref);
15375
+ }
15376
+ }
15331
15377
  if (trunkCi === 'pending') {
15332
15378
  print(`⏸ ship-batch: trunk CI is still running (${tci.detail}) — wait on it (bounded, B1a), then run this command again.`);
15333
15379
  return 3;
@@ -15342,13 +15388,6 @@ function cmdShipBatch(opts) {
15342
15388
  const batchRefs = (lsBatch.ok ? lsBatch.stdout.split('\n') : []).map((l) => l.split('\t'))
15343
15389
  .map(([sha, ref]) => ({ sha: (sha || '').trim(), parsed: shipBatch.parseBatchRef((ref || '').trim()) }))
15344
15390
  .filter((x) => x.sha && x.parsed);
15345
- // #415: every write on the resume path goes through here or shipBatchLand — under --dry, neither writes.
15346
- const deleteRef = (ref) => {
15347
- if (opts.dry) { print(` [dry] would delete ${remote}/${ref}`); return true; }
15348
- const d = git.git(['push', remote, '--delete', ref], repoAbs);
15349
- if (!d.ok) warn(`could not delete ${remote}/${ref}: ${git.gitFailureLine(d.stderr)} — delete it by hand`);
15350
- return d.ok;
15351
- };
15352
15391
  // #605: the sweep is chain-aware. A ref built `--onto` another batch's head is kept while its chain
15353
15392
  // ends at a batch on trunk's tip (lib/ship-batch.js batchChains, read from ls-remote alone); a ref
15354
15393
  // whose parent is gone, or whose root trunk has moved past, is deleted. Without any chained ref this
@@ -15367,11 +15406,7 @@ function cmdShipBatch(opts) {
15367
15406
  const offTrunk = !baseFull.ok || !git.git(['merge-base', '--is-ancestor', baseFull.stdout.trim(), trunkNow], repoAbs).ok;
15368
15407
  if (offTrunk) {
15369
15408
  print(` ${b.parsed.ref} is not rooted at ${trunk}'s tip — ${c.why}; nothing landed from it; deleting it`);
15370
- for (const r of (git.ghRunsForRef(repoAbs, b.parsed.ref, b.sha) || []).filter((x) => x.status !== 'completed' && x.databaseId)) {
15371
- if (opts.dry) { print(` [dry] would cancel run ${r.databaseId} on ${b.parsed.ref}`); continue; }
15372
- const cx = git.ghRunCancel(repoAbs, r.databaseId);
15373
- if (!cx.ok) warn(`could not cancel run ${r.databaseId} on ${b.parsed.ref} — it will finish on a ref that is gone`);
15374
- }
15409
+ cancelRuns(b.parsed.ref, b.sha);
15375
15410
  } else {
15376
15411
  print(` trunk moved since ${b.parsed.ref} was built (${b.parsed.base7} → ${shortSha(trunkNow)}) — nothing landed; rebuilding`);
15377
15412
  }
@@ -470,6 +470,29 @@ function foreignBatchStep(verdict) {
470
470
  return verdict && verdict.state === 'red' ? { step: 'clear', why: verdict.why } : { step: 'wait' };
471
471
  }
472
472
 
473
+ /**
474
+ * #656: a `--batch` call that goes SERIAL before it reaches the existing-batch step (trunk CI not
475
+ * green) is giving up on its members — they go to `colab ship --branch`, one at a time. A ref it
476
+ * staged on an earlier call is then landed by nobody: no caller names that set again, and the ref
477
+ * still reads "in flight" to the next `--batch` at the same base (foreignBatchStep waits on a green
478
+ * ref forever) and to the serial doors (laneHold). Measured: one repo paused 14 h on such a ref.
479
+ *
480
+ * Which refs this call abandons: those whose carried members are ALL named by this call. A ref that
481
+ * also carries a member this call does not name belongs, at least in part, to another caller — it
482
+ * stays, exactly as #581 keeps it. A ref whose members could not be read (empty list) stays too:
483
+ * never deleted on a guess.
484
+ *
485
+ * In: refs `[{ ref, members: [branch…] }]` (the batch refs rooted at trunk's tip, each with the
486
+ * members its own Ship-Batch: trailers carry), members (the branches this call names).
487
+ * Out: the refs to delete, in input order.
488
+ */
489
+ function givenUpRefs({ refs, members } = {}) {
490
+ const named = new Set(Array.isArray(members) ? members : []);
491
+ return (Array.isArray(refs) ? refs : [])
492
+ .filter((r) => r && r.ref && Array.isArray(r.members) && r.members.length && r.members.every((b) => named.has(b)))
493
+ .map((r) => r.ref);
494
+ }
495
+
473
496
  /**
474
497
  * Does a green run on the batch ref count as trunk-green for the SAME sha (trunk fast-forwarded to
475
498
  * the batch head, so the sha is identical)? Only when the same workflows ran there — a workflow that
@@ -678,7 +701,7 @@ module.exports = {
678
701
  MAX_BATCH, REF_PREFIX, PROBE_REF, TRAILER_KEY, WAIT_KEY, STEPS_KEY, SIZE_TRAILER_KEY, DROP_TRAILER_KEY, DROP_CLASSES,
679
702
  parseShipBatch, parseShipBatchWait, parseShipBatchSteps, sizeTrailer, parseSizeTrailer, adaptiveSize, splitHalves, partnerWait, readySince, batchRefName, parseBatchRef, memberTrailer, parseMemberTrailers,
680
703
  droppedTrailer, parseDroppedTrailers, appendTrailers,
681
- branchCiClass, memberEligibility, selectMembers, wiring, combinedVerdict, nextStep, foreignBatchStep,
704
+ branchCiClass, memberEligibility, selectMembers, wiring, combinedVerdict, nextStep, foreignBatchStep, givenUpRefs,
682
705
  batchGreenCoversTrunk, evidenceSuffix, serialLine, notStaged, landPushFailure,
683
706
  LANE_GRACE_SEC, laneHold, settledAt, MAX_CHAIN_DEPTH, batchChains, chainedLandStep,
684
707
  };