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

Function waitForDaemonStartupTarget

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

Source from the content-addressed store, hash-verified

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