Boot Gates

Sequential gate runner for boot-time invariants — vault unseal, KEM key load, TLS material presence, DB schema migration, etc. Each gate is { name, fn, timeoutMs?, exitCode?, onFail? }; the runner walks them in order and on FIRST failure:

1. emits bootgates.failed { name, error, durationMs } audit, 2. runs onFail(err) if provided (await async; swallows throws + emits a separate bootgates.onfail_threw audit), 3. writes a single-line failure summary to stderr, 4. calls process.exit(gate.exitCode || 1).

On success: emits bootgates.passed { name, durationMs } and proceeds. Returns { passed, totalMs } when EVERY gate passes.

Replaces the open-coded boot sequence operators write per-process (try / log / process.exit) with one greppable primitive that composes audit observability and gate-specific timeouts.

b.bootGates.run(gates, opts?) #

stable0.10.9
{
  exitCode:        number,           // default 1 — overall fall-through
  log:             function,         // default console.error.bind(console)
  exit:            function,         // test seam; default process.exit
  overallTimeoutMs: number,          // cap across the full sequence
}

Walk gates in order, awaiting each fn. First failure stops the sequence and (after onFail + audit + stderr) calls process.exit(gate.exitCode || opts.exitCode || 1). Returns { passed: string[], totalMs: number } on full success.

await b.bootGates.run([
  { name: "vault.unseal",       fn: async function () { await b.vault.unseal(); } },
  { name: "tls.material",       fn: async function () { await loadTls(); } },
  { name: "db.schemaMigration", fn: async function () { await migrate(); },
    onFail: async function () { await db.close(); } },
]);

Last updated 2026-08-08T16:39:49.652Z by seeder.