19 tasks covering core testing, Redis hardening, WebSocket client/server adapters, Worker adapter, and final review gates. Iroh adapters are tracked as a deferred placeholder blocked on the @alkdev/iroh fork. Phases: core validation → Redis hardening → review gate → WebSocket adapters → review gate → Worker adapter → review gate → final validation.
3.5 KiB
3.5 KiB
id, name, status, depends_on, scope, risk, impact, level
| id | name | status | depends_on | scope | risk | impact | level | |
|---|---|---|---|---|---|---|---|---|
| websocket-server-adapter | Implement WebSocket server event target adapter | pending |
|
broad | medium | component | implementation |
Description
Implement the createWebSocketServerEventTarget adapter as specified in docs/architecture/event-targets/websocket-server.md.
This is a fan-out (multi-connection) adapter that manages multiple WebSocket connections for the hub/server side. It must implement topic-based fan-out with subscription tracking using __subscribe/__unsubscribe control events.
Key requirements from the architecture:
- Factory returns
WebSocketServerEventTargetwhich extendsTypedEventTargetwithaddConnection(ws)andremoveConnection(ws) addConnectionsets uponmessageandonclosehandlers on the WebSocketremoveConnectioncleans up subscription maps and event handlers (but does NOT close the WebSocket)dispatchEventsends to only connections subscribed to the event type (topic-based fan-out)addEventListenerregisters local listeners (aggregate from all spokes)- Subscription tracking:
Map<string, Set<WebSocket>>from topic to subscribed connections - Control protocol:
__subscribe/__unsubscribemessages from spokes update subscription map - Backpressure: configurable threshold (default 1MB) — disconnect slow consumers
onConnectionandonDisconnectioncallbacks for lifecycle events- Framework-agnostic: takes raw
WebSocketinstances, doesn't handle HTTP upgrade dispatchEventalways returnstrue(errors handled via side effects)
Acceptance Criteria
src/event-target-websocket-server.tsexistscreateWebSocketServerEventTarget(options)returnsWebSocketServerEventTargetWebSocketServerEventTargetextendsTypedEventTargetwithaddConnectionandremoveConnectionaddConnection(ws)sets uponmessageandonclosehandlersremoveConnection(ws)cleans up internal state but does not close the WebSocketaddConnectiononclosehandler automatically callsremoveConnectiondispatchEventsends only to connections subscribed to the event typeaddEventListenerregisters local listeners (aggregate events from all spokes)__subscribecontrol events from spokes add connection to topic's subscriber set__unsubscribecontrol events from spokes remove connection from topic's subscriber set- Duplicate
__subscribeis idempotent (Set handles naturally) - Invalid topic format in control events is silently ignored
- Malformed JSON from spokes is silently ignored (logged)
- Backpressure: before
ws.send(), checkbufferedAmountagainst threshold - Backpressure: exceeding threshold closes connection with code 1013
onBackpressurecallback called before disconnectingonConnectioncallback receives spoke event target and raw WebSocketonDisconnectioncallback receives spoke event target and raw WebSocketdispatchEventalways returnstrue- Send failure (ws.send throws) catches error, removes connection, fires
onDisconnection - No comments in source code (project convention)
- Sub-path export added to
package.jsonandtsup.config.ts - Barrel re-export added to
src/index.ts
References
- docs/architecture/event-targets/websocket-server.md
- docs/architecture/decisions/003-subscription-control-protocol.md
- src/types.ts
Notes
To be filled by implementation agent
Summary
To be filled on completion