4.9 KiB
4.9 KiB
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 statusreports nothing) and no in-flight worktrees with uncommitted work (git worktree listthengit statusin 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.mdmatchesfind packages -maxdepth 3 -name package.jsoncount. Drift here means a prior change archived without regenerating the manifest.
1. Spec authoring
- 1.1 Read design doc §2.2, §5.2a, §6 (worker-marshalling paragraph)
- 1.2 Read umbrella
openspec/changes/api-plugin-foundation/proposal.md - 1.3 Read
openspec/AGENTS.mdSections 13 and 14 - 1.4 Draft
proposal.md - 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/—AbortSignalforwarding (callerAbortController→ wire → calleeAbortController) - 2.5
src/streaming/—ReadableStreammarshal viaTransferable; backpressure ack - 2.6
src/error-reconstruction/—SuaveplanErrorrebuild 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— everyRPC_*code viadefineCodes - 2.12
src/testing/index.ts— pairedMessageChannelfactory 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 withAbortError; 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 preservescodeAND cause chain ANDdetails; non-Suaveplan →RPC_REMOTE_THROW - 3.5
src/backpressure/backpressure.test.ts— outstanding budget enforced; exceeding throwsRPC_BACKPRESSUREat caller BEFORE memory exhaustion - 3.6
src/cloneable-guard/cloneable-guard.test.ts— function argument throwsRPC_NOT_CLONEABLEsynchronously 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 overMessageChannel; everyRPC_*code reachable - 3.9 Every
it(...)carries{ timeout: 5000 }
4. Documentation
- 4.1 Sibling
.mdfor every implementation.ts(≥200 words, basic + advanced examples, full API reference) - 4.2 README links every co-located
.mdunder## 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>);expectTypeOfonWorkerProxyOf<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