Skip to content

Rebuild the snapshot when bin/ or lib/ has uncommitted edits - #71

Closed
DenisovAV wants to merge 1 commit into
devfrom
fix/snapshot-staleness-on-uncommitted-edits
Closed

Rebuild the snapshot when bin/ or lib/ has uncommitted edits#71
DenisovAV wants to merge 1 commit into
devfrom
fix/snapshot-staleness-on-uncommitted-edits

Conversation

@DenisovAV

Copy link
Copy Markdown
Contributor

Editing the tool and re-running it silently executes the previous snapshot.

tool_revision() returns the git HEAD SHA when .git is present, and bin/cache/flutter-tvos.stamp holds the revision from the last successful compile. An uncommitted edit does not move HEAD, so the two match, the recompile is skipped, and the old snapshot runs. Nothing is printed. The file-hashing branch of tool_revision() would catch it, but it only runs when there is no .git — i.e. never during development.

Why not just always hash

That is the obviously correct fix, and it is what the fallback branch does. Measured here: 52 files under bin/ and lib/, ~0.61s per invocation. Paying that on every flutter-tvos command is presumably why the SHA shortcut exists in the first place.

An mtime probe answers the same question for ~9ms-print -quit stops at the first file newer than the stamp, and the stamp is rewritten after every successful compile, so it is a reliable "we have already built this state" marker. That is the same shape as the "$ROOT_DIR/pubspec.yaml" -nt "$stamp_path" check directly above it, so it fits the file rather than introducing a new mechanism.

Verified against a real built snapshot

step with the probe unpatched
warm the snapshot compiles
run again, no edits no recompile
touch lib/tvos_plugins.dart, run recompiles no recompile
run again no recompile

The third row is the bug: same edit, same command, and on the unpatched script the tool keeps running the stale binary.

Found while working on the 3.32.8 line — a source change appeared to have no effect, which cost a debugging cycle chasing the wrong thing.

`tool_revision` returns the git HEAD SHA in a checkout, and the stamp holds the
revision from the last successful compile. HEAD does not move for an
uncommitted edit, so the two match and the snapshot is reused: editing the tool
and re-running it silently executes the previous build. The file-hashing branch
of `tool_revision` would catch it, but it only runs when there is no `.git`.

Always hashing instead of taking the SHA shortcut is correct but costs ~0.6s on
every invocation (52 files under bin/ and lib/), which is presumably why the
shortcut exists. An mtime probe answers the same question in ~9ms: `-print
-quit` stops at the first file newer than the stamp, and the stamp is rewritten
after every successful compile. Same shape as the `pubspec.yaml -nt` check
directly above it.

Verified against the built snapshot: with the probe, a warm run does not
recompile, `touch lib/tvos_plugins.dart` makes the next run recompile, and the
run after that does not. On the unpatched script the same edit produces no
recompile at all.
@DenisovAV

Copy link
Copy Markdown
Contributor Author

Folded into #70 instead — one PR rather than three. The change is unrelated to the 3.32.8 port, but it is one hunk and not worth its own review round.

@DenisovAV DenisovAV closed this Aug 21, 2026
@DenisovAV
DenisovAV deleted the fix/snapshot-staleness-on-uncommitted-edits branch August 21, 2026 06:02
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.

1 participant