Skip to content

Avoid deep input materialization stack overflows - #3209

Open
zpzjzj wants to merge 16 commits into
TraceMachina:mainfrom
zpzjzj:codex/deep-input-stack-repro
Open

zpzjzj wants to merge 16 commits into
TraceMachina:mainfrom
zpzjzj:codex/deep-input-stack-repro

Conversation

@zpzjzj

@zpzjzj zpzjzj commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Deep input trees can overflow a 2 MiB worker stack during materialization, including with directory caching disabled. Box the filesystem-store emplacement future and poll directory-cache child construction through a scoped work queue instead of recursively polling nested directory futures.

Keep subtree reuse, per-digest construction locks, pinning, and eviction behavior. On construction failure, cancel child work and wait for its descendants to exit before removing the parent's temporary tree.

The latest test-only update keeps hard-link source and destination paths on the same filesystem and streams subprocess phase logs rather than buffering them until exit.

How was this verified?

Separate Linux CI tested source commit 77932f53edd625f8fee640fda2451c0b33996de5:

  • Repository-pinned Bazel 9.3.1: ./tools/bazel-retry.sh test //... --config=nl-toolchain --config=nl-quiet --lockfile_mode=error --verbose_failures --nocache_test_results, with a loopback MongoDB test service supplied through NATIVELINK_TEST_MONGO_URL: 145/145 test targets passed. The stack target completed in 15.518 seconds.
  • The Bazel stack matrix also passed three runs pinned to one CPU, with one local test job and the existing 60-second target timeout unchanged: 7.592, 7.685, and 7.521 seconds.
  • 144 isolated subprocess cases across optimized smol and unoptimized test profiles: depths 8/128, stacks 2/16 MiB, no/default/subtree caching, cold/hot paths, and fetch budgets 1/2/64. Every case completed setup and materialization; every hot case completed prewarming. Setup and prewarming use a separate 32 MiB stack; the materialization probe uses the selected 2/16 MiB stack.
  • Real-filesystem tests retain queued and active descendants while a sibling fails, asserting that the parent stays pending and its on-disk marker survives until the descendants stop. Root cancellation also verifies eventual scratch cleanup and successful retry, with no remaining pins or construction locks. Both cache configurations pass.
  • A negative control removes the descendant wait: the new regression test fails with parent completed while a cancelled descendant was still alive.
  • Concurrent requests for the same tree and a parent sharing that tree complete with fetch budgets 1/2, with subtree caching both off and on; cold construction and subsequent hits verify actual file contents.
  • Workspace build, workspace all-target Clippy with -D warnings, pinned formatting, and directory-cache integration/unit/stress, filesystem-store, fast-slow-store, and S3-store tests pass.

The original unoptimized 128-level, 2 MiB stack-overflow reproductions failed during materialization, not setup or prewarming.

Separately, the previous GitHub Linux PR run at 8a523272 hit the stack target's overall 60-second timeout. Its cause remains undetermined: it has not reproduced in the separate Linux CI runs, and the old buffered output did not identify the stalled phase. The latest phase logging improves diagnosis if it happens again; it is not claimed to fix that timeout. GitHub checks for this update must be evaluated independently.

Risk

This changes a worker hot path. Scoped job accounting adds per-ancestor bookkeeping, and cancellation mistakes could leak work or remove a temporary directory too early. The tests exercise constrained budgets and shared-subtree contention, not every possible scheduling interleaving.

Root cancellation still uses background scratch cleanup. These tests do not establish synchronous cancellation of all underlying filesystem I/O, eliminate every recursive path, or establish safety at arbitrary tree depth. No configuration defaults or wire formats change.

AI assistance

OpenAI Codex implemented the fix and tests, investigated CI failures, and drafted this description. Ping directed the investigation, questioned the cancellation and deadlock behavior, and requested the real-filesystem regression and constrained-concurrency checks.

@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nativelink Ready Ready Preview Nov 17, 2026 7:50am UTC
nativelink-aidm Ready Ready Preview Nov 17, 2026 7:50am UTC

Request Review

@MarcusSorealheis

Copy link
Copy Markdown
Member

in general, this is a very risky change

@MarcusSorealheis

Copy link
Copy Markdown
Member

but it is an improvement. I'm doing some more tests now.

@github-actions

Copy link
Copy Markdown
Contributor

Build results for this fork PR at 8a5232720873:

Job Result Links
pull-request 1 failing test Open the build · check run

Fork PRs cannot stream build events, so a trusted workflow publishes them after CI finishes and updates this comment as each job is published. Opening a build needs a Trace Machina sign-in; the check run lists the failing tests and their logs.

This branch had an error being deployed

1 failed (outdated) and 2 active deployments
Preview – nativelink — 77932f53 Deployed Nov 17, 2026 by vercel[bot]
Preview – nativelink-aidm — 77932f53 Deployed Nov 17, 2026 by vercel[bot]
public-ci — 8a523272 Deployed Nov 17, 2026 by zpzjzj via NativeLink / Linux (PR) #779
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.

2 participants