MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / waitForDaemonStartupTarget

Function waitForDaemonStartupTarget

apps/cli/src/main.ts:469–499  ·  view source on GitHub ↗
(input: {
  readonly requestedBaseUrl: string;
})

Source from the content-addressed store, hash-verified

467 });
468
469const waitForDaemonStartupTarget = (input: {
470 readonly requestedBaseUrl: string;
471}): Effect.Effect<string | null, never, FileSystem.FileSystem | PlatformPath.Path> =>
472 Effect.gen(function* () {
473 let readyBaseUrl: string | null = null;
474 let requestedFallbackBaseUrl: string | null = null;
475 const ready = yield* waitForReachable({
476 check: Effect.gen(function* () {
477 // Prefer the manifest: it is written after the server has opened the
478 // owned DB and started serving, and it carries the bearer token the next
479 // API call needs. A bare health response on the requested URL is only a
480 // last-ditch fallback; keep polling for the manifest so tool calls do
481 // not race ahead without auth.
482 const manifest = yield* readReachableLocalServerHint();
483 if (manifest) {
484 readyBaseUrl = manifest.connection.origin;
485 return true;
486 }
487
488 if (yield* isServerReachable(input.requestedBaseUrl)) {
489 requestedFallbackBaseUrl = input.requestedBaseUrl;
490 }
491
492 return false;
493 }),
494 timeoutMs: DAEMON_BOOT_TIMEOUT_MS,
495 intervalMs: DAEMON_BOOT_POLL_MS,
496 });
497
498 return ready ? readyBaseUrl : requestedFallbackBaseUrl;
499 });
500
501// Serialize daemon startup behind a filesystem lock so concurrent CLI invocations don't
502// each spawn their own daemon. The post-lock pointer recheck catches the case where

Callers 2

spawnDaemonAsLockHolderFunction · 0.85
spawnAndWaitForDaemonFunction · 0.85

Calls 3

waitForReachableFunction · 0.90
isServerReachableFunction · 0.85

Tested by

no test coverage detected