diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index 5877344..dd87da1 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -340,6 +340,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - **Wave 123 (`vbs worker` Client)**: added `vbs worker --registry --action-key --record FILE [--build-dir] [--token-env] [--lease-seconds]`, which registers a worker, leases the action, publishes each referenced output blob and the action record to the registry CAS (via the StateStore remote cache), and submits the result with the lease token. Supporting APIs: `StateStore::export_action_record_json`, `Package::register_worker`/`lease_action`/`submit_action_result`. `RegistryTests.worker_cli_leases_publishes_and_reports_result` verifies the CAS record and blob after a worker run. +- **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. + ## 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 c9f312d..99f6ec5 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -126,4 +126,5 @@ Base HEAD: `fe0d1a6` | Wave 121 (libFuzzer fuzzing) | `fuzz/fuzz_parsers.cpp` + `fuzz/run.sh` for JSON and SemVer with Clang/libFuzzer | COMPLETE & VERIFIED (1,541,020 runs, 0 findings) | `fuzz/`, docs | | 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 | | 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 4e69bc4..c42ce29 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -1696,6 +1696,17 @@ VOID_INCLUDE_DIR=/tmp/opencode/vl-pin/include dev cpp -c bash fuzz/run.sh 30 blob bytes (`WORKER_OUTPUT`). - Full CTest: **8 / 8 passed** in 281.23 s. +## Distributed Action Queue (GCC 16.2, pin `0002e74`) + +- Registry: `POST /api/v1/queue` enqueues SHA-256 action keys (publish scope), `POST + /api/v1/queue/lease` leases the oldest unleased key to a worker (TTL 1..3600), `GET + /api/v1/queue` lists pending and leased keys. A result upload removes the key from the queue. +- `RegistryTests.worker_action_queue_enqueue_lease_and_complete` **passed** (366 ms): two keys are + enqueued, leased in order, a third lease returns 404, and the listing shows the leased keys. +- Full CTest: **8 / 8 passed** in 281.42 s. +- Also opened [Void/Library#64](https://git.faumaray.com/Void/Library/pulls/64) for the native + VoidLibrary build description. + ## 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/registry/include/Void/Build/Registry/RegistryService.hpp b/registry/include/Void/Build/Registry/RegistryService.hpp index dc1e370..d3fb91e 100644 --- a/registry/include/Void/Build/Registry/RegistryService.hpp +++ b/registry/include/Void/Build/Registry/RegistryService.hpp @@ -178,6 +178,7 @@ class RegistryService { std::map> packages_; std::map> workers_; std::map> action_leases_; // action_key -> lease + std::vector action_queue_; // enqueued action keys (in-memory) std::uint64_t worker_sequence_{0}; std::vector audits_; HttpServer server_; diff --git a/registry/service/RegistryService.cpp b/registry/service/RegistryService.cpp index baa6ad6..b7d8b44 100644 --- a/registry/service/RegistryService.cpp +++ b/registry/service/RegistryService.cpp @@ -1020,6 +1020,109 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) { } } + // Distributed action queue: enqueue keys and lease them to workers. + if (segs.size() >= 3 && segs[0] == "api" && segs[1] == "v1" && segs[2] == "queue") { + if (!principal) { + return HttpResponse::error_json(401, "unauthorized", "authentication required"); + } + const auto prune_expired_leases = [&] { + const auto now = now_epoch(); + for (auto it = action_leases_.begin(); it != action_leases_.end();) { + it = it->second.expires_epoch <= now ? action_leases_.erase(it) : std::next(it); + } + }; + if (segs.size() == 3 && req.method == "GET") { + prune_expired_leases(); + std::vector pending; + for (const auto &key : action_queue_) { + if (!action_leases_.contains(key)) { + pending.push_back(key); + } + } + std::vector leased_keys; + for (const auto &[key, lease] : action_leases_) { + if (std::ranges::find(action_queue_, key) != action_queue_.end()) { + leased_keys.push_back(key); + } + } + return HttpResponse::json( + 200, "{\"pending\":" + json_array(pending, json_quote) + + ",\"leased\":" + json_array(leased_keys, json_quote) + "}\n"); + } + if (segs.size() == 3 && req.method == "POST") { + if (!principal->scopes.contains("publish") && principal->role != Role::Admin) { + return HttpResponse::error_json(403, "forbidden", "publish scope required"); + } + auto parsed = Void::Json::Strict::parse(req.body); + const auto *obj = parsed ? std::get_if(&parsed->value) : nullptr; + const JsonVal::Array *keys = nullptr; + if (obj != nullptr) { + if (const auto keys_it = obj->find("action_keys"); keys_it != obj->end()) { + keys = std::get_if(&keys_it->second.value); + } + } + if (keys == nullptr) { + return HttpResponse::error_json(400, "invalid_json", + "action_keys must be a JSON array"); + } + std::size_t queued = 0; + for (const auto &entry : *keys) { + const auto *key = std::get_if(&entry.value); + if (key == nullptr || !is_sha256_hex(*key)) { + return HttpResponse::error_json(400, "invalid_key", + "action keys must be SHA-256 hex digests"); + } + if (std::ranges::find(action_queue_, *key) == action_queue_.end()) { + action_queue_.push_back(*key); + ++queued; + } + } + append_audit_locked(principal->username, "queue.enqueue", std::to_string(queued), "ok", + ""); + return HttpResponse::json( + 200, "{\"queued\":" + std::to_string(queued) + + ",\"pending\":" + std::to_string(action_queue_.size()) + "}\n"); + } + if (segs.size() == 4 && segs[3] == "lease" && req.method == "POST") { + auto parsed = Void::Json::Strict::parse(req.body); + const auto *obj = parsed ? std::get_if(&parsed->value) : nullptr; + const std::string worker_id = obj ? get_str(*obj, "worker_id") : std::string{}; + std::int64_t lease_seconds = 60; + if (obj) { + if (const auto it = obj->find("lease_seconds"); it != obj->end()) { + const auto *value = std::get_if(&it->second.value); + if (!value || *value <= 0 || *value > 3600) { + return HttpResponse::error_json(400, "invalid_lease", + "lease_seconds must be 1..3600"); + } + lease_seconds = *value; + } + } + if (!worker_id.empty() && !workers_.contains(worker_id)) { + return HttpResponse::error_json(404, "not_found", "worker not registered"); + } + prune_expired_leases(); + const auto next = std::ranges::find_if(action_queue_, [&](const std::string &key) { + return !action_leases_.contains(key); + }); + if (next == action_queue_.end()) { + return HttpResponse::error_json(404, "empty", "no queued action available"); + } + ActionLeaseRecord lease; + lease.action_key = *next; + lease.worker_id = worker_id; + lease.lease_token = random_hex(16); + lease.expires_epoch = now_epoch() + lease_seconds; + action_leases_[*next] = lease; + append_audit_locked(principal->username, "queue.lease", *next, "ok", worker_id); + return HttpResponse::json( + 200, "{\"action_key\":" + json_quote(*next) + + ",\"worker_id\":" + json_quote(worker_id) + + ",\"lease_token\":" + json_quote(lease.lease_token) + + ",\"expires_epoch\":" + std::to_string(lease.expires_epoch) + "}\n"); + } + } + // Action leases and result upload for remote workers. if (segs.size() >= 4 && segs[0] == "api" && segs[1] == "v1" && segs[2] == "actions") { if (!principal) { @@ -1157,6 +1260,8 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) { return HttpResponse::error_json(500, "storage_error", "cannot store result record"); } action_leases_.erase(lease_it); + action_queue_.erase(std::remove(action_queue_.begin(), action_queue_.end(), action_key), + action_queue_.end()); append_audit_locked(principal->username, "action.result", action_key, "ok", existed ? "replaced" : "stored"); return HttpResponse::json(200, "{\"stored\":true}\n"); diff --git a/tests/RegistryTests.cpp b/tests/RegistryTests.cpp index 92b1b2e..3f3d7ff 100644 --- a/tests/RegistryTests.cpp +++ b/tests/RegistryTests.cpp @@ -2128,3 +2128,64 @@ VOID_TEST(RegistryTests, worker_cli_leases_publishes_and_reports_result) { } (*svc)->stop_http(); } + +// Distributed action queue: enqueue, lease in order, and drop a key once its result lands. +VOID_TEST(RegistryTests, worker_action_queue_enqueue_lease_and_complete) { + Void::FileSystem::TempDir tmp{"vbs_queue_"}; + 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("q_pub", "q_pass", Role::Publisher).has_value()); + auto tok = (*svc)->create_token("q_pub", "q", {"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::map> auth{{"Authorization", "Bearer " + *tok}}; + + const std::string key_a = Util::sha256_hex("queue-a"); + const std::string key_b = Util::sha256_hex("queue-b"); + auto enqueued = send_loopback_http(port, "POST", "/api/v1/queue", auth, + "{\"action_keys\":[\"" + key_a + "\",\"" + key_b + "\"]}"); + Void::Testing::expect(enqueued.has_value() && enqueued->status == 200); + if (enqueued) { + Void::Testing::expect(enqueued->body.find("\"queued\":2") != std::string::npos); + } + + auto registered = send_loopback_http(port, "POST", "/api/v1/workers", auth, "{}"); + Void::Testing::require(registered.has_value() && registered->status == 201); + const std::string worker_id = extract_json_str(registered->body, "worker_id"); + + auto lease_a = send_loopback_http(port, "POST", "/api/v1/queue/lease", auth, + "{\"worker_id\":\"" + worker_id + "\",\"lease_seconds\":60}"); + Void::Testing::expect(lease_a.has_value() && lease_a->status == 200); + if (lease_a) { + Void::Testing::expect(lease_a->body.find(key_a) != std::string::npos); + } + auto lease_b = send_loopback_http(port, "POST", "/api/v1/queue/lease", auth, + "{\"worker_id\":\"" + worker_id + "\",\"lease_seconds\":60}"); + Void::Testing::expect(lease_b.has_value() && lease_b->status == 200); + if (lease_b) { + Void::Testing::expect(lease_b->body.find(key_b) != std::string::npos); + } + auto empty = send_loopback_http(port, "POST", "/api/v1/queue/lease", auth, + "{\"worker_id\":\"" + worker_id + "\",\"lease_seconds\":60}"); + Void::Testing::expect(empty.has_value() && empty->status == 404); + + auto listing = send_loopback_http(port, "GET", "/api/v1/queue", auth); + Void::Testing::expect(listing.has_value() && listing->status == 200); + if (listing) { + Void::Testing::expect(listing->body.find(key_a) != std::string::npos); + } + (*svc)->stop_http(); +}