@ultimat3/cli 31.47.1 → 31.49.0

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 (276) hide show
  1. package/CLAUDE.md +30 -23
  2. package/README.md +96 -4
  3. package/package.json +29 -29
  4. package/src/api-registration.ts +28 -14
  5. package/src/app-load.ts +6 -1
  6. package/src/app-root.ts +7 -1
  7. package/src/clean-services.ts +142 -0
  8. package/src/cmd-auth.ts +3 -0
  9. package/src/cmd-clean-spec.ts +10 -3
  10. package/src/cmd-clean.ts +23 -9
  11. package/src/cmd-db-backfill.ts +6 -0
  12. package/src/cmd-db-branch.ts +10 -4
  13. package/src/cmd-db-recount.ts +5 -12
  14. package/src/cmd-db-rollback.ts +77 -0
  15. package/src/cmd-db-spec.ts +18 -2
  16. package/src/cmd-db-status.ts +5 -10
  17. package/src/cmd-db.ts +105 -33
  18. package/src/cmd-deploy-verify.ts +14 -6
  19. package/src/cmd-docs-topic.ts +94 -0
  20. package/src/cmd-docs.ts +15 -1
  21. package/src/cmd-doctor.ts +109 -41
  22. package/src/cmd-drill.ts +100 -19
  23. package/src/cmd-env.ts +30 -8
  24. package/src/cmd-errors-app.ts +63 -0
  25. package/src/cmd-errors.ts +50 -14
  26. package/src/cmd-generate.ts +17 -4
  27. package/src/cmd-heavy-spec.ts +36 -0
  28. package/src/cmd-heavy.ts +244 -0
  29. package/src/cmd-jobs.ts +27 -1
  30. package/src/cmd-merge-driver-spec.ts +12 -0
  31. package/src/cmd-merge-driver.ts +95 -0
  32. package/src/cmd-new.ts +23 -3
  33. package/src/cmd-policy-spec.ts +9 -1
  34. package/src/cmd-policy.ts +72 -17
  35. package/src/cmd-stop.ts +18 -4
  36. package/src/cmd-tasks-run.ts +87 -0
  37. package/src/cmd-tasks-spec.ts +10 -3
  38. package/src/cmd-tasks.ts +8 -5
  39. package/src/cmd-test.ts +15 -4
  40. package/src/cmd-upgrade-spec.ts +8 -1
  41. package/src/cmd-upgrade.ts +32 -5
  42. package/src/cmd-verify.ts +9 -41
  43. package/src/codemods/agents-doc-row.ts +73 -0
  44. package/src/codemods/define-error-leaf.ts +37 -12
  45. package/src/codemods/docs-many-agents.ts +26 -0
  46. package/src/codemods/docs-worker-commands.ts +26 -0
  47. package/src/codemods/index.ts +6 -0
  48. package/src/codemods/merge-drivers.ts +66 -0
  49. package/src/command.ts +3 -0
  50. package/src/db-applied-edits.ts +117 -0
  51. package/src/db-dev-wire.ts +18 -0
  52. package/src/db-diagnostics.ts +5 -10
  53. package/src/db-generate.ts +82 -7
  54. package/src/db-migrate-pass.ts +51 -0
  55. package/src/db-migrate-through-dev.ts +209 -0
  56. package/src/db-rollback-consent.ts +128 -0
  57. package/src/db-rollback-pass.ts +76 -0
  58. package/src/db-seed-generate.ts +5 -1
  59. package/src/db-seed.ts +7 -1
  60. package/src/deploy-verify-findings.ts +3 -0
  61. package/src/deploy-verify-grade.ts +3 -0
  62. package/src/deploy-verify-processes.ts +32 -0
  63. package/src/dev-boot.ts +3 -0
  64. package/src/dev-db-migrate.ts +155 -0
  65. package/src/dev-db-rollback.ts +33 -0
  66. package/src/dev-db-settled.ts +22 -0
  67. package/src/dev-lock-errors.ts +78 -0
  68. package/src/dev-lock-holder-dir.ts +64 -0
  69. package/src/dev-lock-live.ts +44 -0
  70. package/src/dev-lock.ts +59 -84
  71. package/src/dev-policy.ts +11 -8
  72. package/src/dev-rebuild-schema.ts +116 -13
  73. package/src/dev-rebuild.ts +13 -4
  74. package/src/dev-route-table.ts +7 -0
  75. package/src/dispatch.ts +21 -1
  76. package/src/doctor-advisory-floors.ts +30 -8
  77. package/src/doctor-api-listing.ts +114 -0
  78. package/src/doctor-guarded.ts +41 -0
  79. package/src/doctor-port.ts +90 -17
  80. package/src/doctor-probe.ts +36 -5
  81. package/src/doctor-processes-probe.ts +127 -0
  82. package/src/doctor-processes.ts +136 -0
  83. package/src/doctor-warnings.ts +17 -0
  84. package/src/error-codes-agents.ts +35 -0
  85. package/src/error-codes-processes.ts +30 -0
  86. package/src/error-codes-tooling.ts +11 -3
  87. package/src/error-codes.ts +12 -13
  88. package/src/errors-suite.ts +27 -0
  89. package/src/errors.ts +18 -22
  90. package/src/exec.ts +11 -3
  91. package/src/exercise-registration.ts +4 -3
  92. package/src/framework-env.ts +7 -3
  93. package/src/generate-files.ts +1 -0
  94. package/src/generate-grant-findings.ts +7 -5
  95. package/src/generate-grants.ts +9 -8
  96. package/src/generate-kinds.ts +30 -6
  97. package/src/generate-roles-file.ts +30 -0
  98. package/src/generate-slice-policy.ts +3 -3
  99. package/src/guards.ts +2 -2
  100. package/src/heavy-cores.ts +51 -0
  101. package/src/heavy-env.ts +21 -0
  102. package/src/heavy-errors.ts +54 -0
  103. package/src/heavy-flock.ts +73 -0
  104. package/src/heavy-holders.ts +78 -0
  105. package/src/heavy-ledger.ts +400 -0
  106. package/src/heavy-memory.ts +67 -0
  107. package/src/heavy-pressure.ts +104 -0
  108. package/src/heavy-weights.ts +47 -0
  109. package/src/heavy.ts +308 -0
  110. package/src/i18n-registration.ts +22 -2
  111. package/src/island-harness.ts +2 -2
  112. package/src/job-budget.ts +4 -2
  113. package/src/job-registration.ts +64 -8
  114. package/src/jobs-queue-known.ts +43 -0
  115. package/src/local-cli.ts +6 -5
  116. package/src/mcp-errors-agents.ts +20 -0
  117. package/src/mcp-errors-doctor.ts +27 -0
  118. package/src/mcp-errors-processes.ts +23 -0
  119. package/src/mcp-errors.ts +18 -29
  120. package/src/mcp-host.ts +2 -2
  121. package/src/merge-driver-catalog.ts +58 -0
  122. package/src/merge-driver-config.ts +43 -0
  123. package/src/merge-driver-lines.ts +140 -0
  124. package/src/merge-state.ts +105 -0
  125. package/src/messages-db.ts +22 -1
  126. package/src/messages-processes.ts +13 -0
  127. package/src/messages-upgrade.ts +6 -0
  128. package/src/messages.ts +62 -1
  129. package/src/output-findings.ts +48 -21
  130. package/src/parse.ts +37 -6
  131. package/src/policy-facts.ts +38 -21
  132. package/src/policy-row.ts +99 -0
  133. package/src/port-pair-free.ts +28 -0
  134. package/src/registry-lines.ts +110 -0
  135. package/src/registry.ts +4 -0
  136. package/src/retain-sweep.ts +1 -1
  137. package/src/role-replicator.ts +9 -4
  138. package/src/role-select.ts +86 -0
  139. package/src/role-start.ts +13 -55
  140. package/src/role-sync.ts +10 -5
  141. package/src/runtime-cache-frame.ts +46 -0
  142. package/src/runtime-cache-ttl.ts +23 -0
  143. package/src/runtime-cache.ts +56 -18
  144. package/src/runtime-database-ssl.ts +84 -0
  145. package/src/runtime-idempotency-scope.ts +16 -2
  146. package/src/runtime-jobs-share.ts +52 -0
  147. package/src/runtime-jobs.ts +43 -12
  148. package/src/runtime-overrides.ts +4 -2
  149. package/src/runtime-queue.ts +18 -3
  150. package/src/runtime-services.ts +8 -1
  151. package/src/schema-drift.ts +19 -2
  152. package/src/schema-dump-drift.ts +4 -1
  153. package/src/serve-boot-probe.ts +30 -2
  154. package/src/serve-boot.ts +11 -1
  155. package/src/serve-env.ts +39 -3
  156. package/src/serve.ts +61 -10
  157. package/src/stop-run-start.ts +12 -0
  158. package/src/supervise-boot.ts +61 -0
  159. package/src/supervise-cgroup.ts +84 -0
  160. package/src/supervise-child.ts +206 -0
  161. package/src/supervise-count.ts +244 -0
  162. package/src/supervise-errors.ts +83 -0
  163. package/src/supervise-facts.ts +40 -0
  164. package/src/supervise-messages.ts +84 -0
  165. package/src/supervise-policy.ts +46 -0
  166. package/src/supervise-pool.ts +10 -0
  167. package/src/supervise-probe.ts +158 -0
  168. package/src/supervise-run.ts +54 -0
  169. package/src/supervise.ts +383 -0
  170. package/src/templates/generate-purge.ts +6 -6
  171. package/src/templates/guard-animated-layout-property.ts +2 -2
  172. package/src/templates/guard-bare-error.ts +1 -1
  173. package/src/templates/guard-error-declared.ts +2 -2
  174. package/src/templates/guard-focus-visible.ts +1 -1
  175. package/src/templates/guard-image-dimensions.ts +2 -2
  176. package/src/templates/guard-island-mount-clears.ts +1 -1
  177. package/src/templates/guard-native-confirm.ts +1 -1
  178. package/src/templates/guard-raw-breakpoint.ts +2 -2
  179. package/src/templates/guard-raw-colour.ts +2 -2
  180. package/src/templates/guard-raw-fetch.ts +1 -1
  181. package/src/templates/guard-raw-interval.ts +1 -1
  182. package/src/templates/guard-raw-length.ts +3 -3
  183. package/src/templates/guard-raw-motion.ts +1 -1
  184. package/src/templates/guard-raw-shadow.ts +1 -1
  185. package/src/templates/guard-raw-z-index.ts +1 -1
  186. package/src/templates/guard-released-forms.ts +59 -13
  187. package/src/templates/guard-repo-await-in-loop.ts +1 -1
  188. package/src/templates/guard-repo-raw-sql.ts +4 -4
  189. package/src/templates/guard-repo-unbounded.ts +1 -1
  190. package/src/templates/guard-runtime-pin.ts +1 -1
  191. package/src/templates/guard-semantic-interactive.ts +2 -2
  192. package/src/templates/guard-unbounded-fanout.ts +1 -1
  193. package/src/templates/guard-undeclared-custom-property.ts +3 -3
  194. package/src/templates/guard-undefined-style-class.ts +3 -3
  195. package/src/templates/guard-unzoned-date.ts +3 -3
  196. package/src/templates/query-slice.ts +82 -0
  197. package/src/templates/query.ts +76 -30
  198. package/src/templates/resource-page.ts +3 -2
  199. package/src/templates/scaffold-bin.ts +2 -0
  200. package/src/templates/scaffold-claude-agents.ts +9 -6
  201. package/src/templates/scaffold-claude-commands.ts +7 -1
  202. package/src/templates/scaffold-claude.ts +4 -4
  203. package/src/templates/scaffold-container-compose.ts +47 -7
  204. package/src/templates/scaffold-docs.ts +11 -6
  205. package/src/templates/scaffold-gitattributes.ts +18 -1
  206. package/src/templates/scaffold-helm-templates.ts +9 -0
  207. package/src/templates/scaffold-repo.ts +4 -1
  208. package/src/templates/scaffold-test-services.ts +33 -11
  209. package/src/templates/shapes/offline.ts +0 -7
  210. package/src/templates/shapes/realtime.ts +2 -6
  211. package/src/templates/sign-in-action-tests.ts +6 -4
  212. package/src/templates/sign-in-challenge.ts +62 -0
  213. package/src/templates/sign-in-oidc-mfa.ts +31 -0
  214. package/src/templates/sign-in-oidc.ts +11 -3
  215. package/src/templates/sign-in-password.ts +18 -56
  216. package/src/test-batches.ts +9 -3
  217. package/src/test-shards.ts +117 -37
  218. package/src/test-slots.ts +35 -161
  219. package/src/test-verdict.ts +79 -0
  220. package/src/test-workers.ts +15 -0
  221. package/src/upgrade-gate-codemods.ts +5 -3
  222. package/src/upgrade-gate.ts +19 -1
  223. package/src/upgrade-merge-drivers.ts +25 -0
  224. package/src/upgrade-report.ts +18 -4
  225. package/src/upgrade-scope.ts +62 -0
  226. package/src/verify-checks.ts +6 -11
  227. package/src/verify-coverage-run.ts +9 -5
  228. package/src/verify-deadline.ts +18 -2
  229. package/src/verify-heavy-steps.ts +26 -0
  230. package/src/verify-live.ts +38 -14
  231. package/src/verify-only.ts +67 -0
  232. package/src/verify-progress.ts +7 -3
  233. package/src/verify-run.ts +20 -2
  234. package/src/verify-services-stack.ts +165 -0
  235. package/src/verify-services.ts +84 -2
  236. package/src/verify-test-run.ts +9 -9
  237. package/src/verify-tests.ts +35 -22
  238. package/src/verify-typecheck.ts +25 -2
  239. package/wiki/Actions.md +2 -1
  240. package/wiki/Admin-Dashboard.md +2 -2
  241. package/wiki/Agents.md +5 -5
  242. package/wiki/Auth.md +15 -5
  243. package/wiki/Bare-VM.md +1 -1
  244. package/wiki/Building-Your-Own-Base.md +15 -2
  245. package/wiki/CI-Parallel-Gate.md +4 -4
  246. package/wiki/CLI-Reference.md +127 -48
  247. package/wiki/Caching-And-Invalidation.md +2 -2
  248. package/wiki/Client-Navigation.md +1 -1
  249. package/wiki/Configuration.md +32 -13
  250. package/wiki/Deployment.md +44 -4
  251. package/wiki/Entities-And-Migrations.md +5 -1
  252. package/wiki/FAQ.md +1 -1
  253. package/wiki/Getting-Started.md +2 -2
  254. package/wiki/Home.md +2 -1
  255. package/wiki/I18n.md +5 -3
  256. package/wiki/Installation.md +12 -11
  257. package/wiki/Interface-Rules.md +1 -1
  258. package/wiki/Jobs-And-Workflows.md +24 -4
  259. package/wiki/Known-Gaps.md +2 -2
  260. package/wiki/MCP-And-AI.md +8 -5
  261. package/wiki/Mail.md +1 -1
  262. package/wiki/Many-Agents.md +127 -0
  263. package/wiki/Migrations-And-Backfills.md +18 -0
  264. package/wiki/Notify.md +1 -1
  265. package/wiki/Observability.md +13 -0
  266. package/wiki/Queries-And-Live-Queries.md +2 -2
  267. package/wiki/Realtime.md +10 -1
  268. package/wiki/Routes-And-Render-Modes.md +1 -1
  269. package/wiki/Scheduled-Tasks.md +4 -1
  270. package/wiki/Testing.md +12 -9
  271. package/wiki/Timezones-And-Dates.md +5 -1
  272. package/wiki/Troubleshooting.md +1 -0
  273. package/wiki/Tutorial-01-First-App.md +5 -5
  274. package/wiki/Tutorial-02-First-Feature.md +1 -1
  275. package/wiki/Tutorial-03-Auth-And-Admin.md +7 -6
  276. package/wiki/Upgrading.md +37 -0
