Skip to content

Guard ActionTemplate outputs by the key of the template - #30654

Open
fmeum wants to merge 1 commit into
bazelbuild:masterfrom
fmeum:rewound-action-synchronizer-action-template
Open

Guard ActionTemplate outputs by the key of the template#30654
fmeum wants to merge 1 commit into
bazelbuild:masterfrom
fmeum:rewound-action-synchronizer-action-template

Conversation

@fmeum

@fmeum fmeum commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Description

RemoteRewoundActionSynchronizer keeps a rewound action from preparing for its re-execution while other actions are still consuming its outputs. Both keys were derived from the generating action key of the artifact itself, which is wrong for actions generated by an ActionTemplate: their outputs are TreeFileArtifacts owned by the expansion, whereas consumers depend on the parent tree artifact, which is owned by the template. A rewound expansion action thus acquired a write lock that no consumer would ever lock.

Both sides now derive the key from the outermost tree artifact containing the artifact, so the outputs of an expansion are guarded by the key of the template, which is shared by all tree artifacts a template declares.

Since the actions of a single expansion may form a chain, an action can have an input that is guarded by the very key it holds the write lock of. The locks aren't reentrant, so a rewound action now skips the read lock of that key.

Also keys outputUploadTasks by ActionLookupData instead of by the Action instance, which isn't stable across rewinding for actions generated by an ActionTemplate.

Motivation

Without this, an action that consumes a tree artifact populated by an ActionTemplate can read its files while the expansion action that generated them is being rewound.

Build API Changes

No

Checklist

  • I have added tests for the new use cases (if any).
  • I have updated the documentation (if applicable).

Release Notes

RELNOTES: None

@fmeum
fmeum force-pushed the rewound-action-synchronizer-action-template branch 6 times, most recently from fab692f to 0f4ddc0 Compare August 11, 2026 09:22
Actions generated by an `ActionTemplate` have `TreeFileArtifact`s as
outputs, whose generating action key is that of the expansion action.
Consumers, however, depend on the parent tree artifact and thus lock the
key of the *template*, so a rewound expansion action acquired a write
lock that no consumer ever contended on and could prepare for its
re-execution while its outputs were still being read.

Both the outputs of a rewound action and the inputs of any action are
now mapped to the generating action key of the outermost tree artifact
containing them, which is the template for the outputs of an expansion.
This key is shared by all output trees of a template and is thus still a
single lock per action - the proof of deadlock freedom relies on this.

Since the actions of a single expansion may form a chain, an action can
have an input that is guarded by the very key it holds the write lock
of. As the locks aren't reentrant, a rewound action skips the read lock
of that key.

Also keys `outputUploadTasks` by `ActionLookupData` instead of by the
`Action` instance, which isn't stable across rewinding for actions
generated by an `ActionTemplate`.
@fmeum
fmeum force-pushed the rewound-action-synchronizer-action-template branch from 0f4ddc0 to e03701d Compare August 11, 2026 09:47
@fmeum
fmeum marked this pull request as ready for review August 11, 2026 09:51
@fmeum
fmeum requested a review from a team as a code owner August 11, 2026 09:51
@fmeum
fmeum requested review from coeuvre and justinhorvitz August 11, 2026 09:51
@github-actions github-actions Bot added team-Core Skyframe, bazel query, BEP, options parsing, bazelrc team-Remote-Exec Issues and PRs for the Execution (Remote) team awaiting-review PR is awaiting review from an assigned reviewer labels Aug 11, 2026
@fmeum

fmeum commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author

@justinhorvitz for the new test case in RewindingTestsHelper. It is not specific to Bazel's implementation of rewinding, but if you feel it's not worth having in Blaze, I can move it over to RewindingTest.

@fmeum

fmeum commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author

@bazel-io fork 9.3.0

* <p>The more of them are reading it when the expansion is rewound, the more likely it is that a
* missing mutual exclusion is detected.
*/
private static final int TREE_CONSUMER_COUNT = 8;

@fmeum fmeum Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be reduced to 4 or 3 if it causes issues otherwise.

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

Labels

awaiting-review PR is awaiting review from an assigned reviewer team-Core Skyframe, bazel query, BEP, options parsing, bazelrc team-Remote-Exec Issues and PRs for the Execution (Remote) team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants