Skip to content

Release shared transform results after failed updates - #2244

Merged
robhogan merged 2 commits into
mainfrom
robhogan/release-failed-update-results
Nov 19, 2026
Merged

robhogan merged 2 commits into
mainfrom
robhogan/release-failed-update-results

Conversation

@robhogan

@robhogan robhogan commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

With transformer.unstable_shareTransformResults, a shared result is dropped once no graph holds it, but only paths that a graph commits get released. A live graph's failed update rolls back, so the graph never holds the modules that update transformed for the first time, and nothing releases them.

flowchart TD
  A["Edit: entry.js imports new-with-bad-import.js"] --> B["Update transforms new-with-bad-import.js and keeps the result in memory"]
  B --> C["missing.js can't be resolved, so the update fails and the graph rolls back without new-with-bad-import.js"]
  C --> D["Next edit removes the import from entry.js, and the update succeeds"]
  D -->|main| E["The result stays in memory, because only modules a graph held get released"]
  D -->|This PR| F["The graph releases what its failed update transformed, so the result is dropped unless another graph uses it"]
Loading

This change

DeltaBundler now records the paths each live graph transforms, and releases the ones it doesn't hold once the graph commits an update or ends. A failed update still releases nothing, so its results stay shared with the graph's retries, and with other graphs hitting the same error, while the error lasts.

The cost is one Set insertion per module that an update transforms, and nothing with sharing off.

Graphs that DeltaBundler never registers, ie from getDependencies or a failed first build, still don't release what they add, which keeps prepended scripts shared.

Changelog: Internal

Test plan

New unit tests.

E2E (AI-driven): an IncrementalBundler with sharing on, watching a fixture, ran the edits in the diagram. Building a graph of the new file afterwards read it from the cache store once with this PR, and not at all on main, where the shared result was still held.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 17, 2026
@robhogan
robhogan added this pull request to stack #2245 November 17, 2026 19:13
Base automatically changed from robhogan/share-transform-results to main November 17, 2026 19:18
With `transformer.unstable_shareTransformResults`, `Transformer` drops a shared result once no graph holds it, but only paths that a graph commits get released. A live graph's failed update rolls back, so the graph never holds the modules that update transformed for the first time, and nothing releases them. Eg an edit imports a new file whose own import fails to resolve, then the next edit drops the import: the new file's result stays in memory until something transforms that file again.

This PR has `DeltaBundler` record the paths each live graph transforms. A failed update still releases nothing, so what it transformed stays shared with the graph's retries (and with other graphs hitting the same error) while the error persists. Once the graph next commits an update, or ends, it releases the recorded paths it doesn't hold, which drops their results unless another graph holds them. The cost is one `Set` insertion per module that an update transforms, and nothing with sharing off.

Graphs that `DeltaBundler` never registers, ie from `getDependencies` or a failed first build, still don't release what they add, which keeps prepended scripts shared.

Changelog: Internal

Test plan:

New unit tests.

E2E (AI-driven): an `IncrementalBundler` with sharing on, watching a fixture. An edit imported a new file that failed to resolve its own import, so the update failed. A second edit dropped the import and the update succeeded. Building a graph of the new file then read its result from the cache store once with this PR, and not at all before it, because the shared result was still held.
@robhogan
robhogan force-pushed the robhogan/release-failed-update-results branch from 2d5e1a4 to 32bb61f Compare November 17, 2026 19:18
@robhogan
robhogan marked this pull request as ready for review November 17, 2026 19:41
@robhogan
robhogan requested review from huntie and vzaidman November 17, 2026 19:44
@github-actions

Copy link
Copy Markdown

Metro review: Looks good

Risk: low · Commit: 32bb61f · 5 commands run

With transformer.unstable_shareTransformResults on, DeltaBundler now records which paths each live graph transforms. It releases the ones the graph doesn't hold when the graph next commits an update or ends, so results from a failed update are no longer kept for good. I ran the PR's scenario end to end on base and head: on base the shared result for the file added by the failed update stays after the fix and after endGraph, and on head it's dropped. The change only applies when sharing is on, and its documented limits (first builds that fail, getDependencies) match the code.

No findings.

Verified
  • ✅ yarn jest --no-watchman packages/metro/src/DeltaBundler/__tests__/DeltaBundler-test.js packages/metro/src/DeltaBundler/__tests__/SharedTransformResults-test.js — 21 tests, including the two new failed-update release tests
  • ✅ yarn typecheck
  • ✅ yarn eslint packages/metro/src/DeltaBundler.js packages/metro/src/DeltaBundler/SharedTransformResults.js packages/metro/src/DeltaBundler/__tests__/DeltaBundler-test.js
  • ✅ node e2e/failed-update.js <base-worktree> — Real IncrementalBundler with watch and sharing on. Initial build has 3 shared entries, the failed update (entry imports new.js, which imports a missing file) makes 4, there are still 4 after the fix commits, and 3 after endGraph: new.js's result is retained.
  • ✅ node e2e/failed-update.js <head worktree> — Same steps: 3, then 4 after the failure, then 3 after the fix commits and 2 after endGraph. new.js's result is released, as the PR claims.

Not run: No benchmark. The extra work is one Set.add per transform call, plus a filter over the paths an update transformed, and only when sharing is on. That is negligible next to a transform's cache lookup, and nothing changes with sharing off. I didn't try to reproduce one narrow race in a live run: a path recorded while its transform is still in flight, from orphaned sibling traversals of a failed update, could be taken and released before that result settles, and would then stay. Windows behavior wasn't checked, but the change is platform-neutral.

Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call.

@robhogan
robhogan merged commit c7b487e into main Nov 19, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants