Repository navigation
engine: stop fresh remote-cache engines running out of memory on large module workloads - #14884
Merged
Merged
Conversation
A test that fails today. When a lazy operation's output is installed, the operation's cleanup runs and releases what it built: for a no-source decision, the private object decoded from the row's record, its recipe and the record. The row keeps the cleanup in its release chain and in its installed outputs, and the cleanup keeps its function after running, so everything the operation built stays in memory for as long as the row does. Signed-off-by: Erik Sipsma <[email protected]>
An installed row keeps its install's cleanup in its release chain and in its installed outputs, both as long-lived as the row. The cleanup ran once the part was installed, but kept its function, so everything that function captured stayed in memory with the row. For a lazy operation re-run because a row from the remote cache had no installable content, that is the private object decoded from the row's record, its recipe and the record, about a megabyte a re-run. A fresh engine re-running thousands of such rows grew by gigabytes and was killed. A cleanup that has run now drops its function. A failed one keeps it, so a later release still runs it. Signed-off-by: Erik Sipsma <[email protected]>
A lazy evaluation's span cause-links the call that returned its result and every span that installed it, often hundreds of spans, and part demand runs many evaluations of one result with the same list. Test that the client telemetry store's span index keeps memory proportional to the distinct link lists rather than to every link, including when one span's links grow a row at a time, and that its answers (causal children and parents, log scope) match a straightforward index's. Signed-off-by: Erik Sipsma <[email protected]>
The span index kept every cause link twice, as span-ID strings in a map from each linked span to its linking spans and back. On a fresh remote-cache engine running a large module workload, these maps grew to several gigabytes, and the engine was killed for lack of memory. Intern span IDs and store each distinct set of link targets once, shared by every span carrying it, with an index from each target to the sets containing it. When a span's links grow, it moves to the larger set and a set no span carries any more is dropped, so a span gaining links one at a time keeps the index proportional to its links. Every query returns what it did before. Signed-off-by: Erik Sipsma <[email protected]>
The bounded live span queue drops spans on overflow rather than stall a session, and nothing reports how many. Test that a counted lane reports exactly the spans a stalled consumer never got, zero without overflow, and that a shutdown cut short by its deadline is reported as incomplete rather than as drops, since the queue still hands its spans on. Signed-off-by: Erik Sipsma <[email protected]>
The bounded live span queue drops spans on overflow rather than stall the session, and the SDK keeps its drop count to itself. Count the spans the session's lane takes in and hands on to its exporter, and log the result once per session when its telemetry shuts down: the number dropped when the shutdown completed, a warning when any were, and the number still outstanding, without calling them dropped, when the shutdown was cut short and the queue is still draining. Signed-off-by: Erik Sipsma <[email protected]>
grouville
self-requested a review
October 27, 2026 16:45
grouville
approved these changes
Oct 27, 2026
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.
Symptom
A fresh engine using the remote cache, running a large module workload (our test-base check), grew to about 15.9 GB and was killed for lack of memory, on 16-core, 32 GB machines. Engines that weren't fresh, on the same workload, stayed around 3 GB.
Cause
Heap profiles of the live engine showed most of the growth in cause links: the client telemetry store's span index, and the span-ID strings in it.
When the engine runs deferred work for a lazy result, it starts a hidden evaluation span. That span cause-links the call that returned the result and every span that installed it, which often means hundreds of module calls. On the remote-cache path, each part of a result is evaluated as its own span, and every one repeats the same list. The span index kept each link twice, as strings, in a map from linked span to linking spans and back, and never shared anything between spans.
What this changes
Nothing users see changes. Traces, the TUI, Cloud and every store read are as before. The only addition is one log line per session.
Result
On a 16-core spot machine running the test-base check, seed then fresh with the remote cache, in two runs:
A follow-up change (separate PR) cuts the repeated links at their source, so that later evaluations of a result link only its first one.
Tests
All are package tests in the
test-split/test-packagescheck:TestPartLazyOperationCleanupReleasesItsInvocation(dagql): a completed cleanup no longer keeps its invocation.TestSpanLookupSharedCauseLinksStayCompact,TestSpanLookupGrowingCauseLinksStayCompactandTestSpanLookupCauseLinkAnswers(engine/clientdb): memory proportional to distinct link sets, including a span whose links grow one at a time; answers identical to a straightforward index under randomized inputs.TestSpanQueueCountsDropsandTestSpanQueueCountsShutdownCutShort(engine/telemetry): the drop count is exact against a stalled exporter, and a cut-short shutdown isn't reported as drops.