Repository navigation
feat(railway): optional memory and vCPU limits for runner services - #59
Merged
Merged
Conversation
The tests describe issue #58 before the code exists: the two settings are optional and validated, and when set the limits are applied after serviceCreate and before the first deploy, a refusal deleting the service. The fields exist so the tests compile and fail on behaviour.
On platforms that meter memory, a build's page cache can grow to the container's limit and is billed with the rest. RUNNER_MEMORY_GB and RUNNER_VCPUS cap each runner service through serviceInstanceLimitsUpdate, after serviceCreate and before the first deploy. A refused or unconfirmed limit deletes the service and fails the create, so no runner starts uncapped. Unset keeps today's services and makes no extra call. Load reads the two values without a new branch (errors.Join) so its CRAP stays where it was; Create gains one call to a helper. Refs #58
A vCPU value above 1 let a '> 1' mutant of the vCPU guard survive, and values that print the same at any precision let a precision mutant of the startup log survive. Smaller fractions kill both. The coverage baseline moves up to the total this change measures (91.18%).
parsilver
marked this pull request as ready for review
November 30, 2026 02:17
parsilver
commented
Nov 30, 2026
parsilver
left a comment
Contributor
Author
There was a problem hiding this comment.
Reviewed at cd05b49 against 27592a3. No Blocker. Merging; the suggestions go into a follow-up issue.
Suggestions
internal/railway/railway.go:229-231: a refused limit logs only "create service rr-...: railway: Not Authorized", which looks like a refused create, configure or deploy. Wrap it:resource limits (RUNNER_MEMORY_GB, RUNNER_VCPUS): %w, and assert it.internal/controller/controller.go:595,internal/reconcile/reconcile.go:147: a cap that Railway accepts but the runner cannot start under is silent: each cycle reaps "container ended" and creates again (simulated for an hour with one queued job: 31 services, 0 failed cycles, 0 alerts). A broken image already does this. Describe the symptom in Troubleshooting, and alert when services keep ending before their runner comes online.internal/controller/controller.go:320-327: a refused value is retried at full rate with no backoff (three pools with four or more queued jobs make 49 calls per cycle). Stop creating for the rest of the cycle after a refused limit; rollout step 4 should say to unset at the first refusal.internal/railway/limits_test.go:50-63: a wrong argument name or input type in the mutation leaves every test green. Assert the query text.cmd/controller/main.go:34-35: swapping or dropping the two limits also passes every test. A small testedrailwayConfig(cfg)removes both waivers.- Docs:
docs/deploy.md:119addcat /sys/fs/cgroup/memory.maxinside the job (the dashboard shows the setting, not enforcement) and suggest a separate controller with its own label and prefix for a live install;README.md:144GB appears to be decimal;README.md:307squeezing page cache can slow I/O-heavy builds.
Nits: docs/deploy.md:185 lacks "190 with limits", which the README has; docs/deploy.md:199 "set a lower limit" reads as a minimum; README.md:144 and docs/deploy.md:121 state that a value above the plan is refused, which is not known; the comment at limits_test.go:9-10 is wrong; the refusal test lacks the HTTP error case.
Verified
- Unset: bodies and headers of every create, configure, deploy and failure-path delete are byte-identical to main (8 cases); empty or blank means unset.
- Set: validated against Railway's published CLI schema; sent as 4, 0.5 and 1e+21, unset fields absent; order create, configure, limits, deploy; one create path for all pools, and nothing redeploys or reuses a runner.
- Failure: GraphQL error, false, null, missing data, HTTP 429 and timeout all delete the service and deploy nothing; the JIT runner is removed; an orphan is retried every cycle. Calls per job go from 4 to 5.
- Validation: zero, negative, NaN, Inf, 1e400, "0,5", "4GB" and quoted values stop startup, naming the variable and never its value.
- vet, gofmt and the race tests pass; four of the five new tests fail on the tests-only commit and the fifth is a guard. The gate's two survivors are true equivalents. No workflow change, nothing secret logged.
Not verified: any live call to Railway.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #58
Runner services can now be capped.
RUNNER_MEMORY_GBandRUNNER_VCPUSare optional; when either is set, the controller calls Railway'sserviceInstanceLimitsUpdateon each new runner service afterserviceCreateand the configure call, and beforeserviceInstanceDeployV2. A refused or unconfirmed limit deletes the service and fails the create, so no runner starts uncapped. Unset changes nothing and sends no extra call.Acceptance criteria and evidence
TestCreateWithoutLimitsSendsNoLimitsCall. The existing create tests are unchanged and still pass. The startup log showsmemory_gb=unset vcpus=unset.4,0.5).0,-1,abc,4GB,NaN,Inf,+Infand1e400stop the controller with an error naming the variable:TestARunnerLimitThatIsNotAPositiveNumberIsRefused. Both values parse and show inString():TestTheRunnerLimitsAreOptional.memoryGBandvCPUs:TestCreateAppliesTheLimitsBeforeTheFirstDeploy. Only the set fields are sent, in both directions (memory only, vCPUs only):TestCreateSendsOnlyTheLimitsThatAreSet.false, ornulleach lead to create, configure, limits, delete, with no deploy, an error back to the caller and the delete naming the environment:TestRefusedLimitsDeleteTheServiceAndDeployNothing. The controller already treats a failedCreateas any other create failure: it removes the JIT runner and the error fails the cycle, so it is logged oncycle failedand counts towardALERT_FAILED_CYCLES.MAX_RUNNERS=1and check one runner in the dashboard first) and Sizing; CHANGELOG[Unreleased].Design notes
serviceInstanceLimitsUpdate(input: ServiceInstanceLimitsUpdateInput!): Boolean!withserviceId,environmentId,memoryGB: Float,vCPUs: Float.ServiceInstanceUpdateInput, which the configure call already sends, has no limit fields, so the limits need a call of their own (one more Railway call per job when set).railway.Config(andconfig.Config), not onreconcile.Pool: the planner never needs them, and the issue asks for one setting for every pool. When per-label caps come, the fields should move toPooland leaverailway.Config, replacing this path rather than adding a second.Creategains one call to a newlimithelper;Loadreads the two values with no new branch (errors.Joinon the existing error check), so neither function's CRAP grows.Commands run
Quality gate, run locally with the pinned tools against base 27592a3 and this description rendered by GitHub:
Risks
cycle failedwith Railway's message, then the failing alert and a 503 on/healthz.Not verified
serviceInstanceLimitsUpdate, or that the limit takes effect. A Railway community thread from earlier reported this mutation answeringtruewithout applying a memory limit, and Railway said a fix was planned. Reading the limit back (serviceInstanceLimitOverride) would catch that, but it answers an untyped JSON scalar whose shape cannot be checked here, and it costs one more request per job, so it is left out. The first deploy with a limit set should follow rollout step 4: one runner, then check its limit in the dashboard.Waivers
Equivalent mutant: cmd/controller/main.go:34 wiring inside func main, which no test can run; the prefixes it passes come from Config.Prefixes, which the config tests cover
Equivalent mutant: cmd/controller/main.go:35 wiring inside func main, which no test can run; the two limits it passes are parsed by Load and used by Create, both covered by tests
Equivalent mutant: internal/config/config.go:167 the sign argument of IsInf cannot change which values pass, because negative infinity is already refused by the n > 0 test before it
Equivalent mutant: internal/config/config.go:168 the number returned beside an error is never read, because Load returns an empty Config whenever positive reports an error