Skip to content

Phase 3a: HTTP API + server foundation#6

Merged
StrangeNoob merged 13 commits into
mainfrom
phase3a-http-api
Jun 8, 2026
Merged

Phase 3a: HTTP API + server foundation#6
StrangeNoob merged 13 commits into
mainfrom
phase3a-http-api

Conversation

@StrangeNoob

Copy link
Copy Markdown
Owner

Summary

First Phase 3 sub-project: a JSON HTTP API and an always-on server, plus the broker methods they need. The foundation the dashboard (3b) and producer SDK (3c) will consume. No queue dependency added — routing is stdlib net/http (1.22 method+path patterns); the only state transition introduced (requeue) is a single atomic Lua script.

  • internal/broker — new read/admin methods: Stats (per-queue depth by state via one ZCARD×3+LLEN pipeline), ListDLQ (paged dead-letter inspection), RequeueDLQ (atomic requeue.lua: dlq→ready, resetting attempts to 0, ready-score rebuilt from priority exactly like promote/reaper), and Queues (SCAN-based discovery, deduped + sorted).
  • internal/api (new) — stdlib net/http JSON handler: POST /api/queues/{queue}/jobs (enqueue; 409 on idempotency-key duplicate), GET …/stats, GET …/dlq?limit=&offset=, POST …/dlq/{id}/requeue (404 if not in DLQ), GET /api/queues. {"error":…} envelope; empty lists serialize as [] not null.
  • cmd/server (new) — wires Redis + broker (with a Phase 2 metrics.Recorder, so API enqueues are counted) + the API handler + /metrics (depth gauges for -queues) + /healthz, with graceful shutdown. Flags -addr, -redis, -queues.
  • CLAUDE.md updated to Phase 3a complete.

Design & plan

  • Spec: docs/superpowers/specs/2026-06-08-relay-phase3a-http-api-design.md
  • Plan: docs/superpowers/plans/2026-06-08-relay-phase3a-http-api.md

Test plan

  • go build ./..., go vet ./..., gofmt -l internal/ cmd/ all clean
  • go test -race ./... (uncached) — broker (DB 15), worker (DB 14), metrics (DB 13), api (DB 12), job all pass against a real Redis; test DBs isolated so go test ./... is parallel-safe
  • Broker tests assert real Redis state (counts, scores, hash fields, attempts reset, paging); requeue verified atomic (dlq emptied, back in ready, re-claimable)
  • API tests via httptest cover 201/409/400/404/200, empty-list shape, and the full DLQ→requeue→ready flow
  • cmd/server smoke-tested end-to-end (healthz, enqueue, stats, queues, /metrics)

Implements the HTTP control surface package: api.New wires a Go 1.22
method+path ServeMux; enqueue handler (POST /api/queues/{queue}/jobs)
returns 201, 400, 409, or 500; jobView, toJobView, parseInt64 helpers
defined for Tasks 6-7; stats/listDLQ/requeueDLQ/queues are 501 stubs.
Tests use Redis DB 12 and skip when Redis is unreachable.
Update CLAUDE.md to reflect the shipped HTTP API package and server:
status, "what exists today" bullets, new broker methods and requeue.lua
script, DLQ table row, layout tree, build order, known-limitations
(API/auth/payload/paging caveats), DB allocation (api → DB 12), and
end-to-end run commands.
@StrangeNoob

Copy link
Copy Markdown
Owner Author

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@StrangeNoob StrangeNoob merged commit fd64e19 into main Jun 8, 2026
2 checks passed
@StrangeNoob StrangeNoob deleted the phase3a-http-api branch June 8, 2026 16:42
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.

1 participant