Add remote workers and AMD host support for 2.4.0 #16
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/remote-worker"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Trusted remote hosts can now run Redview jobs against shared media paths while the main server owns SQLite. The opt-in worker API uses a dedicated key, atomic command batches, binary-vector transport and replay receipts; local and remote workers preserve job ownership and recovery. Includes standalone NixOS worker services, setup documentation and Nova ROCm validation. Workers tolerate busy claims, and purge takes write locks before reads with bounded atomic-write retries.
Validation: 185 Node tests, 60 Python tests, Nix package build and installation checks, version policy checks, and main/remote NixOS module evaluations pass. Nova completed real AMD tagging/vectorization and simultaneous local/remote queue work against a disposable API. Development target is 2.4.0-dev4.
Candidate acceptance remains open: production shared mounts and supervised provisioning, host/network loss and mount outages, representative throughput, Lyra contention observation and purge job 92 reconciliation. Deduplication and earlier vectorization failures still need diagnosis. This PR prepares release-candidate testing; it does not publish or deploy a stable release.
Automated code review
Reviewed commit:
c4bfbd7dd40b1552077b2fa1d669c44b0d33dbfbVerdict: Requires further work
Resolve the blocking or important findings and investigate failed deterministic checks before merging.
Overall assessment
This PR introduces remote worker support for Redview v2, allowing trusted workers on separate hosts to execute database commands against a central SQLite instance via an HTTP API. It also includes AMD GPU validation, fixes for SQLite contention (busy claims), and updates the version to 2.4.0-dev4. The implementation uses a dedicated worker key, atomic command batches with retry receipts, and binary-vector transport.
Blocking findings
None.
Important findings
The
createCommandExecutorfunction executes SQL statements provided by the remote worker:const prepared = db.prepare(statement.sql); ... prepared.run(...args);. While arguments are parameterized via...args, the SQL string itself is interpolated directly into the prepared statement. The validation regex/^\s*(SELECT|WITH|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|ALTER)\b/iallows a wide range of statements.Impact: If the worker key is compromised, an attacker could potentially execute arbitrary SQL commands on the central database, including schema modifications or data exfiltration, beyond just job-related operations. The protocol currently trusts the worker host implicitly.
Suggested fix: Restrict the allowed SQL statements to only those necessary for job processing (e.g., SELECT, INSERT, UPDATE, DELETE) and explicitly block DDL (CREATE, DROP, ALTER) unless absolutely required. Consider whitelisting specific table names or prefixes if possible. Ensure that the worker key is treated with the same security as a database superuser.
Suggestions
Race Condition in Receipt Pruning (src/worker-protocol.ts:95; medium confidence)
The receipt pruning logic
if (Date.now() - lastPruned > 60_000)is not atomic. If multiple requests trigger this check simultaneously, they might both prune, or one might prune while another is inserting a receipt that is then deleted.Impact: Receipts might be deleted prematurely, leading to duplicate writes if the worker retries a command after its receipt was pruned but before it received the response (or if the response was lost).
Suggested fix: Use a database-level lock or a more robust mechanism for pruning receipts. For example, prune within the transaction itself or use a separate scheduled task with proper locking.
SharedArrayBuffer Synchronization Complexity (src/remote-worker.ts:50; medium confidence)
The remote worker uses
SharedArrayBufferandAtomicsfor communication between the main thread and the worker thread. This is complex and error-prone. The code relies on precise timing and state management.Impact: If the synchronization logic fails (e.g., timeout, incorrect status codes), it could lead to deadlocks or lost commands. The complexity increases the risk of subtle bugs.
Suggested fix: Consider using a simpler IPC mechanism if performance allows, such as
postMessagewith JSON serialization, which is already used for other parts of the worker. IfSharedArrayBufferis necessary for performance, add extensive logging and error handling to debug synchronization issues.Missing Error Handling in Remote Worker Thread (src/remote-worker-thread.ts:15; medium confidence)
The
runWorkerfunction is called with aRemoteDbinstance. If an error occurs during job execution that is not caught by the worker's internal error handling, it might not be properly reported or handled.Impact: Jobs might fail silently or leave the database in an inconsistent state if errors are not propagated correctly through the remote protocol.
Suggested fix: Ensure that all errors from
runWorkerare caught and logged. Consider adding a global error handler for the worker thread to catch unhandled exceptions.Documentation Clarity on Security Model (REMOTE-WORKERS.md:10; high confidence)
The documentation states: 'The worker key grants privileged database access to trusted workers; keep it out of Nix expressions and the Nix store.'
Impact: Users might not fully understand the implications of the worker key. It is effectively a database superuser key.
Suggested fix: Explicitly state that the worker key provides full database access and should be treated with the same security as the database itself. Provide clear guidelines on how to secure the key in production environments.
Tests and validation
Questions
SharedArrayBufferchosen for IPC between the main thread and worker thread instead ofpostMessage? Is it necessary for performance, or could it be simplified?Review limitations
SharedArrayBuffersynchronization was not benchmarked.Diff coverage
AMD-WORKERS.md: reviewed — included in a context-limited batchCHANGELOG.md: reviewed — included in a context-limited batchENCODER.md: reviewed — included in a context-limited batchREADME.md: reviewed — included in a context-limited batchREMOTE-WORKERS.md: reviewed — included in a context-limited batchREQUIREMENTS-TRACE.md: reviewed — included in a context-limited batchREQUIREMENTS.md: reviewed — included in a context-limited batchVERSION: reviewed — included in a context-limited batchVERSIONING.md: reviewed — included in a context-limited batchacceptance/amd-remote-worker-2026-10-05.md: reviewed — included in a context-limited batchflake.nix: reviewed — included in a context-limited batchnix/package.nix: reviewed — included in a context-limited batchnix/redview-v2.nix: reviewed — included in a context-limited batchnix/remote-worker.nix: reviewed — included in a context-limited batchnix/tests/remote-worker-module.nix: reviewed — included in a context-limited batchpackage.json: reviewed — included in a context-limited batchsrc/app.ts: reviewed — included in a context-limited batchsrc/auth.ts: reviewed — included in a context-limited batchsrc/jobs.ts: reviewed — included in a context-limited batchsrc/remote-db.ts: reviewed — included in a context-limited batchsrc/remote-worker-thread.ts: reviewed — included in a context-limited batchsrc/remote-worker.ts: reviewed — included in a context-limited batchsrc/server.ts: reviewed — included in a context-limited batchsrc/sqlite-contention.ts: reviewed — included in a context-limited batchsrc/worker-protocol.ts: reviewed — included in a context-limited batchsrc/worker.ts: reviewed — included in a context-limited batchtagger-amd.py: reviewed — included in a context-limited batchtests/remote-db.test.mjs: reviewed — included in a context-limited batchtests/remote-protocol.test.mjs: reviewed — included in a context-limited batchtests/remote-worker.test.mjs: reviewed — included in a context-limited batchReview metadata