Skip to content

Conversation

@sirtimid
Copy link
Contributor

@sirtimid sirtimid commented Jan 22, 2026

Summary

  • Extract constants to dedicated constants.ts file
  • Extract PeerStateManager class for peer state management
  • Extract writeWithTimeout and makeErrorLogger to channel-utils.ts
  • Extract makeMessageSizeValidator and makeConnectionLimitChecker to validators.ts
  • Extract reconnection lifecycle logic to reconnection-lifecycle.ts
  • Add comprehensive unit tests for all extracted modules (73 new tests)

This reduces transport.ts from 784 to 521 lines (~33% reduction) while improving testability and maintainability.

Test plan

  • All 1634 unit tests pass
  • Lint passes
  • New test files added for all extracted modules

🤖 Generated with Claude Code


Note

Streamlines transport by extracting core concerns into dedicated, testable modules and updating transport.ts to compose them.

  • Introduces constants.ts, channel-utils.ts (makeErrorLogger, writeWithTimeout), validators.ts (message size/connection limit), peer-state-manager.ts (peer channels/flags/timestamps), and reconnection-lifecycle.ts (orchestrates reconnection)
  • Refactors transport.ts to use PeerStateManager, composed reconnection lifecycle, validators, and shared constants; replaces inline logic and maps
  • Adds unit tests for all new modules (channel-utils, validators, peer-state-manager, reconnection-lifecycle) and adjusts defaults via DEFAULT_* constants
  • Maintains behavior (e.g., intentional close handling, backoff reset, timeouts) while reducing transport.ts size and improving maintainability

Written by Cursor Bugbot for commit ece964a. This will update automatically on new commits. Configure here.

@sirtimid sirtimid requested a review from a team as a code owner January 22, 2026 20:23
sirtimid and others added 7 commits January 22, 2026 22:25
Move transport-related constants to constants.ts:
- DEFAULT_MAX_CONCURRENT_CONNECTIONS
- DEFAULT_MAX_MESSAGE_SIZE_BYTES
- DEFAULT_CLEANUP_INTERVAL_MS
- DEFAULT_STALE_PEER_TIMEOUT_MS
- DEFAULT_WRITE_TIMEOUT_MS
- SCTP_USER_INITIATED_ABORT

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move peer state management to dedicated PeerStateManager class:
- Encapsulates peerStates, lastConnectionTime, intentionallyClosed
- Provides methods: getState, countActiveConnections, updateConnectionTime
- Handles intentional close tracking (mark, check, clear)
- Location hints management (addLocationHints)
- Stale peer detection and removal

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move the writeWithTimeout utility function to a dedicated
channel-utils.ts module for better separation of concerns.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Create factory functions for validators:
- makeMessageSizeValidator: validates message size limits
- makeConnectionLimitChecker: validates connection limits

Both use ResourceLimitError with structured data for error handling.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add factory function for creating error logging functions with
peer context, reducing boilerplate in transport.ts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move handleConnectionLoss and attemptReconnection to reconnection-lifecycle.ts:
- Creates makeReconnectionLifecycle factory function
- Uses holder pattern to break circular dependency
- Encapsulates reconnection orchestration logic

This significantly reduces transport.ts complexity while keeping
the reconnection logic cohesive and testable.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive test coverage for the newly extracted modules:
- validators.test.ts: Tests for message size and connection limit validators
- channel-utils.test.ts: Tests for error logging and writeWithTimeout
- peer-state-manager.test.ts: Tests for PeerStateManager class
- reconnection-lifecycle.test.ts: Tests for reconnection lifecycle functions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@sirtimid sirtimid force-pushed the sirtimid/split-transport-concerns branch from 102ebf4 to ece964a Compare January 22, 2026 20:25
@github-actions
Copy link
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 88.54%
⬆️ +0.17%
5742 / 6485
🔵 Statements 88.42%
⬆️ +0.18%
5834 / 6598
🔵 Functions 87.31%
⬇️ -0.19%
1501 / 1719
🔵 Branches 84.97%
⬆️ +0.54%
2070 / 2436
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/ocap-kernel/src/remotes/platform/channel-utils.ts 100% 80% 100% 100%
packages/ocap-kernel/src/remotes/platform/constants.ts 100% 100% 100% 100%
packages/ocap-kernel/src/remotes/platform/peer-state-manager.ts 100% 100% 100% 100%
packages/ocap-kernel/src/remotes/platform/reconnection-lifecycle.ts 86.2% 86.2% 80% 86.2% 100-104, 124-125, 193-194
packages/ocap-kernel/src/remotes/platform/transport.ts 88.19% 80% 80% 88.19% 89, 108-111, 144, 178-196, 219, 352, 364, 416, 427
packages/ocap-kernel/src/remotes/platform/validators.ts 100% 100% 100% 100%
Generated in workflow #3289 for commit ece964a by the Vitest Coverage Report Action

@sirtimid sirtimid enabled auto-merge January 22, 2026 20:36
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.

2 participants