feat(worker): execute remote action specs from the CAS
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 6s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 6s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s
VoidBuildSystem CI / fuzz-clang (push) Failing after 4s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 57s

This commit is contained in:
faumaray committed 2026-12-05 13:10:18 +03:00
1 parent 9d7c801e2d
commit af2be817a5
6 files changed
+278 -7

No files matched your search

+2
View File
@@ -362,6 +362,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B
- **Wave 134 (CDash Reporting)**: added `Void::Build::Report` (`src/Report/Cdash.cpp`) with CTest-compatible `Test.xml` rendering and multipart submission to `<cdash>/submit.php?project=...`; `vbs test` gained `--cdash URL`, `--cdash-project`, `--cdash-build` and `--cdash-output FILE`. The upload uses Void::Net when linked and a POSIX HTTP/1.1 fallback otherwise. `RegistryTests.cdash_test_report_output_and_submission` captures the submission with a loopback server and checks the XML and multipart fields.
- **Wave 135 (Remote Action Execution)**: `vbs worker --queue` now executes action specs fetched from the CAS when an action is not built locally - it downloads the declared input blobs (verified), materializes them, runs `command` in `working_directory` (bounded by `--exec-timeout`, default 600 s), stores the declared `output_paths` as CAS blobs, and submits the result record. `RegistryTests.worker_executes_remote_action_spec` seeds a spec (`cat input.txt > output.txt`) and verifies the local output, the CAS record (`exit_code 0`) and the uploaded output blob.
## Remaining future scope
- **Superiority plan ([22-superiority-and-gaps.md](../roadmap/22-superiority-and-gaps.md), 2026-12-05)**: revised platform strategy - **macOS deferred**, **Windows via MinGW-w64 cross-compilation + Wine execution** (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`, `dev cpp-gcc -p wine64`), native MSVC deferred; plus packaging parity (ZIP/DEB/RPM), IDE ecosystem, migration tooling, test-runner parity, benchmarks, CI runners, and remote execution in prioritized order.
+1
View File
@@ -135,4 +135,5 @@ Base HEAD: `fe0d1a6`
| Wave 132 (Test labels, resource locks, parallel tests) | `.label()`/`.resource()` SDK, `--label` filter, parallel test runner with exclusive resources | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; E2E passes, full CTest 8/8) | `include/Void/Build.hpp`, `sdk/Build.cpp`, `src/Main.cpp`, `src/Graph/Graph.cpp`, `tests/FullV1Tests.cpp`, docs |
| Wave 133 (CTest-style fixtures) | `.fixture_setup/required/cleanup` SDK; runner pulls in helpers, orders setup->users->cleanup, skips dependents on failed setup | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; E2E passes, full CTest 8/8) | `include/Void/Build.hpp`, `sdk/Build.cpp`, `src/Main.cpp`, `src/Graph/Graph.cpp`, `tests/FullV1Tests.cpp`, docs |
| Wave 134 (CDash reporting) | `Report::Cdash` Test.xml + multipart submission; `vbs test --cdash/--cdash-project/--cdash-build/--cdash-output` | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; E2E captures the submission, full CTest 8/8) | `src/Report/Cdash.cpp`, `include/Void/Build/Report/Cdash.hpp`, `src/Main.cpp`, `tests/RegistryTests.cpp`, docs |
| Wave 135 (Remote action execution) | Worker fetches input blobs, executes the CAS action spec, stores outputs and submits the result; `--exec-timeout` | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; E2E passes, full CTest 8/8) | `src/Main.cpp`, `tests/RegistryTests.cpp`, docs |
| Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) |
+11
View File
@@ -1776,6 +1776,17 @@ VOID_INCLUDE_DIR=/tmp/opencode/vl-pin/include dev cpp -c bash fuzz/run.sh 30
embedded XML), and the written report contains both a passed and a failed test.
- Full CTest: **8 / 8 passed** in 305.48 s.
## Remote Action Execution (GCC 16.2, pin `0002e74`)
- `vbs worker --queue` leases an action, fetches its record from the CAS, and when the record
carries an execution spec (`command`, `working_directory`, `inputs`, `output_paths`) it
downloads and verifies the input blobs, materializes them, runs the command (timeout
`--exec-timeout`, default 600 s), stores the outputs and submits the result.
- `RegistryTests.worker_executes_remote_action_spec` **passed** (434 ms): a seeded spec
`cat input.txt > output.txt` produced `output.txt` locally, the CAS record contains
`output.txt` and `"exit_code":0`, and the output blob is retrievable with the exact bytes.
- Full CTest: **8 / 8 passed** in 301.38 s.
## Limits and Unrun Checks
1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified).
+1 -1
View File
@@ -83,7 +83,7 @@ Concrete work this implies:
6. Test-runner parity.
7. Benchmarks against CMake/Meson/build2 on documented fixtures (including 10k-target scaling).
8. CI on real runners, sanitizer jobs (**sanitizer build run done**), parser fuzzing (**deterministic mutation harness and a Clang/libFuzzer target done**).
9. Remote execution workers (**registry-side worker/lease/result protocol and the `vbs worker` client done**; distributed scheduling remains).
9. Remote execution workers (**registry worker/lease/result protocol, queue, and remote action execution done**; multi-worker orchestration remains).
## 6. Observed baseline (2026-12-05, x86_64, GCC 16.2, Debug, `benchmarks/compare.sh 20`)
+172 -6
View File
@@ -1694,6 +1694,7 @@ struct WorkerCmdOptions {
std::optional<std::string> build_arg;
std::string token_env{"VBS_REGISTRY_TOKEN"};
std::string lease_seconds_arg{"60"};
std::string exec_timeout_arg{"600"};
};
int execute_worker_command(const WorkerCmdOptions &opts) {
@@ -1710,6 +1711,12 @@ int execute_worker_command(const WorkerCmdOptions &opts) {
<< "'\n";
return 2;
}
int exec_timeout_seconds = 600;
if (!Void::Str::to_int(opts.exec_timeout_arg, exec_timeout_seconds) ||
exec_timeout_seconds <= 0 || exec_timeout_seconds > 86400) {
std::cerr << "vbs worker: invalid --exec-timeout value '" << opts.exec_timeout_arg << "'\n";
return 2;
}
const std::string registry = *opts.registry_arg;
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
@@ -1736,6 +1743,157 @@ int execute_worker_command(const WorkerCmdOptions &opts) {
remote.bearer_token = auth.bearer_token;
state->configure_remote_cache(remote);
// Executes an action spec fetched from the CAS (command + inputs + output paths) and
// returns the resulting record JSON, or nullopt when there is no executable spec.
const auto execute_remote_action =
[&](const Package::LeasedAction &leased) -> std::optional<std::string> {
auto remote_json = state->fetch_remote_action(leased.action_key);
if (!remote_json) {
Void::Log::warn("Worker", "Fetching action spec {}: {}", leased.action_key,
remote_json.error().message());
return std::nullopt;
}
if (!remote_json->has_value()) {
return std::nullopt;
}
auto parsed = Void::Json::Strict::parse(**remote_json);
const auto *spec =
parsed ? std::get_if<Void::Json::Strict::Value::Object>(&parsed->value) : nullptr;
if (spec == nullptr) {
return std::nullopt;
}
const Void::Json::Strict::Value::Array *command = nullptr;
if (const auto command_it = spec->find("command"); command_it != spec->end()) {
command = std::get_if<Void::Json::Strict::Value::Array>(&command_it->second.value);
}
if (command == nullptr || command->empty()) {
return std::nullopt; // Not an executable action spec.
}
std::vector<std::string> argv;
for (const auto &entry : *command) {
const auto *arg = std::get_if<std::string>(&entry.value);
if (arg == nullptr) {
return std::nullopt;
}
argv.push_back(*arg);
}
std::filesystem::path working_directory = project_root;
if (const auto wd_it = spec->find("working_directory"); wd_it != spec->end()) {
if (const auto *wd = std::get_if<std::string>(&wd_it->second.value)) {
working_directory = std::filesystem::path{*wd};
}
}
std::error_code wd_ec;
std::filesystem::create_directories(working_directory, wd_ec);
if (const auto inputs_it = spec->find("inputs"); inputs_it != spec->end()) {
const auto *inputs =
std::get_if<Void::Json::Strict::Value::Object>(&inputs_it->second.value);
if (inputs != nullptr) {
for (const auto &[path, ref] : *inputs) {
const auto *ref_object =
std::get_if<Void::Json::Strict::Value::Object>(&ref.value);
if (ref_object == nullptr) {
continue;
}
const std::string *sha = nullptr;
if (const auto sha_it = ref_object->find("sha256");
sha_it != ref_object->end()) {
sha = std::get_if<std::string>(&sha_it->second.value);
}
if (sha == nullptr) {
continue;
}
auto present = state->ensure_remote_blob(*sha);
if (!present) {
std::cerr << "vbs worker: fetching input blob " << *sha << ": "
<< present.error().message() << '\n';
return std::nullopt;
}
if (!*present) {
std::cerr << "vbs worker: input blob " << *sha
<< " is not available in the CAS\n";
return std::nullopt;
}
State::BlobRef blob_ref;
blob_ref.sha256 = *sha;
if (const auto size_it = ref_object->find("size");
size_it != ref_object->end()) {
if (const auto *size = std::get_if<std::int64_t>(&size_it->second.value)) {
blob_ref.size = static_cast<std::uint64_t>(*size);
}
}
if (const auto mode_it = ref_object->find("mode");
mode_it != ref_object->end()) {
if (const auto *mode = std::get_if<std::int64_t>(&mode_it->second.value)) {
blob_ref.mode = static_cast<std::uint32_t>(*mode);
}
}
const auto destination = working_directory / path;
std::filesystem::create_directories(destination.parent_path(), wd_ec);
if (auto materialized = state->materialize_blob(blob_ref, destination);
!materialized) {
std::cerr << "vbs worker: materializing '" << path
<< "': " << materialized.error().message() << '\n';
return std::nullopt;
}
}
}
}
Void::Log::info("Worker", "Executing action {} ({} argv, timeout {}s)...",
leased.action_key, argv.size(), exec_timeout_seconds);
Platform::ProcessRequest exec;
exec.executable = argv.front();
exec.arguments.assign(argv.begin() + 1, argv.end());
exec.working_directory = working_directory;
exec.timeout = std::chrono::seconds{exec_timeout_seconds};
auto executed = Platform::run_supervised(exec);
if (!executed || !executed->succeeded()) {
std::cerr << "vbs worker: action " << leased.action_key << " failed";
if (executed) {
std::cerr << " (exit " << executed->exit_code << ")\n";
if (!executed->stderr_data.empty()) {
std::cerr << executed->stderr_data << '\n';
}
} else {
std::cerr << ": " << executed.error().message() << '\n';
}
return std::nullopt;
}
std::string outputs;
bool first = true;
if (const auto paths_it = spec->find("output_paths"); paths_it != spec->end()) {
const auto *paths =
std::get_if<Void::Json::Strict::Value::Array>(&paths_it->second.value);
if (paths != nullptr) {
for (const auto &entry : *paths) {
const auto *path = std::get_if<std::string>(&entry.value);
if (path == nullptr) {
continue;
}
auto blob = state->store_blob_from_file(working_directory / *path);
if (!blob) {
std::cerr << "vbs worker: storing output '" << *path
<< "': " << blob.error().message() << '\n';
return std::nullopt;
}
if (!first) {
outputs += ',';
}
first = false;
outputs += Util::json_quote(*path) +
std::format(":{{\"sha256\":{},\"size\":{},\"mode\":{}}}",
Util::json_quote(blob->sha256), blob->size, blob->mode);
}
}
}
return std::format(
"{{\"schema_version\":1,\"action_key\":{},\"exit_code\":{},\"outputs\":{{{}}}}}\n",
Util::json_quote(leased.action_key), executed->exit_code, outputs);
};
// Publishes the record's output blobs and the record itself, then reports the result.
const auto process_leased = [&](const Package::LeasedAction &leased) -> int {
const std::string &action_key = leased.action_key;
@@ -1748,14 +1906,20 @@ int execute_worker_command(const WorkerCmdOptions &opts) {
}
record_text = *file_text;
} else {
// Continuous mode: the action must already be built locally.
// Continuous mode: use the local record when the action was built here, otherwise
// execute the action spec fetched from the CAS.
auto exported = state->export_action_record_json(action_key);
if (!exported) {
Void::Log::warn("Worker", "Skipping {}: {}", action_key,
exported.error().message());
return 0;
auto executed = execute_remote_action(leased);
if (!executed) {
Void::Log::warn("Worker", "Skipping {}: {}", action_key,
exported.error().message());
return 0;
}
record_text = std::move(*executed);
} else {
record_text = *exported;
}
record_text = *exported;
}
auto record_json = Void::Json::Strict::parse(record_text);
@@ -3608,7 +3772,9 @@ int main(int argc, char **argv) {
.option_default("--token-env", "", "Environment variable holding bearer token",
worker_opts.token_env, "VBS_REGISTRY_TOKEN")
.option_default("--lease-seconds", "", "Lease TTL in seconds (1..3600)",
worker_opts.lease_seconds_arg, "60");
worker_opts.lease_seconds_arg, "60")
.option_default("--exec-timeout", "", "Remote action timeout in seconds (1..86400)",
worker_opts.exec_timeout_arg, "600");
add_log_flags(worker_cmd);
auto &migrate_cmd = root.subcommand(
+91
View File
@@ -2350,3 +2350,94 @@ void build(Void::Build::Project &p) {
}
server.stop();
}
// `vbs worker --queue` executes a remotely supplied action spec: it downloads the input blobs
// from the CAS, runs the command, stores the outputs and submits the result.
VOID_TEST(RegistryTests, worker_executes_remote_action_spec) {
const auto vbs_bin = locate_vbs_binary();
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
return;
}
Void::FileSystem::TempDir tmp{"vbs_remote_exec_"};
RegistryConfig cfg;
cfg.data_dir = tmp / "reg_data";
cfg.bind_address = "127.0.0.1";
cfg.port = 0;
cfg.bootstrap_admin_user = "admin";
cfg.bootstrap_admin_password = "admin_pw";
auto svc = RegistryService::open(cfg);
Void::Testing::expect(svc.has_value());
if (!svc) {
return;
}
Void::Testing::expect((*svc)->create_user("rex_pub", "rex_pass", Role::Publisher).has_value());
auto tok = (*svc)->create_token("rex_pub", "rex", {"read", "publish"});
Void::Testing::expect(tok.has_value());
if (!tok) {
return;
}
Void::Testing::expect((*svc)->start_http().has_value());
const auto port = (*svc)->bound_port();
const std::string reg_url = "http://127.0.0.1:" + std::to_string(port);
const std::map<std::string, std::string, std::less<>> auth{{"Authorization", "Bearer " + *tok}};
const auto workdir = tmp / "workdir";
std::filesystem::create_directories(workdir);
const std::string input = "REMOTE_INPUT\n";
const std::string input_sha = Util::sha256_hex(input);
auto blob_put = send_loopback_http(port, "PUT", "/api/v1/cas/blobs/" + input_sha, auth, input);
Void::Testing::expect(blob_put.has_value() && blob_put->status == 201);
const std::string action_key = Util::sha256_hex("remote-exec-action");
const std::string spec = "{\"schema_version\":1,\"action_key\":\"" + action_key +
"\",\"command\":[\"/bin/sh\",\"-c\",\"cat input.txt > output.txt\"],"
"\"working_directory\":\"" +
workdir.string() + "\",\"inputs\":{\"input.txt\":{\"sha256\":\"" +
input_sha + "\",\"size\":" + std::to_string(input.size()) +
",\"mode\":420}},\"output_paths\":[\"output.txt\"]}";
auto record_put =
send_loopback_http(port, "PUT", "/api/v1/cas/actions/" + action_key, auth, spec);
Void::Testing::expect(record_put.has_value() && record_put->status == 201);
auto enqueued = send_loopback_http(port, "POST", "/api/v1/queue", auth,
"{\"action_keys\":[\"" + action_key + "\"]}");
Void::Testing::expect(enqueued.has_value() && enqueued->status == 200);
Platform::ProcessRequest worker;
worker.executable = vbs_bin;
worker.arguments = {"worker",
"--registry",
reg_url,
"--queue",
"--once",
"--build-dir",
(tmp / "build").string()};
worker.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
worker.timeout = std::chrono::seconds{120};
auto worker_res = Platform::run_supervised(worker);
Void::Testing::expect_eq(
worker_res ? (worker_res->succeeded() ? std::string{}
: (worker_res->stdout_data + worker_res->stderr_data))
: worker_res.error().message(),
std::string{});
// The command ran locally and produced the declared output.
auto local_output = Void::FileSystem::read_file(workdir / "output.txt");
Void::Testing::require(local_output.has_value());
Void::Testing::expect_eq(*local_output, input);
// The result record and output blob are now in the registry CAS.
auto cas_record = send_loopback_http(port, "GET", "/api/v1/cas/actions/" + action_key, auth);
Void::Testing::expect(cas_record.has_value() && cas_record->status == 200);
if (cas_record) {
Void::Testing::expect(cas_record->body.find("output.txt") != std::string::npos);
Void::Testing::expect(cas_record->body.find("\"exit_code\":0") != std::string::npos);
}
const std::string output_sha = Util::sha256_hex(input);
auto cas_blob = send_loopback_http(port, "GET", "/api/v1/cas/blobs/" + output_sha, auth);
Void::Testing::expect(cas_blob.has_value() && cas_blob->status == 200);
if (cas_blob) {
Void::Testing::expect_eq(cas_blob->body, input);
}
(*svc)->stop_http();
}