Skip to content

Route shared relay clients#20

Merged
TraderSamwise merged 1 commit into
masterfrom
feat/multi-user-chat-routing
May 24, 2026
Merged

Route shared relay clients#20
TraderSamwise merged 1 commit into
masterfrom
feat/multi-user-chat-routing

Conversation

@TraderSamwise

@TraderSamwise TraderSamwise commented May 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • route shared client websocket connections to the owner Durable Object with ownerUserId/shareId pairing
  • authorize shared websocket clients against accepted share participants
  • restrict shared client requests to chat-scoped project routes and inject trusted actor/share headers for the daemon
  • allow app RelayTransport to connect to a shared owner/share
  • pass relay-injected headers through the daemon proxy path

Verification

  • yarn --cwd relay typecheck
  • yarn typecheck
  • yarn --cwd app typecheck
  • yarn vitest run relay/src/sharing.test.ts
  • pre-push: yarn typecheck && yarn lint && yarn test

Summary by CodeRabbit

  • New Features
    • Added shared chat routing support, enabling clients to connect using owner and share identifiers for collaborative sessions.
    • Enhanced relay transport with optional configuration parameters to support shared session functionality.
    • Improved request forwarding with header propagation through the relay infrastructure.

Review Change Stack

@TraderSamwise

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 24, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented May 24, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0c8d161f-a5d4-473b-beac-88b7de1d5926

📥 Commits

Reviewing files that changed from the base of the PR and between 8f57cae and 666b52b.

📒 Files selected for processing (8)
  • app/lib/relay-transport.ts
  • relay/src/index.ts
  • relay/src/relay-object.ts
  • relay/src/sharing.test.ts
  • relay/src/sharing.ts
  • relay/src/types.ts
  • src/daemon.ts
  • src/relay-client.ts

📝 Walkthrough

Walkthrough

This PR adds end-to-end shared chat routing: clients now specify ownerUserId and shareId parameters; the relay server authenticates and routes these requests to the correct owner instance; the relay object validates shared connections and requests using new authorization helpers, tagging connections and preparing metadata headers; and request headers are propagated through the system.

Changes

Shared chat routing and header forwarding

Layer / File(s) Summary
Shared request authorization helpers and tests
relay/src/sharing.ts, relay/src/sharing.test.ts
sharedRelayRequestAccess unwraps proxy-style paths and extracts sessionId from request body or query params, then delegates authorization to existing logic. New test verifies proxy route unwrapping and authorization decisions on proxied agent routes.
Client transport options and server connect routing
app/lib/relay-transport.ts, relay/src/index.ts
Client RelayTransport exports RelayTransportOptions with optional ownerUserId and shareId, passing them as query parameters. Server /client/connect handler fetches Clerk user profiles, validates ownerUserId/shareId presence together, routes using ownerUserId when provided, and forwards profile name/email and share owner headers.
Relay object shared chat support
relay/src/relay-object.ts
Relay imports sharedRelayRequestAccess and getShareChatMode, reads optional shareId from WebSocket query parameters, authorizes shared client connections, tags sockets with share:<id> and user:<userId>, and intercepts client requests to validate routing and prepare header patches before forwarding to daemon.
Request header type and propagation
relay/src/types.ts, src/daemon.ts, src/relay-client.ts
RelayRequest type adds optional headers: Record<string, string>. Daemon routeRequest accepts optional headers map and forwards headers in proxy requests. RelayClient forwards msg.headers from incoming messages to daemon routing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • TraderSamwise/aimux#18: This PR's shared-chat routing (e.g., sharedRelayRequestAccess, getShareChatMode usage) builds on the shared-session primitives and authorization foundation established in that PR.

Poem

🐰 Whiskers twitch with glee—
Shares bloom where they're allowed,
Tags guide the relay dance,
Headers flow like honeydew,
One chat, many viewers! 🌙

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Route shared relay clients' directly and specifically summarizes the main change: implementing routing for shared relay client WebSocket connections with owner/share pairing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/multi-user-chat-routing

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

app/lib/relay-transport.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.


Comment @coderabbitai help to get the list of available commands and usage tips.

@TraderSamwise
TraderSamwise merged commit 98d4205 into master May 24, 2026
1 check passed
@TraderSamwise
TraderSamwise deleted the feat/multi-user-chat-routing branch May 24, 2026 09:09
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