Skip to content

feat(railway): optional memory and vCPU limits for runner services - #59

Merged
parsilver merged 3 commits into
mainfrom
feat/58-optional-memory-vcpu-limits
Nov 30, 2026
Merged

parsilver merged 3 commits into
mainfrom
feat/58-optional-memory-vcpu-limits

Conversation

@parsilver

Copy link
Copy Markdown
Contributor

Closes #58

Runner services can now be capped. RUNNER_MEMORY_GB and RUNNER_VCPUS are optional; when either is set, the controller calls Railway's serviceInstanceLimitsUpdate on each new runner service after serviceCreate and the configure call, and before serviceInstanceDeployV2. 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

  1. Unset by default, no change. Unset sends three calls (create, configure, deploy) and no limits call: TestCreateWithoutLimitsSendsNoLimitsCall. The existing create tests are unchanged and still pass. The startup log shows memory_gb=unset vcpus=unset.
  2. Validated at start. A value must be a positive, finite number (4, 0.5). 0, -1, abc, 4GB, NaN, Inf, +Inf and 1e400 stop the controller with an error naming the variable: TestARunnerLimitThatIsNotAPositiveNumberIsRefused. Both values parse and show in String(): TestTheRunnerLimitsAreOptional.
  3. Applied after create, before the first deploy. The calls go create, configure, limits, deploy, and the limits input carries the service id, the environment id, memoryGB and vCPUs: TestCreateAppliesTheLimitsBeforeTheFirstDeploy. Only the set fields are sent, in both directions (memory only, vCPUs only): TestCreateSendsOnlyTheLimitsThatAreSet.
  4. A refusal deletes the service. A GraphQL error, an answer of false, or null each 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 failed Create as any other create failure: it removes the JIT runner and the error fails the cycle, so it is logged on cycle failed and counts toward ALERT_FAILED_CYCLES.
  5. Docs. A row in the README settings table; the README Limits and Cost sections (calls per job, the cap below the plan's); docs/deploy.md rollout step 4 (try a limit at MAX_RUNNERS=1 and check one runner in the dashboard first) and Sizing; CHANGELOG [Unreleased].

Design notes

  • The schema comes from Railway's own CLI schema: serviceInstanceLimitsUpdate(input: ServiceInstanceLimitsUpdateInput!): Boolean! with serviceId, 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).
  • The two values live on railway.Config (and config.Config), not on reconcile.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 to Pool and leave railway.Config, replacing this path rather than adding a second.
  • Create gains one call to a new limit helper; Load reads the two values with no new branch (errors.Join on the existing error check), so neither function's CRAP grows.
  • The invariant is "no runner is deployed unless Railway accepted the limits". It is not "the limits are in force": see below.

Commands run

$ go vet ./... && go test -race ./...
ok  	github.com/farzai/github-runner-railway/internal/config
ok  	github.com/farzai/github-runner-railway/internal/controller
ok  	github.com/farzai/github-runner-railway/internal/ghapp
ok  	github.com/farzai/github-runner-railway/internal/railway
ok  	github.com/farzai/github-runner-railway/internal/reconcile
ok  	github.com/farzai/github-runner-railway/internal/webhook

Quality gate, run locally with the pinned tools against base 27592a3 and this description rendered by GitHub:

Waivers: pass      4 waivers count (below)
Format: pass       5 changed Go files gofmt clean
Coverage: pass     every changed executable line run by a test, except the two main.go wiring lines (waived);
                   repo 91.18% (baseline was 90.92%, updated in .quality/baseline.json)
CRAP: pass         7 added or changed functions under 10; main 56.0 and Load 17.0 no worse than base
Duplication: pass  0 pairs at 0.8 or above on this PR, 0 on base
Mutation: pass     21 killed, 2 survived and waived as equivalent (23 sites in 2 files)

Risks

  • A cap too small for a build kills the job. Opt-in, and the docs say to size it for the heaviest job of every pool.
  • A value above the plan's per-service maximum, or a project token that may not set limits, fails every create until the variable is unset. That shows up as cycle failed with Railway's message, then the failing alert and a 503 on /healthz.
  • Rollback: unset both variables and redeploy the controller. Nothing else changed; services already running keep the limit they were made with until they are reaped.

Not verified

  • A live run against Railway. I did not call the real API: no proof yet that a project token may call serviceInstanceLimitsUpdate, or that the limit takes effect. A Railway community thread from earlier reported this mutation answering true without 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

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
parsilver marked this pull request as ready for review November 30, 2026 02:17

@parsilver parsilver left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at cd05b49 against 27592a3. No Blocker. Merging; the suggestions go into a follow-up issue.

Suggestions

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. cmd/controller/main.go:34-35: swapping or dropping the two limits also passes every test. A small tested railwayConfig(cfg) removes both waivers.
  6. Docs: docs/deploy.md:119 add cat /sys/fs/cgroup/memory.max inside 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:144 GB appears to be decimal; README.md:307 squeezing 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.

@parsilver
parsilver merged commit 0cfd803 into main Nov 30, 2026
15 checks passed
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.

Optional memory and vCPU limits for runner services

1 participant