@smoothbricks/nx-plugin 0.5.7 → 0.6.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.
Files changed (446) hide show
  1. package/README.md +1097 -360
  2. package/dist/.build-inputs.json +141 -0
  3. package/dist/bin/smoo-nx-cargo-toolchain.d.ts +3 -0
  4. package/dist/bin/smoo-nx-cargo-toolchain.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-cargo-toolchain.js +8 -0
  6. package/dist/bin/smoo-nx-forbidden-spellings.d.ts +3 -0
  7. package/dist/bin/smoo-nx-forbidden-spellings.d.ts.map +1 -0
  8. package/dist/bin/smoo-nx-forbidden-spellings.js +32 -0
  9. package/dist/bin/smoo-nx-nextest-timings.d.ts +3 -0
  10. package/dist/bin/smoo-nx-nextest-timings.d.ts.map +1 -0
  11. package/dist/bin/smoo-nx-nextest-timings.js +28 -0
  12. package/dist/bounded-test-policy.d.ts +1 -1
  13. package/dist/bounded-test-policy.d.ts.map +1 -1
  14. package/dist/bounded-test-policy.js +14 -15
  15. package/dist/build-state-output-policy.d.ts +95 -1
  16. package/dist/build-state-output-policy.d.ts.map +1 -1
  17. package/dist/build-state-output-policy.js +368 -30
  18. package/dist/bun-lock-scope.d.ts +44 -0
  19. package/dist/bun-lock-scope.d.ts.map +1 -0
  20. package/dist/bun-lock-scope.js +97 -0
  21. package/dist/cargo-build-script-env.d.ts +49 -0
  22. package/dist/cargo-build-script-env.d.ts.map +1 -0
  23. package/dist/cargo-build-script-env.js +324 -0
  24. package/dist/cargo-closure-input.d.ts +31 -4
  25. package/dist/cargo-closure-input.d.ts.map +1 -1
  26. package/dist/cargo-closure-input.js +66 -6
  27. package/dist/cargo-retention-hook.d.ts +17 -0
  28. package/dist/cargo-retention-hook.d.ts.map +1 -0
  29. package/dist/cargo-retention-hook.js +85 -0
  30. package/dist/cargo-source-hash.d.ts +25 -7
  31. package/dist/cargo-source-hash.d.ts.map +1 -1
  32. package/dist/cargo-source-hash.js +108 -43
  33. package/dist/cargo-toolchain-paths.d.ts +40 -0
  34. package/dist/cargo-toolchain-paths.d.ts.map +1 -0
  35. package/dist/cargo-toolchain-paths.js +84 -0
  36. package/dist/cargo-toolchain-policy.d.ts +25 -8
  37. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  38. package/dist/cargo-toolchain-policy.js +39 -5
  39. package/dist/cargo-workspace.d.ts +10 -4
  40. package/dist/cargo-workspace.d.ts.map +1 -1
  41. package/dist/cargo-workspace.js +65 -95
  42. package/dist/cross-check-policy.d.ts +9 -9
  43. package/dist/cross-check-policy.d.ts.map +1 -1
  44. package/dist/cross-check-policy.js +11 -11
  45. package/dist/disk-command-policy.d.ts.map +1 -1
  46. package/dist/disk-command-policy.js +1 -0
  47. package/dist/ensure-built-receipt.d.ts +22 -5
  48. package/dist/ensure-built-receipt.d.ts.map +1 -1
  49. package/dist/ensure-built-receipt.js +168 -48
  50. package/dist/ensure-built-witness.d.ts +27 -8
  51. package/dist/ensure-built-witness.d.ts.map +1 -1
  52. package/dist/ensure-built-witness.js +45 -15
  53. package/dist/ensure-built.d.ts.map +1 -1
  54. package/dist/ensure-built.js +9 -1
  55. package/dist/eslint-config-closure.d.ts +7 -0
  56. package/dist/eslint-config-closure.d.ts.map +1 -0
  57. package/dist/eslint-config-closure.js +346 -0
  58. package/dist/executors/bounded-exec/bounds.d.ts +56 -0
  59. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -0
  60. package/dist/executors/bounded-exec/bounds.js +43 -0
  61. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +28 -0
  62. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -0
  63. package/dist/executors/bounded-exec/cpu-pool-thread.js +20 -0
  64. package/dist/executors/bounded-exec/cpu-pool.d.ts +35 -38
  65. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  66. package/dist/executors/bounded-exec/cpu-pool.js +56 -120
  67. package/dist/executors/bounded-exec/executor.d.ts +19 -12
  68. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  69. package/dist/executors/bounded-exec/executor.js +389 -239
  70. package/dist/executors/bounded-exec/gateway-lease.d.ts +23 -19
  71. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  72. package/dist/executors/bounded-exec/gateway-lease.js +102 -29
  73. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +18 -1
  74. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  75. package/dist/executors/bounded-exec/hang-diagnostics.js +148 -30
  76. package/dist/executors/bounded-exec/lease-wait.d.ts +64 -0
  77. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -0
  78. package/dist/executors/bounded-exec/lease-wait.js +72 -0
  79. package/dist/executors/bounded-exec/lock-wait.d.ts +51 -0
  80. package/dist/executors/bounded-exec/lock-wait.d.ts.map +1 -0
  81. package/dist/executors/bounded-exec/lock-wait.js +108 -0
  82. package/dist/executors/bounded-exec/mbx-pool.d.ts +31 -0
  83. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -0
  84. package/dist/executors/bounded-exec/mbx-pool.js +24 -0
  85. package/dist/executors/bounded-exec/owned-subtree.d.ts +84 -0
  86. package/dist/executors/bounded-exec/owned-subtree.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/owned-subtree.js +178 -0
  88. package/dist/executors/bounded-exec/progress.d.ts +4 -1
  89. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  90. package/dist/executors/bounded-exec/progress.js +5 -2
  91. package/dist/executors/bounded-exec/ram-attach.d.ts +19 -0
  92. package/dist/executors/bounded-exec/ram-attach.d.ts.map +1 -0
  93. package/dist/executors/bounded-exec/ram-attach.js +207 -0
  94. package/dist/executors/bounded-exec/ram-detach.d.ts +25 -0
  95. package/dist/executors/bounded-exec/ram-detach.d.ts.map +1 -0
  96. package/dist/executors/bounded-exec/ram-detach.js +207 -0
  97. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +76 -0
  98. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -1
  99. package/dist/executors/bounded-exec/ram-temp-fixtures.js +296 -0
  100. package/dist/executors/bounded-exec/ram-temp.d.ts +388 -88
  101. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  102. package/dist/executors/bounded-exec/ram-temp.js +1213 -399
  103. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +10 -4
  104. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  105. package/dist/executors/bounded-exec/run-cpu-pool.js +122 -35
  106. package/dist/executors/bounded-exec/runner-hook.js +14 -5
  107. package/dist/executors/bounded-exec/runner-lifecycle.d.ts +14 -1
  108. package/dist/executors/bounded-exec/runner-lifecycle.d.ts.map +1 -1
  109. package/dist/executors/bounded-exec/runner-lifecycle.js +27 -6
  110. package/dist/executors/bounded-exec/{cpu-tokens.d.ts → runner-sizing.d.ts} +14 -42
  111. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -0
  112. package/dist/executors/bounded-exec/{cpu-tokens.js → runner-sizing.js} +5 -35
  113. package/dist/executors/bounded-exec/runtime-pin.d.ts +73 -0
  114. package/dist/executors/bounded-exec/runtime-pin.d.ts.map +1 -0
  115. package/dist/executors/bounded-exec/runtime-pin.js +167 -0
  116. package/dist/executors/bounded-exec/schema.d.ts +18 -1
  117. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  118. package/dist/executors/bounded-exec/verdict.d.ts +48 -11
  119. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  120. package/dist/executors/bounded-exec/verdict.js +89 -20
  121. package/dist/executors/cargo-zigbuild/executor.d.ts +21 -0
  122. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  123. package/dist/executors/cargo-zigbuild/executor.js +67 -12
  124. package/dist/executors/clean-outputs/executor.js +1 -0
  125. package/dist/executors/scriptc-native/executor.d.ts +79 -0
  126. package/dist/executors/scriptc-native/executor.d.ts.map +1 -0
  127. package/dist/executors/scriptc-native/executor.js +367 -0
  128. package/dist/executors/scriptc-native/ffi-paths.d.ts +9 -0
  129. package/dist/executors/scriptc-native/ffi-paths.d.ts.map +1 -0
  130. package/dist/executors/scriptc-native/ffi-paths.js +25 -0
  131. package/dist/executors/scriptc-native/schema.d.ts +34 -0
  132. package/dist/executors/scriptc-native/schema.d.ts.map +1 -0
  133. package/dist/executors/scriptc-native/schema.js +1 -0
  134. package/dist/executors/typescript-emit/emit-overrides.d.ts +14 -0
  135. package/dist/executors/typescript-emit/emit-overrides.d.ts.map +1 -0
  136. package/dist/executors/typescript-emit/emit-overrides.js +24 -0
  137. package/dist/executors/typescript-emit/executor.d.ts +3 -1
  138. package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
  139. package/dist/executors/typescript-emit/executor.js +146 -33
  140. package/dist/forbidden-spelling-policy.d.ts +56 -0
  141. package/dist/forbidden-spelling-policy.d.ts.map +1 -0
  142. package/dist/forbidden-spelling-policy.js +176 -0
  143. package/dist/generators/create-package/generator.d.ts.map +1 -1
  144. package/dist/generators/create-package/generator.js +3 -4
  145. package/dist/graph-input-contract.d.ts +14 -0
  146. package/dist/graph-input-contract.d.ts.map +1 -1
  147. package/dist/graph-input-contract.js +67 -2
  148. package/dist/index.d.ts +23 -6
  149. package/dist/index.d.ts.map +1 -1
  150. package/dist/index.js +672 -214
  151. package/dist/managed-assets.d.ts +2 -0
  152. package/dist/managed-assets.d.ts.map +1 -1
  153. package/dist/managed-files/files.d.ts +3 -3
  154. package/dist/managed-files/files.d.ts.map +1 -1
  155. package/dist/managed-files/files.js +28 -3
  156. package/dist/managed-files/managed-format.d.ts.map +1 -1
  157. package/dist/managed-files/managed-format.js +1 -0
  158. package/dist/managed-files/publish-workflow.js +14 -11
  159. package/dist/nextest-code-bound.js +1 -0
  160. package/dist/nextest-timings.d.ts +35 -0
  161. package/dist/nextest-timings.d.ts.map +1 -0
  162. package/dist/nextest-timings.js +168 -0
  163. package/dist/owned-installation.d.ts +6 -5
  164. package/dist/owned-installation.d.ts.map +1 -1
  165. package/dist/owned-installation.js +150 -26
  166. package/dist/package-target-policy.d.ts.map +1 -1
  167. package/dist/package-target-policy.js +2 -3
  168. package/dist/process-children.d.ts +7 -0
  169. package/dist/process-children.d.ts.map +1 -0
  170. package/dist/process-children.darwin.d.ts +7 -0
  171. package/dist/process-children.darwin.d.ts.map +1 -0
  172. package/dist/process-children.darwin.js +13 -0
  173. package/dist/process-children.js +14 -0
  174. package/dist/process-children.linux.d.ts +8 -0
  175. package/dist/process-children.linux.d.ts.map +1 -0
  176. package/dist/process-children.linux.js +25 -0
  177. package/dist/process-group.d.ts +108 -0
  178. package/dist/process-group.d.ts.map +1 -0
  179. package/dist/process-group.js +171 -0
  180. package/dist/process-listing.d.ts +7 -0
  181. package/dist/process-listing.d.ts.map +1 -0
  182. package/dist/process-listing.js +51 -0
  183. package/dist/producer-receipts.d.ts +8 -2
  184. package/dist/producer-receipts.d.ts.map +1 -1
  185. package/dist/producer-receipts.js +514 -47
  186. package/dist/task-graph-policy.d.ts +21 -0
  187. package/dist/task-graph-policy.d.ts.map +1 -0
  188. package/dist/task-graph-policy.js +91 -0
  189. package/dist/test-timings.js +4 -4
  190. package/dist/test-walk-policy.d.ts +14 -5
  191. package/dist/test-walk-policy.d.ts.map +1 -1
  192. package/dist/test-walk-policy.js +8 -2
  193. package/dist/testing.d.ts +73 -28
  194. package/dist/testing.d.ts.map +1 -1
  195. package/dist/testing.js +217 -223
  196. package/dist/tool-bins.d.ts +33 -0
  197. package/dist/tool-bins.d.ts.map +1 -0
  198. package/dist/tool-bins.js +72 -0
  199. package/dist/typecheck-test-policy.d.ts.map +1 -1
  200. package/dist/typecheck-test-policy.js +3 -4
  201. package/dist/wait-why-policy.d.ts +28 -0
  202. package/dist/wait-why-policy.d.ts.map +1 -0
  203. package/dist/wait-why-policy.js +223 -0
  204. package/dist/workspace-config-policy.d.ts +14 -8
  205. package/dist/workspace-config-policy.d.ts.map +1 -1
  206. package/dist/workspace-config-policy.js +60 -16
  207. package/dist/workspace-manifest.d.ts +41 -6
  208. package/dist/workspace-manifest.d.ts.map +1 -1
  209. package/dist/workspace-manifest.js +57 -0
  210. package/executors.json +16 -1
  211. package/loader.js +2 -0
  212. package/managed/raw/envrc +11 -0
  213. package/managed/raw/patches/nx@23.2.1.patch +2840 -199
  214. package/managed/raw/patches/ttsc@0.34.1.patch +119 -0
  215. package/managed/raw/tooling/direnv/cargo-fetch-bound.ts +245 -0
  216. package/managed/raw/tooling/direnv/cargo-fetch-run.ts +299 -0
  217. package/managed/raw/tooling/direnv/compiler-variables.sh +42 -0
  218. package/managed/raw/tooling/direnv/developer-links.ts +464 -25
  219. package/managed/raw/tooling/direnv/devenv.smoo.nix +78 -38
  220. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -12
  221. package/managed/raw/tooling/direnv/installed-bun-links.ts +308 -0
  222. package/managed/raw/tooling/direnv/linked-snapshots.ts +62 -3
  223. package/managed/raw/tooling/direnv/nx-socket-dir.sh +56 -17
  224. package/managed/raw/tooling/direnv/repo-path +68 -6
  225. package/managed/raw/tooling/direnv/secret-references.ts +13 -4
  226. package/managed/raw/tooling/direnv/setup-environment.ts +128 -537
  227. package/managed/raw/tooling/direnv/toolchain-stamp.ts +4 -2
  228. package/managed/raw/tooling/direnv/ttsc-env.sh +9 -0
  229. package/managed/raw/tooling/direnv/uv-relocation.ts +227 -0
  230. package/managed/raw/tooling/git-hooks/commit-msg.sh +2 -1
  231. package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -1
  232. package/managed/raw/tooling/git-hooks/pre-push.sh +2 -1
  233. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +85 -7
  234. package/managed/templates/github/actions/save-nix-devenv/action.yml +12 -2
  235. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  236. package/package.json +95 -14
  237. package/src/bin/smoo-nx-cargo-toolchain.ts +11 -0
  238. package/src/bin/smoo-nx-forbidden-spellings.ts +33 -0
  239. package/src/bin/smoo-nx-nextest-timings.ts +31 -0
  240. package/src/bounded-test-policy.ts +12 -14
  241. package/src/build-state-output-policy.ts +458 -34
  242. package/src/bun-lock-scope.ts +108 -0
  243. package/src/cargo-build-script-env.ts +265 -0
  244. package/src/cargo-closure-input.ts +74 -7
  245. package/src/cargo-retention-hook.ts +94 -0
  246. package/src/cargo-source-hash.ts +138 -41
  247. package/src/cargo-toolchain-paths.ts +95 -0
  248. package/src/cargo-toolchain-policy.ts +49 -5
  249. package/src/cargo-workspace.ts +72 -123
  250. package/src/cross-check-policy.ts +12 -10
  251. package/src/disk-command-policy.ts +1 -0
  252. package/src/ensure-built-receipt.ts +173 -39
  253. package/src/ensure-built-witness.ts +62 -10
  254. package/src/ensure-built.ts +11 -1
  255. package/src/eslint-config-closure.ts +357 -0
  256. package/src/executors/bounded-exec/bounds.ts +76 -0
  257. package/src/executors/bounded-exec/cpu-pool-thread.ts +43 -0
  258. package/src/executors/bounded-exec/cpu-pool.ts +55 -120
  259. package/src/executors/bounded-exec/executor.ts +442 -260
  260. package/src/executors/bounded-exec/gateway-lease.ts +94 -35
  261. package/src/executors/bounded-exec/hang-diagnostics.ts +173 -31
  262. package/src/executors/bounded-exec/lease-wait.ts +116 -0
  263. package/src/executors/bounded-exec/lock-wait.ts +141 -0
  264. package/src/executors/bounded-exec/mbx-pool.ts +48 -0
  265. package/src/executors/bounded-exec/owned-subtree.ts +235 -0
  266. package/src/executors/bounded-exec/progress.ts +9 -3
  267. package/src/executors/bounded-exec/ram-attach.ts +238 -0
  268. package/src/executors/bounded-exec/ram-detach.ts +226 -0
  269. package/src/executors/bounded-exec/ram-temp-fixtures.ts +358 -0
  270. package/src/executors/bounded-exec/ram-temp-registry.txt +440 -0
  271. package/src/executors/bounded-exec/ram-temp.ts +1497 -460
  272. package/src/executors/bounded-exec/run-cpu-pool.ts +129 -35
  273. package/src/executors/bounded-exec/runner-hook.ts +14 -6
  274. package/src/executors/bounded-exec/runner-lifecycle.ts +31 -8
  275. package/src/executors/bounded-exec/{cpu-tokens.ts → runner-sizing.ts} +13 -59
  276. package/src/executors/bounded-exec/runtime-pin.ts +232 -0
  277. package/src/executors/bounded-exec/schema.json +11 -2
  278. package/src/executors/bounded-exec/schema.ts +19 -1
  279. package/src/executors/bounded-exec/verdict.ts +145 -35
  280. package/src/executors/cargo-zigbuild/executor.ts +82 -8
  281. package/src/executors/clean-outputs/executor.ts +1 -0
  282. package/src/executors/scriptc-native/executor.ts +394 -0
  283. package/src/executors/scriptc-native/ffi-paths.ts +29 -0
  284. package/src/executors/scriptc-native/schema.json +60 -0
  285. package/src/executors/scriptc-native/schema.ts +34 -0
  286. package/src/executors/typescript-emit/emit-overrides.ts +24 -0
  287. package/src/executors/typescript-emit/executor.ts +186 -38
  288. package/src/forbidden-spelling-policy.ts +226 -0
  289. package/src/generators/create-package/generator.ts +7 -7
  290. package/src/graph-input-contract.ts +61 -2
  291. package/src/index.ts +788 -224
  292. package/src/managed-assets.ts +3 -0
  293. package/src/managed-files/files.ts +28 -3
  294. package/src/managed-files/managed-format.ts +1 -0
  295. package/src/managed-files/publish-workflow.ts +20 -15
  296. package/src/nextest-code-bound.ts +1 -0
  297. package/src/nextest-timings.ts +106 -0
  298. package/src/owned-installation.ts +150 -23
  299. package/src/package-target-policy.ts +2 -3
  300. package/src/process-children.darwin.ts +14 -0
  301. package/src/process-children.linux.ts +33 -0
  302. package/src/process-children.ts +22 -0
  303. package/src/process-group.ts +209 -0
  304. package/src/process-listing.ts +54 -0
  305. package/src/producer-receipts.ts +92 -41
  306. package/src/task-graph-policy.ts +98 -0
  307. package/src/test-walk-policy.ts +23 -8
  308. package/src/testing.ts +240 -232
  309. package/src/tool-bins.ts +108 -0
  310. package/src/typecheck-test-policy.ts +2 -3
  311. package/src/wait-why-policy.ts +226 -0
  312. package/src/workspace-config-policy.ts +63 -15
  313. package/src/workspace-manifest.ts +89 -6
  314. package/test-timings.json +124 -99
  315. package/dist/bin/smoo-nx-failures.d.ts +0 -3
  316. package/dist/bin/smoo-nx-failures.d.ts.map +0 -1
  317. package/dist/bin/smoo-nx-failures.js +0 -3
  318. package/dist/bin/smoo-nx-nextest-extract.d.ts +0 -3
  319. package/dist/bin/smoo-nx-nextest-extract.d.ts.map +0 -1
  320. package/dist/bin/smoo-nx-nextest-extract.js +0 -42
  321. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +0 -1
  322. package/dist/failure-summary.d.ts +0 -5
  323. package/dist/failure-summary.d.ts.map +0 -1
  324. package/dist/failure-summary.js +0 -118
  325. package/dist/nextest-extraction.d.ts +0 -117
  326. package/dist/nextest-extraction.d.ts.map +0 -1
  327. package/dist/nextest-extraction.js +0 -303
  328. package/managed/raw/patches/ttsc@0.30.4.patch +0 -2255
  329. package/src/__tests__/cargo-closure-filesets.ts +0 -94
  330. package/src/__tests__/cargo-closure-fixture.ts +0 -113
  331. package/src/__tests__/counted-cargo-process.ts +0 -286
  332. package/src/__tests__/counted-cargo.ts +0 -713
  333. package/src/__tests__/directory-change.ts +0 -27
  334. package/src/__tests__/fixture-cargo-home.ts +0 -36
  335. package/src/__tests__/fixture-nx-env.ts +0 -193
  336. package/src/__tests__/owned-installation.ts +0 -13
  337. package/src/__tests__/past-tick.ts +0 -12
  338. package/src/__tests__/progress-clock.ts +0 -43
  339. package/src/__tests__/runtime-input.ts +0 -23
  340. package/src/bin/smoo-nx-bound-failures.test.ts +0 -127
  341. package/src/bin/smoo-nx-failures.ts +0 -4
  342. package/src/bin/smoo-nx-nextest-extract.ts +0 -44
  343. package/src/bounded-test-policy.test.ts +0 -1029
  344. package/src/build-state-output-policy.test.ts +0 -115
  345. package/src/bun-bootstrap.test.ts +0 -102
  346. package/src/bun-file-packages.test.ts +0 -47
  347. package/src/cargo-closure-filesets.test.ts +0 -63
  348. package/src/cargo-closure-input.property.test.ts +0 -50
  349. package/src/cargo-closure-input.test.ts +0 -506
  350. package/src/cargo-closure-key.test.ts +0 -240
  351. package/src/cargo-resolve-cache.test.ts +0 -1181
  352. package/src/cargo-source-hash.test.ts +0 -707
  353. package/src/cargo-workspace.test.ts +0 -615
  354. package/src/cross-check-policy.test.ts +0 -316
  355. package/src/disk-command-policy.test.ts +0 -61
  356. package/src/ensure-built-receipt.test.ts +0 -279
  357. package/src/ensure-built-witness.test.ts +0 -688
  358. package/src/ensure-built.test.ts +0 -1462
  359. package/src/executors/all-verdicts/executor.test.ts +0 -135
  360. package/src/executors/bounded-exec/cargo-progress-host.test.ts +0 -332
  361. package/src/executors/bounded-exec/cpu-pool.test.ts +0 -684
  362. package/src/executors/bounded-exec/cpu-tokens.test.ts +0 -519
  363. package/src/executors/bounded-exec/disk-lease.test.ts +0 -219
  364. package/src/executors/bounded-exec/executor-host.test.ts +0 -800
  365. package/src/executors/bounded-exec/executor.test.ts +0 -1819
  366. package/src/executors/bounded-exec/go-progress-host.test.ts +0 -171
  367. package/src/executors/bounded-exec/hang-diagnostics.test.ts +0 -291
  368. package/src/executors/bounded-exec/progress.test.ts +0 -139
  369. package/src/executors/bounded-exec/ram-temp-held.test.ts +0 -264
  370. package/src/executors/bounded-exec/ram-temp-host.test.ts +0 -635
  371. package/src/executors/bounded-exec/ram-temp.test.ts +0 -750
  372. package/src/executors/bounded-exec/run-cpu-pool.test.ts +0 -79
  373. package/src/executors/bounded-exec/runner-hook.test.ts +0 -193
  374. package/src/executors/bounded-exec/runner-lifecycle.test.ts +0 -82
  375. package/src/executors/bounded-exec/verdict.test.ts +0 -545
  376. package/src/executors/cargo-zigbuild/executor.test.ts +0 -129
  377. package/src/executors/clean-outputs/executor.test.ts +0 -20
  378. package/src/executors/typescript-emit/executor.test.ts +0 -83
  379. package/src/failure-summary.ts +0 -119
  380. package/src/generators/bounded-test-targets/generator.test.ts +0 -138
  381. package/src/generators/bun-test-tracing/generator.test.ts +0 -250
  382. package/src/generators/create-package/generator.test.ts +0 -190
  383. package/src/generators/make-public/generator.test.ts +0 -137
  384. package/src/graph-input-contract.test.ts +0 -379
  385. package/src/host-controller-wiring.test.ts +0 -31
  386. package/src/index.test.ts +0 -3321
  387. package/src/linked-snapshots.nx.test.ts +0 -254
  388. package/src/managed-files/forgejo-artifact.test.ts +0 -395
  389. package/src/managed-files/generator.test.ts +0 -243
  390. package/src/managed-files/github-host-cache-isolation.test.ts +0 -86
  391. package/src/managed-files/json-edit.test.ts +0 -216
  392. package/src/managed-files/managed-content.test.ts +0 -166
  393. package/src/managed-files/managed-format-json.test.ts +0 -308
  394. package/src/managed-files/repo-path.test.ts +0 -172
  395. package/src/managed-files/setup-devenv-free-disk.test.ts +0 -95
  396. package/src/managed-files/trace-db-artifact.test.ts +0 -7
  397. package/src/managed-files/tree-permissions.test.ts +0 -109
  398. package/src/managed-files/tree.test.ts +0 -123
  399. package/src/manifest-hash.test.ts +0 -219
  400. package/src/nextest-code-bound.test.ts +0 -161
  401. package/src/nextest-extraction.test.ts +0 -216
  402. package/src/nextest-extraction.ts +0 -371
  403. package/src/nextest-partitions.test.ts +0 -501
  404. package/src/nx-cache-bound.test.ts +0 -109
  405. package/src/nx-cache-restore-mtime.test.ts +0 -170
  406. package/src/nx-daemon-claim.test.ts +0 -279
  407. package/src/nx-daemon-idle-cpu.test.ts +0 -80
  408. package/src/nx-daemon-idle-policy.test.ts +0 -111
  409. package/src/nx-daemon-ignore-files.test.ts +0 -210
  410. package/src/nx-daemon-root-normalization.test.ts +0 -105
  411. package/src/nx-daemon-start-never.test.ts +0 -292
  412. package/src/nx-daemon-validity.test.ts +0 -1055
  413. package/src/nx-dot-input-policy.test.ts +0 -353
  414. package/src/nx-failure-life-cycles.test.ts +0 -207
  415. package/src/nx-files-archive-racy.test.ts +0 -97
  416. package/src/nx-foreign-workspace-env.test.ts +0 -329
  417. package/src/nx-incomplete-run-summary.test.ts +0 -70
  418. package/src/nx-plugin-load-errors.test.ts +0 -120
  419. package/src/nx-project-graph-errors.test.ts +0 -70
  420. package/src/nx-project-resolution-cache.test.ts +0 -176
  421. package/src/nx-raw-inputs.test.ts +0 -166
  422. package/src/nx-resident-graph-workers.test.ts +0 -112
  423. package/src/nx-run-information.test.ts +0 -118
  424. package/src/nx-skipped-task-exit.test.ts +0 -180
  425. package/src/nx-state-location.test.ts +0 -63
  426. package/src/nx-store-resolution.test.ts +0 -81
  427. package/src/nx-task-graph-cycles.test.ts +0 -148
  428. package/src/nx-task-output-lease.test.ts +0 -550
  429. package/src/nx-use-local.test.ts +0 -105
  430. package/src/owned-installation.test.ts +0 -105
  431. package/src/package-target-policy.test.ts +0 -1014
  432. package/src/producer-receipts.test.ts +0 -285
  433. package/src/release-config-policy.test.ts +0 -311
  434. package/src/runtime-input.test.ts +0 -393
  435. package/src/serial-group-wiring.test.ts +0 -326
  436. package/src/task-history-namespace.test.ts +0 -181
  437. package/src/task-results.test.ts +0 -228
  438. package/src/test-clock-policy.test.ts +0 -338
  439. package/src/test-program.test.ts +0 -303
  440. package/src/test-timings.test.ts +0 -240
  441. package/src/test-walk-policy.test.ts +0 -620
  442. package/src/testing.test.ts +0 -509
  443. package/src/typecheck-test-policy.test.ts +0 -1468
  444. package/src/typescript-resolution.test.ts +0 -76
  445. package/src/version-actions.test.ts +0 -80
  446. package/src/workspace-config-policy.test.ts +0 -737
@@ -1,15 +1,20 @@
1
1
  import { connect } from 'node:net';
2
+ import typia from 'typia';
3
+ import { type CpuLeaseProgress, type CpuLeaseQueued, CpuLeaseWait, type CpuWaitRow } from './lease-wait.js';
4
+
5
+ const isCpuProgress = typia.createEquals<CpuLeaseProgress>();
6
+ const isCpuQueued = typia.createEquals<CpuLeaseQueued>();
2
7
 
3
8
  /**
4
- * The client half of a lease held on the cowshed gateway's control socket: the host
5
- * disk-lifecycle lease (`disk-lease.ts`) and the host CPU budget (`cpu-tokens.ts`) speak the same
6
- * protocol (specs/cowshed/05_gateway.md, "Disk-lifecycle lease" and "Host CPU budget").
9
+ * The client half of a lease held on a unix socket: the gateway's host disk-lifecycle lease
10
+ * (`disk-lease.ts`) and a parent's CPU pool (`cpu-pool.ts`) speak the same protocol
11
+ * (specs/cowshed/05_gateway.md, "Disk-lifecycle lease").
7
12
  *
8
13
  * The client writes one request line and keeps the connection open without half-closing it. The
9
14
  * gateway answers `queued` at once and `granted` when the lease is the client's, and the lease
10
15
  * lasts until the client closes the connection, so a client that dies holding one releases it with
11
- * its socket. A lease never decides whether a command runs: without a grant, it runs without one
12
- * and the caller says why.
16
+ * its socket. The caller decides what a refusal means: disk work may run unleased, while CPU
17
+ * admission fails rather than running outside its parent's count.
13
18
  */
14
19
 
15
20
  /** The cowshed gateway's control socket, at the store root every peer agrees on. */
@@ -25,12 +30,15 @@ export interface LeaseBounds {
25
30
  }
26
31
 
27
32
  /**
28
- * Why a command runs without a lease: no gateway listens, the gateway predates this kind of lease,
29
- * the gateway knows the lease but predates a field the request names (it refuses the field at
30
- * once), or any other refusal, silence or breakage.
33
+ * Why a lease is not held: no gateway listens, the gateway predates this kind of lease, the gateway
34
+ * knows the lease but predates a field the request names (it refuses the field at once), or any
35
+ * other refusal, silence or breakage.
31
36
  */
32
37
  export type UnleasedCause = 'absent' | 'predates' | 'predates-field' | 'other';
33
38
 
39
+ /** A refusal: the lease is not held, and why. A CPU wait that expired carries its typed row. */
40
+ export type Unleased = { granted: false; cause: UnleasedCause; reason: string; code?: string; wait?: CpuWaitRow };
41
+
34
42
  /**
35
43
  * A granted lease with its `granted` answer, held until released, or why there is none. `closed`
36
44
  * resolves when the connection really closes: after `release`, when the gateway ends it, or when
@@ -38,20 +46,20 @@ export type UnleasedCause = 'absent' | 'predates' | 'predates-field' | 'other';
38
46
  */
39
47
  export type HeldLease =
40
48
  | { granted: true; answer: Readonly<Record<string, unknown>>; release: () => void; closed: Promise<void> }
41
- | { granted: false; cause: UnleasedCause; reason: string; code?: string };
49
+ | Unleased;
42
50
 
43
51
  /**
44
52
  * Ask the gateway at `socket` for the lease `request` names, `what` in its messages ("disk
45
- * leases", "the CPU budget"). A gateway from before one-line requests says nothing until it reads
46
- * EOF, so a request not queued within `ackMs` is half-closed and that gateway's refusal read; a
47
- * gateway that reads the line but does not know the operation refuses it at once. Both predate the
48
- * lease.
53
+ * leases", "the parent CPU pool"). A gateway from before one-line requests says nothing until it reads
54
+ * EOF, so a disk request not queued within its ack bound is half-closed to read that gateway's
55
+ * refusal. CPU admission instead uses its own control/silence policy: no compatibility half-close,
56
+ * and no total queue bound (specs/cowshed/05_gateway.md, "Deadlines").
49
57
  */
50
58
  export function holdLease(
51
59
  socket: string,
52
60
  request: Readonly<Record<string, unknown>>,
53
61
  what: string,
54
- bounds: LeaseBounds,
62
+ bounds: LeaseBounds | CpuLeaseWait,
55
63
  onQueued?: () => void,
56
64
  ): Promise<HeldLease> {
57
65
  // `Promise.withResolvers` would read better but needs lib es2024; this package inherits lib
@@ -60,6 +68,8 @@ export function holdLease(
60
68
  const promise = new Promise<HeldLease>((settled) => {
61
69
  resolve = settled;
62
70
  });
71
+ const cpu = bounds instanceof CpuLeaseWait ? bounds : null;
72
+ // eslint-disable-next-line deadline/no-unbounded-wait -- WHY unbounded: CPU connect/send is control-bounded and its answer heartbeat-silence-bounded by armCpu(); disk acknowledgement and half-close are bounded below, and a queued disk lease lasts until its holder releases it
63
73
  const connection = connect(socket);
64
74
  // `closed` is made when a consumer reads it, so a lease nobody watches allocates no promise. The
65
75
  // flag, not `connection.destroyed`, says the socket really closed: `destroy()` sets that flag before
@@ -80,53 +90,94 @@ export function holdLease(
80
90
  }
81
91
  resolve(outcome);
82
92
  };
83
- const unleased = (reason: string, cause: UnleasedCause = 'other', code?: string) =>
84
- settle({ granted: false, cause, reason, ...(code === undefined ? {} : { code }) });
93
+ const unleased = (reason: string, cause: UnleasedCause = 'other', code?: string, wait?: CpuWaitRow) =>
94
+ settle({
95
+ granted: false,
96
+ cause,
97
+ reason,
98
+ ...(code === undefined ? {} : { code }),
99
+ ...(wait === undefined ? {} : { wait }),
100
+ });
85
101
  const wait = (ms: number, onExpiry: () => void) => {
86
102
  clearTimeout(timer);
87
103
  timer = setTimeout(onExpiry, ms);
88
104
  };
105
+ const armCpu = (): void => {
106
+ if (cpu === null || state === 'settled') return;
107
+ wait(cpu.remainingMs(), () => {
108
+ cpu.look();
109
+ const failure = cpu.expired();
110
+ if (failure === null) {
111
+ armCpu();
112
+ return;
113
+ }
114
+ const peer = failure.server === null ? socket : `${socket} (pid ${failure.server})`;
115
+ unleased(
116
+ `${failure.code}: cpu-pool: the lease endpoint ${peer} exceeded ${failure.boundMs} ms (waited ${failure.elapsedMs} ms; last progress: ${failure.last})`,
117
+ 'other',
118
+ failure.code,
119
+ { ...failure, socket },
120
+ );
121
+ });
122
+ };
123
+ armCpu();
89
124
  const answer = (line: string) => {
125
+ if (state === 'settled') return;
90
126
  let parsed: unknown;
91
127
  try {
92
128
  parsed = JSON.parse(line);
93
129
  } catch {
94
- unleased(`the gateway answered something that is not an answer: ${line}`);
130
+ unleased(`the lease endpoint ${socket} answered something that is not an answer: ${line}`);
95
131
  return;
96
132
  }
97
133
  if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
98
- unleased(`the gateway answered something that is not an answer: ${line}`);
134
+ unleased(`the lease endpoint ${socket} answered something that is not an answer: ${line}`);
99
135
  return;
100
136
  }
101
137
  const fields: Readonly<Record<string, unknown>> = Object.fromEntries(Object.entries(parsed));
138
+ if (cpu !== null && isCpuProgress(parsed)) {
139
+ if (!cpu.heartbeat(parsed.progress)) {
140
+ unleased(`the lease endpoint ${socket} sent non-advancing CPU progress: ${line}`);
141
+ } else {
142
+ armCpu();
143
+ }
144
+ return;
145
+ }
102
146
  const lease = fields.lease;
103
147
  if (fields.ok !== true) {
104
148
  const error = String(fields.error ?? '');
105
149
  const why = `${String(fields.code ?? 'refused')}: ${error}`;
106
150
  if (state === 'half-closed' || error.endsWith('unknown gateway control operation')) {
107
- unleased(`the gateway predates ${what} (${why}); restart it with \`cowshed setup\``, 'predates');
151
+ unleased(
152
+ `the lease endpoint ${socket} predates ${what} (${why}); restart it with \`cowshed setup\``,
153
+ 'predates',
154
+ );
108
155
  } else if (error.endsWith('contains an unknown field')) {
109
156
  unleased(
110
- `the gateway predates a field of ${what} (${why}); restart it with \`cowshed setup\``,
157
+ `the lease endpoint ${socket} predates a field of ${what} (${why}); restart it with \`cowshed setup\``,
111
158
  'predates-field',
112
159
  );
113
160
  } else {
114
161
  unleased(
115
- `the gateway refused the lease (${why})`,
162
+ `the lease endpoint ${socket} refused the lease (${why})`,
116
163
  'other',
117
164
  typeof fields.code === 'string' ? fields.code : undefined,
118
165
  );
119
166
  }
120
167
  } else if (state === 'half-closed') {
121
- unleased('the gateway did not queue the request in time; it is alive but overloaded');
168
+ unleased(`the lease endpoint ${socket} did not queue the request in time; it is alive but overloaded`);
122
169
  } else if (state === 'asked' && lease === 'queued') {
123
170
  state = 'queued';
124
171
  onQueued?.();
125
- const grantMs = bounds.grantMs;
126
- if (grantMs === null) {
172
+ if (bounds instanceof CpuLeaseWait) {
173
+ // A pool from before its acknowledgement named its process names none.
174
+ bounds.queued(isCpuQueued(parsed) ? parsed.server : null);
175
+ armCpu();
176
+ } else if (bounds.grantMs === null) {
127
177
  clearTimeout(timer);
128
178
  } else {
129
- wait(grantMs, () => unleased(`the gateway granted nothing within ${grantMs} ms`));
179
+ const grantMs = bounds.grantMs;
180
+ wait(grantMs, () => unleased(`the lease endpoint ${socket} granted nothing within ${grantMs} ms`));
130
181
  }
131
182
  } else if (state === 'queued' && lease === 'granted') {
132
183
  settle({
@@ -136,22 +187,30 @@ export function holdLease(
136
187
  get closed() {
137
188
  closed ??= socketClosed
138
189
  ? Promise.resolve()
139
- : new Promise<void>((done) => connection.once('close', () => done()));
190
+ : // eslint-disable-next-line deadline/no-unbounded-wait -- WHY unbounded: a held lease's connection lasts as long as its holder keeps it; release() destroys it on this side, and the gateway's own end closes it too
191
+ new Promise<void>((done) => connection.once('close', () => done()));
140
192
  return closed;
141
193
  },
142
194
  });
143
195
  } else {
144
- unleased(`the gateway answered out of turn: ${line}`);
196
+ unleased(`the lease endpoint ${socket} answered out of turn: ${line}`);
145
197
  }
146
198
  };
147
199
  connection.on('connect', () => {
148
200
  state = 'asked';
149
- connection.write(`${JSON.stringify(request)}\n`);
150
- wait(bounds.ackMs, () => {
151
- state = 'half-closed';
152
- connection.end();
153
- wait(bounds.afterCloseMs, () => unleased('the gateway answered nothing'));
154
- });
201
+ if (bounds instanceof CpuLeaseWait) {
202
+ connection.write(`${JSON.stringify(request)}\n`, () => {
203
+ bounds.sent();
204
+ armCpu();
205
+ });
206
+ } else {
207
+ connection.write(`${JSON.stringify(request)}\n`);
208
+ wait(bounds.ackMs, () => {
209
+ state = 'half-closed';
210
+ connection.end();
211
+ wait(bounds.afterCloseMs, () => unleased(`the lease endpoint ${socket} answered nothing`));
212
+ });
213
+ }
155
214
  });
156
215
  connection.on('data', (chunk: Buffer) => {
157
216
  buffered += chunk.toString('utf8');
@@ -163,14 +222,14 @@ export function holdLease(
163
222
  });
164
223
  connection.on('error', (error) => {
165
224
  if (state === 'connecting') {
166
- unleased(`the gateway's control socket ${socket} does not answer (${error.message})`, 'absent');
225
+ unleased(`nothing answers for ${what} at ${socket} (${error.message})`, 'absent');
167
226
  } else {
168
227
  unleased(error.message);
169
228
  }
170
229
  });
171
230
  connection.on('close', () => {
172
231
  socketClosed = true;
173
- unleased('the gateway closed the lease connection');
232
+ unleased(`the lease connection for ${what} at ${socket} closed`);
174
233
  });
175
234
  return promise;
176
235
  }
@@ -1,9 +1,52 @@
1
1
  import { spawn } from 'node:child_process';
2
+ import { describeTeardown, killProcessGroupNow, TEARDOWN_PATIENCE } from '../../process-group.js';
2
3
  import { type ProcessEntry, withDescendants } from '../../testing.js';
4
+ import {
5
+ describeHolders,
6
+ type LockWait,
7
+ lockCandidates,
8
+ lockWaits,
9
+ parseLsofFields,
10
+ parseLsofTable,
11
+ } from './lock-wait.js';
3
12
 
4
- export const HANG_CAPTURE_MS = 5_000;
13
+ /**
14
+ * The pre-expiry capture window. Stack samples set it: under load averages of 27-52 on 18 cores one `sudo -n sample`
15
+ * took 1.1-4.6 s, and in a five-second window two of eight real captures lost their sample at its limit.
16
+ */
17
+ export const HANG_CAPTURE_MS = 10_000;
5
18
  const MAX_PROBE_BYTES = 4 * 1024 * 1024;
6
19
  const PS_FIELDS = 'pid=,ppid=,pgid=,stat=,%cpu=,etime=,lstart=,command=';
20
+ /**
21
+ * Stack samples: `sample` suspends a process every millisecond for one second and reports its threads' call graph. The
22
+ * runner and at most this many leaf processes are sampled, all at once. `-mayDie` is not passed: it reads symbols
23
+ * before sampling and measured about a second slower under load, and a process that exits mid-sample is a raced
24
+ * capture all the same.
25
+ */
26
+ const MAX_SAMPLED_LEAVES = 4;
27
+ const SAMPLE_SECONDS = 1;
28
+ /**
29
+ * A process census's limit. The stack samples run until the closing census is this far from the window's end.
30
+ */
31
+ const CENSUS_LIMIT_MS = 1_000;
32
+ /**
33
+ * lsof's mount-table fallback (darwin libproc dmnt.c, readmnt()): a mount it cannot stat(), such as one detaching under a
34
+ * concurrent shed, is kept with its mount-table device. Descriptors come per process from libproc, so this warning omits
35
+ * none of the selected processes' rows.
36
+ */
37
+ const LSOF_MOUNT_FALLBACK =
38
+ /^lsof: WARNING: can't stat\(\) \S+ file system .*\n {6}Output information may be incomplete\.\n {6}assuming "dev=[0-9a-f]+" from mount table\n/gm;
39
+
40
+ /** The lsof stderr that makes its census incomplete: everything except its mount-table fallback. */
41
+ function lsofFaults(stderr: string): string {
42
+ return stderr.replace(LSOF_MOUNT_FALLBACK, '').trim();
43
+ }
44
+
45
+ /** A `sample` report up to its binary-image list: its header and call graph name the stacks; the load map is bulk. */
46
+ function callGraph(report: string): string {
47
+ const end = report.indexOf('\nBinary Images:');
48
+ return (end === -1 ? report : report.slice(0, end)).trim();
49
+ }
7
50
 
8
51
  export interface HangDiagnostics {
9
52
  startedAtMs: number;
@@ -11,6 +54,8 @@ export interface HangDiagnostics {
11
54
  /** Positive when the observation completed before the idle expiry. */
12
55
  offsetFromExpiryMs: number;
13
56
  outcome: 'holders' | 'none' | 'incomplete';
57
+ /** Lock waits the snapshot names: empty unless the capture is complete, and always empty without the open-file census. */
58
+ lockWaits: readonly LockWait[];
14
59
  text: string;
15
60
  }
16
61
 
@@ -53,8 +98,10 @@ export function captureHangDiagnostics(
53
98
  `Hang snapshot: pid=${request.pid} pgid=${request.pgid ?? 'unknown'} startedAtMs=${startedAtMs}`,
54
99
  'Open files and process observations are evidence, not proof of a contested lock or its owner.',
55
100
  ];
56
- let active = 'process census';
101
+ const active = new Set<string>();
102
+ const during = (): string => (active.size === 0 ? 'process census' : [...active].join(', '));
57
103
  let finished = false;
104
+ let waits: readonly LockWait[] = [];
58
105
  // This package targets lib es2022, which does not declare Promise.withResolvers.
59
106
  return new Promise((resolve) => {
60
107
  const finish = (outcome: HangDiagnostics['outcome']): void => {
@@ -70,16 +117,17 @@ export function captureHangDiagnostics(
70
117
  capturedAtMs,
71
118
  offsetFromExpiryMs,
72
119
  outcome,
120
+ lockWaits: outcome === 'incomplete' ? [] : waits,
73
121
  text: `${lines.join('\n')}\nHang snapshot outcome=${outcome} capturedAtMs=${capturedAtMs} offsetFromExpiryMs=${offsetFromExpiryMs}\n`,
74
122
  });
75
123
  };
76
124
  const timer = setTimeout(() => {
77
- lines.push(`Capture incomplete: ${budgetMs}ms deadline reached during ${active}; no empty-holder conclusion.`);
125
+ lines.push(`Capture incomplete: ${budgetMs}ms deadline reached during ${during()}; no empty-holder conclusion.`);
78
126
  finish('incomplete');
79
127
  }, budgetMs);
80
128
  const cancelled = (): void => {
81
129
  if (finished) return;
82
- lines.push(`Capture cancelled during ${active}; its progress generation is no longer current.`);
130
+ lines.push(`Capture cancelled during ${during()}; its progress generation is no longer current.`);
83
131
  finish('incomplete');
84
132
  };
85
133
  request.signal?.addEventListener('abort', cancelled, { once: true });
@@ -93,7 +141,7 @@ export function captureHangDiagnostics(
93
141
  return;
94
142
  }
95
143
  const probe = async (name: string, file: string, args: readonly string[], limitMs: number) => {
96
- active = name;
144
+ active.add(name);
97
145
  lines.push(`${name}: ${file} ${args.join(' ')}`);
98
146
  const result = await source.probe(
99
147
  file,
@@ -101,6 +149,7 @@ export function captureHangDiagnostics(
101
149
  Math.max(0, Math.min(limitMs, endsAtMs - Date.now())),
102
150
  controller.signal,
103
151
  );
152
+ active.delete(name);
104
153
  if (!finished) {
105
154
  lines.push(
106
155
  `${name}: ${result.status}${result.status === 'exited' ? ` code=${result.code}` : ` ${result.detail}`}`,
@@ -110,8 +159,8 @@ export function captureHangDiagnostics(
110
159
  return result;
111
160
  };
112
161
  const census = async (name: string): Promise<ObservedProcess[] | null> => {
113
- // Bare `ps`, resolved through PATH like testing.ts's processTable: NixOS has no /bin/ps.
114
- const result = await probe(name, 'ps', ['-A', '-o', PS_FIELDS], 1_000);
162
+ // Bare `ps`, resolved through PATH like testing.ts's processesOf: NixOS has no /bin/ps.
163
+ const result = await probe(name, 'ps', ['-A', '-o', PS_FIELDS], CENSUS_LIMIT_MS);
115
164
  if (finished) return null;
116
165
  if (result.status !== 'exited' || result.code !== 0) {
117
166
  lines.push(`${name}: could not inspect the process table; not an empty process tree.`);
@@ -152,6 +201,41 @@ export function captureHangDiagnostics(
152
201
  }
153
202
  return tree;
154
203
  };
204
+ /**
205
+ * One-second call stacks of the runner and of its tree's leaf processes, taken at once: a stack names the call a
206
+ * process waits in, which the open-file census cannot. A sample sudo refuses, or one that does not answer, is named
207
+ * as no stack for that process; stacks never change the holder outcome.
208
+ */
209
+ const stackSamples = async (tree: readonly ObservedProcess[]): Promise<void> => {
210
+ const live = tree.filter((entry) => !entry.stat.startsWith('Z'));
211
+ const parents = new Set(live.map((entry) => entry.ppid));
212
+ const leaves = live.filter((entry) => entry.pid !== request.pid && !parents.has(entry.pid));
213
+ const omitted = leaves.slice(MAX_SAMPLED_LEAVES).map((entry) => entry.pid);
214
+ if (omitted.length > 0)
215
+ lines.push(
216
+ `Stack samples bounded to the runner and ${MAX_SAMPLED_LEAVES} leaf processes; not sampled: pid ${omitted.join(', ')}`,
217
+ );
218
+ const limitMs = endsAtMs - Date.now() - CENSUS_LIMIT_MS;
219
+ const sampled = [request.pid, ...leaves.slice(0, MAX_SAMPLED_LEAVES).map((entry) => entry.pid)];
220
+ await Promise.all(
221
+ sampled.map(async (pid) => {
222
+ const name = `stack sample pid ${pid}`;
223
+ // `-file /dev/stdout` writes the report to the probe's pipe alone, not also to a root-owned file in /tmp.
224
+ const args = ['-n', 'sample', String(pid), String(SAMPLE_SECONDS), '-file', '/dev/stdout'];
225
+ const result = await probe(name, 'sudo', args, limitMs);
226
+ if (finished) return;
227
+ const report = callGraph(result.stdout);
228
+ if (result.status === 'exited' && result.code === 0 && report !== '') {
229
+ lines.push(`${name} (${SAMPLE_SECONDS}s; binary image list omitted):\n${report}`);
230
+ return;
231
+ }
232
+ if (report !== '') lines.push(`Partial ${name} output:\n${report}`);
233
+ lines.push(
234
+ `${name}: no stack; sudo -n sample did not answer, so the call this process waits in is not observed.`,
235
+ );
236
+ }),
237
+ );
238
+ };
155
239
  const collect = async (): Promise<void> => {
156
240
  const before = await census('ps before');
157
241
  if (finished) return;
@@ -159,30 +243,62 @@ export function captureHangDiagnostics(
159
243
  let incomplete = false;
160
244
  let observed = before.length > 0;
161
245
  if (source.platform === 'darwin') {
162
- const args = ['-nP', '-p', before.map((entry) => entry.pid).join(',')];
163
- // Bare `sudo`/`lsof` through PATH, like `ps` above: NixOS provides neither /usr/bin/sudo nor /usr/sbin/lsof.
164
- let resources = await probe('lsof privileged', 'sudo', ['-n', 'lsof', ...args], 1_500);
165
- if (finished) return;
166
- const answered = (result: HangProbeResult): boolean =>
167
- result.status === 'exited' && (result.code === 0 || (result.code === 1 && result.stderr.trim() === ''));
168
- if (!answered(resources)) {
169
- incomplete = true;
170
- if (resources.stdout.trim() !== '')
171
- lines.push(`Partial privileged lsof output:\n${resources.stdout.trimEnd()}`);
172
- lines.push(
173
- 'Privileged resource census unavailable; fallback is ordinary-user visibility only, not proof of no holders.',
174
- );
175
- resources = await probe('lsof user-scoped fallback', 'lsof', args, 1_000);
246
+ const openFiles = async (): Promise<void> => {
247
+ const args = ['-nP', '-p', before.map((entry) => entry.pid).join(',')];
248
+ // Bare `sudo`/`lsof` through PATH, like `ps` above: NixOS provides neither /usr/bin/sudo nor /usr/sbin/lsof.
249
+ let resources = await probe('lsof privileged', 'sudo', ['-n', 'lsof', ...args], 1_500);
176
250
  if (finished) return;
177
- }
178
- if (resources.stdout.trim() !== '')
179
- lines.push(`lsof open files/sockets (not contested-lock proof):\n${resources.stdout.trimEnd()}`);
180
- if (!answered(resources) || resources.stderr.trim() !== '') incomplete = true;
181
- observed = resources.stdout.trim() !== '';
182
- if (!observed && answered(resources))
183
- lines.push('lsof reported no open-file matches within its stated visibility.');
251
+ const answered = (result: HangProbeResult): boolean =>
252
+ result.status === 'exited' &&
253
+ (result.code === 0 || (result.code === 1 && lsofFaults(result.stderr) === ''));
254
+ if (!answered(resources)) {
255
+ incomplete = true;
256
+ if (resources.stdout.trim() !== '')
257
+ lines.push(`Partial privileged lsof output:\n${resources.stdout.trimEnd()}`);
258
+ lines.push(
259
+ 'Privileged resource census unavailable; fallback is ordinary-user visibility only, not proof of no holders.',
260
+ );
261
+ resources = await probe('lsof user-scoped fallback', 'lsof', args, 1_000);
262
+ if (finished) return;
263
+ }
264
+ if (resources.stdout.trim() !== '')
265
+ lines.push(`lsof open files/sockets (not contested-lock proof):\n${resources.stdout.trimEnd()}`);
266
+ if (!answered(resources) || lsofFaults(resources.stderr) !== '') incomplete = true;
267
+ else if (resources.stderr.trim() !== '')
268
+ lines.push(
269
+ 'lsof warned only that it could not stat() the named mounts and kept their mount-table devices; that omits no descriptor of the selected processes.',
270
+ );
271
+ observed = resources.stdout.trim() !== '';
272
+ if (!observed && answered(resources))
273
+ lines.push('lsof reported no open-file matches within its stated visibility.');
274
+ // A lock wait needs a complete census of the run's files: a regular file the run holds on a numbered descriptor
275
+ // that another process also holds open. One privileged lsof names those holders; a probe that did not answer
276
+ // makes the capture incomplete, never an empty holder set.
277
+ const rows = incomplete ? [] : parseLsofTable(resources.stdout);
278
+ const candidates = lockCandidates(rows);
279
+ if (candidates.length > 0) {
280
+ const holders = await probe(
281
+ 'lsof lock holders',
282
+ 'sudo',
283
+ ['-n', 'lsof', '-nP', '-F', 'pcn', '--', ...candidates],
284
+ 1_500,
285
+ );
286
+ if (finished) return;
287
+ const openers =
288
+ answered(holders) && lsofFaults(holders.stderr) === '' ? parseLsofFields(holders.stdout) : null;
289
+ if (openers === null) {
290
+ incomplete = true;
291
+ lines.push('Lock holder census incomplete; no lock wait is named.');
292
+ } else {
293
+ waits = lockWaits(rows, new Set(before.map((entry) => entry.pid)), openers);
294
+ }
295
+ }
296
+ };
297
+ await Promise.all([openFiles(), stackSamples(before)]);
298
+ if (finished) return;
184
299
  } else {
185
300
  lines.push(`Open-file census not provided on ${source.platform}; observations below name processes only.`);
301
+ lines.push(`Stack samples not provided on ${source.platform}; no blocking call is observed.`);
186
302
  }
187
303
  const after = await census('ps after');
188
304
  if (finished) return;
@@ -205,16 +321,40 @@ export function captureHangDiagnostics(
205
321
  incomplete = true;
206
322
  lines.push('Process identities or membership changed during capture; open-file census raced.');
207
323
  }
324
+ if (!incomplete) {
325
+ for (const wait of waits) {
326
+ lines.push(
327
+ `Lock wait (open-handle evidence, not a kernel lock owner): ${wait.path} open in the run by pid ${wait.waiters.join(', ')} and outside it by ${describeHolders(wait.holders)}`,
328
+ );
329
+ }
330
+ }
208
331
  finish(incomplete ? 'incomplete' : observed ? 'holders' : 'none');
209
332
  };
210
333
  void collect().catch((error: unknown) => {
211
334
  if (finished) return;
212
- lines.push(`Capture incomplete during ${active}: ${error instanceof Error ? error.message : String(error)}`);
335
+ lines.push(`Capture incomplete during ${during()}: ${error instanceof Error ? error.message : String(error)}`);
213
336
  finish('incomplete');
214
337
  });
215
338
  });
216
339
  }
217
340
 
341
+ /**
342
+ * Ends a probe at its limit without waiting for it, and says whether its group still lists members. An ordinary probe
343
+ * runs as this user, so SIGKILL to its process group ends it and anything it started, and the kill is repeated while
344
+ * the group lists members, since one forked as the signal goes out survives it. `sudo` keeps this user's real uid but
345
+ * runs its command as root, which no signal from this user reaches: a group SIGKILL would end sudo alone and orphan
346
+ * the command. Signalled itself, sudo relays SIGTERM to its command and exits only after it. While sudo starts it
347
+ * holds root's real uid, and this throws EPERM. A probe is its caller's child and stays unreaped while the caller
348
+ * waits here, and the kernel lists it as a member of its own group until then, so a group left listed is expected.
349
+ */
350
+ export function stopProbe(file: string, pid: number): boolean {
351
+ if (file === 'sudo') {
352
+ process.kill(pid, 'SIGTERM');
353
+ return false;
354
+ }
355
+ return killProcessGroupNow(pid, TEARDOWN_PATIENCE);
356
+ }
357
+
218
358
  /** A probe owns its group and output pipes; its deadline never waits for an unresponsive child to reap. */
219
359
  function runProbe(
220
360
  file: string,
@@ -248,9 +388,11 @@ function runProbe(
248
388
  let killFailure = '';
249
389
  if (child.pid !== undefined) {
250
390
  try {
251
- process.kill(-child.pid, 'SIGKILL');
391
+ if (stopProbe(file, child.pid)) {
392
+ killFailure = `; probe group cleanup: ${describeTeardown({ command: file, group: child.pid })}`;
393
+ }
252
394
  } catch (error) {
253
- killFailure = `; probe group cleanup: ${error instanceof Error ? error.message : String(error)}`;
395
+ killFailure = `; probe ${file === 'sudo' ? 'stop through sudo' : 'group cleanup'}: ${error instanceof Error ? error.message : String(error)}`;
254
396
  }
255
397
  }
256
398
  finish({ status, detail: detail + killFailure, stdout, stderr });
@@ -0,0 +1,116 @@
1
+ import type { tags } from 'typia';
2
+
3
+ /** Peer wait classes from specs/cowshed/05_gateway.md, "Deadlines". */
4
+ export const CONTROL_MS = 5_000;
5
+ export const HEARTBEAT_MS = 5_000;
6
+ export const HEARTBEAT_SILENCE_MS = 15_000;
7
+
8
+ /** The CPU pool's actor-authored progress, shared by its server and lease client. */
9
+ export interface CpuLeaseProgress {
10
+ ok: true;
11
+ progress: number;
12
+ }
13
+
14
+ /**
15
+ * The CPU pool's queue acknowledgement, shared by its server and lease client. `server` is the pid of the process the
16
+ * pool runs in, so a wait that falls silent names the process to look at.
17
+ */
18
+ export interface CpuLeaseQueued {
19
+ ok: true;
20
+ lease: 'queued';
21
+ server: number & tags.Type<'uint32'>;
22
+ }
23
+
24
+ type CpuWaitState =
25
+ | { kind: 'sending' }
26
+ | { kind: 'waiting'; at: number; last: string; sequence: number; server: number | null };
27
+
28
+ /** A failed wait, not a failed command: expiry ends this client's admission only. */
29
+ export interface CpuWaitFailure {
30
+ code: 'TIMEOUT' | 'SILENT';
31
+ boundMs: number;
32
+ elapsedMs: number;
33
+ last: string;
34
+ /** The last advancing heartbeat sequence the client read; 0 before the first. */
35
+ sequence: number;
36
+ /** The pool's pid as its queue acknowledgement named it; null before one, or from a pool that names none. */
37
+ server: number | null;
38
+ }
39
+
40
+ /** An expired CPU wait as its client keeps it: the failure, and the socket of the pool it waited on. */
41
+ export interface CpuWaitRow extends CpuWaitFailure {
42
+ socket: string;
43
+ }
44
+
45
+ /** Pure CPU admission policy; its injected monotonic clock performs no I/O or scheduling. */
46
+ export class CpuLeaseWait {
47
+ private readonly started: number;
48
+ private state: CpuWaitState = { kind: 'sending' };
49
+ /** When the client last looked at its wait or read a frame of it. */
50
+ private looked: number;
51
+
52
+ constructor(private readonly now: () => number = () => performance.now()) {
53
+ this.started = now();
54
+ this.looked = this.started;
55
+ }
56
+
57
+ /** The kernel took the complete request; only peer silence bounds the answer from here. */
58
+ sent(): void {
59
+ this.looked = this.now();
60
+ if (this.state.kind === 'sending') {
61
+ this.state = { kind: 'waiting', at: this.now(), last: 'request sent', sequence: 0, server: null };
62
+ }
63
+ }
64
+
65
+ /**
66
+ * A queue entry proves actor progress, not a deadline for returning a token. It names the pool's pid when the pool
67
+ * says it.
68
+ */
69
+ queued(server: number | null): void {
70
+ this.sent();
71
+ if (this.state.kind === 'waiting') {
72
+ this.state = { ...this.state, at: this.now(), last: 'queued', server };
73
+ }
74
+ }
75
+
76
+ /** Only an advancing actor sequence renews silence; duplicate or invalid progress proves nothing. */
77
+ heartbeat(sequence: number): boolean {
78
+ this.sent();
79
+ if (this.state.kind !== 'waiting' || !Number.isSafeInteger(sequence) || sequence <= this.state.sequence)
80
+ return false;
81
+ this.state = { ...this.state, at: this.now(), last: `heartbeat ${sequence}`, sequence };
82
+ return true;
83
+ }
84
+
85
+ /**
86
+ * The client looks at its wait before judging it. A look later than the silence bound plus a heartbeat
87
+ * after its previous look or frame means the client's own event loop did not run (a loaded host), so
88
+ * what the pool sent meanwhile is unread: the pool gets one heartbeat more from now (05_gateway.md
89
+ * "Deadlines"). A client that looks in time judges the pool at the bound.
90
+ */
91
+ look(): void {
92
+ const now = this.now();
93
+ if (this.state.kind === 'waiting' && now - this.looked > HEARTBEAT_SILENCE_MS + HEARTBEAT_MS) {
94
+ this.state = { ...this.state, at: Math.max(this.state.at, now - HEARTBEAT_SILENCE_MS + HEARTBEAT_MS) };
95
+ }
96
+ this.looked = now;
97
+ }
98
+
99
+ /** Milliseconds until the current phase's bound, clipped at zero. */
100
+ remainingMs(): number {
101
+ const due = this.state.kind === 'sending' ? this.started + CONTROL_MS : this.state.at + HEARTBEAT_SILENCE_MS;
102
+ return Math.max(0, due - this.now());
103
+ }
104
+
105
+ /** No total queue age exists: an advancing heartbeat keeps the wait alive indefinitely. */
106
+ expired(): CpuWaitFailure | null {
107
+ if (this.remainingMs() > 0) return null;
108
+ const elapsedMs = this.now() - this.started;
109
+ if (this.state.kind === 'sending') {
110
+ const last = 'connecting or sending request';
111
+ return { code: 'TIMEOUT', boundMs: CONTROL_MS, elapsedMs, last, sequence: 0, server: null };
112
+ }
113
+ const { last, sequence, server } = this.state;
114
+ return { code: 'SILENT', boundMs: HEARTBEAT_SILENCE_MS, elapsedMs, last, sequence, server };
115
+ }
116
+ }