Skip to content

feat(runtime): session manager, router, and protocol documentation#17

Merged
koistya merged 4 commits intomainfrom
dev
Jan 11, 2026
Merged

feat(runtime): session manager, router, and protocol documentation#17
koistya merged 4 commits intomainfrom
dev

Conversation

@koistya
Copy link
Member

@koistya koistya commented Jan 11, 2026

Summary

  • SessionManager: Connection lifecycle (idle → connecting → negotiating → active → retryWait) with automatic reconnection, configurable backoff, and pluggable negotiators
  • Router: Subject-based message dispatch with validation (rpc/, event/, stream/, app/ prefixes), handler registration with priority ordering, and built-in RPC envelope processing
  • SbpNegotiator: SBP handshake implementation with configurable timeouts and capability exchange
  • RpcCorrelationManager: Pending RPC tracking with timeouts and explicit cid correlation
  • Protocol documentation restructured under docs/protocols/ with dedicated sections for SBP, SBRP, SBDP, and RPC

Usage

import { createRouter, createSessionManager, SbpNegotiator } from "@sideband/runtime";
import { asPeerId, isMessageFrame } from "@sideband/protocol";

const router = createRouter();
router.route("rpc/user.get", async (msg) => {
  const userId = (msg.rpc?.params as { id: number }).id;
  await msg.rpc?.reply({ id: userId, name: "Ada" });
});

const manager = createSessionManager({
  endpoint: "wss://relay.example.com",
  transportFactory: (url) => connectWebSocket(url),
  negotiator: new SbpNegotiator({ peerId: asPeerId("browser-ui") }),
  onFrame: async (frame) => {
    if (isMessageFrame(frame)) {
      await router.dispatch(frame, session);
    }
  },
});

const session = await manager.connect();

ADRs

Test plan

  • SessionManager unit tests (state transitions, backoff, negotiator integration)
  • Router unit tests (subject validation, dispatch ordering, RPC context)
  • SbpNegotiator unit tests (handshake flow, timeout handling)
  • RpcCorrelationManager tests (pending tracking, timeout expiry)

SessionManager handles connection lifecycle with automatic reconnection
and configurable backoff. Router provides subject-based message dispatch
with validation and priority ordering. SbpNegotiator implements SBP
handshake with capability exchange.

Also includes protocol documentation restructuring and ADRs for runtime
peer lifecycle and message routing.
@koistya koistya merged commit 256cd7c into main Jan 11, 2026
1 check passed
@koistya koistya deleted the dev branch January 11, 2026 22:49
@github-actions github-actions bot mentioned this pull request Jan 11, 2026
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