Skip to content

Reentrant Execute harness + the file-sink leak it found (FT-9) - #454

Draft
ChrisonSimtian wants to merge 4 commits into
Fallout-build:developfrom
ChrisonSimtian:engine/ft9-reentrancy-harness
Draft

ChrisonSimtian wants to merge 4 commits into
Fallout-build:developfrom
ChrisonSimtian:engine/ft9-reentrancy-harness

Conversation

@ChrisonSimtian

@ChrisonSimtian ChrisonSimtian commented Jun 30, 2026 •

Copy link
Copy Markdown
Collaborator

Adds a test that runs a real build twice in one process, and fixes the log-file leak that test found.

Part of #315 (FT-9, #314).

Stacked on #453 (FT-6). The diff includes its two commits until it merges. Review only the top two commits (the leak fix and the harness). FT-1, FT-2 and FT-4 have already landed.

What changed

  • Host.WriteErrorsAndWarnings replaces Log.Logger to re-print warnings. Setting Log.Logger does not dispose the old logger. That logger owns the run's file sinks, so build.log stayed open. The next run in the same process then failed to reset the file and returned the error exit code with no message. The fix disposes the old logger. Nothing is lost, because the run logs through the new logger from that point.
  • BuildManagerReentrancySpecs runs a small build through BuildManager.Execute twice. It checks that:
    • both runs exit with 0;
    • the second run gets its own BuildContext, ParameterService and in-memory sink;
    • the second run starts with an empty sink;
    • the static facades inside a run point at that run.
  • GitRepositoryWorktreeSpecs joins the shared ProcessGlobalStateCollection. It logs through the process-wide Log and could add lines to a concurrent run's sink.

Why

The earlier FT-9 spec only tested BuildContext directly. Nothing ran two full builds in one process, and that is the case the per-run state work is for.

Limits of the test

  • It pins two process-wide inputs: EnvironmentInfo.ArgumentParser and FalloutBuild.RootDirectory. Making them per-run is a separate change.
  • Runs are sequential. Two runs at the same time still share process-wide state (the value-injection cache, the tool-path resolver settings).

Verification

  • Without the leak fix, all 5 new specs fail. The direct guard is A_second_run_in_the_same_process_also_succeeds. The others fail after it because the leaked file stays open.
  • Fallout.Build.Specs: 275 of 278 pass. The 3 failures are GitRepositoryWorktreeSpecs that need a checkout whose remote is Fallout-build/Fallout.

@ChrisonSimtian ChrisonSimtian added the release/Stable Targets the current/stable release label Jun 30, 2026
@ChrisonSimtian ChrisonSimtian added release/Next Targets the next release and removed release/Stable Targets the current/stable release labels Jul 20, 2026
@ChrisonSimtian
ChrisonSimtian force-pushed the engine/ft9-reentrancy-harness branch from 030c3fe to 7ac7242 Compare July 26, 2026 10:52
@ChrisonSimtian ChrisonSimtian added release/Stable Targets the current/stable release bug Something isn't working and removed release/Next Targets the next release labels Jul 26, 2026
@ChrisonSimtian ChrisonSimtian changed the title BuildContext isolation harness (FT-9) Reentrant Execute harness + the file-sink leak it found (FT-9) Jul 26, 2026
@ChrisonSimtian ChrisonSimtian added release/Next Targets the next release release/Stable Targets the current/stable release and removed release/Stable Targets the current/stable release release/Next Targets the next release labels Aug 4, 2026
@ChrisonSimtian
ChrisonSimtian force-pushed the engine/ft9-reentrancy-harness branch from 7ac7242 to 5404766 Compare September 4, 2026 10:06
@ChrisonSimtian
ChrisonSimtian force-pushed the engine/ft9-reentrancy-harness branch from 5404766 to 89a4884 Compare October 4, 2026 08:15
@ChrisonSimtian
ChrisonSimtian force-pushed the engine/ft9-reentrancy-harness branch from 89a4884 to e26e000 Compare November 18, 2026 06:21
Logging.InMemorySink is now owned per-run by BuildContext.LogSink; the static InMemorySink.Instance
becomes a facade over BuildContext.Current, with a lazy ambient fallback for logging outside a run.
ConfigureInMemory wires the sink at the top of the run and WriteErrorsAndWarnings reads it at the
end — both inside the scope — so a build's warnings and errors are discarded with its context
instead of resurfacing in the next in-process invocation.

The FT-1 InMemorySink.Clear() on dispose is dropped: there is no shared sink left to clear. Clear()
itself stays for explicit resets. The sink constructor becomes internal so a context (and a spec)
can create its own. Non-breaking — the public Logging surface is unchanged.
BuildContextSpecs mirrors the FT-4 parameter-service cases for the sink: the facade resolves the
running context's sink, falls back to a stable ambient sink outside a run, and each run gets its own.

Two existing cases assumed a process-wide sink and had to move with the mechanism:
- Dispose_runs_the_per_run_teardown used the shared sink as its witness and fails once dispose stops
  clearing it — it becomes Log_events_do_not_carry_into_the_next_run, asserting the guarantee
  directly (the next run's sink never saw the previous run's events);
- Disposing_a_superseded_context_leaves_the_shared_state_intact drops its sink witness and keeps the
  resolver-config one, since the sink is no longer shared state.

InMemorySinkSpecs now exercises its own instance rather than the singleton, so it no longer needs
the process-global collection or a normalising reset between cases.
@ChrisonSimtian ChrisonSimtian self-assigned this Nov 21, 2026
@ChrisonSimtian ChrisonSimtian added release/Next Targets the next release and removed release/Stable Targets the current/stable release labels Nov 21, 2026
…s over

Host.WriteErrorsAndWarnings replaces Log.Logger with a console-only logger to re-render the run's
warnings. The logger it replaced owns that run's file sinks, and assigning Log.Logger does not
dispose it — so it leaked and kept `build.log` open for the life of the process.

The next in-process run then threw in Logging.DeleteOldLogFiles trying to truncate that file, and
did so silently: the throw lands before Configure has reassigned Log.Logger, so Execute's own
Host.Error call went to an already-disposed logger. The run just returned the error exit code with
no output. Any second run whose predecessor logged a warning hit this.

Dispose the replaced logger. Nothing is lost — from that point the run logs through the console-only
logger regardless, so the file sinks were already out of the picture.
Runs a fixture build end-to-end, twice in one process, and asserts what the de-static work promised:
both runs succeed, the second gets its own context/parameter service/log sink, it opens on an empty
sink, and the static facades inside a run point at that run.

This is what the original FT-9 commit set out to do. Its unit-level assertions have since landed
with the steps they belong to (FT-2 in Fallout-build#451, FT-4 in Fallout-build#452, FT-6 in Fallout-build#453), so what is left here is
the end-to-end case they could not cover — and it immediately found the leaked file-sink logger
fixed in the previous commit. Verified as a real guard: reverting that fix fails 4 of these 5 specs.

Two process-wide inputs are pinned to make a build runnable under a test host — the argument parser
(swapped and restored) and the statically-resolved root directory (asserted to carry the .fallout
marker, since UpdateNotification prompts for input without it). Both are de-statification candidates
in their own right.
@ChrisonSimtian
ChrisonSimtian force-pushed the engine/ft9-reentrancy-harness branch from e26e000 to 565ef40 Compare November 21, 2026 23:46

This branch has not been deployed

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

Labels

bug Something isn't working release/Next Targets the next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Foundation] Epic: Engine de-statification & extension-pipeline formalization (plugin foundation)

1 participant