Skip to content

ACP stdio NDJSON transport layer #1001

Closed

Description

@malibio

Overview

Implement the low-level transport for communicating with external ACP agents over stdio using newline-delimited JSON-RPC 2.0. This is a pure I/O layer — no business logic, no agent-specific behavior.

Acceptance Criteria

  • AcpTransport trait from Shared types, traits, and interface contracts for agent subsystems #998 fully implemented
  • Can spawn a subprocess, send NDJSON messages, receive responses
  • Handles process crash gracefully (detect broken pipe, report error)
  • Graceful shutdown sequence works (close -> SIGTERM -> SIGKILL)
  • Stderr lines are logged but do not interfere with protocol
  • Buffered reading handles partial lines correctly
  • Concurrent send/receive works without deadlock
  • Unit test with mock subprocess (simple echo server script)
  • Code passes bun run quality:fix

Technical Specifications

New Module

  • packages/desktop-app/src-tauri/src/acp/transport.rs

Process Spawning

  • Launch external agent binary as child process with stdin/stdout/stderr pipes
  • Configurable: command, args, env vars, working directory
  • Use tokio::process::Command for async subprocess management

NDJSON Framing

  • Write: serialize AcpMessage to JSON, append newline, write to stdin
  • Read: BufReader on stdout, read_line() per message, parse as AcpMessage
  • Handle partial lines (buffered reader accumulates until newline)

Bidirectional Streaming

  • Tokio tasks for concurrent read/write
  • Write task: consumes from mpsc::Sender, writes to stdin
  • Read task: reads from stdout, produces to mpsc::Receiver
  • Internal channel-based architecture decouples caller from I/O

Stderr Capture

  • Background task reads stderr lines
  • Log via tracing at warn level
  • Do not treat stderr as protocol data

Lifecycle

  • Graceful shutdown: send close message, wait 5s, SIGTERM, wait 2s, SIGKILL
  • Track process exit status
  • No reconnection (sessions are one-shot)

Error Types

  • Transport errors: pipe broken, process died, spawn failed
  • Protocol errors: invalid JSON, unexpected message format
  • Both surfaced with distinct error variants

Reference Files

  • packages/core/src/mcp/server.rs — existing MCP server (stdio transport pattern)

Exports

  • StdioTransport struct implementing AcpTransport

Dependencies

Related Issues

Activity

  1. malibio commented on Apr 3, 2026

    @malibio
    CollaboratorAuthor

    Baseline: Frontend tests have pre-existing vitest startup error (TypeError: Attempted to assign to readonly property). This is not caused by this PR.

  2. self-assigned this
    on Apr 3, 2026
  3. added a commit that references this issue on Apr 3, 2026
    90f1918
  4. added 2 commits that reference this issue on Jun 22, 2026
    88f09b7
    f179ec2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions