Skip to content

msbuild: a skip decided on a stale value leaves its writes in doubt (#1037) - #1040

Merged
Smaug123 merged 7 commits into
mainfrom
claude/msbuild-stale-gate-skips-1037
Nov 18, 2026
Merged

Smaug123 merged 7 commits into
mainfrom
claude/msbuild-stale-gate-skips-1037

Conversation

@Smaug123

@Smaug123 Smaug123 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1037.

The defect

A gate that reads a value bound before content the walk could not see (a stale value) raises no diagnostic. A gate reading an undefined or unpinned name does raise one. Every skip path judged "may the real build go the other way?" from that diagnostic, so a skip decided on a stale value counted as decided: the walk committed the value it held, while MSBuild, holding the rewritten value, ran the write the walk skipped. A caller global was also exempt from staleness, though hidden content can take it back with TreatAsLocalProperty and write it.

The fix

Every skip asks whether its gate was decided from certain inputs (directory_build::decided_from_certain_inputs, the primitive #1036 introduced for rejections). Where it was not and the gate reads a stale value:

  • a property's own gate marks the name stale;
  • a <PropertyGroup>'s gate marks each name a child may write;
  • a <Choose>, from the first <When> so decided, marks what MSBuild's alternatives may write. Alternatives are the branches up to the first <When> that holds whatever the uncertain names hold (<Otherwise> only if none does), skipping those certainly false. Each alternative is judged from the state before the <Choose> and in its own order, with an undo log, and the marks are applied once all are judged. This holds on the decided and the undecided path, nested <Choose>s included;
  • an <Import>'s or <ImportGroup>'s gate latches the walk opaque again, since the names an unseen file writes are unknowable. An <ImportGroup> latches only if one of its imports may run;
  • an <Import> whose Project/Sdk reads a stale value latches after it is followed: MSBuild may have imported another file;
  • a child of a group the walk cannot evaluate is ruled out only where its gate fails whatever the uncertain names hold. A gate reading nothing stale keeps the earlier test.

go_stale exempts only reserved names, so caller globals go stale too.

The existing trust machinery carries all of it: the stale channel, latch_walk_opaque, apply_property_provenance. A name the walk holds unbound gets no mark, because after a latch every undefined read is inexact already.

Tests

tests/fsproj_stale_gate_diff.rs is a generator. Each project binds gate names, then imports hidden.props under '$(G.ToUpperInvariant())' == 'X', which the walk cannot decide and MSBuild decides on the global G. The hidden file may rewrite the gate names and may take G back with TreatAsLocalProperty. After it, seven routes gate on those names, each writing an output only it writes:

  • a property's own gate;
  • a property group;
  • <Choose>, with nested choices and in-branch enablement;
  • <Import>;
  • <ImportGroup>;
  • an unsupported group with a gated child;
  • a property-selected import path.

Route gates are decided on certain values a quarter of the time. Every project is evaluated under G ∈ {x, y, z}. What the walk commits, served and through the probe, must equal MSBuild's evaluated table, definedness included (evaluated). Each route must move its own output in MSBuild in some cases and stay committed in others. Every evaluation must decline the gate names, so a walk that saw the hidden file would fail rather than pass vacuously. Generated projects MSBuild rejects fail the test. A pinned test holds the four #1037 shapes and three siblings.

  • On main, every route and all four shapes fail (1,260 violations at the fixed seed).
  • Reverting any one of the eleven fix sites fails the test again.
  • Soaks of 15,000 fresh-seed projects pass.

Manifests

No manifest moved. fsproj_msbuild_corpus_diff, sdk_chain_decline_attribution and every step of tools/ci/project-corpus-gate.sh (the project-corpus resolution differential, restore-cone census, restore-graph and source-doc differentials, assembly sweeps) pass unchanged. In the corpus, a stale gate either never arises or decides nothing the walk was committing, and caller globals going stale after a latch withdraw nothing the gates pin. No compile order or TFM moved.

Review findings declined

  • A duplicate import skipped on a stale gate re-latches (codex rounds 1–6). MSBuild skips a second import of a path it certainly imported already (MSB4011), so the latch over-declines there. The fix needs a set of imports MSBuild certainly made: imports_seen also holds imports the walk followed on doubted or stale routes, so discharging against it would be unsound. The decline is sound. Filed as msbuild: a certain duplicate import skipped on a stale gate need not re-latch #1042.
  • An import followed as a doubted walk would also leave the gate names uncommitted (round 6, P3). The vacuity guard would then pass while grading unpinned rather than stale gates; checking foreign_definitions would close that.

Found in passing (separate issue)

An imported file's TreatAsLocalProperty opt-out lasts past the import in MSBuild, but the walk re-protects the global when the import returns. So a later plain <G>other</G> in the entry project is dropped and the walk commits the imported value: a certain-implies-exact violation on main, with no stale gate involved. Filed as #1041.

🤖 Generated with Claude Code

Smaug123 and others added 7 commits November 18, 2026 18:55
…1037)

A gate that reads a value bound before content the walk could not see
raises no diagnostic, unlike one reading an undefined or unpinned name, so
every skip path took such a gate as decided: the walk committed the value it
held where MSBuild, holding the rewritten value, ran the write it skipped.
Each skip now asks whether the gate was decided from certain inputs
(`directory_build::decided_from_certain_inputs`), and where it was not and
it reads a stale value:

- a property's own gate marks the name stale;
- a property group's marks every name a child may write;
- a `<Choose>` marks every name written in a branch MSBuild may take
  instead, from the first `<When>` so decided, on both the decided and the
  undecided path;
- an `<Import>`'s and an `<ImportGroup>`'s latch the walk opaque again,
  since the names the unseen file writes are unknowable;
- a child of a group the walk cannot evaluate is ruled out only by a gate
  decided from certain inputs.

A caller global no longer stays fresh across content the walk could not
see: a file that names it in its project's `TreatAsLocalProperty` may write
it. Only reserved names do.

`tests/fsproj_stale_gate_diff.rs` generates a stale gate on every route
(each under three globals, one taking the hidden file) and holds what the
walk commits, served and probed, to MSBuild; it pins the four shapes of
#1037 beside three more. On main it fails on every route and every shape;
reverting any one site of this change fails it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A skipped `<Choose>` branch marks a write only where neither its own gate
nor its group's (nor a nested `<When>`'s) rules it out whatever the
uncertain names hold, and the scan of the branches MSBuild may take
instead stops at the first `<When>` whose gate holds whatever they hold,
reaching `<Otherwise>` only if none does. A stale `<ImportGroup>` gate
latches only when one of its imports may run. A property's own gate is
judged from certain inputs only when it reads a stale value, which no gate
does before the walk passes content it could not see.

