Drivers
Why
A kind is one process. docs/usage/kinds.mdx describes that process. The jobs of that process run at the step concurrency and share one client. A step calls a function. The function opens the client once for that process.
The worker drains those jobs, then closes the Nest context, then exits. The organization closes the clients it opened.
Who
You add a driver when a step implementation talks to PostgreSQL, Elasticsearch, ClickHouse, S3, Qdrant, or another service that keeps connections.
The drivers live in the organization checkout. The worker loads those secrets once, with installEnvironment, before it accepts jobs.
How
One client for the process
The organization package exports ./drivers. A published install that dropped package exports keeps the module at src/drivers/drivers.module.ts. driversModulePath in packages/supervisor/src/worker/worker.service.ts resolves that file. The catalog entry does not import the module, so loading the catalog does not load the clients.
When WORKER_RUNTIME is set, prepareOrganizationRuntime loads that module and calls warmupWorkerRuntime. WorkerModule in packages/supervisor/src/worker/worker.module.ts does not import the organization module. The module does not open a client when the process starts. A kind that never asks for a client opens nothing.
A handle stores the promise the opener returns. A second get returns that same promise. The opener reads the secret with environment from @ascentstudio/cue-contract. close waits for that promise when get has already been called, then closes the client. A second close returns the same promise. close before any get resolves without opening. get after close rejects.
Close after the drain
WorkerService.finish in packages/supervisor/src/worker/worker.service.ts drains the jobs. closeThenExit then closes the Nest context and exits. main.ts calls attach with that context after createApplicationContext. The process exits 0, or 75 when the command is drain-restart.
WorkerService does not implement OnApplicationShutdown. A close that called that hook would run the drain again. A second run("drain-stop") in createShutdown (packages/engine/src/worker-control.ts) replaces an exit code of 75.
main.ts does not call enableShutdownHooks. The worker listens for SIGINT, SIGTERM, SIGHUP, and SIGQUIT itself. The drain finishes before the Nest context closes, and a restart still exits 75.
The cap
The cap on a client stays below the step concurrency. The connections a service receives are the processes that call that driver, multiplied by the cap.
The orchestrator database stays separate
DATABASE_URL is the orchestrator database. A fixture worker does not open a second database. An organization driver that runs SQL opens another pool, and that pool reads its own secret.