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

78 lines
4.9 KiB
Markdown

# Tasks — `@suaveplan/api-worker-rpc`
> 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
- [x] 1.1 Read design doc §2.2, §5.2a, §6 (worker-marshalling paragraph)
- [x] 1.2 Read umbrella `openspec/changes/api-plugin-foundation/proposal.md`
- [x] 1.3 Read `openspec/AGENTS.md` Sections 13 and 14
- [x] 1.4 Draft `proposal.md`
- [x] 1.5 Draft `specs/api-worker-rpc/spec.md`
- [ ] 1.6 Every requirement carries a `**Verified by:**` line
## 2. Implementation
- [ ] 2.1 Scaffold `packages/api/api-worker-rpc/` (`0.1.0`, `sideEffects: false`, deps: `@suaveplan/error`, `@suaveplan/types`, `zod`)
- [ ] 2.2 `src/protocol/` — Zod-validated wire types
- [ ] 2.3 `src/correlation/` — monotonic id generator + request/response table + orphan detection
- [ ] 2.4 `src/abort/` — `AbortSignal` forwarding (caller `AbortController` → wire → callee `AbortController`)
- [ ] 2.5 `src/streaming/` — `ReadableStream` marshal via `Transferable`; backpressure ack
- [ ] 2.6 `src/error-reconstruction/` — `SuaveplanError` rebuild with depth-bounded cause chain
- [ ] 2.7 `src/backpressure/` — outstanding-message budget + `RPC_BACKPRESSURE`
- [ ] 2.8 `src/cloneable-guard/` — pre-send clone check + `RPC_NOT_CLONEABLE`
- [ ] 2.9 `src/caller/` — `createRpcCaller<T>(port): WorkerProxyOf<T>`
- [ ] 2.10 `src/callee/` — `serveRpc<T>(port, impl)`
- [ ] 2.11 `src/error-codes.ts` — every `RPC_*` code via `defineCodes`
- [ ] 2.12 `src/testing/index.ts` — paired `MessageChannel` factory for conformance harness
- [ ] 2.13 `src/index.ts` — namespace re-exports
## 3. Tests
- [ ] 3.1 `src/correlation/correlation.test.ts` — monotonic ids; orphan response detection (`RPC_ORPHAN_RESPONSE`)
- [ ] 3.2 `src/abort/abort.test.ts` — caller abort propagates; in-flight call rejects with `AbortError`; abort after settle is a no-op
- [ ] 3.3 `src/streaming/streaming.test.ts` — large stream chunked zero-copy; ack throttles producer; consumer cancel propagates
- [ ] 3.4 `src/error-reconstruction/error-reconstruction.test.ts` — round-trip preserves `code` AND cause chain AND `details`; non-Suaveplan → `RPC_REMOTE_THROW`
- [ ] 3.5 `src/backpressure/backpressure.test.ts` — outstanding budget enforced; exceeding throws `RPC_BACKPRESSURE` at caller BEFORE memory exhaustion
- [ ] 3.6 `src/cloneable-guard/cloneable-guard.test.ts` — function argument throws `RPC_NOT_CLONEABLE` synchronously at call site
- [ ] 3.7 `src/caller/caller.spec-conformance.test.ts` — `expectTypeOf<ReturnType<Caller<T>["m"]>>().toEqualTypeOf<Promise<R>>()`
- [ ] 3.8 `tests/conformance/round-trip.test.ts` — pair caller + callee over `MessageChannel`; every `RPC_*` code reachable
- [ ] 3.9 Every `it(...)` carries `{ timeout: 5000 }`
## 4. Documentation
- [ ] 4.1 Sibling `.md` for every implementation `.ts` (≥200 words, basic + advanced examples, full API reference)
- [ ] 4.2 README links every co-located `.md` under `## Modules`; explains the call/serve pair pattern
- [ ] 4.3 Update CLAUDE.md "Network / IO" package listing once shipped
## 5. Pre-archive verification (the 5-gate triple)
- [ ] 5.1 `bun run check` — Biome 0 errors / 0 warnings / 0 info
- [ ] 5.2 `bunx turbo lint typecheck test --filter=@suaveplan/api-worker-rpc` — green
- [ ] 5.3 `bunx turbo test:coverage --filter=@suaveplan/api-worker-rpc` — 100/100/100/100
- [ ] 5.4 `bun scripts/openspec-conformance.ts @suaveplan/api-worker-rpc` — exit 0
- [ ] 5.5 `bunx turbo build --filter=@suaveplan/api-worker-rpc` — green
## 6. Pre-archive 7-row checklist (AGENTS.md Section 13)
- [ ] 6.1 Generics threaded (`createRpcCaller<T>`, `serveRpc<T>`); `expectTypeOf` on `WorkerProxyOf<T>` derivation
- [ ] 6.2 Zod schemas at every wire boundary (`RpcRequest` / `RpcResponse` / etc.)
- [ ] 6.3 Every `RPC_*` code thrown by at least one production path
- [ ] 6.4 Strict-mode behaviors tested both on and off (backpressure budget configurable)
- [ ] 6.5 OTel — N/A (transport layer; consumers attach spans)
- [ ] 6.6 Lifecycle dedup — N/A (no FSM)
- [ ] 6.7 No retroactive tick
## 7. Archive
- [ ] 7.1 Fold spec delta into `openspec/specs/api-worker-rpc/spec.md`
- [ ] 7.2 Move `openspec/changes/api-worker-rpc/` → `openspec/archive/<yyyy-mm-dd>-api-worker-rpc/`
- [ ] 7.3 Tick Stage-3 row in umbrella
- [ ] 7.4 Refresh `MANIFEST.md`