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

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.4"
37
37
  }
package/tools/colab CHANGED
@@ -11104,8 +11104,14 @@ It never waits: each call reads the remote, takes ONE step and exits —
11104
11104
  NOT move (a local pre-push hook, a remote rejection): the push's own output is echoed, and
11105
11105
  re-running hits the same refusal until its cause is fixed (#509)
11106
11106
  One batch per base: a batch at this base carrying OTHER members is waited on (exit 3) while its run
11107
- is pending or green, but a declined one — its combined run red — is deleted and the batch you asked
11108
- for is built in its place, so the survivors of a decline can batch without landing serially first (#391).
11107
+ is pending, or green within ${shipBatch.LANE_GRACE_SEC / 60}m of settling (the serial doors' lane grace, below), but a declined one — its
11108
+ combined run red — is deleted and the batch you asked for is built in its place, so the survivors of a
11109
+ decline can batch without landing serially first (#391). A green one still unlanded past that grace lost
11110
+ its lander and is deleted and rebuilt the same way; a green one whose settle time cannot be read is
11111
+ still waited on — only a provably abandoned batch is deleted (#659).
11112
+ A call that goes serial on trunk CI not green gives up on its members, so it deletes every batch at
11113
+ trunk's tip whose members it ALL names (its run cancelled if still going) — nobody would ever land
11114
+ it, and it would hold this base for every later call; a batch also carrying another member stays (#656).
11109
11115
  The batch also holds the trunk LANE (#581): while a ship-batch/<trunk-sha7> ref at trunk's tip has its
11110
11116
  combined run in flight — or green within ${shipBatch.LANE_GRACE_SEC / 60}m, so its lander can land it — a serial
11111
11117
  \`colab ship --branch\` into trunk pauses with exit 3 (⏸ BATCH-IN-FLIGHT; its --dry --json row
@@ -15322,12 +15328,55 @@ function cmdShipBatch(opts) {
15322
15328
  const gh = isGhUsable(repoAbs);
15323
15329
  if (!gh) throw new UserError(`gh not usable (${ghUnusableWhy(repoAbs)}) — a batch cannot read its combined run`);
15324
15330
 
15331
+ // #415: every write on the resume path goes through here or shipBatchLand — under --dry, neither writes.
15332
+ const deleteRef = (ref) => {
15333
+ if (opts.dry) { print(` [dry] would delete ${remote}/${ref}`); return true; }
15334
+ const d = git.git(['push', remote, '--delete', ref], repoAbs);
15335
+ if (!d.ok) warn(`could not delete ${remote}/${ref}: ${git.gitFailureLine(d.stderr)} — delete it by hand`);
15336
+ return d.ok;
15337
+ };
15338
+ // A ref nothing can land any more may still have its run going: cancel it rather than let it finish.
15339
+ const cancelRuns = (ref, sha) => {
15340
+ for (const r of (git.ghRunsForRef(repoAbs, ref, sha) || []).filter((x) => x.status !== 'completed' && x.databaseId)) {
15341
+ if (opts.dry) { print(` [dry] would cancel run ${r.databaseId} on ${ref}`); continue; }
15342
+ const cx = git.ghRunCancel(repoAbs, r.databaseId);
15343
+ if (!cx.ok) warn(`could not cancel run ${r.databaseId} on ${ref} — it will finish on a ref that is gone`);
15344
+ }
15345
+ };
15346
+
15325
15347
  // ---- (b) trunk CI, read with NO doors: the cure/grant doors apply per member, never to a batch ----
15326
15348
  const tci = shipCiCheck(repoAbs, gh, trunk, trunk, null, null);
15327
15349
  const trunkCi = tci.ok ? 'green' : (tci.class === SELF_CLEARING ? 'pending' : 'red');
15328
15350
  if (trunkCi === 'red') {
15351
+ // #656: going serial here gives up on these members, so a ref this command staged for them on an
15352
+ // earlier call is landed by nobody — and it would read "in flight" to the next --batch at this base
15353
+ // and to every serial door, until trunk moved (which the lock itself was preventing). Delete each
15354
+ // ref rooted at trunk's tip whose members are ALL named here; one that also carries another
15355
+ // caller's member stays (#581). Still fails closed: nothing lands, the members go serial.
15356
+ releaseGivenUpBatches();
15329
15357
  return serial(`trunk CI not green (${tci.detail}) — a batch never passes the cure/grant doors; each member meets them on its own`);
15330
15358
  }
15359
+ function releaseGivenUpBatches() {
15360
+ const ls = git.git(['ls-remote', remote, `refs/heads/${trunk}`, 'refs/heads/ship-batch/*'], repoAbs);
15361
+ 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; }
15362
+ const rows = ls.stdout.split('\n').map((l) => l.split('\t')).filter(([sha, ref]) => sha && ref).map(([sha, ref]) => [sha.trim(), ref.trim()]);
15363
+ const tip = ((rows.find(([, ref]) => ref === `refs/heads/${trunk}`) || [])[0]) || '';
15364
+ const refs = rows.map(([sha, ref]) => ({ sha, parsed: shipBatch.parseBatchRef(ref) })).filter((x) => x.parsed);
15365
+ if (!tip || !refs.length) return;
15366
+ const chains = shipBatch.batchChains({ refs: refs.map((x) => ({ ref: x.parsed.ref, base7: x.parsed.base7, sha: x.sha })), trunkNow: tip });
15367
+ const rooted = refs.filter((x) => chains.get(x.parsed.ref).rooted).map((x) => {
15368
+ // Each ref's OWN members: its trailers name it (a chain child's commits sit above its parent's).
15369
+ const lg = git.git(['log', '--format=%B%x00', `${tip}..${x.sha}`], repoAbs);
15370
+ const own = shipBatch.parseMemberTrailers(lg.ok ? lg.stdout.split('\0') : []).filter((m) => m.ref === x.parsed.ref).reverse();
15371
+ return { ref: x.parsed.ref, sha: x.sha, members: own.map((m) => m.branch) };
15372
+ });
15373
+ for (const ref of shipBatch.givenUpRefs({ refs: rooted, members })) {
15374
+ const b = rooted.find((x) => x.ref === ref);
15375
+ 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)`);
15376
+ cancelRuns(ref, b.sha);
15377
+ deleteRef(ref);
15378
+ }
15379
+ }
15331
15380
  if (trunkCi === 'pending') {
15332
15381
  print(`⏸ ship-batch: trunk CI is still running (${tci.detail}) — wait on it (bounded, B1a), then run this command again.`);
15333
15382
  return 3;
@@ -15342,13 +15391,6 @@ function cmdShipBatch(opts) {
15342
15391
  const batchRefs = (lsBatch.ok ? lsBatch.stdout.split('\n') : []).map((l) => l.split('\t'))
15343
15392
  .map(([sha, ref]) => ({ sha: (sha || '').trim(), parsed: shipBatch.parseBatchRef((ref || '').trim()) }))
15344
15393
  .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
15394
  // #605: the sweep is chain-aware. A ref built `--onto` another batch's head is kept while its chain
15353
15395
  // ends at a batch on trunk's tip (lib/ship-batch.js batchChains, read from ls-remote alone); a ref
15354
15396
  // whose parent is gone, or whose root trunk has moved past, is deleted. Without any chained ref this
@@ -15367,11 +15409,7 @@ function cmdShipBatch(opts) {
15367
15409
  const offTrunk = !baseFull.ok || !git.git(['merge-base', '--is-ancestor', baseFull.stdout.trim(), trunkNow], repoAbs).ok;
15368
15410
  if (offTrunk) {
15369
15411
  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
- }
15412
+ cancelRuns(b.parsed.ref, b.sha);
15375
15413
  } else {
15376
15414
  print(` trunk moved since ${b.parsed.ref} was built (${b.parsed.base7} → ${shortSha(trunkNow)}) — nothing landed; rebuilding`);
15377
15415
  }
@@ -15448,15 +15486,23 @@ function cmdShipBatch(opts) {
15448
15486
  const inBatch = shipBatch.parseMemberTrailers(log.ok ? log.stdout.split('\0') : []).reverse();
15449
15487
  const foreign = inBatch.filter((m) => !members.includes(m.branch));
15450
15488
  // #391: a DECLINED batch (combined run red) is not in flight — clear it and build the one asked for.
15451
- const foreignStep = foreign.length ? shipBatch.foreignBatchStep(shipBatch.combinedVerdict(git.ghRunsForRef(repoAbs, atBase.parsed.ref, atBase.sha))) : null;
15489
+ // #659: nor is a green one past the lane grace (laneHold's rule) — its lander is gone.
15490
+ let foreignStep = null;
15491
+ if (foreign.length) {
15492
+ const runs = git.ghRunsForRef(repoAbs, atBase.parsed.ref, atBase.sha);
15493
+ foreignStep = shipBatch.foreignBatchStep(shipBatch.combinedVerdict(runs), { settledAtMs: shipBatch.settledAt(runs), nowMs: Date.now() });
15494
+ }
15452
15495
  if (foreignStep && foreignStep.step === 'wait') {
15453
- print(`⏸ ship-batch: another batch is in flight at this base — ${atBase.parsed.ref} carries ${inBatch.map((m) => m.branch).join(', ')}.`);
15496
+ print(`⏸ ship-batch: another batch is in flight at this base — ${atBase.parsed.ref} carries ${inBatch.map((m) => m.branch).join(', ')}${foreignStep.why ? ` (${foreignStep.why})` : ''}.`);
15454
15497
  print(' Wait for it to land or be declined, then run this command again.');
15455
15498
  return 3;
15456
15499
  }
15457
15500
  if (foreignStep) {
15458
- print(` ${atBase.parsed.ref} (${inBatch.map((m) => m.branch).join(', ')}) was declined — its combined run is red (${foreignStep.why}); nothing landed from it. Deleting it and building the requested batch.`);
15459
- if (!opts.dry && !deleteRef(atBase.parsed.ref)) throw new UserError(`could not clear the declined ${atBase.parsed.ref} — delete it by hand, then run this command again`);
15501
+ const carried = inBatch.map((m) => m.branch).join(', ');
15502
+ print(foreignStep.reason === 'abandoned'
15503
+ ? ` ${atBase.parsed.ref} (${carried}) was abandoned — its ${foreignStep.why}; nothing landed from it. Deleting it and building the requested batch.`
15504
+ : ` ${atBase.parsed.ref} (${carried}) was declined — its combined run is red (${foreignStep.why}); nothing landed from it. Deleting it and building the requested batch.`);
15505
+ if (!opts.dry && !deleteRef(atBase.parsed.ref)) throw new UserError(`could not clear the ${foreignStep.reason === 'abandoned' ? 'abandoned' : 'declined'} ${atBase.parsed.ref} — delete it by hand (\`git push ${remote} --delete ${atBase.parsed.ref}\`), then run this command again`);
15460
15506
  }
15461
15507
  if (!foreignStep) {
15462
15508
  const heads = inBatch.map((m) => ({ ...m, now: git.branchRefs(repoAbs, m.branch, remote).remoteSha }));
@@ -462,12 +462,54 @@ function nextStep({ enabled, wired, trunkCi, eligibleCount = 0, existing = null,
462
462
  * for. Is it still in flight, or already declined? Only a pending/green (or not-yet-run) batch is in
463
463
  * flight and may make the new request wait; a red one — first attempt or after its re-run — has
464
464
  * been declined (`red-rerun-or-serial` keeps its ref so the one re-run stays possible), and keeping
465
- * it would block every later batch at this base until trunk moved. So:
466
- * clear its combined run is red → delete the ref, then build the requested batch
467
- * wait anything else (pending, none, green, unreadable) → exit 3, exactly as before
465
+ * it would block every later batch at this base until trunk moved.
466
+ *
467
+ * #659: a GREEN one is in flight only for the grace the serial doors give it (laneHold): its lander
468
+ * lands it on its next call, so a green ref still at trunk's tip `graceSec` after its run settled has
469
+ * lost its lander (died after green, before the fast-forward) and would pause every batch at this
470
+ * base until trunk moved for some other reason — while the serial doors already release it. So:
471
+ * clear red → `reason: 'red'`; green, settled ≥ graceSec ago → `reason: 'abandoned'`
472
+ * → delete the ref, then build the requested batch
473
+ * wait anything else → exit 3: pending, none, green within the grace — and green whose settle
474
+ * time could not be read. That last one deliberately differs from laneHold, which releases
475
+ * it: deleting another caller's green run is not undoable, so the batch door clears only a
476
+ * provably abandoned ref (#391's pinned case, kept on purpose — recorded on #659).
477
+ * `settledAtMs` is settledAt() of the ref's runs; `nowMs` the clock.
478
+ */
479
+ function foreignBatchStep(verdict, { settledAtMs = null, nowMs = null, graceSec = LANE_GRACE_SEC } = {}) {
480
+ if (verdict && verdict.state === 'red') return { step: 'clear', reason: 'red', why: verdict.why };
481
+ if (verdict && verdict.state === 'green' && Number.isFinite(settledAtMs) && Number.isFinite(nowMs)) {
482
+ const mins = Math.max(0, Math.round((nowMs - settledAtMs) / 60000));
483
+ if ((nowMs - settledAtMs) >= graceSec * 1000) {
484
+ return { step: 'clear', reason: 'abandoned', why: `combined run green ${mins}m ago and still not landed (grace ${graceSec}s) — treated as abandoned` };
485
+ }
486
+ return { step: 'wait', why: `combined run green ${mins}m ago — its lander lands it on its next call; past ${Math.round(graceSec / 60)}m unlanded it is cleared` };
487
+ }
488
+ return { step: 'wait' };
489
+ }
490
+
491
+ /**
492
+ * #656: a `--batch` call that goes SERIAL before it reaches the existing-batch step (trunk CI not
493
+ * green) is giving up on its members — they go to `colab ship --branch`, one at a time. A ref it
494
+ * staged on an earlier call is then landed by nobody: no caller names that set again, and the ref
495
+ * still reads "in flight" to the next `--batch` at the same base (foreignBatchStep waits on a green
496
+ * ref for LANE_GRACE_SEC since #659 — forever before it) and to the serial doors (laneHold).
497
+ * Measured: one repo paused 14 h on such a ref.
498
+ *
499
+ * Which refs this call abandons: those whose carried members are ALL named by this call. A ref that
500
+ * also carries a member this call does not name belongs, at least in part, to another caller — it
501
+ * stays, exactly as #581 keeps it. A ref whose members could not be read (empty list) stays too:
502
+ * never deleted on a guess.
503
+ *
504
+ * In: refs `[{ ref, members: [branch…] }]` (the batch refs rooted at trunk's tip, each with the
505
+ * members its own Ship-Batch: trailers carry), members (the branches this call names).
506
+ * Out: the refs to delete, in input order.
468
507
  */
469
- function foreignBatchStep(verdict) {
470
- return verdict && verdict.state === 'red' ? { step: 'clear', why: verdict.why } : { step: 'wait' };
508
+ function givenUpRefs({ refs, members } = {}) {
509
+ const named = new Set(Array.isArray(members) ? members : []);
510
+ return (Array.isArray(refs) ? refs : [])
511
+ .filter((r) => r && r.ref && Array.isArray(r.members) && r.members.length && r.members.every((b) => named.has(b)))
512
+ .map((r) => r.ref);
471
513
  }
472
514
 
473
515
  /**
@@ -678,7 +720,7 @@ module.exports = {
678
720
  MAX_BATCH, REF_PREFIX, PROBE_REF, TRAILER_KEY, WAIT_KEY, STEPS_KEY, SIZE_TRAILER_KEY, DROP_TRAILER_KEY, DROP_CLASSES,
679
721
  parseShipBatch, parseShipBatchWait, parseShipBatchSteps, sizeTrailer, parseSizeTrailer, adaptiveSize, splitHalves, partnerWait, readySince, batchRefName, parseBatchRef, memberTrailer, parseMemberTrailers,
680
722
  droppedTrailer, parseDroppedTrailers, appendTrailers,
681
- branchCiClass, memberEligibility, selectMembers, wiring, combinedVerdict, nextStep, foreignBatchStep,
723
+ branchCiClass, memberEligibility, selectMembers, wiring, combinedVerdict, nextStep, foreignBatchStep, givenUpRefs,
682
724
  batchGreenCoversTrunk, evidenceSuffix, serialLine, notStaged, landPushFailure,
683
725
  LANE_GRACE_SEC, laneHold, settledAt, MAX_CHAIN_DEPTH, batchChains, chainedLandStep,
684
726
  };