/** * Worker registration handling: manifest validation, deployment consistency, * admission policy, and the workerId hijack/reconnect guard. * * Split out of `websocket-worker.ts` to keep that module under the * repository's per-file line ceiling — this is the registration slice of the * same WebSocket message handler. * * @module server/runtime/websocket-worker-registration */ import type { ServerWebSocket } from 'bun'; import { type RegisterMessage } from '../../worker/protocol.ts'; import type { ServeOptions } from '../index.ts'; import type { WebSocketData } from '../json-rpc-websocket-runtime.ts'; import type { ServerContext } from './context.ts'; /** * Validate, admit, and register a worker from its `register` message. * * Layering, in order: principal scope check, manifest parse * (`parseWorkerManifest`), embedded/wire protocol-version agreement, * admission policy, manifest digest, then — synchronously, with no further * `await` between any of them — a live-socket check, a read-only deployment- * consistency check, the workerId hijack/reconnect guard, and only once both * of those gates have passed: the deployment-consistency digest record, * registry insertion, and `registerAck`. * * That whole final block must commit atomically with respect to the event * loop for three independent reasons: two concurrent registrations for the * same not-yet-seen workerId could otherwise both pass the hijack guard * before either commits; a peer that closes while the digest above is still * pending leaves `ws.data.workerId` unset, so the close handler runs no * cleanup, and completing registration afterward would create a ghost worker * on a dead socket; and recording the deployment-consistency digest before * every rejection gate — including the hijack guard, not just the admission * policy — has passed would let a worker this function ultimately declines * still permanently poison that deployment/build slot for future legitimate * workers, since the guard never evicts. See {@link commitWorkerRegistration} * for why the digest record specifically runs after, not alongside, the * hijack guard. */ export declare function registerWorker(context: ServerContext, options: ServeOptions, ws: ServerWebSocket, message: RegisterMessage): Promise;