Skip to content

Remote comms: Handle reconnection to previously-dead peers with incarnation ID detection #806

@sirtimid

Description

@sirtimid

Problem

When a connection is marked as permanently dead (no longer retrying), a user action that initiates a new connection to the same peer should:

  1. Clear the permanent failure state and allow the connection
  2. Use incarnation ID logic to detect if it's the same peer instance or a restarted peer
  3. React appropriately based on whether the incarnation changed

Current Gaps

  1. sendRemoteMessage() doesn't clear permanent failure - if a user sends to a permanently-failed peer without calling reconnectPeer() first, the message will fail
  2. Handshake not integrated into connection flow - handshake module exists (handshake.ts) but channels are registered without exchanging incarnation IDs
  3. No incarnation change callback - when incarnation changes (peer restarted), RemoteHandle state needs to be reset

Proposed Solution

Part 1: Clear Permanent Failure on User-Initiated Send

In sendRemoteMessage(), check and clear permanent failure before dialing.

Part 2: Integrate Handshake into Connection Flow

  • Add localIncarnationId parameter to initTransport()
  • Perform outbound/inbound handshake after channel establishment
  • Pass handshake deps to reconnection lifecycle

Part 3: Add Incarnation Change Callback

  • Add OnIncarnationChange callback type
  • In RemoteHandle, add handlePeerRestart() method to:
    • Reject all pending messages
    • Reject pending URL redemptions
    • Reset sequence numbers
    • Clear persisted sequence state

Part 4: Same Incarnation (Resurrection)

No changes needed - normal operation continues with existing sequence numbers.

Files to Modify

  • packages/ocap-kernel/src/remotes/platform/transport.ts
  • packages/ocap-kernel/src/remotes/platform/reconnection-lifecycle.ts
  • packages/ocap-kernel/src/remotes/kernel/RemoteHandle.ts
  • packages/ocap-kernel/src/remotes/kernel/RemoteManager.ts
  • packages/ocap-kernel/src/remotes/types.ts
  • packages/ocap-kernel/src/store/index.ts (may need clearRemoteSeqState())

Behavior Summary

Scenario Behavior
Send to permanently-failed peer Clear failure, dial, handshake, proceed
Same incarnation ID Normal operation, pending messages may still be ACKed
Different incarnation ID Reset RemoteHandle state, reject pending, start fresh

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions