diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index dd87da1..d990b42 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -342,6 +342,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - **Wave 124 (Distributed Action Queue & VoidLibrary PR)**: the registry gained an in-memory action queue (`POST /api/v1/queue` to enqueue keys, `POST /api/v1/queue/lease` to lease the oldest unleased key to a worker, `GET /api/v1/queue` to list pending/leased keys), reusing the existing lease TTL/tokens; a completed result removes its key from the queue. `RegistryTests.worker_action_queue_enqueue_lease_and_complete` covers enqueue, ordered leases, exhaustion and listing. Pull request [Void/Library#64](https://git.faumaray.com/Void/Library/pulls/64) was opened for the native VoidLibrary build branch. +- **Wave 125 (Queue-Driven Worker Mode)**: `vbs worker --queue` (without `--action-key`) leases the next queued action from the registry (`Package::lease_queued_action`), then publishes blobs/record and submits the result exactly like the direct mode. The worker E2E now covers both modes, asserting the queue is empty afterwards. + ## 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 99f6ec5..e71506a 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -127,4 +127,5 @@ Base HEAD: `fe0d1a6` | Wave 122 (Remote worker protocol) | Registry worker registration/heartbeat, exclusive action leases with TTL/tokens, token-checked result upload with blob verification | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; new registry E2E passes, full CTest 8/8) | `registry/include/Void/Build/Registry/RegistryService.hpp`, `registry/service/RegistryService.cpp`, `tests/RegistryTests.cpp`, docs | | Wave 123 (`vbs worker` client) | Worker CLI: register, lease, publish blobs/record, submit result; StateStore export; client APIs | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; worker CLI E2E passes, full CTest 8/8) | `src/Main.cpp`, `src/Package/RegistryClient.cpp`, `src/State/StateStore.cpp`, `tests/RegistryTests.cpp`, docs | | 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 | | 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 c42ce29..b803fc5 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -1707,6 +1707,14 @@ VOID_INCLUDE_DIR=/tmp/opencode/vl-pin/include dev cpp -c bash fuzz/run.sh 30 - Also opened [Void/Library#64](https://git.faumaray.com/Void/Library/pulls/64) for the native VoidLibrary build description. +## Queue-Driven Worker Mode (GCC 16.2, pin `0002e74`) + +- `vbs worker --queue --record ... --build-dir ...` leases the next queued key instead of + `--action-key`, then publishes blobs/record and submits the result. +- `RegistryTests.worker_cli_leases_publishes_and_reports_result` **passed** (435 ms) for both the + direct and queue-driven modes; afterwards `GET /api/v1/queue` reports `"pending":[]`. +- Full CTest: **8 / 8 passed** in 287.29 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/include/Void/Build/Package/RegistryClient.hpp b/include/Void/Build/Package/RegistryClient.hpp index 5885f62..c9e71ed 100644 --- a/include/Void/Build/Package/RegistryClient.hpp +++ b/include/Void/Build/Package/RegistryClient.hpp @@ -71,6 +71,11 @@ register_worker(std::string_view registry_url, std::string_view platform, lease_action(std::string_view registry_url, std::string_view action_key, std::string_view worker_id, std::int64_t lease_seconds, const RegistryAuth &auth = {}); +// Leases the oldest queued action for a worker (the record is not returned by the queue). +[[nodiscard]] Void::Result::Result +lease_queued_action(std::string_view registry_url, std::string_view worker_id, + std::int64_t lease_seconds, const RegistryAuth &auth = {}); + [[nodiscard]] Void::Result::Result submit_action_result(std::string_view registry_url, std::string_view action_key, std::string_view lease_token, std::string_view record_json, diff --git a/src/Main.cpp b/src/Main.cpp index 220f3c0..fdc2e53 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1453,6 +1453,7 @@ struct WorkerCmdOptions { std::optional registry_arg; std::optional action_key_arg; std::optional record_arg; + bool queue_mode{false}; std::string project_arg; std::optional build_arg; std::string token_env{"VBS_REGISTRY_TOKEN"}; @@ -1460,8 +1461,9 @@ struct WorkerCmdOptions { }; int execute_worker_command(const WorkerCmdOptions &opts) { - if (!opts.registry_arg || !opts.action_key_arg || !opts.record_arg) { - std::cerr << "vbs worker: --registry, --action-key, and --record are required\n"; + 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"; return 2; } int lease_seconds = 60; @@ -1472,7 +1474,6 @@ int execute_worker_command(const WorkerCmdOptions &opts) { return 2; } const std::string registry = *opts.registry_arg; - const std::string action_key = *opts.action_key_arg; Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")}; auto record_text = Void::FileSystem::read_file(*opts.record_arg); @@ -1506,13 +1507,26 @@ int execute_worker_command(const WorkerCmdOptions &opts) { } Void::Log::info("Worker", "Registered as {}", registration->worker_id); - auto leased = - Package::lease_action(registry, action_key, registration->worker_id, lease_seconds, auth); - if (!leased) { - std::cerr << "vbs worker: " << leased.error().message() << '\n'; - return 1; + 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); } - Void::Log::info("Worker", "Leased action {} until epoch {}", action_key, leased->expires_epoch); + 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; @@ -1550,7 +1564,7 @@ int execute_worker_command(const WorkerCmdOptions &opts) { << '\n'; return 1; } - if (auto submitted = Package::submit_action_result(registry, action_key, leased->lease_token, + 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'; @@ -3283,6 +3297,8 @@ int main(int argc, char **argv) { worker_opts.registry_arg) .option("--action-key", "", "Action key to lease and publish", worker_opts.action_key_arg) .option("--record", "", "Action record JSON file to publish", worker_opts.record_arg) + .flag("--queue", "", "Lease the next action from the registry queue", + worker_opts.queue_mode) .option_default("--project", "-C", "Project directory", worker_opts.project_arg, cwd) .option("--build-dir", "-B", "Build directory", worker_opts.build_arg) .option_default("--token-env", "", "Environment variable holding bearer token", diff --git a/src/Package/RegistryClient.cpp b/src/Package/RegistryClient.cpp index 4dc0cdb..93c4a6a 100644 --- a/src/Package/RegistryClient.cpp +++ b/src/Package/RegistryClient.cpp @@ -910,6 +910,46 @@ lease_action(std::string_view registry_url, std::string_view action_key, std::st return leased; } +Void::Result::Result +lease_queued_action(std::string_view registry_url, std::string_view worker_id, + std::int64_t lease_seconds, const RegistryAuth &auth) { + auto parsed_url = parse_registry_url(registry_url); + if (!parsed_url) { + return std::unexpected{parsed_url.error()}; + } + const std::string body = std::format("{{\"worker_id\":{},\"lease_seconds\":{}}}", + json_quote_of(worker_id), lease_seconds); + auto reply = + send_http_request(*parsed_url, "POST", "/api/v1/queue/lease", bearer_headers(auth), body); + if (!reply) { + return std::unexpected{reply.error()}; + } + if (reply->status != 200) { + return std::unexpected{make_error( + reply->status == 404 ? Void::System::SystemErrorCode::not_found + : reply->status == 401 || reply->status == 403 + ? Void::System::SystemErrorCode::permission_denied + : Void::System::SystemErrorCode::io_error, + std::format("queue lease failed with HTTP {}: {}", reply->status, reply->body))}; + } + auto json = Void::Json::Strict::parse(reply->body); + const auto *object = json ? std::get_if(&json->value) : nullptr; + if (!object) { + return std::unexpected{ + make_error(Void::System::SystemErrorCode::io_error, "invalid queue lease response")}; + } + LeasedAction leased; + leased.action_key = get_str(*object, "action_key"); + leased.worker_id = get_str(*object, "worker_id"); + leased.lease_token = get_str(*object, "lease_token"); + leased.expires_epoch = get_i64(*object, "expires_epoch", 0); + if (leased.action_key.empty() || leased.lease_token.empty()) { + return std::unexpected{make_error(Void::System::SystemErrorCode::io_error, + "queue lease response is incomplete")}; + } + return leased; +} + Void::Result::Result submit_action_result(std::string_view registry_url, std::string_view action_key, std::string_view lease_token, diff --git a/tests/RegistryTests.cpp b/tests/RegistryTests.cpp index 3f3d7ff..119f640 100644 --- a/tests/RegistryTests.cpp +++ b/tests/RegistryTests.cpp @@ -2126,6 +2126,31 @@ VOID_TEST(RegistryTests, worker_cli_leases_publishes_and_reports_result) { if (cas_blob) { Void::Testing::expect(cas_blob->body == "WORKER_OUTPUT"); } + + // Queue-driven mode: the worker leases the next queued key instead of --action-key. + 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 queued_worker = worker; + queued_worker.arguments = {"worker", + "--registry", + reg_url, + "--record", + record_file.string(), + "--build-dir", + (tmp / "build").string(), + "--queue"}; + auto queued_res = Platform::run_supervised(queued_worker); + Void::Testing::expect_eq( + queued_res ? (queued_res->succeeded() ? std::string{} + : (queued_res->stdout_data + queued_res->stderr_data)) + : queued_res.error().message(), + std::string{}); + auto queue_state = send_loopback_http(port, "GET", "/api/v1/queue", auth); + Void::Testing::expect(queue_state.has_value() && queue_state->status == 200); + if (queue_state) { + Void::Testing::expect(queue_state->body.find("\"pending\":[]") != std::string::npos); + } (*svc)->stop_http(); }