The differential now gives each route an output only it writes, so a
route's census counts what the route itself moves (and fails with every
route's XML discarded); routes take gates decided on certain values a
quarter of the time, so the walk must go on committing what they leave
alone; and `<Choose>` and `<ImportGroup>` children carry gates decided on
certain values too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The branches MSBuild may take instead of the walk's are alternatives: it
takes at most one. Each is now judged from the state before any of them, in
its own order (a write in a branch may enable a later gate in it), and what
any may write is marked once all are judged. A nested `<Choose>` takes the
same first-match rule as the outer one: stop at the first `<When>` that
holds whatever the uncertain names hold, `<Otherwise>` only if none does.

A child of a group the walk cannot evaluate keeps its earlier test, and
adds the certain-inputs one only for a gate that reads a stale value, so a
project with no hidden content judges it as before. A stale
`<ImportGroup>` gate probes its imports' gates only once it is known stale.

The differential's `<Choose>` branches now nest, and now and then write a
name before a write gated on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An `<Import>` whose `Project` (or `Sdk`) reads a value content the walk
could not see may have rewritten names another file in the real build: what
the walk followed, MSBuild may not have, and what MSBuild followed, the walk
did not see. The walk now latches opaque again once it has followed one, as
for an import it skips on a stale gate. That covers a name a stale-gated
skip left in doubt too, since the skip marks it stale.

A stale `<Choose>`'s alternatives are judged before the walk's arm is
walked, from the state before the `<Choose>`, and marked after it, so the
walk's arm no longer sees the effects of arms exclusive of it. Each
alternative's marks are undone from a log of the entries it touched rather
than by copying the table, and within a group each write is judged after
the ones before it are marked.

A child of a stale-skipped group is ruled out wherever its gate fails
whatever the uncertain names hold (`false And …` short-circuits), the
earlier exactness test still applying where the gate reads nothing stale.

The differential gains an import-path route: `Side` bound before the
hidden file, or after it and rewritten on a stale gate, selecting between a
file that writes nothing and one that writes the route's output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…only (#1037)

On a `<Choose>` the walk could not decide, the arms before the undecided
gate (from the first decided on a stale value) are judged from the state
before the `<Choose>`, ahead of the undecided arms' marks, and marked with
them: MSBuild takes one arm, so a later arm's writes cannot enable an
earlier arm's gate.

A skipped alternative's undo log records each touched name's trust once,
not its whole entry: marking leaves every value alone.

The differential reads MSBuild's evaluated table (`evaluated`), which tells
an undefined name from one defined empty, and holds the walk's `Unset` to
the former.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The differential asserts in every evaluation that the walk commits neither
gate name, which only content before the hidden import binds: a walk that
saw the hidden file would grade no stale gate, and pass. A generated
project MSBuild rejects now fails the test rather than dropping out of it.

A skipped alternative marks each name once and reports it once, however
often its branches (or nested ones) write it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…set (#1037)

A stale gate exists only once the walk has passed content it could not see,
after which every undefined read is inexact already. A skipped write to a
name the walk holds unbound therefore needs no stale mark, and making one
turned the read's verdict from `UnsetInexact` (no value held) into
`Untrusted` (a value held but doubted), which readers treat differently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Smaug123
Smaug123 enabled auto-merge November 18, 2026 21:50
@Smaug123
Smaug123 added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 90e320a Nov 18, 2026
20 checks passed
@Smaug123
Smaug123 deleted the claude/msbuild-stale-gate-skips-1037 branch November 18, 2026 22:26
Smaug123 added a commit that referenced this pull request Nov 18, 2026
The calls #1040 added still passed a source string and a path. The
differential's projects are written to disk at a canonical path, so they are
read back through `ProjectFile::read`; the unit tests' documents are
buffers at a full path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

msbuild: writes skipped on a gate decided from stale values are published as exact (certain-implies-exact violations)

1 participant