Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
Plan: Assembler code for ECS-service-default (Lambda as optional cost-mode)
Date: 2026-07-15 (revised)
Spec: .ai/specs/2026-07-15-assembler-deployment.md
Scope: code only — Rust assembler + @carbon/jobs + Dockerfile. IaC (ECS
service, ALB, autoscaling, VPC, SST/CI) is a downstream handoff.
Pivot (Sid, 2026-07-15)
Run the assembler as a standing ECS service (the primary), async submit→poll over HTTP behind a load balancer. Lambda stays available as an optional cost-mode (scale-to-zero) if idle cost ever bites — but it is no longer the default. This diverges from the spec's Lambda-default stance; the spec needs a changelog update to record the flip (noted in Tasks).
Why this is less code, not more
The assembler is already a standing async HTTP service and its job store is already multi-replica-safe:
apps/assembler/src/jobs.rs—Backend::Rediskeeps job status + pointers in Redis, and holds the pending late-mint artifact bytes in Redis under a short TTL "so ANY replica's poll can drain it" (its own doc comment).Backend::Memoryis process-local (single-process/dev).- So with
ASSEMBLER_REDIS_URLset, N replicas behind a round-robin LB Just Work: submit lands on replica A, the poll can be served by replica B (status from Redis, pending bytes from Redis). No sticky sessions, no refactor. packages/jobs/.../assembler-client.tsalready does submit→poll againstASSEMBLER_SERVICE_URLwithinternalizeStorageUrl(no-op in prod). Pointing that URL at the ECS load balancer is the whole integration change.
The big sync/run-job/router refactor from the earlier draft was only for Lambda.
It moves to an optional workstream, gated on cost.
Verified current state
main.rs— axum/v1/{convert,optimize,plan}(submit → 202),/v1/jobs/:id(long-poll, drains late-mint viaX-Carbon-Upload-Urls),/v1/cache/invalidate,/health,/v1discovery.main()→ tokio runtime →serve().config.rs—max_concurrency(semaphore),shutdown_grace(default 600 s),max_source_bytes(0 = unlimited, set earlier),redis_url(Redis when set + reachable, else Memory), TTLs, URL/SSRF policy (require_https/verify_tlsoff underASSEMBLER_DEV_MODE).actions/optimize.rs— inlinerun_optimize(streaming glTF→GLB repack done; bounded memory), a size ladder gate (cannot_fit_budget).Dockerfile— static OCCT+Draco,EXPOSE 8000,/health,USER assembler.
Workstream A — ECS-service readiness (the real code work; small)
- Redis is the prod default. No code change (env:
ASSEMBLER_REDIS_URLset). Add a boot log line that states the backend (Redis/Memory) and, on Redis, warn loudly if unset in a multi-replica context — a Memory backend behind an LB with >1 task silently breaks cross-replica polls. Confirmexisting_active/set_pending/ late-mint all round-trip on Redis (they do by design; add an integration test against a local redis). - Graceful shutdown / SIGTERM drain. Verify
serve()installs a shutdown signal handler (SIGTERM/SIGINT) withaxum::serve(...).with_graceful_shutdownthat (a) stops accepting new work, (b) waits up toshutdown_gracefor in-flight jobs, then exits. If not wired, add it. This is what makes rolling deploys + scale-in / (later) Spot drains lossless. AlignstopTimeout(IaC) withshutdown_grace. - Concurrency / backpressure. Confirm the
max_concurrencysemaphore returns 429 +Retry-Afterwhen full (so the LB/autoscaler sheds instead of OOM). Defaultmax_concurrencyshould track the task's vCPU (OCCT is CPU-bound); document thevCPU → max_concurrencyguidance. - Autoscaling signal. Prefer CPU target-tracking (no code). If queue-depth
scaling is wanted later, expose in-flight + pending counts on
/v1discovery (cheap) for a custom CloudWatch metric — optional, deferred. - Health vs readiness.
/healthexists (liveness). Confirm it returns healthy only once the server is actually serving (post-bind); that doubles as the LB target-group health check. A separate readiness gate is unnecessary (stateless workers).
Workstream B — Per-job robustness / bounding (applies to any runtime)
- Memory bounding — the streaming glTF→GLB repack (done) keeps geometry in an
mmap'd
/tmpfile off-heap. Confirm the optimiser working set fits the task's RAM (4 vCPU / 16 GB tier); document the practical max input. jemalloc on linux already curbs fragmentation. -
/tmpdiscipline — temps (download + repacked glb) understd::env:: temp_dir(); promptremove_fileon done/error (present). On ECS the container FS is ephemeral + sized by task storage — set the ephemeral//tmpsize in the task-def (IaC) to fitraw + repacked + output. - Time/size gates — the size ladder exists. A wall-clock budget is not required for an ECS service (no 15-min cap) — a long job just runs. Keep it optional, only wired if the Lambda cost-mode (Workstream C) is enabled.
- SSRF/auth for prod —
ASSEMBLER_ALLOWED_URL_HOSTSset,ASSEMBLER_DEV_MODEunset (https + TLS verify + private-IP default-deny — wired), bearer on every non-/healthroute (present).
Workstream C — Optional Lambda cost-mode (deferred; only if idle cost bites)
Everything from the earlier draft, kept but not on the critical path:
- Sync execution via
X-Carbon-Sync: 1+ request-carriedupload_url(inline run + upload + return JSON), therun-jobCLI (arg-dispatch inmain()), the wall-clock time-budget gate (the 900 s fit), Redis-off-on-Lambda, LWA extension in the Dockerfile, and the TS router (size pre-route → Lambda invoke-and-await → fallback to the ECS service). - The ECS service (Workstream A) is the fallback target for Lambda overflow — no separate one-shot RunTask path needed once a standing service exists (a simpler topology than the spec's Lambda+one-shot-ECS).
Full detail preserved in the spec (2026-07-15-assembler-deployment.md P1/§Design);
implement only when cost forces scale-to-zero.
Workstream D — Dockerfile / image
- Confirm the standing-service image is complete:
EXPOSE 8000,/health, non-root, static OCCT/Draco, sane defaultCMD= the HTTP server. No LWA needed for the ECS service (LWA is added only under Workstream C for Lambda). -
ASSEMBLER_BIND=0.0.0.0:8000in the container so the LB/target group reaches it (dev binds127.0.0.1).
Workstream E — TS job layer (minimal)
- No refactor. Keep
submitAssemblerJob+pollAssemblerJobOnce. The only prod wiring:ASSEMBLER_SERVICE_URL= the ECS load-balancer URL,ASSEMBLER_SERVICE_API_KEY= the bearer (both already in@carbon/env).internalizeStorageUrlno-ops in prod.model-optimize/assembly-convert/assembly-planare unchanged. - (Only if Workstream C lands) add the
invokeAssemblerrouter.
Workstream G — Inngest job-layer hardening (for a standing service)
A standing service restarts on every deploy and scales; the Inngest tasks must tolerate that. Grounded in the current code.
- Fix retry classification (bug).
assembler-client.ts::submitAssemblerJobthrowsNonRetriableErroron every non-429 status, so a 5xx during a rolling deploy fails the job permanently. Split it:- 4xx (bad input / permanent reject) →
NonRetriableError(fail fast). ✓ - 5xx / connection refused / timeout (outage / deploy / restart) → a plain
Error(retryable — Inngest retries after the service returns). Shared client → fixesmodel-optimize+assembly-convert+assembly-planat once. Mirror inpollAssemblerJobOnce(a transient poll 5xx should retry, not fail — it already throws a plainError; keep it that way).
- 4xx (bad input / permanent reject) →
- Raise retries for deploy resilience.
model-optimizeisretries: 2; a rolling deploy can outlast 2 exponential backoffs. Bump to ~4–5 (and audit convert/plan) so a job survives a deploy window. Idempotent byjobId(optimize-${modelUploadId}+ the assembler'sexisting_active+ declared-hash result cache), so extra retries just re-attach / hit the cache — never double-compute. - Align the wait budget with uncapped ECS jobs.
MAX_OPTIMIZE_WAIT_MS = 15 minwas sized to the (old) Lambda-ish ceiling. On a standing service there is no cap — a big job (e.g. the 1.73 GB glTF) can exceed 15 min, at which point the Inngest poll loop gives up while the service is still working and uploads the artifact anyway → row goesFaileddespite a good GLB (state mismatch). RaiseMAX_OPTIMIZE_WAIT_MSto the real max (≈assembly-plan's 40 min, or derive from size); the Inngest budget is now the effective cap, so make it generous. Auditassembly-convertsimilarly (assembly-planalready 40 min). - Align concurrency with the service's capacity. Inngest
model-optimizeconcurrency is[{limit:4},{company:2}]; the assembler caps in-flight via itsmax_concurrencysemaphore (per replica). Set Inngest global concurrency ≈replicas × max_concurrencyso it doesn't 429-storm a single replica (theBUSY_RETRIES+Retry-Afterbackoff is the safety net, but tuning avoids the churn). Document the relationship; it's a deploy-time number. - Dedup rapid re-triggers (optional).
model-optimizefires from several call sites (upload, both drag routes, Part/Tool insert, the Retry route). The assembler dedups server-side (Idempotency-Key), but two near-simultaneous triggers still spawn two function runs that both attach + both persist. Consider an Inngestidempotency: "event.data.modelUploadId"(windowed) to collapse them. - Terminal-failure row status is already right —
model-optimizeonFailure→optimizeStatus: "Failed",assembly-planonFailure→Failed. Confirmassembly-convertdoes the same so the viewer's Retry surfaces on every path.
Workstream F — Tests & verification
- Rust: an integration test of the Redis backend cross-replica invariant —
set_pendingon oneJobStore, poll/finalize from a secondJobStoresharing the same redis (proves multi-replica polling). A graceful-shutdown test (SIGTERM mid-job → in-flight completes, no new accepts). -
cargo test -p assembler; image builds; run the container with a local redis + 2 replicas behind a tiny round-robin proxy → submit on one, poll on the other → success (the horizontal-scale proof). - TS: a
submitAssemblerJobunit test asserting 5xx / connection error → retryable throw, 4xx →NonRetriableError(the deploy-resilience fix). Path still green (pnpm --filter @carbon/jobs typecheck+test).
Out of scope (downstream IaC)
ECS service definition (desired count, rolling deploy), ALB + target group +
health check, service-autoscaling policy (CPU target-tracking), VPC/subnets/SG, the
Redis the service points at (existing @carbon/kv redis or an ElastiCache), SST/CI,
GovCloud fan-out, ECR repos. This plan produces the code + image those consume.
Sequencing
- A + B + D + E + G — make the standing service production-solid (Redis-default
log, graceful drain, 429 backpressure, bind
0.0.0.0, cross-replica test) and the Inngest layer deploy-resilient (5xx-retryable, wait budget, retries). Small. The retry-classification fix (G) is worth doing now regardless of deployment — it's a latent bug the moment the dev/prod service ever restarts mid-job. - Hand to IaC for the ECS service + ALB + autoscaling.
- C (Lambda cost-mode) — only if/when idle cost justifies the sync refactor.
Decisions (locked)
- Primary = standing ECS service, async submit→poll, multi-replica via the existing Redis job store. Lambda = optional cost-mode, deferred.
- Update the deployment spec's changelog to record this flip from Lambda-default.
Risks
| Risk | Mitigation |
|---|---|
| Memory backend behind an LB with >1 task → cross-replica poll misses | Redis is the prod default + a loud boot warn when Memory + scaled; cross-replica integration test |
| Graceful drain not wired → rolling deploys drop in-flight jobs | verify/add with_graceful_shutdown + shutdown_grace; align stopTimeout |
| Standing service = non-zero idle cost | accepted trade for simplicity; Lambda cost-mode (Workstream C) is the escape hatch |
| Long/huge job on a small task → OOM | size the task tier (4 vCPU/16 GB); streaming repack (done) bounds memory; 429 backpressure sheds overload |