Skip to content

Optional memory and vCPU limits for runner services #58

Done

Description

@parsilver

Runner services are created without resource limits, so a build can use as much memory as the plan allows. Railway exposes serviceInstanceLimitsUpdate (memoryGB, vCPUs), so the controller can cap each service it creates.

Proposal:

  • Two optional settings, RUNNER_MEMORY_GB and RUNNER_VCPUS (unset by default: no change to today's behavior).
  • Applied after serviceCreate and before the first deploy. If the limits cannot be applied, delete the service and report the error like any other create failure, instead of starting a runner without them.
  • Fake GraphQL tests for set, unset and refused limits; a row in the settings table of the README.

Why: on platforms that meter memory, a build's page cache can grow to the container's limit and is metered with the rest. A cap bounds it. Opt-in, because a cap that is too small can kill a job, and a build that really needs the memory will need a higher one.

Later (not in this issue): different caps per label, so small checks and heavy builds do not share one size.

Activity

  1. parsilver commented on Nov 30, 2026

    @parsilver
    ContributorAuthor

    Work has started on this.

  2. parsilver commented on Nov 30, 2026

    @parsilver
    ContributorAuthor

    Plan for this issue.

    Acceptance criteria

    1. RUNNER_MEMORY_GB and RUNNER_VCPUS are optional. Unset (the default), runner services are created exactly as today: create, configure, deploy, three API calls and no limits call.
    2. A value must be a positive, finite number (4, 0.5). Anything else (0, -1, abc, NaN, Inf) stops the controller at start with an error that names the variable.
    3. When either is set, the controller calls serviceInstanceLimitsUpdate after serviceCreate and the configure call, and before serviceInstanceDeployV2. Only the set fields are sent; an unset one is left out so Railway keeps its own value.
    4. If Railway refuses the limits (a GraphQL error, an HTTP error, or the mutation answering false), the service is deleted, nothing is deployed, and the error goes back like any other create failure (the controller already removes the JIT runner and counts the failed create).
    5. The startup log line shows the limits. The README settings table, docs/deploy.md and the Unreleased section of CHANGELOG.md describe the two settings.

    Approach

    • internal/config: read the two variables with a small positive-float reader next to number; keep them on Config as RunnerMemoryGB and RunnerVCPUs (0 means unset) and print them in String().
    • internal/railway: two fields on railway.Config (MemoryGB, VCPUs), wired in cmd/controller/main.go. Create sends the limits through the existing fail path, so a refused limit deletes the half-made service the same way a refused configure does.
    • The schema comes from Railway's CLI schema: serviceInstanceLimitsUpdate(input: ServiceInstanceLimitsUpdateInput!): Boolean!, with serviceId, environmentId, memoryGB: Float and vCPUs: Float.
    • One setting for every pool, as the issue asks. Per-label caps stay out of scope.

    Invariants

    • Unset means no new API call and no change to the request shape (keeps the rate-limit budget and the existing tests as they are).
    • No runner is ever deployed without the limits it was asked to have.
    • Errors name the variable, never a token; nothing new is logged from Railway answers.

    Tests (fake GraphQL server, written first)

    • Both set: four calls in order create, configure, limits, deploy; the limits input carries the service id, environment id, memoryGB and vCPUs.
    • Only one set: the other field is absent from the input.
    • Unset: three calls, none of them the limits mutation.
    • Refused by an error, and answered false: the last call is serviceDelete and no deploy was sent.
    • Config: both parsed; unset gives 0; each bad value refused with the variable named; String() shows them.

    Not verified here

    • A live run against Railway. A Railway community thread from earlier reported this mutation answering true without applying a memory limit; Railway said a fix was planned. Reading the limit back (serviceInstanceLimitOverride) would catch that, but its answer is an untyped JSON scalar whose shape I cannot check without calling the real API, and it would add a request per runner. I will leave it out and name it in the PR, so the first deploy with a limit set should check one runner's limit in the Railway dashboard.
  3. parsilver commented on Nov 30, 2026

    @parsilver
    ContributorAuthor

    Status: in progress. The work is on draft PR #59 (branch feat/58-optional-memory-vcpu-limits). The plan above was reviewed and revised: Create gains only a call to a small limit helper and Load gains no branch, so neither grows its CRAP score. The README Limits section and the rollout guide now cover the extra call per job and a first try at one runner. Tests and the local quality gate pass. Next: mark the PR ready for review.

  4. parsilver commented on Nov 30, 2026

    @parsilver
    ContributorAuthor

    Status: PR #59 is ready for review. CI is green on its head commit: tests, the quality gate (4 waivers: two main.go wiring lines and two equivalent mutants, each explained in the PR) and the image builds. Next: review and merge.

    Not verified: a live run against Railway. Before limits are set in production, check that the project token may call serviceInstanceLimitsUpdate, and that one runner's limit shows in the dashboard (rollout step 4 in docs/deploy.md).

    Notes: Railway's ServiceInstanceUpdateInput has no limit fields, so limits always cost a separate call. And a vCPU test value above 1 lets a '> 1' mutant of a '> 0' guard survive, so test with a fraction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions