Remote Collaboration for AI Coding Assistants: Architecture, Protocol, and Acceptance Criteria

    This article describes a production-ready design for keeping one coding-assistant session consistent across a primary workstation, mobile devices, and the browser. It covers scope and non-goals, per-device capability matrices, view-versus-storage separation, a unified session event protocol, connection and encryption policy, permissions and approvals, gray-release gates, rollback rules, long-lived connection recovery, and operational troubleshooting.

    Scope and Non-Goals

    The scenario is a single development session that must attach from a primary workstation, a mobile device, and a browser, with history and live state remaining consistent. Intended readers include client, server, and plugin engineers, as well as architects evaluating whether to adopt the capability.

    Out of scope:

    • Multi-user real-time editing of the same file and conflict merge. That belongs to a collaborative-editing system and should be designed separately.
    • A guarantee that NAT traversal always succeeds on arbitrary public networks. Strict NAT, enterprise firewalls, and carrier policy can block direct paths; a relay fallback is mandatory.
    • Replacing a code-hosting platform. The remote plugin does not store repositories and does not manage versions.

    Experimental boundary: the capability is off by default and limited to internal canary users. Do not roll it out fully until the acceptance metrics in section 7 are met.

    Terminal Capability Matrix

    Compute, network, and interaction differ by device. Set default privileges and degradation per terminal type.

    Terminal Runtime Network Primary interaction Default privileges Degradation
    Primary workstation Local assistant with workspace access Typically wired or stable Wi-Fi Text, images, approval, stop Read allowed; writes and command execution require approval Fall back to TURN relay if P2P fails
    Mobile Connected to host only; no command execution Weak networks, frequent handoffs Progress, text prompts, approval Read-only; approvals need a second confirmation Pause streaming on weak networks; sync only critical events
    Browser No local client Often behind corporate proxies and firewalls Text prompts, read-only view Read-only; image upload cap 5 MB Auto-disconnect after 30 minutes idle; restore after re-login

    Define the minimum capability set first, then decide whether to open writes or command execution. Mobile and browser should not receive execute privileges by default.

    Architecture: Separate View from Storage

    The remote plugin stores only a session view, not business data. The native workspace remains the single source of truth. The plugin maps native session history and live events into a remote-protocol event stream.

    Data ownership and cleanup:

    • View cache lives in the plugin directory, retained at most 24 hours, then deleted.
    • On uninstall, delete view cache, device keys, and access tokens.
    • Audit logs are stored separately, retained 90 days by default, then deleted per organization policy. Audit logs do not contain payload plaintext.
    • Native workspace session records are unchanged by plugin uninstall.

    Benefits: a single data copy (no version drift), and a compromised plugin leaks only view cache, not native storage. Trade-off: remote clients cannot browse history while the host is offline.

    Session Event Protocol

    Native events map to a unified remote event. All implementations must honor these fields:

    Field Type Required Description
    event_id string (UUID) Yes Unique event id
    session_id string Yes Session id
    event_type enum Yes One of history, frame, interactive, control
    seq int64 Yes Monotonic per session, starting at 1, assigned by the host
    ts int64 Yes UTC milliseconds; display and diagnostics only
    source_device_id string Yes Originating device
    payload object Yes Max 64 KB per event; shard if larger
    chunk_index / chunk_total int Required when sharded Shard index and total
    idempotency_key string Yes Same value for all retries of one operation
    permission_ctx object Yes role, granted_scopes, expires_at
    schema_version string Yes Protocol version; currently 1.0

    Ordering and deduplication:

    1. Clients consume events in seq order. Out-of-order events go into a buffer of 200 events or 2 seconds, whichever is hit first.
    2. After buffer timeout, the client requests history catch-up with last_seq.
    3. Dedup key is idempotency_key. The server keeps 10 minutes of records; duplicate keys return the existing result.
    4. seq must be assigned on the host from a single serial queue. Unsynchronized multi-thread increments create gaps.

    Resume: on reconnect the client sends last_seq; the server returns events with seq greater than last_seq. If last_seq is older than the retention window (default last 5000 events), the server returns a full snapshot and the snapshot’s starting seq.

    Connection Strategy and Encryption

    5.1 Connection order and failure

    1. P2P: gather ICE candidates, 3-second timeout.
    2. If not connected within 15 seconds, treat direct connect as failed and switch to TURN.
    3. After connect, if packet loss exceeds 5% for 30 seconds, switch to relay.
    4. If relay also fails, show a clear error and network-check guidance.

    Retries use exponential backoff: 1s, 2s, 4s, 8s, cap 30s, at most 6 attempts. After that, stop automatic retry until the user acts.

    5.2 Encryption

    • Transport: TLS 1.3 or DTLS 1.2+.
    • Application: end-to-end encrypt payload with AES-256-GCM or ChaCha20-Poly1305.
    • Pairing: X25519 key agreement.
    • Session keys rotate every 1 hour or every 100,000 messages.
    • TURN nodes see ciphertext and metadata only.

    5.3 Key management

    • Private keys in the OS keystore (macOS Keychain, Windows DPAPI, Linux Secret Service).
    • Private keys, tokens, and payload plaintext must not appear in logs. Logs record event_id and hashes only.
    • On device revoke, delete the key and invalidate tokens within 60 seconds.

    Permissions, Directory Import, and Approval

    6.1 Permission matrix

    Capability Default Approval Required audit fields
    Workspace file read Allowed No path, file hash
    Workspace file write Denied Yes, show diff path, diff hash, approver
    Command execution Denied Required outside allowlist command, cwd, exit code
    Image upload Allowed, 5 MB cap No size, MIME, sha256
    Model switch Org allowlist only No model ids before/after
    External directory import Needs grant Yes path, owner, grant scope

    Approval requests auto-deny after 5 minutes with no response. Records must include requester, approver, timestamp, and decision.

    6.2 Directory import checklist

    • Imported directories are project context for the external assistant only; they are not written into assistant storage.
    • Canonicalize paths, then verify they sit under the authorized root.
    • Do not follow symlinks that leave the authorized tree.
    • Audit logs are append-only.
    • After import, sample-read 3 files and confirm path and content match the grant.

    Canary Release and Rollback

    7.1 Stages

    Advance 1% → 10% → 50% → 100%. Each stage runs at least 48 hours and must meet:

    Metric Gate
    Connection success (direct + relay) ≥ 98%
    Reconnect P50 ≤ 3 s
    Reconnect P95 ≤ 10 s
    First-screen sync P95 ≤ 800 ms
    Event loss (by seq, after catch-up) 0
    Relay traffic share ≤ 30%
    Privilege-violation events 0

    7.2 Switch granularity

    Three levels: organization, user, feature. Feature flags can disable a capability other than approval (for example image upload) independently.

    7.3 Rollback triggers

    Rollback if any of:

    • Connection success below 95% for 15 consecutive minutes.
    • Event loss above 0.1%.
    • Any privilege-violation event.
    • Audit-log write failure above 0.5%.

    Rollback steps:

    1. Flip the corresponding switch; stop accepting new sessions.
    2. Notify existing sessions to end; 30-second graceful window.
    3. Force disconnect after timeout; keep audit logs.
    4. Record cause, blast radius, and recovery plan; notify owners.

    Long-Lived Connection Recovery

    1. Heartbeat every 15 seconds. Three missed replies (~45 s) means disconnected.
    2. Client reconnects with section 5 backoff.
    3. Reconnect carries session_id, last_seq, and access token. Server validates token and device state.
    4. Server returns incremental events after last_seq, or a snapshot if outside the window.
    5. Client checks seq continuity and idempotency_key uniqueness; refetch on anomaly.

    When multiple endpoints are online, only one device holds the write lease for a session. Lease TTL is 30 seconds; holder renews every 10 seconds. Others are read-only. Takeover requires an explicit request, preventing split-brain dual writes.

    Recovery is accepted when there are no seq gaps, no duplicate idempotency_keys, and exactly one lease holder.

    Design Comparison

    Approach Pros Cons Fit
    P2P only Low latency, no relay cost High traversal failure, no fallback Same LAN or controlled office networks
    Central relay High reachability, simpler Bandwidth cost, central SPOF Strict NAT, frequent cross-network access
    P2P first, relay fallback Latency plus reachability More complex; TURN to operate Default for most teams

    View-layer cache is easy to purge but unavailable offline. If offline history is required, keep an encrypted plugin cache and document retention and cleanup in config.

    Common Troubleshooting

    • Stuck in checking: verify STUN/TURN reachability. If UDP is blocked, use TCP/TLS relay on port 443.
    • Duplicate events: retries regenerated idempotency_key. Reuse the same key for one operation.
    • Missing seq: host assignment is not atomic across threads.
    • Mobile approval UI missing: check push path and token expiry.
    • Assistant reads files outside the grant after import: canonicalize first and do not follow outbound symlinks.

    Conclusion and Fit

    This design fits teams that must continue one coding session across terminals and can tolerate a canary cycle. It requires the host to be online and is not for fully offline collaboration. Security depends on key management, the permission matrix, and audit logs together. Keep the experimental flag until section 7 gates are met, and honor the rollback conditions.