// #1676 — orchestrator adapter over the SHARED async guards in `agent-relay-sdk`. // // The primitives themselves live in `sdk/src/async-guard.ts` because #1665 is the same // defect class in the runner: an unguarded `void ` / async timer callback whose // rejection reaches the runtime and (in Bun) exits the process. One implementation, two // processes. Import from `agent-relay-sdk` directly if you are outside this package. // // All this file adds is the `[orchestrator]` log prefix, so the daemon's log format is // unchanged and call sites pass a bare label ("Relay heartbeat", not the prefix). import { fireAndForget as sdkFireAndForget, guardedInterval as sdkGuardedInterval, guardedTimeout as sdkGuardedTimeout, installUnhandledRejectionGuard as sdkInstallUnhandledRejectionGuard, type GuardLog, } from "agent-relay-sdk"; export { describeFailure, isAbortError, type GuardLog } from "agent-relay-sdk"; const PREFIX = "[orchestrator]"; /** See {@link import("agent-relay-sdk").fireAndForget}. Replaces bare `void promise()`. */ export function fireAndForget(label: string, work: Promise | (() => Promise | unknown), log?: GuardLog): Promise { return sdkFireAndForget(`${PREFIX} ${label}`, work, log); } /** See {@link import("agent-relay-sdk").guardedInterval}. Replaces `setInterval(asyncFn, ms)`. */ export function guardedInterval(label: string, intervalMs: number, fn: () => Promise | unknown, log?: GuardLog): ReturnType { return sdkGuardedInterval(`${PREFIX} ${label}`, intervalMs, fn, log); } /** See {@link import("agent-relay-sdk").guardedTimeout}. Replaces `setTimeout(asyncFn, ms)`. */ export function guardedTimeout(label: string, delayMs: number, fn: () => Promise | unknown, log?: GuardLog): ReturnType { return sdkGuardedTimeout(`${PREFIX} ${label}`, delayMs, fn, log); } /** Install the non-fatal unhandled-rejection backstop. See the SDK function for the * reasoning behind "log and survive" and why `uncaughtException` stays fatal. */ export function installUnhandledRejectionGuard(log?: GuardLog): () => void { return sdkInstallUnhandledRejectionGuard(PREFIX, log); }