Data flows
Inference request
- The gateway authenticates from a periodically refreshed hashed-credential snapshot and bounds the request body and request ID.
- It reads the alias from the atomic in-memory route directory; PostgreSQL is not queried.
- It rewrites the alias to the common upstream model and forwards to the local vLLM Router.
- Response headers and bytes are streamed back; SSE chunks are flushed incrementally.
- Accounting is queued after completion and persisted asynchronously with bounded capacity.
Asynchronous apply
- An operator submits tenant-scoped desired state with an idempotency key.
- PostgreSQL returns the existing operation or stores a new pending operation.
- One replica claims it with
SKIP LOCKED, records a lease, and heartbeats during execution. - The handler validates tenant-owned targets and atomically converges the deployment.
- Completion and audit state are persisted. An expired lease can be recovered by another replica; retryable failures return to pending with bounded exponential delay.
Reconciliation
- A replica loads active deployments and their targets from PostgreSQL.
- Worker health/model endpoints are probed concurrently under a fixed bound.
- Healthy membership and routing policy produce a deterministic worker-set hash.
- If local state differs, the replica replaces its supervised router process and records an instance-owned generation.
- A complete route snapshot is published atomically; the previous valid snapshot survives temporary database or reconciliation failures.
Schema startup
- The process connects to PostgreSQL with a bounded pool.
- One connection obtains the migration advisory lock.
- Unapplied embedded migrations execute transactionally in filename order.
- The migration version is recorded in the same transaction.
- The lock is released before serving commands or traffic.
Hugging Face model search
- An authenticated principal with read permission calls
GET /api/v1/catalog/hugging-face/search. - The control API validates
queryandlimit, then answers from a bounded in-memory cache when the same query and limit were answered in the last 10 minutes. - Otherwise it sends three unauthenticated HTTPS requests to the public Hugging Face models API,
one per pipeline (
text-generation,image-text-to-text,feature-extraction), under one 4-second deadline and an 8-search concurrency bound. Redirects are not followed. - Results are merged, marked
reviewed: false, cached on success, and returned.
Automatic model check
Only when the operator setINFERCRANE_HUGGING_FACE_METADATA_ENABLED=true:
- A planning request (
POST /api/v1/planning/intents), a check (GET /api/v1/catalog/hugging-face/check), or an optimization proposal names a Hugging Face repository that is not a reviewed model. - When a
model_secret_reference_idis named, the control API loads that tenant’s secret reference and resolves the token through the configured secret resolver. internal/modelcheckpins the revision to a commit with one model-info request, then readsconfig.jsonat that commit: two HTTPS requests under one 8-second deadline and an 8-request concurrency bound, redirects followed only on the same host. Results are cached in memory by commit; reads made with a token are cached under the tenant and credential.- The check compares the architecture with the committed runtime registry snapshot, sizes the GPU from the price catalog already in memory, and returns. The planner itself never reads the network.
Provisioning
The durable workflow resolves a registered provider backend by cloud, runtime, and persisted adapter identity. RunPod elastic uses the native Pods adapter by default. Explicit SkyPilot manifests may add long-tail execution targets, but do not supply InferCrane’s price authority. AWS EC2 delegates API compatibility and STS to AWS CLI v2 while InferCrane retains idempotency, adoption, private-network, tag, and deletion policy. Both return a target that follows the same runtime and reconciliation path as an existing worker.Governed external fallback
- Reconciliation excludes policy-owned external targets from ordinary primary membership.
- Only when no primary is healthy, the coordinator loads an enabled, privacy-acknowledged policy, resolves its reference-only credential in memory, and checks the exact model mapping.
- A bounded request/cost batch is atomically reserved in PostgreSQL and prefetched into memory.
- The gateway authorizes each request from that in-memory lease before transmission; PostgreSQL never enters the inference path.
- The selected target and any denial are persisted in bounded request evidence. Requests are not replayed or duplicated after a possible send.
GPU profile capture
infercrane profileruns where the serving engine’s HTTP port and trace directory are reachable. It calls the engine’s/start_profile, waits at most 30 seconds, calls/stop_profile(always, even when interrupted), and reads the Kineto trace the engine wrote. The parser keeps kernel, operator, and runtime-call names, times, devices, streams, correlations, and matrix-multiply shapes, and skips Python frames, operator arguments, and every annotation other than engine-step markers.internal/gputraceanalyzes the trace on that host; the full trace never leaves it.- The CLI posts one bounded
infercrane.gpu-profile/v2recording (analysis, call stacks, and an excerpt of at most 20,000 events) toPOST /api/v1/deployments/{name}/gpu-profileswith deploy permission. Other collectors may post a call-stack-only v1 recording. The control API rejects unknown fields, bodies over 8 MiB, out-of-range analyses, captures that claim content, and anything but measured evidence before touching PostgreSQL. - In one transaction the store resolves the deployment’s active revision, inserts the capture into
gpu_profilesas one JSONB document keyed by tenant, deployment, revision, tool, start, and end, and removes captures that ended more than 30 days ago and all but the newest eight for that deployment. A retry with the same samples returns the stored receipt; a retry with different samples is a conflict. GET /api/v1/endpoints/{name}/gpu-profilereads the newest capture whose revision is still the active revision of a deployment bound to the endpoint;GET …/gpu-profileslists every retained capture of those deployments,GET …/gpu-profiles/{id}reads one, andGET …/gpu-profiles/comparecompares two analyzed captures. None is a typed 404.- A proposal planned from an endpoint diagnosis reads the newest capture’s kernel-class shares.
Neither capture nor read runs on the inference path, and the gateway never reads
gpu_profiles.
Optimization run notifications
- A workspace admin adds a destination with
POST /api/v1/notifications/subscriptions. The control API seals the destination URL and a generated signing secret withINFERCRANE_CREDENTIAL_ENCRYPTION_KEY(AES-256-GCM bound to tenant and destination ID) and stores them innotification_subscriptions. Only a host-level hint is stored in the clear. - Every candidate transition that changes a campaign’s aggregate state also records the change in
optimization_campaign_transitions, in the same transaction as the state update. A failed campaign keeps the first candidate failure code inoptimization_campaigns.failure_code. Cleanup rewrites the aggregate state seconds after a decision; these rows keep the decision readable. - Every 15 seconds each control-plane replica derives events for workspaces with an enabled
destination: waiting states from campaigns updated in the last 24 hours, and decisions, failures,
and rollouts from the recorded transitions. A decision reads the outcome report. Each new event
becomes one
notification_deliveriesrow per destination, holding the exact body;UNIQUE(subscription_id, event_id)makes a second replica’s insert a no-op. - The same pass leases due rows with
FOR UPDATE SKIP LOCKED, decrypts the destination in memory, and sends one signed POST throughinternal/alert’s public-network-checked client. Retries back off from 30 seconds to an hour, at most six attempts; a 4xx other than 429 stops at once. - None of this runs on the inference path, and the gateway never reads these tables.
Agent sync
infercrane agent runprobes local servers (/v1/models, version and loaded-model endpoints,/metrics) and reads the host’s accelerators. Nothing listens for the control plane.- Each new healthy server is registered with
POST /api/v1/agent/servers: one observe-only endpoint whose target carries the agent’s ID and the agent-local server key. - Every poll interval the agent sends
POST /api/v1/agent/sync(gzip JSON): hardware, servers and health, one metric relay per server with a new scrape (the current scrape and the oldest scrape of the same engine process in the trailing five minutes, both filtered on the machine), and request shapes from the optional local gateway. - The control plane re-checks that the agent is active, validates each item on its own (refused
items come back in
rejected), records the heartbeat, sets each registered server’s health, parses both scrapes withmetrics.ParseEngine, derives rows withmetrics.EngineMeasurements, and stores them intarget_measurementskeyed by the target. Request shapes becomerequest_recordswith the endpoint’s identities and compute modeagent-gateway; shape IDs make retries idempotent andsent_atcorrects clock skew. - Endpoint monitoring and optimization readiness read deployment-bound and target-bound measurements through the endpoint’s bindings. The reconciler never probes an agent’s target and marks it unhealthy when its agent has been silent for three minutes.
- Revocation disables the agent’s principal; the next sync is refused with HTTP 401
(
agent_revoked, oragent_unauthenticatedonce the credential snapshot has dropped the key), and the agent stops.
Agent data plane
- A key with
deploymakes an agent’s endpoint agent-managed (PUT /api/v1/adoptions/endpoints/{name}/ownership). In one transaction the adoption and its binding becomeagent-managedand the endpoint’s residencycustomer-cloud. The reconciler removes any hosted route for the endpoint, marks it resident in the route directory, and sets its state from the agent’s health reports. - Every poll interval the agent (
infercrane agent run --serve) callsGET /api/v1/agent/data-plane?generation=. The relay reads the agent’s agent-managed active-plan bindings, the tenant’s live non-agent credential digests narrowed to keys that may call those endpoints, their admission policies, and the request quota, digests the content, and answers with the snapshot, orunchangedand a newvalid_until. - The agent validates the snapshot, maps each binding’s server key to a server it detected and
sees healthy, and publishes the routes in its own in-memory directory. Its quota pool leases
requests with
POST /api/v1/agent/quota-leases, which uses the same minute-window allocator as the hosted gateway. - An application calls the agent with an InferCrane API key. The agent’s gateway (the code of
internal/gateway) authenticates against the digests, applies endpoint restrictions, admission, and quota, routes, streams, and records the request in memory. No database is read. - The next sync carries each request as a shape with
source: data-planeand its binding. The relay checks the binding belongs to an agent-managed server of this agent and stores a request record with compute modeagent-data-plane. - The hosted gateway answers a request for the endpoint with
403 residency_errorand forwards nothing; asynchronous inference refuses it before storing anything.
Agent candidate run
- A key with
deploycallsPOST /api/v1/agents/{id}/candidate-runs. The relay validates the spec, resolves the endpoint to the agent’s server key, and stores a queuedagent_commandsrow (at most 16 open per agent). - The agent’s long poll (
GET /api/v1/agent/commands?wait=25s) leases it withFOR UPDATE SKIP LOCKED; a replica checks every 2 seconds and answers at once when the command was queued through it. Commands past their deadline expire; a lease that lapses three times fails the command. - The agent checks the image and accelerator against its allowlists, applies one Deployment and
one Service with
provision.Kubernetesin its namespace, waits for readiness, runs AIPerf against the current setup, the candidate, and the current setup again, and runs the answer check on both, all inside the cluster. It reports each phase withPOST /api/v1/agent/commands/{id}, which extends the lease and tells it when the run was cancelled. - The agent deletes the candidate and posts the result: AIPerf summaries, the noise figure, per-prompt agreement scores and digests, readiness time, and cleanup. Nothing else is sent.