You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by "juergbi (via GitHub)" <gi...@apache.org> on 2025/07/04 08:32:29 UTC

[PR] Support remote action cache for nested local execution [buildstream]

juergbi opened a new pull request, #2031:
URL: https://github.com/apache/buildstream/pull/2031

   This generalizes the `remote-execution` config section to support using the Remote Execution API while still using local execution, only using the CAS and Action Cache services of the REAPI. I.e., this allows a `remote-execution` config section with `action-cache-service` also if no `execution-service` is configured.
   
   This branch supports a remote action cache with local execution only for nested REAPI clients using the remote execution protocol. Using an action cache (local or remote) also for BuildStream build jobs is not implemented in this branch but is planned for a follow-up.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@buildstream.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support remote action cache for nested local execution [buildstream]

Posted by "abderrahim (via GitHub)" <gi...@apache.org>.
abderrahim commented on code in PR #2031:
URL: https://github.com/apache/buildstream/pull/2031#discussion_r2188277955


##########
src/buildstream/_remote.py:
##########
@@ -72,10 +71,6 @@ def init(self):
             self._initialized = True
 
     def close(self):
-        if self.channel:
-            self.channel.close()
-            self.channel = None
-
         self._initialized = False

Review Comment:
   Is there any value in keeping the `close()` method now? AFAICT, there is no more cleanup to do now that everything goes through buildbox-casd.



##########
requirements/requirements.in:
##########
@@ -4,7 +4,7 @@ Jinja2 >= 2.10
 importlib_metadata >= 3.6; python_version < "3.10"
 packaging
 pluginbase
-protobuf <6.0dev,>=5.26.1
+protobuf <6.0dev,>=5.29

Review Comment:
   Personal preference, but I like to have updating .proto files and updating the grpcio-tools version that generates them in different commits.



##########
src/buildstream/sandbox/_sandboxbuildboxrun.py:
##########
@@ -32,6 +34,27 @@
 # BuildBox-based sandbox implementation.
 #
 class SandboxBuildBoxRun(SandboxREAPI):
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+
+        context = self._get_context()
+        cascache = context.get_cascache()
+
+        re_specs = context.remote_execution_specs
+        if re_specs and re_specs.action_spec and not re_specs.exec_spec:

Review Comment:
   Is there a value in excluding this when we have `re_specs.exec_spec`? IIUC, we can use this sandbox even though remote-execution is configured in code paths that go through `Element._prepare_sandbox()` (which sets allow_remote=False) such as `bst shell`.
   
   Is there a reason to prevent using the action cache in that situation?



##########
src/buildstream/sandbox/_sandboxbuildboxrun.py:
##########
@@ -91,8 +114,10 @@ def _execute_action(self, action, flags):
         casd = cascache.get_casd()
         config = self._get_config()
 
-        if config.remote_apis_socket_path and context.remote_cache_spec:
-            raise SandboxError("'remote-apis-socket' is not currently supported with 'storage-service'.")
+        if config.remote_apis_socket_path and context.remote_cache_spec and not self.re_remote:
+            raise SandboxError(
+                "'remote-apis-socket' is not supported with 'storage-service' without 'action-cache-service'."

Review Comment:
   So IIUC, we now support
   
   * fully local: the buildbox-casd started by buildstream handles everything (storage, execution, action cache)
   * fully remote: the remote execution servers handle everything (cache storage-service could double as storage for remote execution)
   * local with remote action cache: execution is done locally, storage can be either the `cache` storage-service or the `remote-execution` storage-service, action cache has to be configured in `remote-execution`.
   
   Assuming the above is correct, I find that this error message a bit confusing as you can't set the `action-cache-service` in the `cache` configuration.



##########
tests/integration/sandbox.py:
##########
@@ -59,3 +60,24 @@ def test_remote_apis_socket(cli, datafiles):
 
     result = cli.run(project=project, args=["build", element_name])
     assert result.exit_code == 0
+
+
+# Test configuration with remote action cache for nested REAPI.
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
+@pytest.mark.datafiles(DATA_DIR)
+def test_remote_apis_socket_with_action_cache(cli, tmpdir, datafiles):
+    project = str(datafiles)
+    element_name = "sandbox/remote-apis-socket.bst"
+
+    with create_artifact_share(os.path.join(str(tmpdir), "remote")) as share:
+        cli.configure(
+            {
+                "remote-execution": {
+                    "storage-service": {"url": share.repo},
+                    "action-cache-service": {"url": share.repo, "push": True},

Review Comment:
   Could you please add tests for the other possible configurations? (cache storage-service with remote-execution action-cache-service, and both storage services with remote-execution action-cache-service)
   
   Slightly related, considering the case where both the `cache` and `remote-execution` storage services are configured, does this lead to a sensible outcome? (e.g. are blobs downloaded from the remote-execution storage uploaded to the cache storage?)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@buildstream.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support remote action cache for nested local execution [buildstream]

Posted by "abderrahim (via GitHub)" <gi...@apache.org>.
abderrahim merged PR #2031:
URL: https://github.com/apache/buildstream/pull/2031


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@buildstream.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support remote action cache for nested local execution [buildstream]

Posted by "juergbi (via GitHub)" <gi...@apache.org>.
juergbi commented on code in PR #2031:
URL: https://github.com/apache/buildstream/pull/2031#discussion_r2200662256


##########
src/buildstream/sandbox/_sandboxbuildboxrun.py:
##########
@@ -91,8 +114,10 @@ def _execute_action(self, action, flags):
         casd = cascache.get_casd()
         config = self._get_config()
 
-        if config.remote_apis_socket_path and context.remote_cache_spec:
-            raise SandboxError("'remote-apis-socket' is not currently supported with 'storage-service'.")
+        if config.remote_apis_socket_path and context.remote_cache_spec and not self.re_remote:
+            raise SandboxError(
+                "'remote-apis-socket' is not supported with 'storage-service' without 'action-cache-service'."

Review Comment:
   I've adjusted the error message, hope it's clearer now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@buildstream.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support remote action cache for nested local execution [buildstream]

Posted by "juergbi (via GitHub)" <gi...@apache.org>.
juergbi commented on code in PR #2031:
URL: https://github.com/apache/buildstream/pull/2031#discussion_r2200658248


##########
src/buildstream/_remote.py:
##########
@@ -72,10 +71,6 @@ def init(self):
             self._initialized = True
 
     def close(self):
-        if self.channel:
-            self.channel.close()
-            self.channel = None
-
         self._initialized = False

Review Comment:
   I think it's indeed no longer necessary. Removed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@buildstream.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support remote action cache for nested local execution [buildstream]

Posted by "juergbi (via GitHub)" <gi...@apache.org>.
juergbi commented on code in PR #2031:
URL: https://github.com/apache/buildstream/pull/2031#discussion_r2200664152


##########
tests/integration/sandbox.py:
##########
@@ -59,3 +60,24 @@ def test_remote_apis_socket(cli, datafiles):
 
     result = cli.run(project=project, args=["build", element_name])
     assert result.exit_code == 0
+
+
+# Test configuration with remote action cache for nested REAPI.
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
+@pytest.mark.datafiles(DATA_DIR)
+def test_remote_apis_socket_with_action_cache(cli, tmpdir, datafiles):
+    project = str(datafiles)
+    element_name = "sandbox/remote-apis-socket.bst"
+
+    with create_artifact_share(os.path.join(str(tmpdir), "remote")) as share:
+        cli.configure(
+            {
+                "remote-execution": {
+                    "storage-service": {"url": share.repo},
+                    "action-cache-service": {"url": share.repo, "push": True},

Review Comment:
   I've added these configuration tests.
   
   Upload to cache storage-service was missing in case two different CAS remotes are configured. I've added this, reusing code we already had for remote execution.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@buildstream.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support remote action cache for nested local execution [buildstream]

Posted by "juergbi (via GitHub)" <gi...@apache.org>.
juergbi commented on code in PR #2031:
URL: https://github.com/apache/buildstream/pull/2031#discussion_r2200962544


##########
src/buildstream/sandbox/_sandboxbuildboxrun.py:
##########
@@ -148,7 +173,14 @@ def _execute_action(self, action, flags):
                 interactive=(flags & _SandboxFlags.INTERACTIVE),
             )
 
-            return remote_execution_pb2.ActionResult().FromString(result_file.read())
+            action_result = remote_execution_pb2.ActionResult().FromString(result_file.read())
+
+        if self.re_remote and context.remote_execution_specs.storage_spec and context.remote_cache_spec:
+            # This ensures that the outputs are uploaded to the cache storage-service
+            # in case different CAS remotes have been configured in the `cache` and `remote-execution` sections.

Review Comment:
   > Or is it due to the fact that buildbox-run can only take a single instance for both the nested REAPI and where it stores its output? So it will upload its output to the remote-execution CAS as well and we need to transfer it to the cache CAS?
   
   That's exactly the reason. While latest buildbox-run actually supports a separate instance for nested REAPI, this is not currently configurable in BuildStream (but it probably makes sense to add this configuration in a follow-up).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@buildstream.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support remote action cache for nested local execution [buildstream]

Posted by "abderrahim (via GitHub)" <gi...@apache.org>.
abderrahim commented on code in PR #2031:
URL: https://github.com/apache/buildstream/pull/2031#discussion_r2200948853


##########
src/buildstream/sandbox/_sandboxbuildboxrun.py:
##########
@@ -148,7 +173,14 @@ def _execute_action(self, action, flags):
                 interactive=(flags & _SandboxFlags.INTERACTIVE),
             )
 
-            return remote_execution_pb2.ActionResult().FromString(result_file.read())
+            action_result = remote_execution_pb2.ActionResult().FromString(result_file.read())
+
+        if self.re_remote and context.remote_execution_specs.storage_spec and context.remote_cache_spec:
+            # This ensures that the outputs are uploaded to the cache storage-service
+            # in case different CAS remotes have been configured in the `cache` and `remote-execution` sections.

Review Comment:
   I'm having a hard time wrapping my head around this one. Since we're building locally, shouldn't the outputs be uploaded to the cache storage-service by default? Then we only need to upload them to the remote-execution storage if we're also uploading the action?
   
   Or is it due to the fact that buildbox-run can only take a single instance for both the nested REAPI and where it stores its output? So it will upload its output to the remote-execution CAS as well and we need to transfer it to the cache CAS?
   
   I agree this is an exotic configuration, and shouldn't block landing this MR. I just wanted to raise it just in case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@buildstream.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support remote action cache for nested local execution [buildstream]

Posted by "juergbi (via GitHub)" <gi...@apache.org>.
juergbi commented on code in PR #2031:
URL: https://github.com/apache/buildstream/pull/2031#discussion_r2200660210


##########
src/buildstream/sandbox/_sandboxbuildboxrun.py:
##########
@@ -32,6 +34,27 @@
 # BuildBox-based sandbox implementation.
 #
 class SandboxBuildBoxRun(SandboxREAPI):
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+
+        context = self._get_context()
+        cascache = context.get_cascache()
+
+        re_specs = context.remote_execution_specs
+        if re_specs and re_specs.action_spec and not re_specs.exec_spec:

Review Comment:
   When we add action cache support for BuildStream actions, we need to make sure that we're not attempting to cache interactive shells. However, I don't think we need to disable remote execution or action cache access for sandboxed REAPI clients, so I've removed this condition.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@buildstream.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support remote action cache for nested local execution [buildstream]

Posted by "juergbi (via GitHub)" <gi...@apache.org>.
juergbi commented on code in PR #2031:
URL: https://github.com/apache/buildstream/pull/2031#discussion_r2200658757


##########
requirements/requirements.in:
##########
@@ -4,7 +4,7 @@ Jinja2 >= 2.10
 importlib_metadata >= 3.6; python_version < "3.10"
 packaging
 pluginbase
-protobuf <6.0dev,>=5.26.1
+protobuf <6.0dev,>=5.29

Review Comment:
   Makes sense. Split into two commits.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@buildstream.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org