feat(api): solver service Phase 3b — server endpoints and job definitions #160

Merged
forbes merged 1 commits from feat/solver-service into main 2026-02-20 18:15:21 +00:00
Owner

Summary

Add server-side solver service module (Phase 3b from docs/SOLVER.md) with REST API endpoints, database schema, job definitions, and runner result caching.

Changes

New files

  • migrations/021_solver_results.sql — solver_results table with upsert on (item_id, revision_number, operation)
  • internal/db/solver_results.go — SolverResultRepository (Upsert, GetByItem, GetByItemRevision)
  • internal/api/solver_handlers.go — all solver API handlers + maybeCacheSolverResult async hook
  • jobdefs/assembly-solve.yaml — manual constraint solve job (tags: solver, timeout: 300s)
  • jobdefs/assembly-validate.yaml — auto-validate on revision creation (tags: solver, timeout: 120s)
  • jobdefs/assembly-kinematic.yaml — manual kinematic simulation (tags: solver, timeout: 1800s)

Modified files

  • internal/config/config.go — SolverConfig struct (max_context_size_mb, default_timeout, auto_diagnose_on_commit)
  • internal/modules/modules.go, loader.go — register solver module (depends on jobs)
  • internal/db/jobs.go — ListSolverJobs helper with definition_name prefix filter
  • internal/api/handlers.go — wire SolverResultRepository into Server
  • internal/api/routes.go — /api/solver/* routes + /api/items/{partNumber}/solver/results
  • internal/api/runner_handlers.go — async result cache hook on job completion

API endpoints

Method Path Auth Description
POST /api/solver/jobs Editor Submit solver job
GET /api/solver/jobs Viewer List solver jobs (with status/item/operation filters)
GET /api/solver/jobs/{id} Viewer Get solver job status
POST /api/solver/jobs/{id}/cancel Editor Cancel solver job
GET /api/solver/solvers Viewer Registry of available solvers from online runners
GET /api/items/{pn}/solver/results Viewer Cached solve results for item

Design decisions

  • Thin wrapper over existing job queue — packs solver context into scope_metadata JSONB
  • max_context_size_mb enforced at HTTP boundary via MaxBytesReader
  • Results cached asynchronously via background goroutine on job completion
  • Solver registry aggregated from online runner metadata (solver tag)

Also fixes

  • Pre-existing test compilation errors: missing workflows param in NewServer calls across 6 test files

Verification

  • go build ./...
  • go vet ./...
  • go test ./internal/workflow/ ./internal/modules/ ./internal/jobdef/
## Summary Add server-side solver service module (Phase 3b from docs/SOLVER.md) with REST API endpoints, database schema, job definitions, and runner result caching. ## Changes ### New files - `migrations/021_solver_results.sql` — solver_results table with upsert on (item_id, revision_number, operation) - `internal/db/solver_results.go` — SolverResultRepository (Upsert, GetByItem, GetByItemRevision) - `internal/api/solver_handlers.go` — all solver API handlers + maybeCacheSolverResult async hook - `jobdefs/assembly-solve.yaml` — manual constraint solve job (tags: solver, timeout: 300s) - `jobdefs/assembly-validate.yaml` — auto-validate on revision creation (tags: solver, timeout: 120s) - `jobdefs/assembly-kinematic.yaml` — manual kinematic simulation (tags: solver, timeout: 1800s) ### Modified files - `internal/config/config.go` — SolverConfig struct (max_context_size_mb, default_timeout, auto_diagnose_on_commit) - `internal/modules/modules.go`, `loader.go` — register solver module (depends on jobs) - `internal/db/jobs.go` — ListSolverJobs helper with definition_name prefix filter - `internal/api/handlers.go` — wire SolverResultRepository into Server - `internal/api/routes.go` — /api/solver/* routes + /api/items/{partNumber}/solver/results - `internal/api/runner_handlers.go` — async result cache hook on job completion ### API endpoints | Method | Path | Auth | Description | |--------|------|------|-------------| | POST | /api/solver/jobs | Editor | Submit solver job | | GET | /api/solver/jobs | Viewer | List solver jobs (with status/item/operation filters) | | GET | /api/solver/jobs/{id} | Viewer | Get solver job status | | POST | /api/solver/jobs/{id}/cancel | Editor | Cancel solver job | | GET | /api/solver/solvers | Viewer | Registry of available solvers from online runners | | GET | /api/items/{pn}/solver/results | Viewer | Cached solve results for item | ### Design decisions - Thin wrapper over existing job queue — packs solver context into `scope_metadata` JSONB - `max_context_size_mb` enforced at HTTP boundary via MaxBytesReader - Results cached asynchronously via background goroutine on job completion - Solver registry aggregated from online runner metadata (solver tag) ### Also fixes - Pre-existing test compilation errors: missing `workflows` param in NewServer calls across 6 test files ## Verification - `go build ./...` ✓ - `go vet ./...` ✓ - `go test ./internal/workflow/ ./internal/modules/ ./internal/jobdef/` ✓
forbes added 1 commit 2026-02-20 18:08:55 +00:00
Add server-side solver service module with REST API endpoints, database
schema, job definitions, and runner result caching.

New files:
- migrations/021_solver_results.sql: solver_results table with upsert constraint
- internal/db/solver_results.go: SolverResultRepository (Upsert, GetByItem, GetByItemRevision)
- internal/api/solver_handlers.go: solver API handlers and maybeCacheSolverResult hook
- jobdefs/assembly-solve.yaml: manual solve job definition
- jobdefs/assembly-validate.yaml: auto-validate on revision creation
- jobdefs/assembly-kinematic.yaml: manual kinematic simulation job

Modified:
- internal/config/config.go: SolverConfig struct with max_context_size_mb, default_timeout
- internal/modules/modules.go, loader.go: register solver module (depends on jobs)
- internal/db/jobs.go: ListSolverJobs helper with definition_name prefix filter
- internal/api/handlers.go: wire SolverResultRepository into Server
- internal/api/routes.go: /api/solver/* routes + /api/items/{partNumber}/solver/results
- internal/api/runner_handlers.go: async result cache hook on job completion

API endpoints:
- POST   /api/solver/jobs          — submit solver job (editor)
- GET    /api/solver/jobs          — list solver jobs with filters
- GET    /api/solver/jobs/{id}     — get solver job status
- POST   /api/solver/jobs/{id}/cancel — cancel solver job (editor)
- GET    /api/solver/solvers       — registry of available solvers
- GET    /api/items/{pn}/solver/results — cached results for item

Also fixes pre-existing test compilation errors (missing workflows param
in NewServer calls across 6 test files).
forbes merged commit e5cae28a8c into main 2026-02-20 18:15:21 +00:00
forbes deleted branch feat/solver-service 2026-02-20 18:15:22 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/silo#160