deepline 0.3.509 → 0.3.511

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.
Files changed (152) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +159 -0
  2. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  3. package/dist/bundling-sources/shared_libs/monitors/org-monitor-limits.ts +7 -2
  4. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +3 -3
  5. package/dist/bundling-sources/shared_libs/play-runtime/deployment/commands/roll-execution-relay.ts +94 -43
  6. package/dist/bundling-sources/shared_libs/play-runtime/deployment/commands/roll-receipt-gateway.ts +111 -27
  7. package/dist/bundling-sources/shared_libs/play-runtime/deployment/commands/runtime-topology.ts +79 -6
  8. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-machines.ts +80 -6
  9. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-transient-retry.ts +571 -0
  10. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +218 -33
  11. package/dist/cli/artifacts-G6JHRHY5.mjs +268 -0
  12. package/dist/cli/artifacts-PLF5ZUS7.js +268 -0
  13. package/dist/cli/{auth-6IR2QH4N.mjs → auth-2XMJMDWG.mjs} +5 -5
  14. package/dist/cli/auth-PI2KS2CD.js +43 -0
  15. package/dist/cli/{billing-WEWHH6ST.mjs → billing-6C5AI42X.mjs} +7 -7
  16. package/dist/cli/{billing-SYBK3ZYU.js → billing-Z3XFXP3H.js} +82 -82
  17. package/dist/cli/{chunk-JZJNA57M.js → chunk-2Q4H2Y6N.js} +6 -6
  18. package/dist/cli/{chunk-VTVZ7EUA.js → chunk-2YVRIXVR.js} +9 -9
  19. package/dist/cli/{chunk-RSKAPLST.mjs → chunk-5WTLXL6O.mjs} +1 -1
  20. package/dist/cli/{chunk-YJM3NOME.mjs → chunk-77DPQI6W.mjs} +94 -10
  21. package/dist/cli/{chunk-FNLGMMJJ.mjs → chunk-ASXOFBF7.mjs} +2 -2
  22. package/dist/cli/{chunk-AO63MXT6.js → chunk-BHV7JKXQ.js} +1 -1
  23. package/dist/cli/{chunk-RA2NKHV5.js → chunk-D5VWSR4D.js} +5 -5
  24. package/dist/cli/{chunk-CMSPA5VX.js → chunk-FAGSSIOY.js} +6 -6
  25. package/dist/cli/{chunk-J5P4PDRT.js → chunk-FF25PDQ2.js} +94 -10
  26. package/dist/cli/{chunk-SEQIB5WJ.mjs → chunk-FTT2SBBH.mjs} +5 -5
  27. package/dist/cli/{chunk-5Y3I5LEQ.js → chunk-FV4PASXH.js} +16 -16
  28. package/dist/cli/{chunk-GTAU4C44.js → chunk-GD3ES3JU.js} +14 -14
  29. package/dist/cli/{chunk-HMAETS53.js → chunk-GGQHOLH6.js} +3 -3
  30. package/dist/cli/{chunk-T67NAGSD.mjs → chunk-GJWL4KTY.mjs} +4 -4
  31. package/dist/cli/{chunk-6KBVQ76G.mjs → chunk-HLEZQDEZ.mjs} +2 -2
  32. package/dist/cli/{chunk-WJ6H2W3O.mjs → chunk-ISY7PBIK.mjs} +5 -5
  33. package/dist/cli/{chunk-AD45WJHN.js → chunk-IYWN7M4I.js} +5 -5
  34. package/dist/cli/{chunk-3CZHC24N.mjs → chunk-JDDKJIZU.mjs} +1 -1
  35. package/dist/cli/{chunk-E3HWUGDT.mjs → chunk-JHBZBCU4.mjs} +1 -1
  36. package/dist/cli/{chunk-7KALZEDZ.js → chunk-JIY25SUX.js} +4 -4
  37. package/dist/cli/{chunk-726UDAV2.js → chunk-JYFLIQPE.js} +7 -7
  38. package/dist/cli/{chunk-DGOSW42X.js → chunk-K4JB2BZP.js} +96 -96
  39. package/dist/cli/{chunk-XEQH65DT.mjs → chunk-KK6NZHAJ.mjs} +1 -1
  40. package/dist/cli/chunk-KUDNPJ43.js +77 -0
  41. package/dist/cli/{chunk-IZW7IOD6.mjs → chunk-KXGH4YUQ.mjs} +1 -1
  42. package/dist/cli/{chunk-Q7G6WORO.js → chunk-KZBKQPSA.js} +2 -2
  43. package/dist/cli/{chunk-4DVANPBN.js → chunk-LDZYGM7W.js} +41 -41
  44. package/dist/cli/{chunk-XPKBYMJH.js → chunk-LKSJXTRP.js} +53 -53
  45. package/dist/cli/{chunk-Q5UO2ENN.js → chunk-NVMNMKZW.js} +3 -3
  46. package/dist/cli/{chunk-VZ773N7G.js → chunk-O37BQ2CG.js} +21 -10
  47. package/dist/cli/{chunk-OOD5LGUS.mjs → chunk-OQ4YBPOQ.mjs} +3 -3
  48. package/dist/cli/{chunk-UART6FGK.mjs → chunk-PCI4MMH7.mjs} +1 -1
  49. package/dist/cli/{chunk-2ZJRCAHG.js → chunk-PI45LZ5B.js} +11 -11
  50. package/dist/cli/{chunk-O527H5GY.js → chunk-PUFEARWT.js} +16 -16
  51. package/dist/cli/{chunk-25MAOMVS.mjs → chunk-QDWNVTTO.mjs} +2 -2
  52. package/dist/cli/{chunk-WUKNKFB3.mjs → chunk-RPPU3XB3.mjs} +2 -2
  53. package/dist/cli/{chunk-XIBNY6H6.mjs → chunk-S5C4CWSS.mjs} +5 -5
  54. package/dist/cli/{chunk-2U7Z4LFG.mjs → chunk-S6KEACD3.mjs} +6 -6
  55. package/dist/cli/{chunk-Y4M5HPQV.mjs → chunk-SI4QXATV.mjs} +5 -5
  56. package/dist/cli/{chunk-R2KNJMOY.mjs → chunk-VEOFISLZ.mjs} +1 -1
  57. package/dist/cli/{chunk-Z2LVZDO5.js → chunk-VHFTN6VY.js} +44 -44
  58. package/dist/cli/{chunk-54YPOG5W.mjs → chunk-VQ74WMKG.mjs} +15 -4
  59. package/dist/cli/{chunk-ZXGMWXZW.js → chunk-WDBEWOU6.js} +2 -2
  60. package/dist/cli/{chunk-6TBRWRJ2.js → chunk-XGXXNT4O.js} +270 -199
  61. package/dist/cli/chunk-XREZY4FA.mjs +77 -0
  62. package/dist/cli/{chunk-K2RCVD7S.mjs → chunk-XSBGWMI6.mjs} +72 -1
  63. package/dist/cli/{chunk-S7JEF2MR.mjs → chunk-XXQZYLLL.mjs} +2 -2
  64. package/dist/cli/{chunk-EEEWADSR.mjs → chunk-XZ6IZIQJ.mjs} +2 -2
  65. package/dist/cli/{chunk-WPBTWRKG.js → chunk-YX7E2VQM.js} +26 -26
  66. package/dist/cli/{chunk-FQCIYGQY.mjs → chunk-ZFJ2U76O.mjs} +2 -2
  67. package/dist/cli/{chunk-7NMPGX3W.js → chunk-ZWGBQKW7.js} +21 -21
  68. package/dist/cli/{chunk-VH522HUP.mjs → chunk-ZYVR4A4P.mjs} +10 -10
  69. package/dist/cli/command-docs.js +2 -2
  70. package/dist/cli/command-docs.mjs +1 -1
  71. package/dist/cli/{csv-4LAJ2ZKG.mjs → csv-CNK6ZF3T.mjs} +4 -4
  72. package/dist/cli/{csv-5KNONIAX.js → csv-S44OGG2O.js} +13 -13
  73. package/dist/cli/{db-BEVCJI66.mjs → db-AVO6QJU6.mjs} +6 -6
  74. package/dist/cli/{db-5PEXOSN3.js → db-WKZ6EXNG.js} +27 -27
  75. package/dist/cli/{describe-TDJIUSD6.mjs → describe-2HQRT5MI.mjs} +18 -18
  76. package/dist/cli/describe-CCK77NER.js +50 -0
  77. package/dist/cli/describe-core.d.mts +2 -2
  78. package/dist/cli/describe-core.d.ts +2 -2
  79. package/dist/cli/{executions-KXCPU6YC.mjs → executions-DKHOR7HD.mjs} +6 -6
  80. package/dist/cli/{executions-36GV3A27.js → executions-MTAHNARA.js} +8 -8
  81. package/dist/cli/{feedback-GEUUT4S7.mjs → feedback-K6SJS4LG.mjs} +11 -7
  82. package/dist/cli/{feedback-SPQABV33.js → feedback-R2UABU3E.js} +15 -11
  83. package/dist/cli/{git-AE36X2R6.mjs → git-3EPA7433.mjs} +5 -5
  84. package/dist/cli/git-7L3PY2A4.js +25 -0
  85. package/dist/cli/index.js +177 -156
  86. package/dist/cli/index.mjs +80 -59
  87. package/dist/cli/{legacy-noops-TKPHN7WT.js → legacy-noops-3Q2D2F24.js} +9 -8
  88. package/dist/cli/{legacy-noops-LUEDAK7J.mjs → legacy-noops-66OPCJJD.mjs} +6 -5
  89. package/dist/cli/{monitors-JHJZ5XG7.mjs → monitors-2PYPRWT4.mjs} +7 -7
  90. package/dist/cli/{monitors-B2EAIGZI.js → monitors-KHH4MZDF.js} +100 -100
  91. package/dist/cli/{org-GUICCEBZ.mjs → org-WAW3OL7B.mjs} +6 -6
  92. package/dist/cli/{org-PYCPXEAU.js → org-X5G36B2Q.js} +72 -72
  93. package/dist/cli/{pages-Y2XI36HY.mjs → pages-KABWXDGW.mjs} +6 -6
  94. package/dist/cli/{pages-CV4TQNFY.js → pages-XDPHCHHU.js} +18 -18
  95. package/dist/cli/{play-VWCQNGZZ.mjs → play-654B2HQU.mjs} +18 -18
  96. package/dist/cli/{play-MTVK66JK.js → play-UE5FKQCO.js} +317 -317
  97. package/dist/cli/{providers-N72BUCXZ.js → providers-QT2BZMJ7.js} +9 -9
  98. package/dist/cli/{providers-ZOZTST3A.mjs → providers-SKNGX6IT.mjs} +6 -6
  99. package/dist/cli/{quickstart-DXIC3NHS.mjs → quickstart-BX7XMJIQ.mjs} +4 -4
  100. package/dist/cli/{quickstart-FK53VZB3.js → quickstart-XWDVAQTT.js} +6 -6
  101. package/dist/cli/{run-NNAYDCEN.js → run-C6YYD4AK.js} +41 -41
  102. package/dist/cli/{run-IL2KI33N.mjs → run-JTU4K4MY.mjs} +23 -23
  103. package/dist/cli/{search-7IPVMQCO.mjs → search-NHV4Y4SX.mjs} +8 -8
  104. package/dist/cli/search-RIFW5JCK.js +33 -0
  105. package/dist/cli/{search-output-ZY2GE35S.mjs → search-output-AAOMFK7K.mjs} +4 -4
  106. package/dist/cli/{search-output-YHTWLSDE.js → search-output-WLFFEGCY.js} +6 -6
  107. package/dist/cli/{secrets-ZML76SH2.js → secrets-H4WTLQJJ.js} +15 -15
  108. package/dist/cli/{secrets-BGUMHDZ7.mjs → secrets-S66PZSRO.mjs} +6 -6
  109. package/dist/cli/sessions-EFWO62XJ.js +18 -0
  110. package/dist/cli/{sessions-F5XO6HZJ.mjs → sessions-PY6FJX3O.mjs} +6 -5
  111. package/dist/cli/{settings-73SMIICV.mjs → settings-V7BM42KQ.mjs} +39 -12
  112. package/dist/cli/{settings-TOX2P5M5.js → settings-YO4FFPN6.js} +109 -82
  113. package/dist/cli/{setup-DNFHFQ7N.js → setup-IFZYYQ2W.js} +50 -50
  114. package/dist/cli/{setup-FDJZYBMS.mjs → setup-VUBM2HMH.mjs} +10 -10
  115. package/dist/cli/{skills-6HJ2IAY6.mjs → skills-EYWRSQQJ.mjs} +8 -8
  116. package/dist/cli/skills-LFP53SWQ.js +37 -0
  117. package/dist/cli/tools-SR2Q7KC5.js +57 -0
  118. package/dist/cli/{tools-4FJIIE4R.mjs → tools-VZOW4MUD.mjs} +17 -17
  119. package/dist/cli/update-ADZBZZZS.js +35 -0
  120. package/dist/cli/{update-UMRPPILV.mjs → update-CQDJJYU2.mjs} +10 -10
  121. package/dist/cli/{workflow-LSFOG5VU.mjs → workflow-2VRDIPF3.mjs} +7 -7
  122. package/dist/cli/{workflow-SK3BUHB4.js → workflow-XS3JEU6X.js} +17 -17
  123. package/dist/{client-DMpsMNH9.d.mts → client-By7bUS8h.d.mts} +1 -1
  124. package/dist/{client-BlwD-G4v.d.ts → client-CmlKSBXd.d.ts} +1 -1
  125. package/dist/{client-core-DwBLuEkm.d.ts → client-core-BM0mKhgp.d.ts} +93 -1
  126. package/dist/{client-core-CITtRTbB.d.mts → client-core-BZ3tpY_J.d.mts} +93 -1
  127. package/dist/index.d.mts +3 -3
  128. package/dist/index.d.ts +3 -3
  129. package/dist/index.js +9 -9
  130. package/dist/index.mjs +6 -6
  131. package/dist/install-integrity.json +111 -106
  132. package/dist/plays/play-description.d.mts +1 -1
  133. package/dist/plays/play-description.d.ts +1 -1
  134. package/dist/plays/run-request.d.mts +1 -1
  135. package/dist/plays/run-request.d.ts +1 -1
  136. package/dist/release.d.mts +1 -1
  137. package/dist/release.d.ts +1 -1
  138. package/dist/release.js +2 -2
  139. package/dist/release.mjs +1 -1
  140. package/dist/server.d.mts +2 -2
  141. package/dist/server.d.ts +2 -2
  142. package/dist/server.js +5 -5
  143. package/dist/server.mjs +3 -3
  144. package/package.json +1 -1
  145. package/dist/cli/auth-SUTQ4SZQ.js +0 -43
  146. package/dist/cli/describe-ZB6G6DOV.js +0 -50
  147. package/dist/cli/git-UX7L6R32.js +0 -25
  148. package/dist/cli/search-OZHP5ZE2.js +0 -33
  149. package/dist/cli/sessions-WDINUUZ3.js +0 -17
  150. package/dist/cli/skills-NE7WN5PP.js +0 -37
  151. package/dist/cli/tools-ETX4MNNO.js +0 -57
  152. package/dist/cli/update-N2DMPSUH.js +0 -35
@@ -21,6 +21,14 @@
21
21
  import { spawn, spawnSync } from 'node:child_process';
22
22
  import { resolve } from 'node:path';
23
23
  import { FlyMachinesClient, requireFlyToken } from '../fly-machines';
24
+ import {
25
+ applyToEveryMachine,
26
+ classifyFlyRequestError,
27
+ createWithReadBeforeRetry,
28
+ describeMachineFailures,
29
+ runFlyctlWithTransientRetry,
30
+ runFlyctlWithTransientRetrySync,
31
+ } from '../fly-transient-retry';
24
32
  import {
25
33
  RECEIPT_GATEWAY_DRAIN_TIMEOUT,
26
34
  stopAndDestroyCordonedMachines,
@@ -144,12 +152,29 @@ export function runReceiptGatewayCommand(
144
152
  echoStdout?: boolean;
145
153
  timeoutMs?: number;
146
154
  spawnCommand?: ReceiptGatewayCommandSpawn;
155
+ /**
156
+ * Retry transient Fly API failures of a flyctl command that converges
157
+ * when repeated. `read` may also repeat after a timeout.
158
+ */
159
+ flyTransientRetry?: 'read' | 'idempotent-write';
160
+ sleep?: (milliseconds: number) => void;
147
161
  } = {},
148
162
  ): string {
149
163
  const spawnCommand: ReceiptGatewayCommandSpawn =
150
164
  options.spawnCommand ??
151
165
  ((executable, commandArgs, spawnOptions) =>
152
166
  spawnSync(executable, commandArgs, spawnOptions));
167
+ if (options.flyTransientRetry && command === 'flyctl') {
168
+ return runFlyctlWithTransientRetrySync(args, {
169
+ operation: options.flyTransientRetry,
170
+ env,
171
+ timeoutMs: options.timeoutMs,
172
+ echoStdout: options.echoStdout,
173
+ spawn: (executable, commandArgs, spawnOptions) =>
174
+ spawnCommand(executable, commandArgs, spawnOptions),
175
+ ...(options.sleep ? { sleep: options.sleep } : {}),
176
+ });
177
+ }
153
178
  const result = spawnCommand(command, args, {
154
179
  encoding: 'utf8',
155
180
  env,
@@ -204,6 +229,23 @@ function runAsync(
204
229
  });
205
230
  }
206
231
 
232
+ /** Cordon and uncordon converge when repeated; retry transient Fly errors. */
233
+ async function setMachineRouting(
234
+ transition: 'cordon' | 'uncordon',
235
+ machineId: string,
236
+ ): Promise<void> {
237
+ await runFlyctlWithTransientRetry(
238
+ ['machine', transition, machineId, '-a', fleet.app],
239
+ { operation: 'idempotent-write', spawn: spawnSync },
240
+ );
241
+ }
242
+
243
+ function releaseFlyClient(): FlyMachinesClient {
244
+ return new FlyMachinesClient(fleet.app, requireFlyToken(), fetch, {
245
+ transientRetry: true,
246
+ });
247
+ }
248
+
207
249
  function receiptGatewayImage(operationId: string): string {
208
250
  return `registry.fly.io/${fleet.app}:git-${operationId}`;
209
251
  }
@@ -269,6 +311,7 @@ function machines(): FlyMachine[] {
269
311
  {
270
312
  echoStdout: false,
271
313
  timeoutMs: FLY_MACHINE_INVENTORY_TIMEOUT_MS,
314
+ flyTransientRetry: 'read',
272
315
  },
273
316
  );
274
317
  const parsed: unknown = JSON.parse(output);
@@ -767,7 +810,7 @@ async function persistCandidatePhase(input: {
767
810
  candidates: readonly FlyMachine[];
768
811
  phase: ReceiptGatewayOperationPhase;
769
812
  }): Promise<void> {
770
- const client = new FlyMachinesClient(fleet.app, requireFlyToken(), fetch);
813
+ const client = releaseFlyClient();
771
814
  await Promise.all(
772
815
  input.candidates.map(async (candidate) => {
773
816
  if (!candidate.id) throw new Error('Receipt candidate has no identity.');
@@ -814,7 +857,7 @@ async function removeCordoned(operationId: string): Promise<void> {
814
857
  'Refusing to remove a receipt candidate that received public traffic.',
815
858
  );
816
859
  }
817
- const client = new FlyMachinesClient(fleet.app, requireFlyToken(), fetch);
860
+ const client = releaseFlyClient();
818
861
  await stopAndDestroyCordonedMachines({
819
862
  machineIds: targets.map((machine) => machine.id!).filter(Boolean),
820
863
  readMachines: machines,
@@ -832,7 +875,7 @@ async function removeCordoned(operationId: string): Promise<void> {
832
875
  /** The public green candidates are the durable Fly operation record. Their
833
876
  * source metadata is the only authority for destructive blue retirement. */
834
877
  async function drain(operationId: string): Promise<void> {
835
- const client = new FlyMachinesClient(fleet.app, requireFlyToken(), fetch);
878
+ const client = releaseFlyClient();
836
879
  const green = candidatesFor(operationId, await client.listMachines());
837
880
  if (
838
881
  green.length < fleet.minimumMachines ||
@@ -889,12 +932,9 @@ async function prepare(operationId: string): Promise<void> {
889
932
  if (existing.length > 0) {
890
933
  assertCandidateSourceGeneration({ candidates: existing, serving: blue });
891
934
  }
892
- const client = new FlyMachinesClient(fleet.app, requireFlyToken(), fetch);
893
- for (const [index, source] of blue.entries()) {
894
- const name = candidateName(operationId, index);
895
- if (existing.some((machine) => machine.name === name)) continue;
896
- if (!source.id) throw new Error('Serving Machine has no identity.');
897
- await client.createMachine({
935
+ const client = releaseFlyClient();
936
+ const createCandidate = (name: string, sourceId: string) =>
937
+ client.createMachine({
898
938
  name,
899
939
  region: fleet.primaryRegion,
900
940
  skip_service_registration: true,
@@ -905,13 +945,31 @@ async function prepare(operationId: string): Promise<void> {
905
945
  metadata: {
906
946
  deepline_gateway_role: 'receipt',
907
947
  deepline_gateway_rollout: operationId,
908
- deepline_gateway_source_machine: source.id,
948
+ deepline_gateway_source_machine: sourceId,
909
949
  [RECEIPT_GATEWAY_OPERATION_PHASE_METADATA_KEY]:
910
950
  ReceiptGatewayOperationPhase.Prepared,
911
951
  fly_process_group: fleet.processGroup,
912
952
  },
913
953
  }),
914
954
  });
955
+ for (const [index, source] of blue.entries()) {
956
+ const name = candidateName(operationId, index);
957
+ if (existing.some((machine) => machine.name === name)) continue;
958
+ if (!source.id) throw new Error('Serving Machine has no identity.');
959
+ const sourceId = source.id;
960
+ // A transient create failure is ambiguous; re-read before any retry so a
961
+ // candidate Fly already created is adopted, never duplicated. The result
962
+ // is unused (waitForCandidates re-reads), and the create response and the
963
+ // inventory entry are different FlyMachine shapes, so neither narrows T.
964
+ await createWithReadBeforeRetry<unknown>({
965
+ create: () => createCandidate(name, sourceId),
966
+ findExisting: async () =>
967
+ candidatesFor(operationId, await client.listMachines()).find(
968
+ (machine) => machine.name === name,
969
+ ),
970
+ classify: classifyFlyRequestError,
971
+ options: { label: `Create receipt gateway candidate ${name}` },
972
+ });
915
973
  }
916
974
  const ready = await waitForCandidates(operationId, blue.length);
917
975
  await assertPublic(blue.map((machine) => machine.id!));
@@ -1030,8 +1088,13 @@ export async function activateCordonedReceiptCandidates(input: {
1030
1088
  onRetry: reportGatewayRouteProbeRetry,
1031
1089
  });
1032
1090
  } catch (error) {
1033
- for (const machineId of input.greenMachineIds)
1034
- await input.cordon(machineId);
1091
+ // Attempt every candidate even when one fails, then report every Machine
1092
+ // that could still be admitted.
1093
+ const removed = await applyToEveryMachine({
1094
+ machineIds: input.greenMachineIds,
1095
+ action: 'cordon',
1096
+ apply: input.cordon,
1097
+ });
1035
1098
  await input.sleep(POLL_MS);
1036
1099
  await waitForGatewayRouteProbe({
1037
1100
  description: 'Receipt gateway rollback generation',
@@ -1039,6 +1102,12 @@ export async function activateCordonedReceiptCandidates(input: {
1039
1102
  sleep: input.sleep,
1040
1103
  onRetry: reportGatewayRouteProbeRetry,
1041
1104
  });
1105
+ if (removed.failed.length > 0) {
1106
+ throw new Error(
1107
+ `Receipt gateway candidate activation failed and ${removed.failed.length}/${input.greenMachineIds.length} candidate Machine(s) [${removed.failed.map(({ machineId }) => machineId).join(', ')}] could not be cordoned: ${describeMachineFailures('cordon', removed.failed)}`,
1108
+ { cause: error },
1109
+ );
1110
+ }
1042
1111
  throw error;
1043
1112
  }
1044
1113
  }
@@ -1062,7 +1131,21 @@ export async function restoreReceiptGatewaySourceGeneration(input: {
1062
1131
  'Gateway rollback requires exact green and blue Machine identities.',
1063
1132
  );
1064
1133
  }
1065
- for (const machineId of input.blueMachineIds) await input.uncordon(machineId);
1134
+ // Attempt every source Machine even when one fails, so one provider error
1135
+ // cannot leave the rest of the retained fleet cordoned and unreported.
1136
+ const restored = await applyToEveryMachine({
1137
+ machineIds: input.blueMachineIds,
1138
+ action: 'uncordon',
1139
+ apply: input.uncordon,
1140
+ });
1141
+ if (restored.failed.length > 0) {
1142
+ // Keep the candidate generation admitted: cordoning it beside an
1143
+ // incomplete source fleet could drop receipt capacity below its minimum.
1144
+ // Rerunning rollback converges because uncordon is idempotent.
1145
+ throw new Error(
1146
+ `Receipt gateway rollback could not restore ${restored.failed.length}/${input.blueMachineIds.length} source Machine(s) [${restored.failed.map(({ machineId }) => machineId).join(', ')}]; the candidate generation [${input.greenMachineIds.join(', ')}] stays admitted: ${describeMachineFailures('uncordon', restored.failed)}`,
1147
+ );
1148
+ }
1066
1149
  await input.sleep(POLL_MS);
1067
1150
  await waitForGatewayRouteProbe({
1068
1151
  description: 'Receipt gateway rollback source generation',
@@ -1070,7 +1153,11 @@ export async function restoreReceiptGatewaySourceGeneration(input: {
1070
1153
  sleep: input.sleep,
1071
1154
  onRetry: reportGatewayRouteProbeRetry,
1072
1155
  });
1073
- for (const machineId of input.greenMachineIds) await input.cordon(machineId);
1156
+ const removed = await applyToEveryMachine({
1157
+ machineIds: input.greenMachineIds,
1158
+ action: 'cordon',
1159
+ apply: input.cordon,
1160
+ });
1074
1161
  await input.sleep(POLL_MS);
1075
1162
  await waitForGatewayRouteProbe({
1076
1163
  description: 'Receipt gateway restored source generation',
@@ -1078,6 +1165,11 @@ export async function restoreReceiptGatewaySourceGeneration(input: {
1078
1165
  sleep: input.sleep,
1079
1166
  onRetry: reportGatewayRouteProbeRetry,
1080
1167
  });
1168
+ if (removed.failed.length > 0) {
1169
+ throw new Error(
1170
+ `Receipt gateway rollback restored the source generation but could not cordon ${removed.failed.length}/${input.greenMachineIds.length} candidate Machine(s) [${removed.failed.map(({ machineId }) => machineId).join(', ')}]: ${describeMachineFailures('cordon', removed.failed)}`,
1171
+ );
1172
+ }
1081
1173
  }
1082
1174
 
1083
1175
  function assertExactCordonedCandidates(input: {
@@ -1255,12 +1347,8 @@ async function activate(operationId: string): Promise<void> {
1255
1347
  uncordonMachineIds: green
1256
1348
  .filter((machine) => machine.cordoned === true)
1257
1349
  .map((machine) => machine.id!),
1258
- uncordon: (machineId) => {
1259
- run('flyctl', ['machine', 'uncordon', machineId, '-a', fleet.app]);
1260
- },
1261
- cordon: (machineId) => {
1262
- run('flyctl', ['machine', 'cordon', machineId, '-a', fleet.app]);
1263
- },
1350
+ uncordon: (machineId) => setMachineRouting('uncordon', machineId),
1351
+ cordon: (machineId) => setMachineRouting('cordon', machineId),
1264
1352
  assertPublic,
1265
1353
  sleep: (milliseconds) =>
1266
1354
  new Promise((resolve) => setTimeout(resolve, milliseconds)),
@@ -1280,7 +1368,7 @@ async function activate(operationId: string): Promise<void> {
1280
1368
  );
1281
1369
  for (const machine of blue) {
1282
1370
  if (machine.cordoned === false) {
1283
- run('flyctl', ['machine', 'cordon', machine.id!, '-a', fleet.app]);
1371
+ await setMachineRouting('cordon', machine.id!);
1284
1372
  }
1285
1373
  }
1286
1374
  await new Promise((resolve) => setTimeout(resolve, POLL_MS));
@@ -1320,12 +1408,8 @@ async function rollback(operationId: string): Promise<void> {
1320
1408
  await restoreReceiptGatewaySourceGeneration({
1321
1409
  greenMachineIds,
1322
1410
  blueMachineIds: sourceIds,
1323
- uncordon: (machineId) => {
1324
- run('flyctl', ['machine', 'uncordon', machineId, '-a', fleet.app]);
1325
- },
1326
- cordon: (machineId) => {
1327
- run('flyctl', ['machine', 'cordon', machineId, '-a', fleet.app]);
1328
- },
1411
+ uncordon: (machineId) => setMachineRouting('uncordon', machineId),
1412
+ cordon: (machineId) => setMachineRouting('cordon', machineId),
1329
1413
  assertPublic,
1330
1414
  sleep: (milliseconds) =>
1331
1415
  new Promise((resolve) => setTimeout(resolve, milliseconds)),
@@ -30,6 +30,12 @@ import {
30
30
  shouldCreateDetachedProcessGroup,
31
31
  terminateChildProcessTree,
32
32
  } from '../process-tree';
33
+ import {
34
+ classifyFlyCommandError,
35
+ classifyFlyCommandFailure,
36
+ FlyCommandError,
37
+ withFlyTransientRetry,
38
+ } from '../fly-transient-retry';
33
39
 
34
40
  export enum TopologyOperation {
35
41
  ReconcilePlatform = 'reconcile-platform',
@@ -109,6 +115,11 @@ export type RuntimeTopologyCommand = (input: {
109
115
  args: string[];
110
116
  environment: Record<string, string>;
111
117
  description: string;
118
+ /**
119
+ * A flyctl command that converges when repeated (a staged secret write of
120
+ * the same values). Transient Fly API failures are retried.
121
+ */
122
+ flyTransientRetry?: 'idempotent-write';
112
123
  }) => void | Promise<void>;
113
124
 
114
125
  /**
@@ -122,6 +133,7 @@ export type RuntimeTopologyParallelCommand = (input: {
122
133
  args: string[];
123
134
  environment: Record<string, string>;
124
135
  description: string;
136
+ flyTransientRetry?: 'idempotent-write';
125
137
  }) => Promise<void>;
126
138
 
127
139
  export type RuntimeTopologySpawn = (
@@ -149,9 +161,13 @@ const activeRuntimeTopologyCommands = new Set<ActiveRuntimeTopologyCommand>();
149
161
  const runtimeTopologyCancellationSignals: readonly RuntimeTopologyCancellationSignal[] =
150
162
  ['SIGINT', 'SIGTERM'];
151
163
 
164
+ /** Set once cancellation is requested so no transient retry starts after it. */
165
+ let runtimeTopologyCancellation: RuntimeTopologyCancellationSignal | undefined;
166
+
152
167
  function cancelActiveRuntimeTopologyCommands(
153
168
  signal: RuntimeTopologyCancellationSignal,
154
169
  ): number {
170
+ runtimeTopologyCancellation ??= signal;
155
171
  for (const command of activeRuntimeTopologyCommands) command.cancel(signal);
156
172
  return activeRuntimeTopologyCommands.size;
157
173
  }
@@ -254,18 +270,61 @@ export function runRuntimeTopologyCommand(
254
270
  }
255
271
  }
256
272
 
273
+ /** Enough trailing output to classify a flyctl transport failure. */
274
+ const FLY_RETRY_OUTPUT_TAIL_CHARACTERS = 16_384;
275
+
257
276
  export async function runRuntimeTopologyAsyncCommand(input: {
258
277
  command: string;
259
278
  args: string[];
260
279
  environment: Record<string, string>;
261
280
  description: string;
281
+ flyTransientRetry?: 'idempotent-write';
262
282
  }): Promise<void> {
283
+ if (!input.flyTransientRetry || input.command !== 'flyctl') {
284
+ await runRuntimeTopologyAsyncAttempt(input);
285
+ return;
286
+ }
287
+ const operation = input.flyTransientRetry;
288
+ await withFlyTransientRetry(
289
+ async (attempt) => {
290
+ if (attempt > 1 && runtimeTopologyCancellation) {
291
+ throw new Error(
292
+ `${input.description} was not retried: cancellation requested by ${runtimeTopologyCancellation}.`,
293
+ );
294
+ }
295
+ await runRuntimeTopologyAsyncAttempt({ ...input, operation });
296
+ },
297
+ classifyFlyCommandError,
298
+ { label: input.description },
299
+ );
300
+ }
301
+
302
+ /**
303
+ * One child process. With `operation` set, its output is forwarded live and a
304
+ * bounded tail is kept to classify a failure as a transient Fly API error.
305
+ */
306
+ async function runRuntimeTopologyAsyncAttempt(input: {
307
+ command: string;
308
+ args: string[];
309
+ environment: Record<string, string>;
310
+ description: string;
311
+ operation?: 'idempotent-write';
312
+ }): Promise<void> {
313
+ let outputTail = '';
314
+ const capture = (chunk: Buffer, sink: NodeJS.WriteStream): void => {
315
+ sink.write(chunk);
316
+ outputTail = `${outputTail}${chunk.toString('utf8')}`.slice(
317
+ -FLY_RETRY_OUTPUT_TAIL_CHARACTERS,
318
+ );
319
+ };
263
320
  await new Promise<void>((resolve, reject) => {
264
321
  const child = spawn(input.command, input.args, {
265
322
  env: { ...process.env, ...input.environment },
266
- stdio: 'inherit',
323
+ stdio: input.operation ? ['ignore', 'pipe', 'pipe'] : 'inherit',
267
324
  detached: shouldCreateDetachedProcessGroup(),
268
325
  });
326
+ child.stdout?.on('data', (chunk: Buffer) => capture(chunk, process.stdout));
327
+ child.stderr?.on('data', (chunk: Buffer) => capture(chunk, process.stderr));
269
328
  const activeCommand: ActiveRuntimeTopologyCommand = {
270
329
  cancel: (signal) => {
271
330
  if (child.exitCode === null && child.signalCode === null) {
@@ -301,12 +360,24 @@ export async function runRuntimeTopologyAsyncCommand(input: {
301
360
  resolve();
302
361
  return;
303
362
  }
363
+ const message = signal
364
+ ? `${input.description} was terminated by ${signal}.`
365
+ : `${input.description} failed with exit code ${status ?? '<unknown>'}.`;
366
+ if (!input.operation) {
367
+ reject(new Error(message));
368
+ return;
369
+ }
304
370
  reject(
305
- new Error(
306
- signal
307
- ? `${input.description} was terminated by ${signal}.`
308
- : `${input.description} failed with exit code ${status ?? '<unknown>'}.`,
309
- ),
371
+ new FlyCommandError({
372
+ message,
373
+ status,
374
+ classification: classifyFlyCommandFailure({
375
+ status,
376
+ signal,
377
+ output: outputTail,
378
+ operation: input.operation,
379
+ }),
380
+ }),
310
381
  );
311
382
  });
312
383
  });
@@ -376,6 +447,8 @@ async function stageSecrets(input: {
376
447
  ],
377
448
  environment: input.environment,
378
449
  description: `Stage secrets for ${app}`,
450
+ // Staging the same values again converges; Fly resets are transient.
451
+ flyTransientRetry: 'idempotent-write' as const,
379
452
  }));
380
453
  await runIndependentTopologyCommands(input, commands);
381
454
  }
@@ -38,6 +38,15 @@ import {
38
38
  runtimeMachineImageMatches,
39
39
  type FlyMachineImageRef,
40
40
  } from './fly-registry';
41
+ import {
42
+ classifyFlyRequestError,
43
+ FlyPermanentHttpError,
44
+ FlyRequestTimeoutError,
45
+ FlyTransientHttpError,
46
+ isTransientFlyHttpStatus,
47
+ parseRetryAfterMs,
48
+ withFlyTransientRetry,
49
+ } from './fly-transient-retry';
41
50
 
42
51
  export const FLY_MACHINES_API_BASE = 'https://api.machines.dev/v1';
43
52
  export const FLY_REGISTRY_HOST = 'registry.fly.io';
@@ -139,6 +148,34 @@ export const FLY_READ_RATE_LIMIT_RETRY_DELAYS_MS = [
139
148
  /** A provider request may not hold the production release fence forever. */
140
149
  export const FLY_MACHINES_REQUEST_TIMEOUT_MS = 30_000;
141
150
 
151
+ /**
152
+ * Machines API requests that converge when repeated, so a transient failure
153
+ * (5xx, 429, timeout, connection reset) may be retried. Excluded on purpose:
154
+ * `POST /machines` (create) and `POST /machines/{id}` (config update) each
155
+ * produce a new effect, `POST .../lease` fails once the first call won, and
156
+ * `POST /secrets` advances the secrets version. Their callers re-read state.
157
+ */
158
+ export function isIdempotentFlyMachinesRequest(
159
+ method: string,
160
+ path: string,
161
+ ): boolean {
162
+ if (method === 'GET' || method === 'DELETE') return true;
163
+ return (
164
+ method === 'POST' &&
165
+ /^\/machines\/[^/]+\/(?:cordon|uncordon|start|stop|metadata\/[^/]+)$/.test(
166
+ path,
167
+ )
168
+ );
169
+ }
170
+
171
+ export type FlyMachinesTransientRetryOptions = Readonly<{
172
+ attempts?: number;
173
+ baseDelayMs?: number;
174
+ deadlineMs?: number;
175
+ now?: () => number;
176
+ random?: () => number;
177
+ }>;
178
+
142
179
  export type FetchLike = (
143
180
  input: string,
144
181
  init?: {
@@ -764,6 +801,12 @@ export class FlyMachinesClient {
764
801
  wait?: (ms: number) => Promise<void>;
765
802
  retryDelaysMs?: readonly number[];
766
803
  requestTimeoutMs?: number;
804
+ /**
805
+ * Opt-in bounded retry of transient failures (5xx, 429, timeouts,
806
+ * connection resets) for idempotent requests only. Release and recovery
807
+ * CLIs enable it; long-running controllers keep their own cadence.
808
+ */
809
+ transientRetry?: true | FlyMachinesTransientRetryOptions;
767
810
  /** Preview CLI diagnostics only; no provider arguments or bodies. */
768
811
  phaseTiming?: Readonly<{
769
812
  now?: () => number;
@@ -838,6 +881,28 @@ export class FlyMachinesClient {
838
881
  path: string,
839
882
  body?: unknown,
840
883
  leaseNonce?: string,
884
+ ): Promise<unknown> {
885
+ const transientRetry = this.rateLimitOptions.transientRetry;
886
+ if (!transientRetry || !isIdempotentFlyMachinesRequest(method, path)) {
887
+ return await this.requestOnce(method, path, body, leaseNonce);
888
+ }
889
+ const policy = transientRetry === true ? {} : transientRetry;
890
+ return await withFlyTransientRetry(
891
+ () => this.requestOnce(method, path, body, leaseNonce),
892
+ classifyFlyRequestError,
893
+ {
894
+ ...policy,
895
+ label: `Fly Machines API ${method} /apps/${this.app}${path}`,
896
+ sleep: this.rateLimitOptions.wait ?? sleep,
897
+ },
898
+ );
899
+ }
900
+
901
+ private async requestOnce(
902
+ method: string,
903
+ path: string,
904
+ body?: unknown,
905
+ leaseNonce?: string,
841
906
  ): Promise<unknown> {
842
907
  const retryDelaysMs =
843
908
  this.rateLimitOptions.retryDelaysMs ??
@@ -865,7 +930,7 @@ export class FlyMachinesClient {
865
930
  );
866
931
  } catch (error) {
867
932
  if (signal.aborted) {
868
- throw new Error(
933
+ throw new FlyRequestTimeoutError(
869
934
  `Fly Machines API ${method} ${path} timed out after ${requestTimeoutMs}ms.`,
870
935
  { cause: error },
871
936
  );
@@ -897,9 +962,15 @@ export class FlyMachinesClient {
897
962
  }
898
963
  if (!response.ok) {
899
964
  const detail = await response.text().catch(() => '');
900
- throw new Error(
901
- `Fly Machines API ${method} ${path} failed: ${response.status} ${detail}`,
902
- );
965
+ const message = `Fly Machines API ${method} ${path} failed: ${response.status} ${detail}`;
966
+ if (isTransientFlyHttpStatus(response.status)) {
967
+ throw new FlyTransientHttpError(
968
+ message,
969
+ response.status,
970
+ parseRetryAfterMs(response.headers?.get('retry-after'), Date.now()),
971
+ );
972
+ }
973
+ throw new FlyPermanentHttpError(message, response.status);
903
974
  }
904
975
  if (response.status === 204) return null;
905
976
  return await readJsonResponseBody({
@@ -1719,7 +1790,7 @@ async function cmdBoot(flags: Record<string, string | boolean>): Promise<void> {
1719
1790
  app,
1720
1791
  requireFlyToken(),
1721
1792
  globalThis.fetch as FetchLike,
1722
- { phaseTiming: previewMachinePhaseTiming(flags) },
1793
+ { phaseTiming: previewMachinePhaseTiming(flags), transientRetry: true },
1723
1794
  );
1724
1795
  await bootLane({
1725
1796
  client,
@@ -1764,7 +1835,7 @@ async function cmdReplace(
1764
1835
  app,
1765
1836
  requireFlyToken(),
1766
1837
  globalThis.fetch as FetchLike,
1767
- { phaseTiming: previewMachinePhaseTiming(flags) },
1838
+ { phaseTiming: previewMachinePhaseTiming(flags), transientRetry: true },
1768
1839
  );
1769
1840
  await replaceLane({
1770
1841
  client,
@@ -1810,6 +1881,7 @@ async function cmdList(flags: Record<string, string | boolean>): Promise<void> {
1810
1881
  app,
1811
1882
  requireFlyToken(),
1812
1883
  globalThis.fetch as FetchLike,
1884
+ { transientRetry: true },
1813
1885
  );
1814
1886
  const release = typeof flags.release === 'string' ? flags.release : null;
1815
1887
  const machines = release
@@ -1933,6 +2005,7 @@ async function cmdDrain(
1933
2005
  app,
1934
2006
  requireFlyToken(),
1935
2007
  globalThis.fetch as FetchLike,
2008
+ { transientRetry: true },
1936
2009
  );
1937
2010
  await drainLane({
1938
2011
  client,
@@ -2392,6 +2465,7 @@ async function cmdRetire(
2392
2465
  app,
2393
2466
  requireFlyToken(),
2394
2467
  globalThis.fetch as FetchLike,
2468
+ { transientRetry: true },
2395
2469
  );
2396
2470
  await retireLane({
2397
2471
  client,