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

Function waitForDaemonStartupTarget

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

Source from the content-addressed store, hash-verified

486 });
487
488const waitForDaemonStartupTarget = (input: {
489 readonly requestedBaseUrl: string;
490}): Effect.Effect<string | null, never, FileSystem.FileSystem | PlatformPath.Path> =>
491 Effect.gen(function* () {
492 let readyBaseUrl: string | null = null;
493 let requestedFallbackBaseUrl: string | null = null;
494 const ready = yield* waitForReachable({
495 check: Effect.gen(function* () {
496 // Prefer the manifest: it is written after the server has opened the
497 // owned DB and started serving, and it carries the bearer token the next
498 // API call needs. A bare health response on the requested URL is only a
499 // last-ditch fallback; keep polling for the manifest so tool calls do
500 // not race ahead without auth.
501 const manifest = yield* readReachableLocalServerHint();
502 if (manifest) {
503 readyBaseUrl = manifest.connection.origin;
504 return true;
505 }
506
507 if (yield* isServerReachable(input.requestedBaseUrl)) {
508 requestedFallbackBaseUrl = input.requestedBaseUrl;
509 }
510
511 return false;
512 }),
513 timeoutMs: DAEMON_BOOT_TIMEOUT_MS,
514 intervalMs: DAEMON_BOOT_POLL_MS,
515 });
516
517 return ready ? readyBaseUrl : requestedFallbackBaseUrl;
518 });
519
520// Serialize daemon startup behind a filesystem lock so concurrent CLI invocations don't
521// 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