Skip to content

The signup-record pick-up process

CAOS-1986. There is no public signup website yet (the owner’s decision — see Onboarding & provisioning for the aspirational full flow). What exists today is the private half: a record shape, a table to hold it, and a process that turns one unprocessed record into a real org.

caos.signup_record (migration 0156). Control-plane only — row-level security is enabled with no policy at all, so only the owner/service connection can read or write it, never a tenant and never public. See the field table in docs/architecture/CAOS-1986-signup-record-pickup.md for every column.

record_id is the one field worth understanding before anything else: it is the caller’s idempotency key, and it is reused verbatim as the org’s orgId. There is no second idempotency mechanism — a record picked up twice resolves to a duplicate refusal, never a second org, because that is exactly what provisionOrg’s own “does this org already exist” check already guarantees.

import { pickUpOneSignupRecord } from '@caos/kernel/provisioning';
const outcome = await pickUpOneSignupRecord({
db, // a Queryable over the control-plane connection
callProvisioning: async (verb, body) => {
/* call `provisioning/create-account` or `provisioning/create` and return
{ ok, data } or { ok: false, error } */
},
});
if (!outcome.picked) {
// the queue is empty — nothing to do
} else if (outcome.result.ok) {
// outcome.result.orgId, outcome.result.hostname, outcome.result.adminInviteSent
} else {
// outcome.result.reason: 'bad_email' | 'payment_required' | 'reserved_name'
// | 'taken_name' | 'duplicate' | 'provisioning_failed'
}

callProvisioning is intentionally transport-agnostic: an operator job wires it to a real call against the deployed kernel’s provisioning/* routes (the same control-plane secret every other provisioning caller uses); the kernel’s own integration test wires it to an in-process ApiSubstrate dispatch instead, so the suite proves the real route logic with no network call.

Call it in a loop (while ((await pickUpOneSignupRecord(deps)).picked) {}) to drain the whole queue; each call does at most one record, FOR UPDATE SKIP LOCKED, so two concurrent runners divide the queue rather than racing onto the same row.

What it refuses, and why nothing is left half-made

Section titled “What it refuses, and why nothing is left half-made”

Six refusal reasons, each checked before anything that can’t be cheaply undone:

  • bad_email, payment_required (a production request without payment_status: 'paid' — a trial request needs no payment) — refused before any control-plane call is made.
  • reserved_name, taken_name — the CAOS-201 reserved-word list and a uniqueness probe, via the kernel’s own reserveVanity, checked before any control-plane call.
  • duplicate — record_id already names a real org.
  • provisioning_failed — anything else create-account/create itself refuses (a malformed name, an over-limit plan). If this happens AFTER the account was minted, the account is deleted before returning — there is no “account with no org attached” left behind.

See the architecture page for the full gap analysis this process closes versus what the Engine’s existing provisioning routes could already do on their own.