Skip to content

ADR-0035: The render check runs in a child process with operating system limits

  • Status: Proposed
  • Date: 2026-11-14

Context

The render check (design 8.2.2, internal/gitops/semdiff) builds the Kustomization path of a change twice with the kustomize API and compares the outputs. Until now it ran in the executor's own process. Git contents are untrusted (invariant 4), and kustomize grows its output from small input: a value that a transformer copies into every place it reaches, a patch merged into a wide mapping, a name copied into every reference.

Each growth found so far got a static bound on the input, checked before the render: the build bytes and documents (#482, #488), the refusal of anchors and JSON patch copy (#488), what patches and transformers can add (MaxTransformBytes, #495, #626) and the keys patches can merge into one mapping (MaxMergedKeys, #626). A review on 2026-11-09 found a fifth case (#614): a base adds a 64 KiB annotation, an overlay moves it into a ConfigMap name with a JSON patch, and kustomize copies the new name into 1,000 references. About 100 KB of input is within every budget; the render reached 66 MB of output and 374 MiB of Go heap in 5.6 s (measured 2026-11-14 in the test process, Go 1.27.4, arm64), and the check passed. In the executor's container (256 Mi from #615 until this decision) such a tree ends the process on every recheck. #626 listed more cases past its estimate (keys merged under sibling paths, labels added across overlays, patches wrapped in nested List documents, JSON 6902 moves, a list created by a JSON add and then merged).

The estimates only over-count, and each round made them more complex without closing the class. A render cannot be cancelled once it has started, and a Go process cannot bound the memory of one call. On 2026-11-10 the static estimates were stopped there, and bounding the render itself was chosen for #614 ("child-process render with an OS memory and CPU limit, needs an ADR").

Decision

semdiff.Check validates its input in the executor, then runs the walk, both renders and the comparison in a child process: the executor's own binary, started again with one fixed argument (semdiff.RunRenderProcess, called first in main). Nothing else changes in what the check proves.

  1. The child sets its limits before it reads any input: a CPU time limit (RLIMIT_CPU, semdiff.MaxRenderCPUSeconds, 20 s; a SIGXCPU at the soft limit makes it exit, a SIGKILL from the kernel 5 s later if it did not) and, on Linux, a data limit (RLIMIT_DATA, semdiff.MaxRenderData, 384 MiB of private writable mappings, the soft and hard values equal so the child cannot raise them). It then samples the memory its Go runtime holds every millisecond and exits past semdiff.MaxRenderMemory (128 MiB), with Go's soft memory limit at three quarters of that so the collector works harder first.
  2. The parent is the second sampler, on Linux: while it waits for the answer it reads the child's resident size from /proc/<pid>/statm every millisecond and kills the child past semdiff.MaxRenderResident (192 MiB). Its resident size counts the binary's text (about 44 MiB at the start), so the limit sits above what the child's own sampling lets it reach: the executor's binary as the child peaked at 145 MiB resident on builds that pass and at 118 to 179 MiB when its own sampling stopped it (point 9). A failed read of statm is neither a refusal nor an error: the child may have ended, and its end is read as usual. A race detector build (tests only) uses four times the limit, since its shadow memory is resident too.
  3. Memory is bounded by these two samplers and the container's limit, not by the kernel. No limit an unprivileged container can set bounds the child's resident memory: RLIMIT_AS refuses honest renders (see the alternatives), a cgroup per render needs a delegated cgroup tree, and RLIMIT_DATA is no hard bound for a Go process. Linux checks the data limit when a mapping adds to the process's writable private memory, and counts only the growth net of the mappings it replaces. The Go runtime maps its heap with mmap(MAP_FIXED) over address space it reserved earlier with PROT_NONE (sysMapOS in runtime/mem_linux.go, Go 1.27.4), which replaces a mapping of the same size, so the kernel checks nothing. Measured 2026-11-14 on Linux 6.12 (arm64): with a data limit of 64 MiB, a fresh 512 MiB writable mapping was refused, while a 512 MiB PROT_NONE reservation mapped writable with MAP_FIXED succeeded and took VmData to 552 MiB; in the render process, with the 384 MiB limit and its sampling off, one 384 MiB allocation succeeded and took VmData to 466 MiB. The data limit stays as a partial guard: the process ends at its next fresh mapping past it (runtime metadata, a work queue of the collector). Then the Go runtime either exits with "fatal error: out of memory", "fatal error: runtime: out of memory" or "fatal error: runtime: cannot allocate memory", or it crashes with a SIGSEGV in its collector, because newSpanSPMC (runtime/mgcmark_greenteagc.go) does not check the result of sysAlloc. Of eight runs of that 384 MiB burst with the collector on, seven ended with the SIGSEGV. Neither end proves the data limit: Linux refuses a fresh mapping with the same ENOMEM when the node is short of memory to commit, and the Go runtime then writes the same fatal error line.
  4. On Linux the child also raises its own OOM score adjustment to 1000 before it reads any input (raising it needs no privilege). It helps only where the kernel's OOM killer ends one process: on cgroup v1, and on cgroup v2 nodes whose kubelet sets singleProcessOOMKill. Elsewhere on cgroup v2 a container OOM ends every process in the container (see the consequences). A failed write is not fatal and is not reported: the child has no one to tell, since the parent reads its stderr only for the Go runtime's fatal error line, and the render then runs with its other limits.
  5. The parent writes the input as JSON to the child's stdin and reads one answer from its stdout: a result, a refusal with its reason and detail, or a failure. The answer is read up to 64 KiB. A refusal is taken only with one of the package's own reasons (any other is an error for a retry), and its detail is cut at 2 KiB, room for two repository paths of 512 bytes; the reason and detail then go where they went before (the request's condition shows only the reason). The child gets an empty environment. Go code in the child writes nothing to stderr (os.Stderr and the log package point at nothing), and the parent keeps only the first line of it that starts with fatal error:, which the Go runtime writes when it ends the process.
  6. The child writes a ready line once its limits are set. Only the ends a limit chose are refusals at once, with TooLarge and a message that names the limit: the child's own exit at the memory sampling ("the render needs more than 128 MiB of memory"), its own exit at the CPU time limit ("more than 20 s of CPU time"), and the parent's kill at the resident limit ("more than 192 MiB of resident memory"; only when the parent sent the kill and the child's wait status then says it ended by SIGKILL: a child that crashed just before the kill reached it is read by its own end). The same build ends the same way on every retry, so a refusal is the right end and the person reads it on the request. A child that could not be started or ended before its ready line is an error for a retry. Every other end after the ready line is a semdiff.RenderEnded for a retry: a child that could not read its input or answered nothing readable; a child killed by a signal the parent did not send, such as an OOM killer's SIGKILL, which says nothing about the build; the Go runtime's out of memory exit (exit code 2 with a fatal error line that says "out of memory" or "cannot allocate memory"), which the data limit and a node short of memory cause alike (point 3); and any other crash, the runtime's SIGSEGV at the data limit included, since a crash cannot be told apart from a fault that a retry clears. When the caller's context ends the child is killed and Check returns the context's error, also for a retry: a node starved of CPU must not turn into a refusal.
  7. The retries of a RenderEnded have an end of their own. The request's deadline does not give one: recording the pull request clears it (design 6), and a waiting pull request is rendered again whenever the target branch moves. So the executor counts, in memory, the RenderEnded ends in a row per request UID and plan digest, in one place (the render check of the pull request steps). At the fifth the check is refused with TooLarge and the message "The render process ended without an answer 5 times in a row; the last time it" followed by the last cause (for example "crashed before it answered"). An answer (a result or a refusal) clears the count, another plan digest starts a new one, and a check whose context ended neither counts nor clears. Counts are dropped when the request ends, is being deleted or is gone, and at most 1,024 are kept (when full, one count starts again). When more than 1,024 requests have a count at once, eviction can drop a live count, so five attempts are guaranteed only while the entry survives. After a restart or a change of leader the count starts at zero, so a Pod that a render takes down with it (the group OOM kill of the consequences) never reaches five; point 11 counts those renders in the request's status instead (amended 2026-11-15, #714).
  8. The CPU time limit is reached inside the step that runs the check. The pull request step bounds the load of the build, the wait for the render slot and the render by one context of 2 minutes (controller.DefaultWriteTimeout). At the executor's CPU limit in the chart (500m, shared by the executor and the child) 20 s of CPU time take 40 s of wall time, so even with one render at the limit ahead of it in the slot the refusal arrives before the step's deadline (TestRenderCPURefusalWithinTheStep, computed from the chart's value). The largest builds the input budgets allow used at most 3.9 s of CPU time (hack/load/render at 500m CPU and 384 MiB, Linux arm64, 2026-11-14: heavy 4095 3.9 s, docs 4095 3.5 s, dense 100 3.1 s, patches 1708 2.8 s, flat 4 1.3 s), so the limit leaves five times that. With 60 s, as first proposed, the limit took 120 s of wall time, the step's deadline came first, and the request was retried until its own deadline without the refusal.
  9. The executor runs one render process at a time, as it ran one render at a time before, so its memory is its own plus one child's. The container's memory limit covers both with a stated margin: the executor's Go soft limit, plus the parent's resident limit for the child, plus 128 MiB (semdiff.RenderOutsideData) for what the soft limit does not count (the executor's binary text, stacks, pipe buffers, page tables) and what a child can add between two samples, must fit in the limit, and a chart test checks the sum from the chart's values and the package's constants (TestExecutorMemoryLimitHoldsARenderProcess). The chart refuses to render an executor whose memory limit is below its GOMEMLIMIT (the default or executor.goMemLimit) plus 192 MiB plus 128 MiB, with a message that says so (TestChartRefusesAnExecutorMemoryLimitBelowItsBudget). It reads the forms a memory limit is written in (bytes, or a number with an optional fraction and a binary or decimal suffix, such as 1.5Gi or 600M) and skips the check for a valid quantity it does not read (an exponent such as 1e9, or milli) instead of refusing it (TestChartReadsTheFormsOfAMemoryLimit, TestChartSkipsTheBudgetOfAFormItCannotRead). The chart raises the executor's limit from 256 Mi to 640 Mi (request unchanged) and sets its GOMEMLIMIT to 36 percent of the limit instead of 90, which keeps the executor's Go soft limit at 241591910 bytes (230.4 MiB), as before: 230.4 + 192 + 128 is 550.4 MiB. The margin is twice the largest growth of a child between two of the parent's readings measured so far, 64 MiB (see the residual risk below); 64 MiB, the first margin, left no room for the executor's own memory outside its Go heap. Both installs carry the sum: the manifests in config/manager set the same limit and the same GOMEMLIMIT bytes. The child's memory was measured on 2026-11-14 with the executor's binary (stripped, as the image builds it) started as the render process on the input of each hack/load/render shape, in a container of 0.5 CPU (Linux arm64), reading VmData and VmRSS every 0.1 ms: it starts at 83 MiB of VmData and 44 MiB resident; at the largest builds the input budgets allow (heavy 4095, dense 100, denseannotations 100, images 100 and the others of point 8) it peaked at 112 to 157 MiB of VmData and 75 to 119 MiB resident; on chained builds of the #614 shape (chained, a value of 4 to 20 KiB moved into a name copied into 1,000 references) that pass, at up to 224 MiB of VmData and 145 MiB resident; on larger chains, which its own sampling stopped, at up to 245 MiB of VmData and 118 to 179 MiB resident. VmData grows past the Go memory the child samples because heap the runtime has returned to the system stays mapped. The data limit is 1.5 times the largest VmData seen, so it does not refuse what the sampling lets through.
  10. The input budgets are not removed or widened: they refuse most large builds early, with a precise message, at the policy check before any plan is made. The process limits bound what they miss.
  11. A render that takes the executor down with it has an end too (amended 2026-11-15, #714). The executor cannot count it in memory, since it is the process that ends. So before it starts the render process it records in the request's status that a render of the plan started: status.unfinishedRenders, a typed field next to the pull request state (not a condition), with the plan digest and the count of renders of that plan that started in a row and did not finish, raised by one in its own status write, with the identity of the executor process (128 random bits drawn when the process starts). When the render check returns, whatever it returns (a pass, a refusal, a RenderEnded, a context that ended), the executor is alive, so it removes the mark in a status write of its own that the step's deadline and cancellation do not end; a pass of a waiting pull request records its rendered head in that same write. If that write conflicts because the request changed during the render (a person's kubectl annotate or label), the executor reads the request again and removes the mark there, in at most four tries, as long as it is still the mark this render wrote. A mark for another plan digest counts as zero, and so does a mark of the process that reads it: that process is alive, so its render returned and only the removal was lost (retries used up, an API timeout); the mark is cleared before the next render and not counted. Only a mark of a process that is gone counts, and a lost leader election is such an end, since the executor exits then without a graceful shutdown. The controller ignores updates of a request that change only the mark, so these writes do not wake the request before the backoff or delay its reconcile returned. When the check is about to start with the count at 3 (MaxUnfinishedRenders, a constant, not a flag or chart value) for the current plan, no render starts: the request ends in NeedsIntervention with the reason RenderNeverFinished and a fixed message, and the executor records a Warning Event with the same reason; a waiting pull request is closed first, as for any refusal of the waiting render, and before the commit nothing is committed. One or two unfinished renders, such as an ordinary rollout of the executor or a node drain in the middle of a render, never end a request. In a handoff the replacement ends Cancelled with HandoffAborted, as for the other refusals of its render, and its message names RenderNeverFinished. A status write of the mark that fails is an error for a retry and the render does not start, since an unmarked render could take the executor down uncounted; a removal that fails is an error for a retry too, and the outcome of that render is not used. The decision reads only the recorded count, digest and process identity, no timestamps. The schema bounds the count from 1 to 3 and the process identity to 32 lowercase hexadecimal characters; validation rules make a new mark, or one for another plan digest, start at 1, and let a write for the same plan digest raise the count by exactly 1 or leave the mark as it is (only removing the mark sets it back). A request stored before the field existed has none and stays valid. Cost: one more status write before every render and one after it. The executor stays the only writer of request status; RBAC and the App's permissions do not change.

The executor's container, 640Mi and 500m CPU, holds the executor and one render process. The executor validates the input, waits for the render slot and starts its own binary again with one fixed argument and an empty environment, then reads the render process's resident size every millisecond and kills it past 192 MiB. The render process sets 20 s of CPU time, 384 MiB of data mappings (a partial guard), 128 MiB of Go memory and an OOM score adjustment of 1000 before it reads its input on stdin, then answers on stdout. Three ends: an answer (a result, or a refusal with a known reason and a detail cut at 2 KiB); a TooLarge refusal for the ends a limit chose (the render process's memory and CPU exits, the parent's kill at the resident limit when the process ended by it); an error for a retry for everything else (no ready line, a signal the parent did not send such as an OOM killer's, the Go runtime's out of memory exit, another crash, an unreadable answer, the step's context ending), of which the executor counts the ends after the ready line and refuses the change with TooLarge at the fifth in a row. Before the start the executor marks the request in its status and removes the mark when the check returns, so a render that takes the container down is counted across restarts and ends the request in NeedsIntervention (RenderNeverFinished) after three in a row. Memory: 230.4 MiB for the executor, 192 MiB for the render process and a 128 MiB margin, 550.4 MiB of 640. The two processes share the user, file system and network.

sequenceDiagram
    participant E as Executor (semdiff.Check)
    participant C as Render process (same binary)
    E->>E: Validate the input, wait for the one render slot
    Note over E: Status: unfinishedRenders + 1 for the plan, with this process's identity (its own old mark is cleared, not counted; at 3: NeedsIntervention, RenderNeverFinished, no render)
    E->>C: Start with the fixed argument, empty environment
    C->>C: Set RLIMIT_CPU and RLIMIT_DATA, start the memory sampling
    C-->>E: Ready line
    E->>C: Input as JSON on stdin
    loop Every millisecond until the child ends (Linux)
        E->>E: Read the child's resident size, kill it past 192 MiB
    end
    C->>C: Walk, render before and after, compare
    alt Answer
        C-->>E: Result or refusal as JSON, exit 0
        E->>E: Take a refusal only with a known reason, cut its detail
    else A limit stops the child
        C-->>E: Exit at the memory sampling or the CPU limit, or the parent's kill (ended by SIGKILL)
        E->>E: Refuse with TooLarge
    else Killed by a signal the parent did not send, the runtime's out of memory exit, another crash
        C-->>E: Exit without an answer
        E->>E: Error for a retry, counted per request and plan: TooLarge at the fifth in a row
    else The context ends
        E->>C: Kill
        E->>E: Error for a retry, not counted
    end
    Note over E: Status: unfinishedRenders removed, read again on a conflict (not reached when the container ends with the render)

Consequences

  • A build that grows past the estimates is refused with TooLarge instead of ending the executor. The #614 case is refused in about 1 s (TestCheckBoundsAChainedNameReference), with the executor's own heap under 64 MiB, and an ordinary chain of the same shape renders (TestCheckRendersAnOrdinaryChain).
  • A render can now be cancelled: the process is killed when the context ends.
  • Each check starts one process and copies the build's files through a pipe, at most a few MiB.
  • Every binary that calls Check must call semdiff.RunRenderProcess first in main, test binaries from TestMain. A binary that does not fails its flag parsing on the fixed argument and exits before the ready line, so the check fails with an error for a retry; it never starts the binary as itself and never passes.
  • The executor's container needs 640 Mi instead of 256 Mi (a chart value users see), with the executor's GOMEMLIMIT at 36 percent of the limit. A user who sets executor.goMemLimit or lowers the limit has to leave room for one render process, the soft limit plus 192 MiB plus 128 MiB, or the chart refuses to render. A limit written as an exponent or in milli is not checked: the chart does not read those forms, and the executor then needs executor.goMemLimit. Builds that need more than 128 MiB of Go memory or 20 s of CPU time in the render are refused with TooLarge where they passed before.
  • The memory bound is measured, not a kernel guarantee: two samplers (the child's own and the parent's, each every millisecond) and a container limit sized with a stated margin. On cgroup v2 the kubelet sets memory.oom.group on every container since Kubernetes 1.28 (kubernetes#117793), so an OOM of the container kills every process in it; since 1.32 the kubelet setting singleProcessOOMKill turns that off, and its default is false (kubernetes#126096, kubelet configuration). AKS nodes run cgroup v2 (Ubuntu 22.04 and later, Azure Linux; AKS supported versions). So a container OOM ends the executor with the child, and the pod restarts. The budget makes that unreachable from the child's side as long as the samplers hold: the child is stopped at 192 MiB resident, and 230.4 + 192 + 128 MiB fits in 640 Mi.
  • Residual risk: an allocation burst that outruns both samplers by more than the 128 MiB margin, or an executor far above its Go soft limit, ends the pod by the group OOM kill. The pod restarts and the request is retried. The executor's count of point 7 is in memory and starts again with the pod; since the amendment of 2026-11-15 (point 11, #714) the mark in status counts such renders across restarts, and the third in a row ends the request in NeedsIntervention with RenderNeverFinished. Measured to judge it unlikely (2026-11-14, Linux arm64, a container of 0.5 CPU): when the child's own sampling stopped a render, its resident size was at most 179 MiB, 7 MiB over its starting 44 MiB plus 128 MiB. A child that allocates and fills 4 MiB blocks as fast as it can, with its own sampling off, was killed by the parent in 20 runs at 1 to 48 MiB over the limit (up to 240 MiB), having grown by 16 to 64 MiB since the reading before (go test -run 'TestRenderProcessResident$' -count 20 -v ./internal/gitops/semdiff/ in a golang:1.27.4 container with --cpus=0.5; the test logs both figures for each run). A 64 MiB margin, the first one, would have held that growth with no room left; the margin is 128 MiB, twice the largest growth, because it also holds the executor's memory outside its Go heap, and the executor's own peak was not measured in a running Pod (hack/load/measure.sh in a Kind cluster would show it). Throttling of the container's CPU stops the child as well as the parent.
  • macOS, used for development only, refuses a small data limit and has no /proc, so there the child's own sampling is the only memory bound. Other platforms refuse to render. A binary built with the race detector (tests only) sets no data limit, since its shadow memory takes terabytes of address space, allows eight times the CPU time and four times the resident size, and gives the child GORACE=atexit_sleep_ms=0, so that it does not sleep a second before it exits.
  • The executor's identity, RBAC and image are unchanged. The child is the same binary with an empty environment, so no token in its environment, and no network use; it reads only its stdin.
  • Residual risk to confidentiality: the child runs in the same container as the executor, as the same user, with the same file system and network. The limits bound its memory and CPU time, not what a render exploited through a flaw in kustomize or YAML parsing could read or reach: the tokens mounted in the Pod (the executor's service account token, and its workload identity token when it has one) and the network the executor may use. The empty environment keeps the executor's environment from it, and nothing in the child's normal path opens a file or a connection; a sandbox (another user, a seccomp profile of its own, no network) would need privileges the executor does not have and is not part of this decision.
  • Invariant 4 holds more strongly: the cost of untrusted Git content is bounded by the process, not by an estimate of it. Invariant 3 is unchanged: a refusal commits nothing.

Alternatives considered

  • Another estimate round (a compositional estimate: any value an earlier stage could create counts at its largest size for later stages). It would refuse the #614 case, but every round so far left a gap a review found, and the estimate already over-counts honest trees. Rejected on 2026-11-10.
  • A memory limit inside the executor's process (Go's soft memory limit, or a watchdog that stops the render). The soft limit only makes the collector work harder, and kustomize cannot be stopped mid-render, so a watchdog could only end the whole executor.
  • A separate render binary in the image. The same isolation, with a second binary to build, sign, ship and find at run time. Starting the executor's own binary needs none of that.
  • A cgroup per render. A kernel bound on resident memory, but it needs write access to a delegated cgroup tree, which the non-root executor with all capabilities dropped does not have.
  • A container memory limit sized for RLIMIT_DATA (the executor's soft limit plus the data limit plus a margin), proposed on 2026-11-14 to make the group OOM kill unreachable from the child's side. Rejected the same day: the Go runtime's heap mappings pass the data limit unchecked (decision, point 3).
  • RLIMIT_AS. The Go runtime reserves large ranges of address space it never uses, so a useful address space limit would refuse honest renders.

Amendments

  • 2026-11-15 (#714): point 11 added, and point 7, the diagrams and the residual risk changed to match. A render that ends the executor's Pod with it (the group OOM kill on cgroup v2) was retried without an end, because the count of point 7 lives in the process that ends. The executor now marks each render in the request's status before it starts and removes the mark when the check returns; at three unfinished renders in a row of the same plan the request ends in NeedsIntervention with RenderNeverFinished. Chosen over a condition (a typed field carries the digest and the count with schema bounds) and over counting in memory or in a ConfigMap (a new write the executor does not have). The mark carries the identity of the process that wrote it, so a removal lost while that process lives (a conflict with someone's label or annotation, an API timeout) is not counted as a render that never finished; a removal that conflicts is tried again on the request read again; and the controller ignores updates that change only the mark, so the two writes do not shorten a backoff or a Retry-After delay. Cost: two status writes per render, a third when a lost removal is cleared.