@@ -3,6 +3,7 @@
3
3
 
4
4
  import type { WorkerRecord } from '@ultimat3/jobs';
5
5
  import { printableBuild } from './cmd-deploy-verify-sample';
6
+ import type { WorkerContainer } from './deploy-verify-processes';
6
7
 
7
8
  /** One `GET /readyz`. A `null` status is a sample nothing answered: refused, reset, timed out. */
8
9
  export interface Sample {
@@ -152,6 +153,8 @@ export interface QueueGrade {
152
153
  readonly unserved: readonly UnservedQueue[];
153
154
  /** On `--idle-ok`, no serving worker, depth 0. */
154
155
  readonly idle: readonly string[];
156
+ /** The registry's rows of this build per container (`deploy-verify-processes.ts`). */
157
+ readonly containers?: readonly WorkerContainer[];
155
158
  }
156
159
 
157
160
  /** No `DATABASE_URL`, or a window that never closed: nothing was read, so nothing passed. */
@@ -0,0 +1,32 @@
1
+ // `x deploy verify`'s processes fact: the worker registry's live rows of this build, grouped by the
2
+ // container that wrote them. A container running `ULTIMATE_PROCESSES=N` registers N rows under one
3
+ // `host` (children share the container's hostname), each with its own share of the slots.
4
+
5
+ import type { WorkerRecord } from '@ultimat3/jobs';
6
+
7
+ export interface WorkerContainer {
8
+ readonly host: string;
9
+ /** Registry rows (processes) this container has serving this build. */
10
+ readonly processes: number;
11
+ /** Their slots summed: the container's `jobs.concurrency` total, however it was split. */
12
+ readonly slots: number;
13
+ }
14
+
15
+ /** Serving rows of `build` per host, sorted by host. A draining or older row is the roll's, not this build's. */
16
+ export function workerContainers(
17
+ workers: readonly WorkerRecord[],
18
+ build: string,
19
+ ): readonly WorkerContainer[] {
20
+ const byHost = new Map<string, { processes: number; slots: number }>();
21
+ for (const worker of workers) {
22
+ if (worker.drainingAt !== undefined || worker.build !== build) continue;
23
+ const seen = byHost.get(worker.host) ?? { processes: 0, slots: 0 };
24
+ byHost.set(worker.host, {
25
+ processes: seen.processes + 1,
26
+ slots: seen.slots + worker.concurrency,
27
+ });
28
+ }
29
+ return [...byHost.entries()]
30
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
31
+ .map(([host, seen]) => ({ host, ...seen }));
32
+ }
package/src/dev-boot.ts CHANGED
@@ -44,6 +44,7 @@ import { releaseOrThrow, startServices } from './runtime-services';
44
44
  import { metricsPortFor, releaseBoot } from './serve';
45
45
  import type { ListenerTls } from './serve-env-tls';
46
46
  import { loopFacts, loopFinding, loopNotice } from './statement-loop';
47
+ import { logDevProcesses } from './supervise-boot';
47
48
 
48
49
  export interface DevServer {
49
50
  readonly url: string;
@@ -114,6 +115,8 @@ export async function startDev(options: StartDevOptions): Promise<DevServer> {
114
115
  // EVERY boot: a scratch server (`x shot`, `ui.shot`) boots here too, and without this a
115
116
  // fail-closed dev actor installs nothing — the picture is of a 401. Idempotent.
116
117
  declareDevEnvironment(options.env);
118
+ // One process, always: a count the `.env` asks for production is said once and ignored here.
119
+ logDevProcesses(options.env);
117
120
  // Before the first scan: the watcher's rescans evict a saved module AND everything importing it,
118
121
  // and that needs the import graph recorded as each module is first loaded (`app-reload-graph.ts`).
119
122
  enableReloadTracking(true);
@@ -0,0 +1,155 @@
1
+ // `POST /_x/db/migrate|rollback|ledger`: `x db migrate`, `rollback` and `gen`'s ledger read beside
2
+ // a live `x dev`, done BY the process that holds the embedded database. PGlite takes one writer,
3
+ // so the command asks the holder instead of opening `.x/pgdata` a second time. Loopback Host and
4
+ // peer, same-origin: the `/_x/db` doors.
5
+
6
+ import { NotImplementedError, renderThrowable, UltimateError } from '@ultimat3/core';
7
+ import type { DriftDifference } from '@ultimat3/db';
8
+ import { checkDrift, db, migrate } from '@ultimat3/db';
9
+ import type { CatalogDescription } from '@ultimat3/db/schema-dump';
10
+ import { introspectCatalog } from '@ultimat3/db/schema-dump';
11
+ import type { Route, UltimateRequest } from '@ultimat3/http';
12
+ import { jsonResponse } from '@ultimat3/http';
13
+ import { loadAppConfig } from './app-config-load';
14
+ import { acceptCreatedTables } from './db-accept-created';
15
+ import { DEV_LEDGER_PATH, DEV_MIGRATE_PATH, DEV_ROLLBACK_PATH } from './db-dev-wire';
16
+ import { frameworkStorageDrift } from './db-object-drift';
17
+ import { assertSameOrigin, hostRefusal } from './dev-dashboard-guard';
18
+ import { ledgerInDev, rollbackInDev, stepsOf } from './dev-db-rollback';
19
+ import { ledgerMoved } from './dev-db-settled';
20
+ import { readMigrations } from './migrations';
21
+ import { rowSecurityDeclared } from './row-security-boot';
22
+ import { stopRunStartFix } from './stop-run-start';
23
+
24
+ /** The command that works when this process cannot apply: the embedded database to itself. */
25
+ export const MIGRATE_ALONE_FIX = stopRunStartFix(['db', 'migrate']);
26
+
27
+ /** One applied pass as it crosses the wire: `runMigrations`' report, and the live catalog. */
28
+ export interface DevMigrateData {
29
+ readonly applied: readonly string[];
30
+ readonly skipped: number;
31
+ readonly appVersion: string;
32
+ readonly durationMs: number;
33
+ readonly drift: readonly DriftDifference[];
34
+ /** What `x db migrate` compares its replayed dump against, read here: only this process may. */
35
+ readonly catalog: CatalogDescription;
36
+ readonly storage: readonly DriftDifference[];
37
+ }
38
+
39
+ type Env = Readonly<Record<string, string | undefined>>;
40
+
41
+ /**
42
+ * With `database.rowSecurity`, this process serves as `x_app` and a migration must run as
43
+ * `x_migrator` from the bootstrap session — one embedded session cannot be both while it serves.
44
+ */
45
+ export async function devCanMigrate(root: string): Promise<boolean> {
46
+ return !rowSecurityDeclared(await loadAppConfig(root));
47
+ }
48
+
49
+ /** Refused where this process serves as `x_app`; `fix` is the command run alone, start to start. */
50
+ async function assertDevCanMigrate(root: string, fix: string): Promise<void> {
51
+ if (await devCanMigrate(root)) return;
52
+ throw new NotImplementedError({
53
+ cause:
54
+ 'this x dev serves the embedded database as x_app (database.rowSecurity), and migrations run as x_migrator — one embedded session cannot hold both',
55
+ fix,
56
+ });
57
+ }
58
+
59
+ /**
60
+ * `serve.ts`'s `runMigrations` over the client this process already holds: the same file list,
61
+ * the same ledger, the same post-condition. No boot and no `stop()` — the database is `x dev`'s.
62
+ */
63
+ export async function migrateInDev(root: string, env: Env): Promise<DevMigrateData> {
64
+ await assertDevCanMigrate(root, MIGRATE_ALONE_FIX);
65
+ const migrations = await readMigrations(root);
66
+ const report = await migrate({
67
+ migrations,
68
+ ...(env['APP_VERSION'] === undefined ? {} : { appVersion: env['APP_VERSION'] }),
69
+ });
70
+ const drift = acceptCreatedTables(await checkDrift({ migrations }), migrations);
71
+ const client = db();
72
+ const [catalog, storage] = await Promise.all([
73
+ introspectCatalog({ client }),
74
+ frameworkStorageDrift(client),
75
+ ]);
76
+ return {
77
+ applied: report.applied.map((entry) => entry.id),
78
+ skipped: report.skipped.length,
79
+ appVersion: report.appVersion,
80
+ durationMs: report.durationMs,
81
+ drift: drift.differences,
82
+ catalog,
83
+ storage,
84
+ };
85
+ }
86
+
87
+ /** The refusal as the command re-throws it: the code, cause and fix of whatever stopped the pass. */
88
+ function refusalOf(error: unknown): { code: string; cause: string; fix: string } {
89
+ if (error instanceof UltimateError) {
90
+ return { code: error.code, cause: error.cause, fix: error.fix };
91
+ }
92
+ return {
93
+ code: 'X_DB_MIGRATE_FAILED',
94
+ cause: `x dev could not apply the migrations: ${renderThrowable(error)}`,
95
+ fix: MIGRATE_ALONE_FIX,
96
+ };
97
+ }
98
+
99
+ export interface DevMigrateRouteInput {
100
+ readonly root: string;
101
+ readonly env: Env;
102
+ /** This dev server's URL, read per request — only what a refused Host's `fix:` line names. */
103
+ readonly devUrl: () => string;
104
+ }
105
+
106
+ /**
107
+ * One POST per path. A failed pass answers 200 with `ok: false` and the error's own three fields,
108
+ * never the pipeline's rendered page: the caller is a CLI that re-throws them under the same code.
109
+ */
110
+ function door(
111
+ input: DevMigrateRouteInput,
112
+ path: string,
113
+ name: string,
114
+ run: (request: UltimateRequest) => Promise<unknown>,
115
+ ): Route {
116
+ return {
117
+ method: 'POST',
118
+ path,
119
+ meta: { name, auth: 'public', tags: ['_x'] },
120
+ handler: async (request: UltimateRequest): Promise<Response> => {
121
+ const refused = hostRefusal(request, input.devUrl());
122
+ if (refused !== undefined) return refused;
123
+ assertSameOrigin(request);
124
+ try {
125
+ return jsonResponse({ ok: true, data: await run(request) });
126
+ } catch (error) {
127
+ return jsonResponse({ ok: false, error: refusalOf(error) });
128
+ }
129
+ },
130
+ };
131
+ }
132
+
133
+ /**
134
+ * A pass that moved the ledger ends in a generation (`dev-db-settled.ts`), so this process's
135
+ * findings stop saying what the ledger said before it — in the `finally`: a pass that failed
136
+ * halfway moved it too.
137
+ */
138
+ export function devMigrateRoutes(input: DevMigrateRouteInput): readonly Route[] {
139
+ const { root, env } = input;
140
+ return [
141
+ door(input, DEV_MIGRATE_PATH, 'dev._x.db.migrate', () =>
142
+ migrateInDev(root, env).finally(ledgerMoved),
143
+ ),
144
+ door(input, DEV_ROLLBACK_PATH, 'dev._x.db.rollback', async (request) => {
145
+ const steps = stepsOf(request.url.searchParams.get('steps'));
146
+ await assertDevCanMigrate(
147
+ root,
148
+ stopRunStartFix(['db', 'rollback', '--steps', String(steps)]),
149
+ );
150
+ return rollbackInDev(root, env, steps).finally(ledgerMoved);
151
+ }),
152
+ // A read, behind the same doors and the same verb: nothing under `/_x/db` answers a GET.
153
+ door(input, DEV_LEDGER_PATH, 'dev._x.db.ledger', () => ledgerInDev()),
154
+ ];
155
+ }
@@ -0,0 +1,33 @@
1
+ // The two other things `x db` asks of a live `x dev` that holds the embedded database, beside the
2
+ // migrate pass: reverse applied migrations (`x db rollback`), and read the ledger's checksums
3
+ // (`x db gen`'s edited-migration check). Bodies only — `dev-db-migrate.ts` mounts and guards them.
4
+
5
+ import { db, isLedgerMissing, readLedger } from '@ultimat3/db';
6
+ import { ROLLBACK_STEPS } from './db-dev-wire';
7
+ import { reverseApplied } from './db-rollback-pass';
8
+ import { parseIntFlag } from './flag-number';
9
+
10
+ type Env = Readonly<Record<string, string | undefined>>;
11
+
12
+ /** `?steps=n`, through the command's own reader: the door refuses what the flag refuses. */
13
+ export const stepsOf = (raw: string | null): number => parseIntFlag(raw ?? '', ROLLBACK_STEPS);
14
+
15
+ /** `rollback()` over the client this process already holds, with the command's own two refusals. */
16
+ export async function rollbackInDev(
17
+ root: string,
18
+ env: Env,
19
+ steps: number,
20
+ ): Promise<{ readonly reverted: readonly string[] }> {
21
+ return { reverted: await reverseApplied(root, env, steps) };
22
+ }
23
+
24
+ /** Each applied migration's id and the checksum it was applied with; no ledger is no rows. */
25
+ export async function ledgerInDev(): Promise<{
26
+ readonly ledger: readonly { readonly id: string; readonly checksum: string }[];
27
+ }> {
28
+ const rows = await readLedger(db()).catch((error: unknown) => {
29
+ if (!isLedgerMissing(error)) throw error;
30
+ return [];
31
+ });
32
+ return { ledger: rows.map((row) => ({ id: row.id, checksum: row.checksum })) };
33
+ }
@@ -0,0 +1,22 @@
1
+ // The one thing `x dev` must do after its database's ledger moved under it — a migrate or a
2
+ // rollback applied through `/_x/db` — and nothing on disk changed for the watcher to see: build a
3
+ // generation, so the findings (`X_APP_MIGRATIONS_UNAPPLIED`) say what the ledger now says.
4
+
5
+ /** The file a ledger-triggered rebuild is reported under: the directory the pass read. */
6
+ export const LEDGER_MOVED_FILE = 'packages/db/migrations';
7
+
8
+ let rebuild: ((file: string) => void) | undefined;
9
+
10
+ /**
11
+ * `devRebuilder` registers its own trigger: one `x dev` per process, so one slot, and the newest
12
+ * rebuilder is the running one. A slot and not an import, because the route that applies the pass
13
+ * is mounted before the rebuilder exists and neither module may import the other's graph.
14
+ */
15
+ export function onLedgerMoved(trigger: (file: string) => void): void {
16
+ rebuild = trigger;
17
+ }
18
+
19
+ /** Called by the `/_x/db` routes once a pass changed the ledger. No rebuilder, nothing to say. */
20
+ export function ledgerMoved(): void {
21
+ rebuild?.(LEDGER_MOVED_FILE);
22
+ }
@@ -0,0 +1,78 @@
1
+ // The three refusals `x dev`'s lock claim raises that are NOT another `x dev`: an unreadable lock,
2
+ // a state directory that refuses the claim, and a port a stranger holds. Split from `dev-lock.ts`,
3
+ // which keeps the claim itself and `X_DEV_ALREADY_RUNNING`.
4
+
5
+ import { stringField, UltimateError } from '@ultimat3/core';
6
+ import { ownerText, type PortOwner } from './dev-lock-holder-dir';
7
+ import { quoteArg } from './shell-quote';
8
+
9
+ /**
10
+ * The lock file exists, this process could not read it and could not remove it — which is not
11
+ * "another x dev is running", and was reported as exactly that.
12
+ *
13
+ * `DevAlreadyRunningError` needs a `DevLock`, and the only one in hand on that path was `mine`:
14
+ * the refusal then read `pid <this process> is already running x dev` with `fix: … kill <this
15
+ * process>`, a remedy that kills the reader and a cause naming the wrong holder. Axiom 4 wants a
16
+ * runnable fix and an honest cause, so the honest answer is its own code — the file is the
17
+ * problem, and removing it is what a reader can actually do.
18
+ */
19
+ export class DevLockUnreadableError extends UltimateError {
20
+ constructor(input: { readonly path: string; readonly stateDir: string }) {
21
+ super({
22
+ code: 'X_DEV_LOCK_UNREADABLE',
23
+ cause: `${input.path} could not be parsed as a dev lock and could not be removed, so x dev cannot tell whether another process owns ${input.stateDir}`,
24
+ fix: `rm ${quoteArg(input.path)} # then re-run x dev`,
25
+ meta: { path: input.path, stateDir: input.stateDir },
26
+ });
27
+ }
28
+ }
29
+
30
+ /**
31
+ * The state directory refused the claim itself: it could not be created, the lock could not be
32
+ * staged in it, or the filesystem would not hard-link the staged file into place. None of that is
33
+ * another `x dev` — only `EEXIST` is — and escaping raw it reached the operator as
34
+ * `X_CLI_UNEXPECTED` with `fix: x doctor --json`, which says nothing about `.x/`.
35
+ */
36
+ export class DevStateUnwritableError extends UltimateError {
37
+ constructor(input: { readonly stateDir: string; readonly error: unknown }) {
38
+ // Read the field, never cast and dereference: `unknown` is what a catch hands over.
39
+ const errno = stringField(input.error, 'code') ?? 'an unreported errno';
40
+ super({
41
+ code: 'X_DEV_STATE_UNWRITABLE',
42
+ cause: `${input.stateDir} could not be created, written, or hard-linked into (${errno}), so x dev cannot take its lock — a read-only checkout, a .x/ this user may not write, or a filesystem without hard links`,
43
+ fix: `ls -ld ${quoteArg(input.stateDir)} # make it writable by this user, on a filesystem that supports hard links, then re-run x dev`,
44
+ meta: { stateDir: input.stateDir, errno },
45
+ sourceError: input.error,
46
+ });
47
+ }
48
+ }
49
+
50
+ /**
51
+ * The port is bound by something that is not us. Named separately from the lock case because the
52
+ * remedy is different: a stranger's port is worked around with `--port`, while a second `x dev` on
53
+ * this checkout is not a port problem at all and moving it would still fail on the database.
54
+ *
55
+ * The holder is NAMED when the OS will say. On a developer machine :3000 is usually another
56
+ * project's dev server, and "pid 41234, bun" is the difference between knowing that and guessing —
57
+ * which decides whether the right move is `--port` or stopping the other thing. Both are offered,
58
+ * `--port` first: moving your own server is always safe, and killing someone else's is not.
59
+ */
60
+ export class DevPortInUseError extends UltimateError {
61
+ constructor(input: {
62
+ readonly port: number;
63
+ readonly suggestion: number;
64
+ readonly holder?: PortOwner;
65
+ }) {
66
+ const holder = input.holder ?? {};
67
+ const named = ownerText(holder) ?? 'another process';
68
+ super({
69
+ code: 'X_PORT_IN_USE',
70
+ cause: `:${input.port} is already bound by ${named}, so the web role cannot listen — on a machine running several projects this is usually another one's dev server, not a stale copy of this one`,
71
+ fix:
72
+ holder.pid === undefined
73
+ ? `x dev --port ${quoteArg(String(input.suggestion))}`
74
+ : `x dev --port ${quoteArg(String(input.suggestion))} # or free it, if that pid is yours: kill ${holder.pid}`,
75
+ meta: { port: input.port, ...holder },
76
+ });
77
+ }
78
+ }
@@ -0,0 +1,64 @@
1
+ // Where a port's holder runs. A pid alone cannot tell a reader whether the server is theirs; the
2
+ // directory can, and it is what lets `x doctor` separate this checkout from a neighbour.
3
+
4
+ // why: Bun ships no readlink primitive and no existence check for a directory.
5
+ import { existsSync, readlinkSync } from 'node:fs';
6
+ // why: Bun ships no path-join primitive.
7
+ import { join } from 'node:path';
8
+ import { type PortHolder, portHolder } from './dev-lock-port-holder';
9
+ import { exec, type Runner } from './exec';
10
+
11
+ export interface PortOwner extends PortHolder {
12
+ /** The holder's working directory, when the OS will say. */
13
+ readonly cwd?: string;
14
+ }
15
+
16
+ const PROC = '/proc';
17
+
18
+ /** `/proc` where it exists; `lsof`'s cwd record (`n<path>`) elsewhere. `undefined` when neither says. */
19
+ export async function holderDir(
20
+ pid: number,
21
+ runner: Runner = exec,
22
+ procRoot: string = PROC,
23
+ ): Promise<string | undefined> {
24
+ if (existsSync(join(procRoot, 'self'))) {
25
+ try {
26
+ return readlinkSync(join(procRoot, String(pid), 'cwd'));
27
+ } catch {
28
+ return undefined; // Gone, or another user's.
29
+ }
30
+ }
31
+ try {
32
+ const { stdout } = await runner(['lsof', '-a', '-p', String(pid), '-d', 'cwd', '-Fn'], {
33
+ cwd: process.cwd(),
34
+ });
35
+ return stdout
36
+ .split('\n')
37
+ .find((line) => line.startsWith('n'))
38
+ ?.slice(1);
39
+ } catch {
40
+ return undefined; // No `lsof`: the refusal still stands, without a directory in it.
41
+ }
42
+ }
43
+
44
+ /** Who holds `port`: the OS's answer, plus the directory of the process it names. */
45
+ export async function portOwner(
46
+ port: number,
47
+ runner: Runner = exec,
48
+ find: (port: number, runner: Runner) => Promise<PortHolder> = portHolder,
49
+ procRoot: string = PROC,
50
+ ): Promise<PortOwner> {
51
+ const holder = await find(port, runner);
52
+ if (holder.pid === undefined) return holder;
53
+ const cwd = await holderDir(holder.pid, runner, procRoot);
54
+ return cwd === undefined ? holder : { ...holder, cwd };
55
+ }
56
+
57
+ /** `pid 41 (bun) in /work/app`, as far as it is known; `undefined` with no pid to name. */
58
+ export function ownerText(owner: PortOwner): string | undefined {
59
+ if (owner.pid === undefined) return undefined;
60
+ const command = owner.command === undefined ? '' : ` (${owner.command})`;
61
+ // Printed into one finding line: a directory name may hold anything.
62
+ const dir = owner.cwd === undefined ? '' : ` in ${owner.cwd.replace(/\p{Cc}/gu, ' ')}`;
63
+ return `pid ${String(owner.pid)}${command}${dir}`;
64
+ }
@@ -0,0 +1,44 @@
1
+ // Whether a LIVE `x dev` holds a state directory, asked by the commands that must not open or
2
+ // delete its embedded database beside it. A pid alone is not the holder: a kill -9 leaves the lock
3
+ // and the kernel reuses the number, and a stranger on that pid refused every `x db` command.
4
+
5
+ import { DevAlreadyRunningError, type DevLock, liveDevLock } from './dev-lock';
6
+ import { reusedPid } from './dev-lock-identity';
7
+ import { resolveServices } from './runtime-bindings';
8
+
9
+ /** The lock of the `x dev` that wrote it and is still running; a reused pid is no holder. */
10
+ export async function liveDevLockChecked(stateDir: string): Promise<DevLock | undefined> {
11
+ const lock = liveDevLock(stateDir);
12
+ return lock === undefined || (await reusedPid(lock)) ? undefined : lock;
13
+ }
14
+
15
+ /**
16
+ * `X_DEV_ALREADY_RUNNING` when an `x dev` holds the embedded database under `stateDir`. PGlite
17
+ * takes no lock of its own: a second process opens the directory, writes, and the holder's next
18
+ * write replaces the catalog it wrote — measured, a `create table` from the second opener is gone.
19
+ */
20
+ export async function refuseBesideDev(stateDir: string, resume?: readonly string[]): Promise<void> {
21
+ const holder = await liveDevLockChecked(stateDir);
22
+ if (holder !== undefined) {
23
+ throw new DevAlreadyRunningError({
24
+ lock: holder,
25
+ stateDir,
26
+ embeddedDb: true,
27
+ ...(resume === undefined ? {} : { resume }),
28
+ });
29
+ }
30
+ }
31
+
32
+ /**
33
+ * The same refusal for a command that WRITES through its own boot (`x db seed`, `x jobs retry`):
34
+ * only when this checkout's database is the embedded one — an external Postgres takes any number
35
+ * of writers. `resume` is the command as typed, which the fix runs between `x stop` and `x dev`.
36
+ */
37
+ export async function refuseEmbeddedWriteBesideDev(
38
+ root: string,
39
+ env: Readonly<Record<string, string | undefined>>,
40
+ resume: readonly string[],
41
+ ): Promise<void> {
42
+ const services = resolveServices(root, env);
43
+ if (services.db.mode === 'embedded') await refuseBesideDev(services.stateDir, resume);
44
+ }
package/src/dev-lock.ts CHANGED
@@ -20,11 +20,17 @@
20
20
  import { linkSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
21
21
  import { join } from 'node:path';
22
22
  import { stringField, UltimateError } from '@ultimat3/core';
23
+ import {
24
+ DevLockUnreadableError,
25
+ DevPortInUseError,
26
+ DevStateUnwritableError,
27
+ } from './dev-lock-errors';
28
+ import { type PortOwner, portOwner } from './dev-lock-holder-dir';
23
29
  import { reusedPid, startedOf } from './dev-lock-identity';
24
- import { type PortHolder, portHolder } from './dev-lock-port-holder';
30
+ import type { PortHolder } from './dev-lock-port-holder';
25
31
  import { stealStale } from './dev-lock-steal';
26
- import { portPairAfter } from './flag-number';
27
- import { quoteArg } from './shell-quote';
32
+ import { freeDevPortPair } from './port-pair-free';
33
+ import { stopRunStartFix } from './stop-run-start';
28
34
 
29
35
  /** Where the running dev server records itself, inside the state directory it already owns. */
30
36
  export const DEV_LOCK_FILE = 'dev.lock';
@@ -121,6 +127,19 @@ export class DevAlreadyRunningError extends UltimateError {
121
127
  readonly stateDir: string;
122
128
  /** True when this checkout's database is the embedded one. */
123
129
  readonly embeddedDb?: boolean;
130
+ /**
131
+ * The refused command's own words (`['db', 'seed', 'dev']`), for one that needs the embedded
132
+ * database to itself: the fix then stops the holder, runs it, and starts `x dev` again.
133
+ */
134
+ readonly resume?: readonly string[];
135
+ /** Why the holder could not do the work itself, when it was asked: closes the cause. */
136
+ readonly unanswered?: string;
137
+ /**
138
+ * The read-only command that says whether a request the holder may have run did run (`['db',
139
+ * 'status']`): set when the request was sent and its answer lost, so the fix reads, never
140
+ * repeats — a rollback asked twice reverses two migrations.
141
+ */
142
+ readonly settle?: readonly string[];
124
143
  }) {
125
144
  const single =
126
145
  input.embeddedDb === true
@@ -128,84 +147,15 @@ export class DevAlreadyRunningError extends UltimateError {
128
147
  : ' — x dev runs every role in one process, so a second one on this checkout is unsupported';
129
148
  super({
130
149
  code: 'X_DEV_ALREADY_RUNNING',
131
- cause: `pid ${input.lock.pid} is already running x dev on ${input.lock.url} and holds ${input.stateDir}${single}`,
150
+ cause: `pid ${input.lock.pid} is already running x dev on ${input.lock.url} and holds ${input.stateDir}${single}${input.unanswered === undefined ? '' : `; asked to do it instead, ${input.unanswered}`}`,
132
151
  // `x stop`, not `kill <pid>`: a kill returns before the drain ends and the next boot refuses.
133
- fix: `x stop --json # or use the one already running at ${input.lock.url}`,
134
- meta: { pid: input.lock.pid, port: input.lock.port, stateDir: input.stateDir },
135
- });
136
- }
137
- }
138
-
139
- /**
140
- * The lock file exists, this process could not read it and could not remove it — which is not
141
- * "another x dev is running", and was reported as exactly that.
142
- *
143
- * `DevAlreadyRunningError` needs a `DevLock`, and the only one in hand on that path was `mine`:
144
- * the refusal then read `pid <this process> is already running x dev` with `fix: … kill <this
145
- * process>`, a remedy that kills the reader and a cause naming the wrong holder. Axiom 4 wants a
146
- * runnable fix and an honest cause, so the honest answer is its own code — the file is the
147
- * problem, and removing it is what a reader can actually do.
148
- */
149
- export class DevLockUnreadableError extends UltimateError {
150
- constructor(input: { readonly path: string; readonly stateDir: string }) {
151
- super({
152
- code: 'X_DEV_LOCK_UNREADABLE',
153
- cause: `${input.path} could not be parsed as a dev lock and could not be removed, so x dev cannot tell whether another process owns ${input.stateDir}`,
154
- fix: `rm ${quoteArg(input.path)} # then re-run x dev`,
155
- meta: { path: input.path, stateDir: input.stateDir },
156
- });
157
- }
158
- }
159
-
160
- /**
161
- * The state directory refused the claim itself: it could not be created, the lock could not be
162
- * staged in it, or the filesystem would not hard-link the staged file into place. None of that is
163
- * another `x dev` — only `EEXIST` is — and escaping raw it reached the operator as
164
- * `X_CLI_UNEXPECTED` with `fix: x doctor --json`, which says nothing about `.x/`.
165
- */
166
- export class DevStateUnwritableError extends UltimateError {
167
- constructor(input: { readonly stateDir: string; readonly error: unknown }) {
168
- // Read the field, never cast and dereference: `unknown` is what a catch hands over.
169
- const errno = stringField(input.error, 'code') ?? 'an unreported errno';
170
- super({
171
- code: 'X_DEV_STATE_UNWRITABLE',
172
- cause: `${input.stateDir} could not be created, written, or hard-linked into (${errno}), so x dev cannot take its lock — a read-only checkout, a .x/ this user may not write, or a filesystem without hard links`,
173
- fix: `ls -ld ${quoteArg(input.stateDir)} # make it writable by this user, on a filesystem that supports hard links, then re-run x dev`,
174
- meta: { stateDir: input.stateDir, errno },
175
- sourceError: input.error,
176
- });
177
- }
178
- }
179
-
180
- /**
181
- * The port is bound by something that is not us. Named separately from the lock case because the
182
- * remedy is different: a stranger's port is worked around with `--port`, while a second `x dev` on
183
- * this checkout is not a port problem at all and moving it would still fail on the database.
184
- *
185
- * The holder is NAMED when the OS will say. On a developer machine :3000 is usually another
186
- * project's dev server, and "pid 41234, bun" is the difference between knowing that and guessing —
187
- * which decides whether the right move is `--port` or stopping the other thing. Both are offered,
188
- * `--port` first: moving your own server is always safe, and killing someone else's is not.
189
- */
190
- export class DevPortInUseError extends UltimateError {
191
- constructor(input: {
192
- readonly port: number;
193
- readonly suggestion: number;
194
- readonly holder?: PortHolder;
195
- }) {
196
- const holder = input.holder ?? {};
197
- const named =
198
- holder.pid === undefined
199
- ? 'another process'
200
- : `pid ${holder.pid}${holder.command === undefined ? '' : ` (${holder.command})`}`;
201
- super({
202
- code: 'X_PORT_IN_USE',
203
- cause: `:${input.port} is already bound by ${named}, so the web role cannot listen — on a machine running several projects this is usually another one's dev server, not a stale copy of this one`,
204
152
  fix:
205
- holder.pid === undefined
206
- ? `x dev --port ${quoteArg(String(input.suggestion))}`
207
- : `x dev --port ${quoteArg(String(input.suggestion))} # or free it, if that pid is yours: kill ${holder.pid}`,
208
- meta: { port: input.port, ...holder },
153
+ input.settle !== undefined
154
+ ? `${stopRunStartFix(input.settle)} # the request may have run before its answer was lost: read the ledger before asking again`
155
+ : input.resume === undefined
156
+ ? `x stop --json # or use the one already running at ${input.lock.url}`
157
+ : `${stopRunStartFix(input.resume)} # the embedded database takes one process at a time; pass the flags you passed`,
158
+ meta: { pid: input.lock.pid, port: input.lock.port, stateDir: input.stateDir },
209
159
  });
210
160
  }
211
161
  }
@@ -310,6 +260,30 @@ const readLock = async (path: string): Promise<DevLock | null> => {
310
260
  return raw === null ? null : parseLock(raw);
311
261
  };
312
262
 
263
+ /**
264
+ * Remove the lock `judged` was read from, for a caller that found its pid reused (`x stop`). Under
265
+ * the same guard a boot's steal holds, and only while the file still holds those bytes: a claim
266
+ * made since is another `x dev`'s, and is never deleted.
267
+ */
268
+ export function clearStaleLock(stateDir: string, judged: DevLock): void {
269
+ const path = lockPath(stateDir);
270
+ let raw: string;
271
+ try {
272
+ raw = readFileSync(path, 'utf-8');
273
+ } catch {
274
+ return;
275
+ }
276
+ const now = parseLock(raw);
277
+ if (now === null || now.pid !== judged.pid || now.started !== judged.started) return;
278
+ const mine: DevLock = { pid: process.pid, port: 0, url: '', startedAt: new Date().toISOString() };
279
+ stealStale({
280
+ path,
281
+ judged: raw,
282
+ claim: (guard) => claimExclusive(stateDir, guard, mine),
283
+ alive: isProcessAlive,
284
+ });
285
+ }
286
+
313
287
  export interface PreflightInput {
314
288
  readonly stateDir: string;
315
289
  readonly port: number;
@@ -320,7 +294,7 @@ export interface PreflightInput {
320
294
  /** Injected by the test; `isPortBound` in production. */
321
295
  readonly portBound?: (port: number, hostname: string) => boolean;
322
296
  readonly alive?: (pid: number) => boolean;
323
- readonly holder?: (port: number) => Promise<PortHolder>;
297
+ readonly holder?: (port: number) => Promise<PortOwner>;
324
298
  /** Injected by the test; `node:fs` in production. */
325
299
  readonly files?: ClaimFiles;
326
300
  }
@@ -435,10 +409,11 @@ export const preflight = async (input: PreflightInput): Promise<PreflightResult>
435
409
  release();
436
410
  throw new DevPortInUseError({
437
411
  port: input.port,
438
- // `portPairAfter`, never `port + 1`: `x dev` binds a PAIR, so the holder is most often
439
- // another `x dev` whose sync role already sits on `port + 1`.
440
- suggestion: portPairAfter(input.port),
441
- holder: await (input.holder ?? portHolder)(input.port),
412
+ // A pair, never `port + 1`: `x dev` binds two ports, so the holder is most often another
413
+ // `x dev` whose sync role already sits on `port + 1`. Asked, because a third may sit on the
414
+ // next pair, and a fix naming it fails again.
415
+ suggestion: await freeDevPortPair(input.port, (port) => !bound(port, input.hostname)),
416
+ holder: await (input.holder ?? portOwner)(input.port),
442
417
  });
443
418
  }
444
419
  return { clearedStale, release };