centralu 0.1.0-beta.55 → 0.1.0-beta.56

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.
@@ -7,7 +7,7 @@ import { existsSync, openSync, rmSync, writeFileSync, writeSync } from 'node:fs'
7
7
  import { userInfo } from 'node:os'
8
8
  import { join } from 'node:path'
9
9
  import { answerLine, isAlive, say, sayTo, runCaptured, tail, sleep } from './serve-util.mjs'
10
- import { SERVE_LOG_FILE, serveDataDir, ensureServeState, markStopped, rotateServeLog } from './serve-files.mjs'
10
+ import { SERVE_LOG_FILE, serveDataDir, ensureServeState, markStopped, rotateServeLog, markStarting, clearStarting, liveStarts, lockHolder, isWriter, readServePid } from './serve-files.mjs'
11
11
  import { askPowershell, detachHow, windowsArg, wmiScript, parseWmiAnswer, wmiBlockedMessage, windowsPowershell, windowsTool, wslCommandLine } from './serve-windows.mjs'
12
12
  import { CHILD_FLAG } from './serve-args.mjs'
13
13
  import { startInSignIn } from './serve-autostart.mjs'
@@ -123,91 +123,102 @@ export async function runDetach({
123
123
  timeoutMs = 30_000,
124
124
  noStartMs = 10_000,
125
125
  write = (line) => process.stdout.write(line),
126
+ // What the folder's host answers (a test's stand-in for the host coming up at a given moment)
127
+ look = describe,
126
128
  }) {
127
129
  // Created here, so the token exists before the launcher reads it and `answered` reads it again
128
130
  const { dataDir } = serveFolder({ env, home, cliPath, platform })
129
131
  const fail = (reason, message) => answerLine(write, 'detach', { ok: false, how, reason, message })
130
132
  const answered = async (already, as = how) => {
131
- const d = await describe({ env, dataDir, state: ensureServeState(dataDir, platform), entry, version })
133
+ const d = await look({ env, dataDir, state: ensureServeState(dataDir, platform), entry, version })
132
134
  if (!d?.hostRunning) return false
133
135
  write(`${connectionLine({ ...d, detach: { ok: true, how: as, already } })}\n`)
134
136
  return true
135
137
  }
136
138
  if (await answered(true)) return 0
137
-
138
- const log = join(dataDir, SERVE_LOG_FILE)
139
139
  /*
140
- * One start per log: the earlier ones are kept beside it, three of them (`rotateServeLog`, #1143), and its absence is
141
- * how a start that never ran shows. So a log that cannot be moved aside is removed rather than left to read as a start
140
+ * From here a start is in progress (#2150): a `--stop` meanwhile waits for it rather than find nothing running, write
141
+ * the stopped mark and leave the host to come up after it. This process's record is removed on every way out; the
142
+ * launcher it starts writes its own, which covers a launcher still starting when this gave up (`SERVE_STARTING_DIR`)
142
143
  */
143
- const freshLog = () => rotateServeLog(log)
144
+ markStarting(dataDir)
145
+ try {
146
+ const log = join(dataDir, SERVE_LOG_FILE)
147
+ /*
148
+ * One start per log: the earlier ones are kept beside it, three of them (`rotateServeLog`, #1143), and its absence is
149
+ * how a start that never ran shows. So a log that cannot be moved aside is removed rather than left to read as a start
150
+ */
151
+ const freshLog = () => rotateServeLog(log)
144
152
 
145
- /*
146
- * Windows: in the person's sign-in when someone is signed in (#1224), through the scheduled task, and through WMI only
147
- * when nobody is. WMI's process keeps this ssh session's network logon, where Git cannot use the credentials saved in
148
- * Windows. A task-started host that does not answer in time is left to the lock: the WMI start below then either
149
- * holds the folder or is refused by it, never a second host on it. Which way it went, and why, is one line of
150
- * serve.log (#1223): the task's serve writes no serve.log, so that line is written here; a WMI launcher writes its own
151
- */
152
- let notInSignIn = null
153
- if (how === 'wmi') {
154
- const s = await signIn({ dataDir, env, home, platform })
155
- if (s.started) {
156
- const line = `started centralu serve in the Windows sign-in (the scheduled task "${s.name}"); waiting for its host`
157
- say(line)
158
- freshLog()
159
- try {
160
- writeFileSync(log, `[centralu serve] ${line}\n`)
161
- } catch {
162
- // the line on stderr is all there is
163
- }
164
- const t0 = Date.now()
165
- while (Date.now() - t0 < signInMs) {
166
- if (await answered(false, 'task')) return 0
167
- await sleep(250)
153
+ /*
154
+ * Windows: in the person's sign-in when someone is signed in (#1224), through the scheduled task, and through WMI only
155
+ * when nobody is. WMI's process keeps this ssh session's network logon, where Git cannot use the credentials saved in
156
+ * Windows. A task-started host that does not answer in time is left to the lock: the WMI start below then either
157
+ * holds the folder or is refused by it, never a second host on it. Which way it went, and why, is one line of
158
+ * serve.log (#1223): the task's serve writes no serve.log, so that line is written here; a WMI launcher writes its own
159
+ */
160
+ let notInSignIn = null
161
+ if (how === 'wmi') {
162
+ const s = await signIn({ dataDir, env, home, platform })
163
+ if (s.started) {
164
+ const line = `started centralu serve in the Windows sign-in (the scheduled task "${s.name}"); waiting for its host`
165
+ say(line)
166
+ freshLog()
167
+ try {
168
+ writeFileSync(log, `[centralu serve] ${line}\n`)
169
+ } catch {
170
+ // the line on stderr is all there is
171
+ }
172
+ const t0 = Date.now()
173
+ while (Date.now() - t0 < signInMs) {
174
+ if (await answered(false, 'task')) return 0
175
+ await sleep(250)
176
+ }
177
+ notInSignIn = `the host the sign-in task "${s.name}" started did not answer within ${Math.round(signInMs / 1000)} s`
178
+ // The WMI launcher's first line says so; the task's line goes, so `serve.log.1` keeps the start before this one
179
+ rmSync(log, { force: true, maxRetries: 5 })
180
+ } else {
181
+ notInSignIn = signInMissed(s)
168
182
  }
169
- notInSignIn = `the host the sign-in task "${s.name}" started did not answer within ${Math.round(signInMs / 1000)} s`
170
- // The WMI launcher's first line says so; the task's line goes, so `serve.log.1` keeps the start before this one
171
- rmSync(log, { force: true, maxRetries: 5 })
172
- } else {
173
- notInSignIn = signInMissed(s)
183
+ say(`${notInSignIn}: starting the host through WMI${s.reason === 'nosession' ? ', outside any sign-in, where Git cannot use the credentials saved in Windows' : ''}`)
174
184
  }
175
- say(`${notInSignIn}: starting the host through WMI${s.reason === 'nosession' ? ', outside any sign-in, where Git cannot use the credentials saved in Windows' : ''}`)
176
- }
177
185
 
178
- freshLog()
179
- // Where this was asked for from (#1223): the launcher runs outside this ssh session, so it is told
180
- const asked = serveFrom(env, from)
181
- const childEnv = asked ? { ...env, CENTRALU_STARTED_FROM: JSON.stringify(asked) } : env
182
- const startedHow = `through ${how === 'wmi' ? 'WMI' : how === 'wsl' ? 'a WMI-created wsl.exe' : how}${notInSignIn ? `: ${notInSignIn}` : ''}`
183
- const args = [cliPath, 'serve', ...(port !== null ? ['--port', String(port)] : []), `${CHILD_FLAG}${encodeChildSpec({ env: childEnv, log, start: startedHow })}`]
184
- let started
185
- try {
186
- started = await start({ how, execPath, args, env, cwd })
187
- } catch (e) {
188
- return fail('failed', `could not start centralu serve in the background: ${e.message}`)
189
- }
190
- if (!started.ok) return fail(started.blocked ? 'wmi_blocked' : 'failed', started.message)
191
- say(`started centralu serve in the background (${how}, pid ${started.pid ?? 'unknown'}); waiting for its host`)
186
+ freshLog()
187
+ // Where this was asked for from (#1223): the launcher runs outside this ssh session, so it is told
188
+ const asked = serveFrom(env, from)
189
+ const childEnv = asked ? { ...env, CENTRALU_STARTED_FROM: JSON.stringify(asked) } : env
190
+ const startedHow = `through ${how === 'wmi' ? 'WMI' : how === 'wsl' ? 'a WMI-created wsl.exe' : how}${notInSignIn ? `: ${notInSignIn}` : ''}`
191
+ const args = [cliPath, 'serve', ...(port !== null ? ['--port', String(port)] : []), `${CHILD_FLAG}${encodeChildSpec({ env: childEnv, log, start: startedHow })}`]
192
+ let started
193
+ try {
194
+ started = await start({ how, execPath, args, env, cwd })
195
+ } catch (e) {
196
+ return fail('failed', `could not start centralu serve in the background: ${e.message}`)
197
+ }
198
+ if (!started.ok) return fail(started.blocked ? 'wmi_blocked' : 'failed', started.message)
199
+ say(`started centralu serve in the background (${how}, pid ${started.pid ?? 'unknown'}); waiting for its host`)
192
200
 
193
- let exited
194
- started.exited?.then((c) => (exited = c ?? 'unknown'))
195
- const t0 = Date.now()
196
- while (Date.now() - t0 < timeoutMs) {
197
- if (await answered(false)) return 0
198
- const why = tail(log)
199
- if (exited !== undefined) return fail('exited', `centralu serve exited (${exited}) before its host answered${why ? `:\n${why}` : ''}`)
200
- const gone = started.alive?.() === false
201
- if (how !== 'setsid' && !existsSync(log) && (gone || Date.now() - t0 > noStartMs)) {
202
- // WMI said yes, and nothing ran: the process was stopped before Node started, or hangs (`startDetached`)
203
- if (!gone) await started.stop?.()
204
- return fail('wmi_blocked', wmiBlockedMessage(gone ? `process ${started.pid} ended before it started` : `nothing started within ${Math.round(noStartMs / 1000)} s`))
201
+ let exited
202
+ started.exited?.then((c) => (exited = c ?? 'unknown'))
203
+ const t0 = Date.now()
204
+ while (Date.now() - t0 < timeoutMs) {
205
+ if (await answered(false)) return 0
206
+ const why = tail(log)
207
+ if (exited !== undefined) return fail('exited', `centralu serve exited (${exited}) before its host answered${why ? `:\n${why}` : ''}`)
208
+ const gone = started.alive?.() === false
209
+ if (how !== 'setsid' && !existsSync(log) && (gone || Date.now() - t0 > noStartMs)) {
210
+ // WMI said yes, and nothing ran: the process was stopped before Node started, or hangs (`startDetached`)
211
+ if (!gone) await started.stop?.()
212
+ return fail('wmi_blocked', wmiBlockedMessage(gone ? `process ${started.pid} ended before it started` : `nothing started within ${Math.round(noStartMs / 1000)} s`))
213
+ }
214
+ if (gone) return fail('exited', `centralu serve exited before its host answered${why ? `:\n${why}` : ''}`)
215
+ await sleep(250)
205
216
  }
206
- if (gone) return fail('exited', `centralu serve exited before its host answered${why ? `:\n${why}` : ''}`)
207
- await sleep(250)
217
+ const why = tail(log)
218
+ return fail('timeout', `the host did not answer within ${Math.round(timeoutMs / 1000)} s${why ? `:\n${why}` : ''}`)
219
+ } finally {
220
+ clearStarting(dataDir)
208
221
  }
209
- const why = tail(log)
210
- return fail('timeout', `the host did not answer within ${Math.round(timeoutMs / 1000)} s${why ? `:\n${why}` : ''}`)
211
222
  }
212
223
 
213
224
  /** Why the host was not started in the Windows sign-in, from `startInSignIn`'s answer, for serve.log and stderr */
@@ -276,13 +287,89 @@ export async function runStop({
276
287
  home,
277
288
  entry,
278
289
  platform = process.platform,
279
- timeoutMs = 30_000,
280
- graceMs = 15_000,
290
+ budgetMs = STOP_BUDGET_MS,
291
+ graceMs = 10_000,
281
292
  kill = (pid, sig) => process.kill(pid, sig),
282
293
  write = (line) => process.stdout.write(line),
283
294
  }) {
284
295
  const dataDir = serveDataDir(env, home)
296
+ const deadline = Date.now() + budgetMs
297
+ const mark = () => {
298
+ if (env.CENTRALU_STOP_BY !== 'hub') markStopped(dataDir, env.CENTRALU_STOP_BY === 'quit' ? 'quit' : 'stop')
299
+ }
300
+ /*
301
+ * A start in progress (#2150, `SERVE_STARTING_DIR`): its host is not up yet, so the folder reads as not running, and
302
+ * stopped here it would come up after the stop, under a stopped mark. Waited for while it has not taken the folder: a
303
+ * host that has held host.lock for `LOCK_GRACE_MS` with its start still named is stopped as any running host is,
304
+ * answering or not (one that hung before it listened, #1903, is ended by `stopServedHost`). The wait leaves the stop its share of the budget; when that is reached, a start
305
+ * whose launcher is known (serve.pid) is ended, the launcher and the host it started, and any other is said to be
306
+ * still starting, with nothing stopped
307
+ */
308
+ const known = new Map()
309
+ // Since when a live host holds host.lock while a start is still named: a host that is up ends its start within a moment
310
+ let heldSince = null
311
+ const tookTheFolder = () => {
312
+ const h = lockHolder(dataDir)
313
+ const key = h ? `lock:${h.pid}:${h.started}:${h.at}` : null
314
+ if (key && !known.has(key)) known.set(key, isWriter(h) === true)
315
+ if (!key || !known.get(key) || !isAlive(h.pid)) return (heldSince = null), false
316
+ heldSince ??= Date.now()
317
+ return Date.now() - heldSince > LOCK_GRACE_MS
318
+ }
319
+ let waiting = false
320
+ for (let starts = liveStarts(dataDir, known); starts.length > 0 && !tookTheFolder(); starts = liveStarts(dataDir, known)) {
321
+ if (!waiting) say(`centralu serve is starting a host for ${dataDir}; waiting for it, to stop it`)
322
+ waiting = true
323
+ if (Date.now() < deadline - STOP_RESERVE_MS) {
324
+ await sleep(100)
325
+ continue
326
+ }
327
+ const launcher = readServePid(dataDir)
328
+ const ending = launcher && starts.some((r) => r.pid === launcher.pid) ? [launcher.hostPid, launcher.pid].filter((p) => Number.isInteger(p) && isAlive(p)) : []
329
+ if (ending.length === 0) {
330
+ return answerLine(write, 'stop', { ok: false, wasRunning: true, starting: true, message: `centralu serve is still starting a host for ${dataDir}; nothing was stopped` })
331
+ }
332
+ for (const pid of ending) {
333
+ try {
334
+ kill(pid, platform === 'win32' ? 'SIGKILL' : 'SIGTERM')
335
+ } catch {
336
+ // gone in the meantime
337
+ }
338
+ }
339
+ const t1 = Date.now()
340
+ while (ending.some((p) => isAlive(p)) && Date.now() - t1 < 5_000) await sleep(100)
341
+ for (const pid of ending.filter((p) => isAlive(p))) {
342
+ try {
343
+ kill(pid, 'SIGKILL')
344
+ } catch {
345
+ // gone in the meantime
346
+ }
347
+ }
348
+ const gone = !ending.some((p) => isAlive(p))
349
+ if (gone) mark()
350
+ return answerLine(write, 'stop', gone
351
+ ? { ok: true, wasRunning: true, how: 'ended', message: `ended a start that was still in progress (pid ${ending.join(', ')})` }
352
+ : { ok: false, wasRunning: true, starting: true, message: `centralu serve is still starting a host for ${dataDir}, and pid ${ending.join(', ')} did not end` })
353
+ }
354
+ // What is left of the budget: the host is waited for, after its request to stop, for all of it but the grace and the ends that follow
355
+ const left = deadline - Date.now()
356
+ const timeoutMs = Math.max(3_000, left - graceMs - 10_000)
285
357
  const stopped = await stopServedHost({ dataDir, entry, platform, forUpdate: env.CENTRALU_STOP_FOR === 'update', timeoutMs, graceMs, kill })
286
- if (stopped.ok && env.CENTRALU_STOP_BY !== 'hub') markStopped(dataDir, env.CENTRALU_STOP_BY === 'quit' ? 'quit' : 'stop')
358
+ if (stopped.ok) mark()
287
359
  return answerLine(write, 'stop', stopped)
288
360
  }
361
+
362
+ /**
363
+ * The longest a whole `serve --stop` takes (#2150 review): the window's "Quit completely" gives it 60 s (keeper
364
+ * `serve_window.rs` `STOP_TIMEOUT`), and so a start waited for and the stop after it fit in this together, with room.
365
+ * Worst case: the wait up to `STOP_BUDGET_MS - STOP_RESERVE_MS`, then the host asked and waited for (at least 3 s), its
366
+ * grace after a signal (10 s; Windows 5) and the ends that follow (5 s and 5 s)
367
+ */
368
+ export const STOP_BUDGET_MS = 45_000
369
+ /**
370
+ * How long a host may hold host.lock while its start is still named before `--stop` stops it rather than wait: a host that is
371
+ * up ends its start at its ready line, and `--detach` answers within a look (250 ms) of that; one past this hung
372
+ */
373
+ export const LOCK_GRACE_MS = 10_000
374
+ /** What the wait for a start leaves of the budget for the stop itself */
375
+ export const STOP_RESERVE_MS = 23_000
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { execFileSync } from 'node:child_process'
7
7
  import { createHash, createHmac, randomBytes } from 'node:crypto'
8
- import { chmodSync, existsSync, linkSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, statSync, writeSync, closeSync } from 'node:fs'
8
+ import { chmodSync, existsSync, linkSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeSync, closeSync } from 'node:fs'
9
9
  import { join } from 'node:path'
10
10
  import { isAlive, renameRetrying, replaceFile, sleepSync } from './serve-util.mjs'
11
11
  import { CREDENTIAL_ID_RE, PAIR_LABEL_RE } from './serve-args.mjs'
@@ -122,6 +122,82 @@ export function readStopped(dataDir) {
122
122
  return { by: o?.by === 'quit' ? 'quit' : 'stop', at: typeof o?.at === 'number' && Number.isFinite(o.at) ? o.at : null }
123
123
  }
124
124
 
125
+ /**
126
+ * Starts in progress (#2150): each process that is starting a host in the folder writes its own record here, and removes it
127
+ * when its part is over. `--detach` writes one before it starts the launcher and removes it once it has answered, whichever
128
+ * way; the launcher writes its own before it starts the host and removes it once the host is ready or has exited. `--stop`
129
+ * waits while a record names a live process, so a host that is starting is stopped once it is up rather than reported as not
130
+ * running and left to come up after the stop. One file per writer, `<pid>.json`: two starts at once each keep theirs, a
131
+ * writer that was killed (an ssh that dropped) leaves a record of a dead process, which counts for nothing, and a WSL
132
+ * launcher writes its own from inside WSL, where a `--stop` there reads it. Each is `{ pid, started, at }`, as host.lock
133
+ * names its writer, so a pid another process got since is not taken for it
134
+ */
135
+ export const SERVE_STARTING_DIR = 'serve-starting'
136
+
137
+ /**
138
+ * How old a record may be and still count. Longer than any start takes (`--detach`: its sign-in task's 20 s, then 30 s): a
139
+ * record older than this names a start that hung, and a `--stop` goes on and stops what holds the folder, if anything
140
+ */
141
+ export const STARTING_MAX_MS = 120_000
142
+
143
+ const startingFile = (dataDir, pid) => join(dataDir, SERVE_STARTING_DIR, `${pid}.json`)
144
+
145
+ /** Names `pid` (by default this process) as one starting a host in the folder; never fatal */
146
+ export function markStarting(dataDir, pid = process.pid, startOf = processStartTime, now = Date.now()) {
147
+ try {
148
+ mkdirSync(join(dataDir, SERVE_STARTING_DIR), { recursive: true })
149
+ replaceFile(startingFile(dataDir, pid), `${JSON.stringify({ pid, started: startOf(pid), at: now })}\n`)
150
+ } catch {
151
+ // nowhere to write it: a --stop meanwhile reads the folder as before
152
+ }
153
+ }
154
+
155
+ /** Removes `pid`'s record (by default this process's) */
156
+ export function clearStarting(dataDir, pid = process.pid) {
157
+ try {
158
+ rmSync(startingFile(dataDir, pid), { force: true })
159
+ } catch {
160
+ // gone already
161
+ }
162
+ }
163
+
164
+ /** The records as `{ pid, started, at? }`; one that does not parse is left out */
165
+ export function readStarting(dataDir) {
166
+ let names = []
167
+ try {
168
+ names = readdirSync(join(dataDir, SERVE_STARTING_DIR)).filter((n) => /^\d+\.json$/.test(n))
169
+ } catch {
170
+ return []
171
+ }
172
+ return names.flatMap((n) => {
173
+ try {
174
+ const r = parseLockHolder(readFileSync(join(dataDir, SERVE_STARTING_DIR, n), 'utf8'))
175
+ return r ? [r] : []
176
+ } catch {
177
+ return []
178
+ }
179
+ })
180
+ }
181
+
182
+ /**
183
+ * The starts in progress: the records that name the live process that wrote them, no older than `maxAgeMs`. `known` keeps
184
+ * what was learnt of a record between calls (a Windows creation time costs a PowerShell), so a caller that asks again and
185
+ * again pays it once per record.
186
+ */
187
+ export function liveStarts(dataDir, known = new Map(), { maxAgeMs = STARTING_MAX_MS, now = Date.now(), startOf = processStartTime, createdAt = processCreatedAt } = {}) {
188
+ return readStarting(dataDir).filter((r) => {
189
+ if (typeof r.at === 'number' && now - r.at > maxAgeMs) return false
190
+ const key = `${r.pid}:${r.started}:${r.at}`
191
+ if (!known.has(key)) known.set(key, isWriter(r, startOf, createdAt) === true)
192
+ return known.get(key) === true && isAlive(r.pid)
193
+ })
194
+ }
195
+
196
+ /** Whether a start is in progress (`liveStarts`) */
197
+ export function startingNow(dataDir, known = new Map(), o = {}) {
198
+ return liveStarts(dataDir, known, o).length > 0
199
+ }
200
+
125
201
  /** The data folder: the host's own rule (`dataRoot()` in agent-host), CC_DATA_DIR or ~/.centralu */
126
202
  export function serveDataDir(env, home) {
127
203
  return env.CC_DATA_DIR || join(home, '.centralu')
package/bin/serve-run.mjs CHANGED
@@ -4,7 +4,7 @@ import { writeFileSync, writeSync } from 'node:fs'
4
4
  import { dirname, join } from 'node:path'
5
5
  import { createInterface } from 'node:readline'
6
6
  import { isAlive, say } from './serve-util.mjs'
7
- import { SERVE_STATE_FILE, SERVE_PID_FILE, readStopped, serveDataDir, ensureServeState, recordServePort, rotateServeToken, heldHere, lockHolder, lockHolderPid, holderWho, removeServePid, pairServe, pairKeyServe, dropVerifierUnder, revokeServe } from './serve-files.mjs'
7
+ import { SERVE_STATE_FILE, SERVE_PID_FILE, readStopped, markStarting, clearStarting, serveDataDir, ensureServeState, recordServePort, rotateServeToken, heldHere, lockHolder, lockHolderPid, holderWho, removeServePid, pairServe, pairKeyServe, dropVerifierUnder, revokeServe } from './serve-files.mjs'
8
8
  import { DEFAULT_SERVE_PORT, SERVE_PORT_TRIES, chooseServePort, listensHere, windowsListening } from './serve-port.mjs'
9
9
  import { keepLauncher, installInfo } from './serve-install.mjs'
10
10
  import { protocolVersionOf, connectionLine, hostEnv, hostCommand, readyPort, probeHost, probeKeyProof, serveFrom, keyLine, takesKeyHellos } from './serve-host.mjs'
@@ -167,6 +167,8 @@ export async function runServe({ env, home, entry, version, cliPath, port: asked
167
167
  }
168
168
 
169
169
  const plan = hostCommand(execPath, entry, { port, dataDir, platform })
170
+ // A start in progress (#2150): this launcher's own record, removed once its host is ready or has exited (below)
171
+ markStarting(dataDir)
170
172
  /*
171
173
  * The host gets the key on stdin and the path of serve.json, whose full credentials it checks at each hello (#1405);
172
174
  * nothing it gets opens it whole
@@ -209,6 +211,8 @@ export async function runServe({ env, home, entry, version, cliPath, port: asked
209
211
  const p = readyPort(line)
210
212
  if (p === null || ready) return
211
213
  ready = true
214
+ // A start `--detach` handed to this launcher is over (#2150)
215
+ clearStarting(dataDir)
212
216
  try {
213
217
  recordServePort(dataDir, p, platform)
214
218
  } catch (e) {
@@ -240,12 +244,14 @@ export async function runServe({ env, home, entry, version, cliPath, port: asked
240
244
  return await new Promise((resolve) => {
241
245
  child.on('error', (e) => {
242
246
  removeServePid(dataDir, process.pid)
247
+ clearStarting(dataDir)
243
248
  say(`could not start the host (${plan.command}): ${e.message}`)
244
249
  resolve(1)
245
250
  })
246
251
  child.on('exit', (code, signal) => {
247
252
  for (const s of signals) process.off(s, forward)
248
253
  removeServePid(dataDir, process.pid)
254
+ clearStarting(dataDir)
249
255
  if (!ready && code !== 0) {
250
256
  const holder = lockHolder(dataDir)
251
257
  if (holder && holder.pid !== child.pid && isAlive(holder.pid)) {
package/bin/serve.mjs CHANGED
@@ -24,7 +24,7 @@
24
24
  * (`serve-autostart.mjs`), the hub's version switch (`serve-switch.mjs`), Windows, WSL and PowerShell (`serve-windows.mjs`), and small helpers
25
25
  * (`serve-util.mjs`).
26
26
  */
27
- export { SERVE_STATE_FILE, SERVE_LOG_FILE, SERVE_PID_FILE, serveDataDir, readServeState, ensureServeState, recordServePort, rotateServeToken, pairServe, pairKeyServe, dropVerifierUnder, revokeServe, verifierOf, limitedOf, changeServeState, heldHere, startedByServe, foreignHolder, holderWho, lockHolderIsAlive, processStartTime, processCreatedAt, lockHolder, lockHolderPid, readServePid, SERVE_STOPPED_FILE, SERVE_LOGS_KEPT, markStopped, readStopped, rotateServeLog } from './serve-files.mjs'
27
+ export { SERVE_STATE_FILE, SERVE_LOG_FILE, SERVE_PID_FILE, serveDataDir, readServeState, ensureServeState, recordServePort, rotateServeToken, pairServe, pairKeyServe, dropVerifierUnder, revokeServe, verifierOf, limitedOf, changeServeState, heldHere, startedByServe, foreignHolder, holderWho, lockHolderIsAlive, processStartTime, processCreatedAt, lockHolder, lockHolderPid, readServePid, SERVE_STOPPED_FILE, SERVE_LOGS_KEPT, markStopped, readStopped, rotateServeLog, SERVE_STARTING_DIR, STARTING_MAX_MS, markStarting, clearStarting, readStarting, liveStarts, startingNow } from './serve-files.mjs'
28
28
  export { detachHow, windowsArg, wslCommandLine, wmiScript, parseWmiAnswer, wmiBlockedMessage, windowsPowershell, ownLogon } from './serve-windows.mjs'
29
29
  export { DEFAULT_SERVE_PORT, SERVE_PORT_TRIES, chooseServePort, listensHere, parseNetstatListening } from './serve-port.mjs'
30
30
  export { SERVE_HELP, AUTOSTART_ACTIONS, parseServeArgs, PAIR_LABEL_RE, CREDENTIAL_ID_RE } from './serve-args.mjs'
@@ -35,5 +35,5 @@ export { parseLinkPublicKey, hostLinkPublicKey, signedHostKey, linkTranscript }
35
35
  export { runWindow } from './serve-window.mjs'
36
36
  export { AUTOSTART_FILE, AUTOSTART_ENV, autostartHow, autostartUnsupported, pathKey, autostartName, autostartLauncher, systemdUnit, taskActionScript, taskScript, parseTaskAnswer, readAutostartMark, autostartInfo, lingerMessage, runAutostart, startInSignIn } from './serve-autostart.mjs'
37
37
  export { printConnection, runServe, rotateToken, revokeCredential } from './serve-run.mjs'
38
- export { CARRIED_ENV, encodeChildSpec, decodeChildSpec, startDetached, runDetach, runDetachedChild, runStop } from './serve-detach.mjs'
38
+ export { CARRIED_ENV, encodeChildSpec, decodeChildSpec, startDetached, runDetach, runDetachedChild, runStop, STOP_BUDGET_MS, STOP_RESERVE_MS, LOCK_GRACE_MS } from './serve-detach.mjs'
39
39
  export { SWITCH_FILE, SWITCH_LOCK, SWITCH_RUNNER, lockIsLive, decodeSwitch, readSwitch, setPointers, prune, storeBackup, storeRestore, hostLogTail, runSwitcher, reconcile, beforeHostStart, gateHostStart, clockOf, RUNNER_ENV, rerunAs, runSwitch, runSwitchRun, runSwitchStatus } from './serve-switch.mjs'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "centralu",
3
- "version": "0.1.0-beta.55",
3
+ "version": "0.1.0-beta.56",
4
4
  "description": "Run, watch and steer several Claude Code and Codex CLI sessions from one window",
5
5
  "license": "MIT",
6
6
  "author": "ijun17",
@@ -38,9 +38,9 @@
38
38
  "win32"
39
39
  ],
40
40
  "optionalDependencies": {
41
- "@centralu/darwin-arm64": "0.1.0-beta.55",
42
- "@centralu/linux-arm64": "0.1.0-beta.55",
43
- "@centralu/linux-x64": "0.1.0-beta.55",
44
- "@centralu/win32-x64": "0.1.0-beta.55"
41
+ "@centralu/darwin-arm64": "0.1.0-beta.56",
42
+ "@centralu/linux-arm64": "0.1.0-beta.56",
43
+ "@centralu/linux-x64": "0.1.0-beta.56",
44
+ "@centralu/win32-x64": "0.1.0-beta.56"
45
45
  }
46
46
  }