Files
suaveplan/openspec/archive/2026-05-26-api-saga/tasks.md
2026-05-27 23:29:53 +01:00

5.3 KiB

Tasks — @suaveplan/api-saga

Every checkbox MUST reflect work actually done in this change.

0. Pre-flight (non-negotiable)

  • 0.1 Confirm clean working tree (git status reports nothing) and no in-flight worktrees with uncommitted work (git worktree list then git status in each)
  • 0.2 If any worktrees exist under .claude/worktrees/, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (git worktree remove) before opening a new one — code that has been lost twice on main is the failure mode this guards against.
  • 0.3 Confirm the package set in MANIFEST.md matches find packages -maxdepth 3 -name package.json count. Drift here means a prior change archived without regenerating the manifest.

1. Spec authoring

  • 1.1 Read design doc §9.1 (sagas) and §9.3 (engine choice)
  • 1.2 Read umbrella openspec/changes/api-plugin-foundation/proposal.md (Stage 6 acceptance)
  • 1.3 Read openspec/AGENTS.md Sections 13 and 14
  • 1.4 Draft proposal.md from openspec/templates/proposal.md
  • 1.5 Draft specs/api-saga/spec.md from openspec/templates/spec-delta.md
  • 1.6 Every requirement carries a **Verified by:** line naming concrete it(...) titles

2. Implementation

  • 2.1 Scaffold packages/api/api-saga/ with package.json ("version": "0.1.0", "sideEffects": false), tsconfig.json, tsup.config.ts
  • 2.2 src/orchestrator/orchestrator.ts — createSagaOrchestrator(deps) factory + SagaOrchestrator class
  • 2.3 src/registry/participant-registry.ts — owner + participant registration, validation of declared step → plugin → action wiring
  • 2.4 src/persistence/persistence.ts — SagaPersistence interface bound against host metadata DB; CRUD over suaveplan_saga_instances and suaveplan_saga_steps
  • 2.5 src/recovery/recovery.ts — boot-time replay: query incomplete instances, resume each through orchestrator
  • 2.6 src/idempotency/idempotency.ts — per-step idempotency wrapper using @suaveplan/idempotency keyed by {sagaId, stepName}; honour per-action idempotency: "manual" opt-out
  • 2.7 src/events/events.ts — Zod schemas for every saga event payload (saga.step.requested, .completed, .failed, .compensated, plus .instance.*); typed emitter helpers
  • 2.8 src/compensation/compensation.ts — reverse-order compensation runner with retry up to maxCompensationAttempts; compensation_failed terminal state
  • 2.9 src/tenant/cross-tenant.ts — capability check for saga.cross-tenant; refuse step dispatch otherwise
  • 2.10 src/state/state-machine.ts — SagaInstanceState + SagaStepState transition table with invalid-transition guard
  • 2.11 src/instruments/instruments.ts — OTel instrument registration (span/counter/histogram/gauge per design §9.1)
  • 2.12 src/error-codes.ts — 10 SAGA_* codes; every code thrown from at least one production path
  • 2.13 ./testing subpath — runSagaParticipantConformance suite
  • 2.14 src/index.ts — explicit named re-exports

3. Tests

  • 3.1 Unit tests per module (every it(...) { timeout: 5000 })
  • 3.2 src/orchestrator/orchestrator.spec-conformance.test.ts — runs the conformance suite against a reference participant
  • 3.3 src/persistence/persistence.test.ts — Postgres integration via @suaveplan/testing-integration-postgres ({ timeout: 30000 }); pins recovery-after-restart
  • 3.4 tests/integration/cross-plugin-saga.test.ts — full two-plugin saga end-to-end with forced compensation ({ timeout: 60000 })
  • 3.5 Every test imports test-runner primitives from @suaveplan/testing/runner

4. Documentation

  • 4.1 Sibling .md for every implementation .ts (≥200 words, basic + advanced examples)
  • 4.2 README.md at package root linking every co-located .md under ## Modules; calls out owner-vs-participant model

5. Pre-archive verification (the 5-gate triple)

  • 5.1 bun run check — Biome 0/0/0
  • 5.2 bunx turbo lint typecheck test --filter=@suaveplan/api-saga — green
  • 5.3 bunx turbo test:coverage --filter=@suaveplan/api-saga — 100/100/100/100
  • 5.4 bun scripts/openspec-conformance.ts @suaveplan/api-saga — exit 0
  • 5.5 bunx turbo build --filter=@suaveplan/api-saga — green

6. Pre-archive 7-row checklist (AGENTS.md Section 13)

  • 6.1 Generics threaded through SagaOrchestrator<TInput, TOutput>; expectTypeOf assertions on every literal-type claim
  • 6.2 Zod schemas wired at every event-payload boundary and at the manifest-tree consumer
  • 6.3 Every SAGA_* error code thrown by at least one production path
  • 6.4 Strict-mode behaviour tested both on and off (idempotency manual-opt-out, cross-tenant gate)
  • 6.5 OTel instruments emitted from production paths and asserted with a real in-memory MeterProvider
  • 6.6 Lifecycle dedup tested: re-dispatching a completed step is a no-op; resume after restart does not double-fire
  • 6.7 No retroactive tick — every box above reflects work done in this change

7. Archive

  • 7.1 Fold spec delta into openspec/specs/api-saga/spec.md
  • 7.2 Move openspec/changes/api-saga/ → openspec/archive/<yyyy-mm-dd>-api-saga/
  • 7.3 Tick the Stage-6 row in umbrella openspec/changes/api-plugin-foundation/tasks.md
  • 7.4 Refresh MANIFEST.md