Skip to content

Conversation

@brianduff
Copy link

This PR adds a new --experimental_remote_upload_mode flag that controls when Bazel waits for remote cache uploads to complete, similar to --bes_upload_mode.

Motivation

Currently, Bazel blocks at the end of every build waiting for all remote cache uploads to complete. For builds with large outputs, or on slow connections, this can add significant time to the build even though the uploads don't affect build correctness. Users who want faster build completion times should be able to defer this waiting.

Implementation

The flag supports two modes:

  • wait_for_upload_complete (default): Current behavior - block at end of build
  • nowait_for_upload_complete: Return immediately, wait at start of next command

When using nowait_for_upload_complete:

  • The build completes as soon as action execution finishes
  • Uploads continue in the background
  • The next command waits up to 30 seconds for uploads to complete
  • Server shutdown (bazel shutdown) also waits up to 30 seconds
  • Temp files and RPC logs are cleaned up via a future listener after uploads complete

Changes

  • RemoteOptions.java: Add RemoteUploadMode enum and --experimental_remote_upload_mode flag
  • RemoteExecutionService.java: Modify uploadOutputs() and shutdown() to accept upload mode
  • RemoteModule.java: Add cross-invocation state (pendingUploadsFuture), wait logic in beforeCommand(), resource cleanup, and blazeShutdown() handling

Testing

  • Added integration tests in RemoteUploadModeIntegrationTest.java
  • Added unit tests for shutdown(RemoteUploadMode) in RemoteExecutionServiceTest.java
  • Manually verified async uploads work correctly

Closes #14638

@brianduff brianduff requested a review from a team as a code owner December 4, 2025 09:26
@github-actions github-actions bot added team-Remote-Exec Issues and PRs for the Execution (Remote) team awaiting-review PR is awaiting review from an assigned reviewer labels Dec 4, 2025
@brianduff brianduff force-pushed the experimental-remote-upload-mode branch from 0323fc9 to 110d2bc Compare December 4, 2025 09:29
@fmeum fmeum self-requested a review December 4, 2025 09:53
}

@Option(
name = "experimental_remote_upload_mode",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of adding a new flag, how about turning --remote_cache_async into an enum-valued flag with three states? A BoolOrEnumConverter would preserve backwards compatibility.

// Only track futures for async upload modes
final boolean trackUpload =
remoteOptions.experimentalRemoteUploadMode != RemoteUploadMode.WAIT_FOR_UPLOAD_COMPLETE;
final SettableFuture<Void> uploadFuture = trackUpload ? SettableFuture.create() : null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is quite subtle, but I think that Futures and in particular SettableFutures are not the right tool here:

  1. When upload futures are canceled because they take too long, the cancelation should propagate to the actual download futures. But the SettableFutures aren't linked to those in any way, so I don't think that would be the case.
  2. Future cancelation is an immediate operation that doesn't wait for the canceled task to complete. This can be problematic if an upload continues for some time while the uploaded file is already being overwritten by the new invocation.

Instead, we could probably use awaitTermination on the backgroundTaskExecutor and call shutdownNow if it takes too long.

Stopwatch stopwatch = Stopwatch.createStarted();
try {
// Wait up to 30 seconds for uploads from previous invocation to complete
Uninterruptibles.getUninterruptibly(future, 30, SECONDS);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should let the user know what we are waiting for. It should probably also be interruptible to respect Ctrl + C.

Instead of a fixed timeout, perhaps canceling downloads on the first Ctrl + C would be an option? That would be more difficult to implement though and could be done as follow-up work.

@bharadwaj08-one
Copy link

@brianduff Could you please take a look at the failing checks?

@bharadwaj08-one bharadwaj08-one added awaiting-user-response Awaiting a response from the author and removed awaiting-review PR is awaiting review from an assigned reviewer labels Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-user-response Awaiting a response from the author team-Remote-Exec Issues and PRs for the Execution (Remote) team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR: Add a --remote_upload_mode that mirrors the behavior of --bes_upload_mode

3 participants