Skip to content

feat(railway): set Service CPU and memory limits - #2203

Open
husseinraoouf wants to merge 1 commit into
alchemy-run:mainfrom
husseinraoouf:feat/railway-service-limits
Open

husseinraoouf wants to merge 1 commit into
alchemy-run:mainfrom
husseinraoouf:feat/railway-service-limits

Conversation

@husseinraoouf

@husseinraoouf husseinraoouf commented Oct 11, 2026 •

Copy link
Copy Markdown

Railway.Service can now declare per-replica resource limits, the dashboard's Resource Limits setting.

const api = yield* Railway.Service("Api", {
  project,
  image: "ghcr.io/acme/api:latest",
  limits: { cpu: 1, memoryBytes: 4_000_000_000 },
});
api.limits; // { cpu: 1, memoryBytes: 4000000000 }
  • Reconcile writes services[id].deploy.limitOverride.containers with environmentPatchCommit under withEnvironmentConfigLock, the same path region uses. It patches only the fields that differ, then waits until the config reflects them (bounded, failing with ServiceLimitsNotApplied).
  • Omitting limits leaves the current limits untouched, and omitting a field keeps that field's value.
  • The patch commit redeploys the service by itself, so reconcile does not add a deploy. I checked this against a live service.
  • read reports the observed value as the new limits attribute. ServiceRegion.ts now exports its readEnvironmentConfig and environmentPatchCommit helpers so both modules share them.

Testing

  • test/Railway/ServiceLimits.test.ts covers the pure helpers: reading the override, patching only differing fields, and leaving matching limits alone. It passes, as does ServiceRegion.test.ts.
  • New live test in Service.test.ts: set a service's resource limits and change them. Create ({ cpu: 1, memoryBytes: 1e9 }) and update ({ memoryBytes: 2e9 }, keeping cpu: 1) passed their assertions, the environment config showed the new override, and the deployment reached SUCCESS. The final stack.destroy() failed with Not Authorized, because the account I tested with can't run serviceDelete (see Railway.Service delete removes the service from every environment #2179), so cleanup still needs a run with delete rights.
  • tsc -b packages/alchemy/tsconfig.json, which builds the referenced distilled projects first, exits 0 with no errors.

Fixes #2202

🤖 Generated with Claude Code

`Railway.Service` takes a `limits: { cpu, memoryBytes }` prop and exposes the
observed value as a `limits` attribute. Reconcile writes
`services[id].deploy.limitOverride.containers` with `environmentPatchCommit`,
the same path `region` uses, and only for fields that differ. Omitting the prop
leaves the current limits alone, and omitted fields keep their value. The patch
commit redeploys the service, so reconcile needs no extra deploy.

Fixes alchemy-run#2202

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Railway.Service cannot set CPU and memory limits

1 participant