codex-pooler
Self-hosted gateway for sharing Codex account capacity across trusted agents and tools
About this chart
Codex Pooler Helm Chart
Deploy Codex Pooler, a self-hosted gateway for sharing Codex account capacity across trusted agents and tools, on Kubernetes.
Website · Docs · Helm guide · GitHub · X · Reddit
Prerequisites
- Kubernetes 1.24+
- Helm 3.10+
- PostgreSQL database reachable from the cluster
- Existing Kubernetes Secret with the release bootstrap values, unless
secrets.create=trueis used from a private values source
Install
helm repo add icoretech https://icoretech.github.io/helm
helm repo update
helm upgrade --install codex-pooler icoretech/codex-pooler \
-n codex-pooler --create-namespace \
--version 0.18.1 \
--values values.production.yaml
OCI:
helm upgrade --install codex-pooler oci://ghcr.io/icoretech/charts/codex-pooler \
-n codex-pooler --create-namespace \
--version 0.18.1 \
--values values.production.yaml
Required Secret
By default, the chart expects an existing Secret named codex-pooler-secrets:
secrets:
create: false
existingSecret: codex-pooler-secrets
The Secret must contain these keys:
database-urlsecret-key-basetotp-encryption-keytotp-key-versionupstream-secret-keyupstream-secret-key-version
Do not put upstream access tokens, API keys, cookies, auth.json, SMTP passwords, or raw client payloads in chart values.
Roles
appserves HTTP withOBAN_MODE=webandPHX_SERVER=trueoban.workerruns background jobs withOBAN_MODE=workeroban.schedulerruns scheduled jobs withOBAN_MODE=schedulermigrationsruns release migrations and imports the vendored pricing feed
A worker with a positive replica count requires an enabled local scheduler with a positive replica count. Workers execute queues but cannot lead Oban: without a scheduler, due scheduled jobs and retries remain unpromoted. The scheduler owns leader-gated staging and Cron, Lifeline and Pruner maintenance; it does not execute queues.
For a scheduler managed in another release, set oban.externalScheduler: true and disable or scale down this release's scheduler explicitly. This acknowledges that an operational scheduler uses the same PostgreSQL database, schema and Oban instance name. The flag does not deploy a scheduler, change database configuration, disable the local scheduler, or verify that an external scheduler exists. Multiple schedulers sharing that Oban identity elect one database leader for staging and maintenance; separate Oban identities do not share that election.
App-only maintenance and releases with both Oban roles disabled or the worker scaled to zero remain valid. Those configurations do not execute background queues unless another release supplies workers.
The migration Job is part of the release, not a Helm hook, so it is visible in helm get manifest and removed by helm uninstall. Helm creates the Secret before the Job, and each release revision renders its own Job because a Job's pod template is immutable.
Each app, worker and scheduler pod first runs a wait-for-schema init container using its own application image and database Secret. It starts only the repository dependencies, reads that image's migration versions and waits until every version is present in the database. It neither starts the application nor creates tables or runs migrations: the migration Job remains the only migration writer. This orders startup on fresh installs and upgrades before heartbeat, settings, request handling or background jobs can touch an incomplete schema.
The startup wait also applies when migrations.enabled=false, so externally managed migrations must complete before the serving containers can start. Its outer process timeout uses migrations.activeDeadlineSeconds; the read-only loop leaves ten seconds for process startup and exit and bounds each query by the remaining monotonic deadline. A missing schema leaves the pod in initialization rather than starting an application that must crash and restart. A timeout reports schema_wait_timeout; inspect the migration Job and database connectivity instead of increasing readiness delays.
Images containing CodexPooler.Platform.JobRuntime, including the default 0.17.1, additionally recheck the required schema before each Oban start or restart. This remains a runtime safeguard if the schema becomes unavailable after initialization. Readiness probes report serving state separately:
- the worker and scheduler readiness probes ask the release about the database. Images exporting
CodexPooler.Release.readiness_check/0, including0.11.5, verify every migration they carry. Older images use a fallback requiring one appliedschema_migrationsrow. The init container supplies the complete startup check even for those older images. - the app's readiness is
/readyz, which reports database connectivity on images up to0.7.8and the applied schema on newer ones. It runs only after the startup schema wait succeeds.
helm test waits up to nine minutes for every migration to become applied and fails if any remain pending, on any image — run it after an install or upgrade if you want a single answer. helm --wait does not wait for Jobs unless you also pass --wait-for-jobs (spec.install.disableWaitForJobs: false and spec.upgrade.disableWaitForJobs: false in a Flux HelmRelease); use these wait settings to report migration failure as a failed release operation. Flux also requires waiting itself to remain enabled (disableWait: false). These Helm flags report completion; the pod init container supplies startup ordering.
helm rollback renders the target revision's Job again, so it re-runs the migration with the rolled-back image. Ecto.Migrator applies only pending migrations and never reverses one, so that is a no-op when the schema is already ahead of the image.
Keep app.replicaCount at 1 unless app clustering is intentionally configured and verified. When app.replicaCount is >= 2, the chart requires app clustering and automatically enables websocket owner forwarding on app pods.
Chart 0.13.0 removes the inert app.websocketContinuity.allowUnsafeMultiReplica setting. Remove that field from existing values, even when it is false: schema validation now rejects it. It never bypassed the clustering requirements. Multiple app replicas still require clustering.enabled=true and clustering.participants.app=true, with owner forwarding enabled automatically. The chart defaults to application image 0.17.1; explicit older image overrides retain the startup limitations above.
Rolling Updates And Browser Affinity
Codex Pooler keeps its compiled browser assets inside the release image. No shared object storage or external asset synchronization is required.
With multiple app replicas, a rolling update temporarily serves both the old and new release. Phoenix uses revision-specific digested CSS and JavaScript paths, so a browser can receive HTML from one revision and then request its asset from a pod running the other revision. Ingress controllers that balance every HTTP request independently can return a transient asset 404 in that mixed-revision window.
The chart remains ingress-controller neutral:
app.service.annotationspasses arbitrary annotations to the app Serviceingress.annotationspasses arbitrary annotations to the Ingressapp.service.sessionAffinityandapp.service.sessionAffinityConfigexpose the standard Kubernetes Service affinity fields
Configure browser cookie affinity using the annotations supported by your ingress controller. For example, Traefik reads its cookie-affinity configuration from the backend Service:
app:
service:
annotations:
traefik.ingress.kubernetes.io/service.sticky.cookie: "true"
traefik.ingress.kubernetes.io/service.sticky.cookie.name: codex-pooler-affinity
traefik.ingress.kubernetes.io/service.sticky.cookie.secure: "true"
traefik.ingress.kubernetes.io/service.sticky.cookie.httponly: "true"
traefik.ingress.kubernetes.io/service.sticky.cookie.samesite: lax
Other controllers may require affinity annotations on the Ingress instead; use ingress.annotations for those integrations. Kubernetes sessionAffinity: ClientIP can help clients that connect directly to the Service, but it is not equivalent to per-browser cookie affinity when an ingress proxy is the Service client:
app:
service:
sessionAffinity: ClientIP
sessionAffinityConfig:
clientIP:
timeoutSeconds: 300
Do not shorten app.minReadySeconds, the websocket drain timeout, or the termination grace period to hide asset skew. Those settings protect in-flight websocket turns and spread reconnect load across the rollout; configure affinity at the HTTP routing layer instead.
Websocket Rollout Drain
The app Deployment keeps app.minReadySeconds: 120 by default. That delay spaces pod replacement so clients do not all reconnect at once; it is separate from the drain that starts when Kubernetes begins terminating an old pod.
At termination, the app first closes admission for new upstream dispatches, then shares the configured 85-second drain budget across every websocket activity still owned by that pod:
- local websocket owners
- direct websocket turns being handled by the pod
- proxy turns whose websocket is on the pod while their owner runs on another app pod
- retained accounting receipt settlements, including workers registered after drain begins
The drain waits for these activities together, not one class after another. New upstream dispatches are refused once admission closes. Work already admitted retains only the right to complete that exact execution; it does not authorize another request or transfer completion authority to a replacement owner.
Native compaction needs an application image that retains admitted collection through owner drain. For that execution, collecting a provider terminal and settling the request are separate from handing the result to the downstream client. The runtime waits within the existing budget for the matching request/attempt settlement and delivery receipt; provider completion or a successful database row alone does not establish client delivery. Cancellation, lost ownership, and the drain cutoff still prevent a late result from becoming a success. The chart hook cannot add this behavior to an older application image.
Retained usage also requires an application image that supports receipt continuation. When trusted provider usage has already reached the owner, the runtime hands it to an independently supervised receipt worker before blocking drain persistence. The worker can finish accounting after the client disconnects or the owner exits; it does not keep cancelled generation running or change a cancelled delivery into a success. Usage that never arrived remains unknown, and an in-memory receipt is not durable until its database commit succeeds.
The drain includes late receipt workers and waits for their producers to finish handing off. Owners, turns and receipts share the same absolute shutdown deadline and existing bounded settlement allowance; a late worker does not restart the clock. The runtime reports failed or aborted receipt work explicitly instead of treating an unfinished settlement as a successful drain. Process, node or database failure can still prevent a commit.
A turn still active at the deadline is finalized as owner_drained; clients should use their normal reconnect or retry path. The preStop hook writes the readiness-withdrawal marker before its drain RPC, then keeps the configured 10-second wait before SIGTERM. The app's total termination grace period remains 120 seconds, with an 85-second drain setting; compaction and retained accounting receipts do not extend those budgets. Owner drain and proxy drain are distinct: terminating only the proxy does not demonstrate completion during termination of the pod that owns the upstream compaction.
This guarantee is Kubernetes- and ingress-controller-neutral: it does not depend on a particular ingress annotation, shared asset store, or external rollout controller. It takes effect only after the rollout that introduces this behavior has replaced all older app pods, because a terminating pod running an earlier release cannot apply the new admission and drain protocol. During a mixed-version rollout, older owners cannot acquire receipt retention or completion acknowledgement behavior from chart hooks or configuration; the owner application image must implement it.
Browser affinity prevents cross-revision HTML and asset requests from bouncing between pods. It does not extend the websocket drain budget.
Monitoring
The app service can render a Prometheus Operator ServiceMonitor:
monitoring:
serviceMonitor:
enabled: true
labels:
release: kube-prometheus-stack
interval: 10s
scrapeTimeout: 5s
path: /metrics
If metrics bearer authentication is enabled in Codex Pooler, keep the raw token in a Kubernetes Secret and reference it through monitoring.serviceMonitor.bearerTokenSecret.
Flux Example
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
name: icoretech
namespace: flux-system
spec:
type: oci
interval: 30m
url: oci://ghcr.io/icoretech/charts
---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: codex-pooler
namespace: codex-pooler
spec:
interval: 5m
install:
disableWaitForJobs: false
upgrade:
disableWaitForJobs: false
chart:
spec:
chart: codex-pooler
version: "0.18.1"
sourceRef:
kind: HelmRepository
name: icoretech
Deploy codex-pooler with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has codex-pooler on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartcodex-pooler is pinned at v0.18.1 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply