Skip to content

Make shared composite state thread-safe for background steps - #4862

Open
erezcor wants to merge 1 commit into
actions:mainfrom
erezcor:fix-composite-shared-state-race
Open

erezcor wants to merge 1 commit into
actions:mainfrom
erezcor:fix-composite-shared-state-race

Conversation

@erezcor

@erezcor erezcor commented Nov 15, 2026

Copy link
Copy Markdown

Fixes #4789

Background and parallel: steps run composite actions on several threads, but some job-level collections those steps write are plain Dictionary, HashSet and Stack. When two composites write at once, the collection is corrupted, and later reads fail unrelated steps and post steps too (Operations that change non-concurrent collections must have exclusive access…, Unable to process file command 'state' successfully.).

  • EmbeddedIntraActionState is now a ConcurrentDictionary. GITHUB_STATE and save-state add a step's state with GetOrAdd.
  • RegisterPostJobStep updates PostJobSteps, StepsWithPostRegistered and EmbeddedStepsWithPostRegistered under a lock on the job context.
  • ActionManager's composite caches (CachedEmbeddedStepIds, CachedEmbeddedPreSteps, CachedEmbeddedPostSteps, CachedActionContainers) are now ConcurrentDictionary. Every background step that uses a local composite prepares and loads it on its own thread.

There is no feature flag because the change only adds synchronization and doesn't change behavior.

Tests: two L0 tests in ExecutionContextL0 register post steps and save state from 256 background steps at once. Against main they failed in 6 of 6 and 4 of 6 local runs, with lost entries, KeyNotFoundException and IndexOutOfRangeException. With this change they passed in 10 of 10 runs.

Not covered here
  • The Collection was modified; enumeration operation may not execute. failures in the issue have another cause. On released runners, every embedded step shallow-copies the job-level github context (CompositeActionHandler) on its background thread, while the main thread keeps setting github.action on that same object for each step it queues. Fix GitHub context inheritance in embedded execution contexts #4799 fixes this behind actions_fix_embedded_github_context, and v2.338.2 doesn't include it yet, so this PR leaves it alone.
  • Embedded steps of a background step write GITHUB_ENV and GITHUB_PATH straight to Global.EnvironmentVariables and Global.PrependPath. Only the background step's own commands are deferred. Other threads enumerate those collections when they set up a step. Deferring them, or synchronizing them, changes behavior, so it needs its own decision.

Background and parallel steps write the job context's embedded action
state, post step registrations and ActionManager's composite caches
from several threads. Concurrent writes corrupted these collections
and failed unrelated steps.

Fixes actions#4789

Co-Authored-By: Claude <[email protected]>
@erezcor
erezcor marked this pull request as ready for review November 15, 2026 18:31
@erezcor
erezcor requested a review from a team as a code owner November 15, 2026 18:31
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.

Parallel composite actions race on shared runner state

1 participant