diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index a412188..8542a59 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -346,6 +346,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - **Wave 126 (VoidLibrary Test Wiring)**: the `build-vbs` branch now declares per-module package tests (`tests/package/Only/main.cpp` → `void__tests`) and its CI runs the full `vbs test` instead of a single smoke target. Verified in the clone: 156 actions, and the core/algorithms/crypto/sqlite/unicode/… test binaries all PASSED with exit 0. +- **Wave 127 (Continuous Worker Loop)**: `vbs worker --queue` now loops - lease, process, repeat - exiting when the queue is empty (or after one action with `--once`). In loop mode the record is exported from the local state store (`--record` is optional), transient lease failures are retried three times, and actions that are not built locally are skipped with a warning. The worker E2E exercises the loop and asserts the `queue empty` exit. + ## 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. diff --git a/docs/agent-workflow/TASKS.md b/docs/agent-workflow/TASKS.md index e26ea96..e648506 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -129,4 +129,5 @@ Base HEAD: `fe0d1a6` | Wave 124 (Distributed queue + VoidLibrary PR) | Registry action queue (enqueue/lease/list, result removes the key); PR Void/Library#64 opened | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; queue E2E passes, full CTest 8/8) | `registry/service/RegistryService.cpp`, `registry/include/Void/Build/Registry/RegistryService.hpp`, `tests/RegistryTests.cpp`, Void/Library#64, docs | | Wave 125 (`vbs worker --queue`) | Queue-driven worker lease mode with `lease_queued_action`; E2E covers both modes | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; worker E2E passes, full CTest 8/8) | `src/Main.cpp`, `src/Package/RegistryClient.cpp`, `include/Void/Build/Package/RegistryClient.hpp`, `tests/RegistryTests.cpp`, docs | | Wave 126 (VoidLibrary test wiring) | Per-module package tests declared in the branch build.cpp; CI runs `vbs test` | COMPLETE & VERIFIED IN CLONE (156 actions; module test binaries PASSED, exit 0) | [Void/Library build-vbs](https://git.faumaray.com/Void/Library/src/branch/build-vbs), `contrib/voidlibrary-migration/`, docs | +| Wave 127 (Continuous worker loop) | `vbs worker --queue` loop with local record export, retries, skip-on-missing, `--once`, exit on empty queue | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; worker 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) | diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index b803fc5..5e898d7 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -1715,6 +1715,12 @@ VOID_INCLUDE_DIR=/tmp/opencode/vl-pin/include dev cpp -c bash fuzz/run.sh 30 direct and queue-driven modes; afterwards `GET /api/v1/queue` reports `"pending":[]`. - Full CTest: **8 / 8 passed** in 287.29 s. +## Continuous Worker Loop (GCC 16.2, pin `0002e74`) + +- `vbs worker --queue` (no `--record`) loops: it leases a queued action, exports the record from the local state store, publishes blobs/record, submits the result, and repeats until the queue is empty; `--once` stops after one action. Lease failures are retried up to three times; locally unbuilt actions are skipped with a warning. +- `RegistryTests.worker_cli_leases_publishes_and_reports_result` **passed** (506 ms), covering direct, single queue and continuous loop modes; the loop output contains the action key and `queue empty`. +- Full CTest: **8 / 8 passed** in 294.19 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). diff --git a/src/Main.cpp b/src/Main.cpp index fdc2e53..5f43aee 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1454,6 +1454,7 @@ struct WorkerCmdOptions { std::optional action_key_arg; std::optional record_arg; bool queue_mode{false}; + bool once{false}; std::string project_arg; std::optional build_arg; std::string token_env{"VBS_REGISTRY_TOKEN"}; @@ -1461,9 +1462,10 @@ struct WorkerCmdOptions { }; int execute_worker_command(const WorkerCmdOptions &opts) { - if (!opts.registry_arg || !opts.record_arg || (!opts.action_key_arg && !opts.queue_mode)) { - std::cerr << "vbs worker: --registry, --record, and --action-key (or --queue) are " - "required\n"; + if (!opts.registry_arg || (!opts.record_arg && !opts.queue_mode) || + (!opts.action_key_arg && !opts.queue_mode)) { + std::cerr << "vbs worker: --registry and --action-key (or --queue) are required; " + "--record is optional in queue mode\n"; return 2; } int lease_seconds = 60; @@ -1476,19 +1478,6 @@ int execute_worker_command(const WorkerCmdOptions &opts) { const std::string registry = *opts.registry_arg; Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")}; - auto record_text = Void::FileSystem::read_file(*opts.record_arg); - if (!record_text) { - std::cerr << "vbs worker: " << record_text.error().message() << '\n'; - return 1; - } - auto record_json = Void::Json::Strict::parse(*record_text); - const auto *record_object = - record_json ? std::get_if(&record_json->value) : nullptr; - if (record_object == nullptr) { - std::cerr << "vbs worker: --record must contain a JSON object\n"; - return 1; - } - const std::filesystem::path project_root{opts.project_arg}; const std::filesystem::path build_root = opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build"); @@ -1507,71 +1496,123 @@ int execute_worker_command(const WorkerCmdOptions &opts) { } Void::Log::info("Worker", "Registered as {}", registration->worker_id); - Package::LeasedAction leased; - if (opts.queue_mode && !opts.action_key_arg) { - auto queued = - Package::lease_queued_action(registry, registration->worker_id, lease_seconds, auth); - if (!queued) { - std::cerr << "vbs worker: " << queued.error().message() << '\n'; - return 1; - } - leased = std::move(*queued); - } else { - auto direct = Package::lease_action(registry, *opts.action_key_arg, registration->worker_id, - lease_seconds, auth); - if (!direct) { - std::cerr << "vbs worker: " << direct.error().message() << '\n'; - return 1; - } - leased = std::move(*direct); - } - const std::string action_key = leased.action_key; - Void::Log::info("Worker", "Leased action {} until epoch {}", action_key, leased.expires_epoch); - State::RemoteCacheConfig remote; remote.url = registry; remote.bearer_token = auth.bearer_token; state->configure_remote_cache(remote); - // Publish every referenced output blob, then the action record itself. - if (const auto outputs_it = record_object->find("outputs"); - outputs_it != record_object->end()) { - if (const auto *outputs = - std::get_if(&outputs_it->second.value)) { - for (const auto &[path, ref] : *outputs) { - const auto *ref_object = std::get_if(&ref.value); - if (ref_object == nullptr) { - continue; - } - const auto sha_it = ref_object->find("sha256"); - if (sha_it == ref_object->end()) { - continue; - } - const auto *sha = std::get_if(&sha_it->second.value); - if (sha == nullptr) { - continue; - } - if (auto published = state->publish_remote_blob(*sha); !published) { - std::cerr << "vbs worker: publishing blob " << *sha << ": " - << published.error().message() << '\n'; - return 1; + // 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; + std::string record_text; + if (opts.record_arg) { + auto file_text = Void::FileSystem::read_file(*opts.record_arg); + if (!file_text) { + std::cerr << "vbs worker: " << file_text.error().message() << '\n'; + return 1; + } + record_text = *file_text; + } else { + // Continuous mode: the action must already be built locally. + auto exported = state->export_action_record_json(action_key); + if (!exported) { + Void::Log::warn("Worker", "Skipping {}: {}", action_key, + exported.error().message()); + return 0; + } + record_text = *exported; + } + + auto record_json = Void::Json::Strict::parse(record_text); + const auto *record_object = + record_json ? std::get_if(&record_json->value) + : nullptr; + if (record_object == nullptr) { + std::cerr << "vbs worker: action record must be a JSON object\n"; + return 1; + } + + if (const auto outputs_it = record_object->find("outputs"); + outputs_it != record_object->end()) { + if (const auto *outputs = + std::get_if(&outputs_it->second.value)) { + for (const auto &[path, ref] : *outputs) { + const auto *ref_object = + std::get_if(&ref.value); + if (ref_object == nullptr) { + continue; + } + const auto sha_it = ref_object->find("sha256"); + if (sha_it == ref_object->end()) { + continue; + } + const auto *sha = std::get_if(&sha_it->second.value); + if (sha == nullptr) { + continue; + } + if (auto published = state->publish_remote_blob(*sha); !published) { + std::cerr << "vbs worker: publishing blob " << *sha << ": " + << published.error().message() << '\n'; + return 1; + } } } } - } - if (auto published = state->publish_remote_action(action_key, *record_text); !published) { - std::cerr << "vbs worker: publishing action record: " << published.error().message() + if (auto published = state->publish_remote_action(action_key, record_text); !published) { + std::cerr << "vbs worker: publishing action record: " << published.error().message() + << '\n'; + return 1; + } + if (auto submitted = Package::submit_action_result(registry, action_key, leased.lease_token, + record_text, auth); + !submitted) { + std::cerr << "vbs worker: " << submitted.error().message() << '\n'; + return 1; + } + std::cout << "worker " << registration->worker_id << " completed action " << action_key << '\n'; + return 0; + }; + + if (opts.queue_mode && !opts.action_key_arg) { + // Continuous loop: lease, process, repeat; exits when the queue is empty or on --once. + while (true) { + std::optional queued; + for (int attempt = 0; attempt < 3 && !queued; ++attempt) { + auto leased = Package::lease_queued_action(registry, registration->worker_id, + lease_seconds, auth); + if (leased) { + queued = std::move(*leased); + break; + } + if (leased.error().kind() == Void::Result::ErrorKind::not_found) { + std::cout << "queue empty\n"; + return 0; + } + Void::Log::warn("Worker", "lease attempt {} failed: {}", attempt + 1, + leased.error().message()); + std::this_thread::sleep_for(std::chrono::milliseconds{100}); + } + if (!queued) { + std::cerr << "vbs worker: giving up after repeated lease failures\n"; + return 1; + } + if (const int code = process_leased(*queued); code != 0) { + return code; + } + if (opts.once) { + return 0; + } + } + } + + auto direct = Package::lease_action(registry, *opts.action_key_arg, registration->worker_id, + lease_seconds, auth); + if (!direct) { + std::cerr << "vbs worker: " << direct.error().message() << '\n'; return 1; } - if (auto submitted = Package::submit_action_result(registry, action_key, leased.lease_token, - *record_text, auth); - !submitted) { - std::cerr << "vbs worker: " << submitted.error().message() << '\n'; - return 1; - } - std::cout << "worker " << registration->worker_id << " completed action " << action_key << '\n'; - return 0; + return process_leased(*direct); } struct MigrateCmdOptions { diff --git a/tests/RegistryTests.cpp b/tests/RegistryTests.cpp index 119f640..0cc188e 100644 --- a/tests/RegistryTests.cpp +++ b/tests/RegistryTests.cpp @@ -2151,6 +2151,25 @@ VOID_TEST(RegistryTests, worker_cli_leases_publishes_and_reports_result) { if (queue_state) { Void::Testing::expect(queue_state->body.find("\"pending\":[]") != std::string::npos); } + + // Continuous loop: process every queued action (record from the local state) and exit + // when the queue drains. + auto enqueued_again = send_loopback_http(port, "POST", "/api/v1/queue", auth, + "{\"action_keys\":[\"" + action_key + "\"]}"); + Void::Testing::expect(enqueued_again.has_value() && enqueued_again->status == 200); + Platform::ProcessRequest loop_worker = worker; + loop_worker.arguments = { + "worker", "--registry", reg_url, "--build-dir", (tmp / "build").string(), "--queue"}; + auto loop_res = Platform::run_supervised(loop_worker); + Void::Testing::expect_eq(loop_res ? (loop_res->succeeded() + ? std::string{} + : (loop_res->stdout_data + loop_res->stderr_data)) + : loop_res.error().message(), + std::string{}); + if (loop_res) { + Void::Testing::expect(loop_res->stdout_data.find("queue empty") != std::string::npos); + Void::Testing::expect(loop_res->stdout_data.find(action_key) != std::string::npos); + } (*svc)->stop_http(); }