Skip to content

Dispatch DVM jobs to worker processes and publish results back #731

Description

@Priyanshubhartistm

Description

Follow-up to #639, #727 (job persistence), and #729 (job ingestion). The relay can now recognize NIP-90 job request events and record them as submitted jobs, but nothing actually hands them off to a worker process yet.

This issue covers dispatch: pick up a pending job, spawn/communicate with its configured worker, wait for a result (with a timeout), update job state through its lifecycle, and publish the result back as a NIP-90 event.

What needs to be done

  • Pick up submitted jobs (via DvmJobRepository.findPendingJobs()) and assign them to a worke (DvmJobRepository.assignWorker(), already atomic/race-safe from feat(dvm): add dvm job persistence migration and repository #727).
  • Spawn/communicate with the worker process, extending the existing spawn()-based pattern in src/cli/utils/process.ts (timeout/kill/error-classification) rather than inventing a second spawn convention.
  • Frame messages to/from the worker as newline-delimited JSON over stdin/stdout no existing convention covers this (process.ts buffers all output into one string, which doesn't work for a long-lived worker handling multiple in-flight jobs), so this needs new code.
  • On timeout: mark the job timed_out via DvmJobRepository.updateStatus() and kill the worker process (soft Node-level guard — timeout + child.kill(), not full OS-level sandboxing; that's a stretch goal, not required for this).
  • On success: mark the job completed, publish a kind 6000-6999 job result event.
  • On worker error/crash: mark the job failed with an error message.
  • Tests for the dispatch flow: successful completion, timeout, worker crash, and the state transitions in each case.

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions