Skip to content

feat(dvm): add dvm job persistence migration and repository - #727

Open
Priyanshubhartistm wants to merge 3 commits into
cameri:mainfrom
Priyanshubhartistm:feat/dvm-job-persistence
Open

feat(dvm): add dvm job persistence migration and repository#727
Priyanshubhartistm wants to merge 3 commits into
cameri:mainfrom
Priyanshubhartistm:feat/dvm-job-persistence

Conversation

@Priyanshubhartistm

@Priyanshubhartistm Priyanshubhartistm commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Description

Adds the DVM job persistence layer: a migration and a repository for tracking NIP-90 job state in the database, so job lifecycle survives relay restarts. This is a persistence-only PR — no event ingestion or IPC dispatch yet, those are separate follow-up PRs.

  • New dvm_jobs table (migration 20260812_150000_create_dvm_jobs_table.js): id, requester_pubkey, kind, worker_index, status (Postgres enum: submitted / picked_up / completed / failed / timed_out), result_event_id, error, and lifecycle timestamps (picked_up_at, completed_at, created_at, updated_at), with named indexes on requester_pubkey, status, and kind.
  • New domain types in src/@types/dvm.ts (DvmJob, DvmJobStatus, DBDvmJob), following the existing camelCase/snake_case split used by Invoice/DBInvoice.
  • New DvmJobRepository (src/repositories/dvm-job-repository.ts) and IDvmJobRepository interface (src/@types/repositories.ts): create, findById, assignWorker (atomic conditional UPDATE gated on status = 'submitted', so two workers can't race to pick up the same job), updateStatus (sets completed_at only for terminal statuses), findPendingJobs.
  • The repository is intentionally not wired into any worker or event strategy yet — event ingestion (trapping kind 5000-5999 requests) and IPC dispatch are separate follow-up PRs.
  • Added src/repositories/dvm-job-repository.ts to .knip.json's ignore list since it has no consumer yet, mirroring the existing invite-code-repository.ts entry for the same situation.

Related Issue

Part of #639

Motivation and Context

Following up on the worker registry/process topology added in #721, the relay needs somewhere to durably track each DVM job's lifecycle (submitted, picked up, completed, failed, timed out) so in-flight jobs aren't silently lost if the relay restarts. This PR adds that persistence layer in isolation so it can be reviewed independently of the ingestion and IPC-dispatch logic that will build on top of it.

How Has This Been Tested?

  • Added 20 unit tests for DvmJobRepository covering every method (create, findById, assignWorker including the atomic-pickup race guard, updateStatus including terminal-status handling, findPendingJobs), following the existing InviteCodeRepository test conventions (stubbed Knex query-builder chains).
  • Ran the full local CI suite: pnpm exec commitlint, pnpm exec changeset status, pnpm lint,
    pnpm check:format, pnpm check:deps, pnpm run build:check, pnpm run build,
    pnpm run verify:cli:build, pnpm run test:unit (1564 passing), pnpm run test:cli,
    pnpm run cover:unit (dvm-job-repository.ts at 97%+ statement coverage, 100% function coverage), pnpm run docker:test:integration and pnpm run docker:cover:integration (99 scenarios / 489 steps passing) — confirms the migration applies cleanly against real Postgres.

Screenshots (if appropriate):

N/A — persistence layer change, no UI.

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • I added a changeset, or this is docs-only and I added an empty changeset.
  • All new and existing tests passed.

Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
@changeset-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5c212bf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nostream Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Priyanshubhartistm
Priyanshubhartistm requested review from Anshumancanrock, Justxd22 and cameri and removed request for Justxd22 August 12, 2026 10:44
@coveralls

coveralls commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 69.843% (+0.1%) from 69.748% — Priyanshubhartistm:feat/dvm-job-persistence into cameri:main

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new persistence layer for NIP-90 DVM job lifecycle tracking, introducing a dvm_jobs table plus a typed repository API so job state can survive relay restarts (with ingestion/dispatch intentionally deferred to follow-up PRs).

Changes:

  • Added dvm_jobs migration and new DVM domain types (DvmJob, DvmJobStatus, DBDvmJob).
  • Implemented DvmJobRepository + IDvmJobRepository interface for creating, assigning, updating, and polling pending jobs.
  • Added unit tests for the new repository and updated .knip.json/changeset metadata for the new files.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/unit/repositories/dvm-job-repository.spec.ts Unit tests for repository behavior and query-builder interactions.
src/repositories/dvm-job-repository.ts New repository implementing DVM job persistence operations.
src/@types/repositories.ts Adds IDvmJobRepository to the repository type surface.
src/@types/dvm.ts Introduces DVM job domain/DB row types and status enum.
migrations/20260812_150000_create_dvm_jobs_table.js Creates dvm_jobs table and indexes to support job lifecycle persistence.
.knip.json Ignores the new repository until it’s wired into a consumer.
.changeset/dvm-job-persistence.md Declares a minor release for the new persistence feature.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread migrations/20260812_150000_create_dvm_jobs_table.js
Comment thread src/repositories/dvm-job-repository.ts
… in updateStatus

Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants