Repository navigation
Closed
Description
Overview
Implement the session lifecycle for external agent interactions: initialize a session with an agent, manage the state machine, handle message routing, and ensure clean teardown. This orchestrates the ACP transport and registry into a coherent session experience.
Acceptance Criteria
- State machine enforces valid transitions, rejects invalid operations
- Full lifecycle: create session, exchange messages, complete cleanly
- Initialization handshake: send ACP
initialize, receive capabilities, transition to Active - Timeout handling: 30s initialization, configurable message timeout
- Error recovery: transport failure transitions to Failed with diagnostic reason
- Multi-session: concurrent sessions with different agent types work
- Single-session per agent: second session for same agent type is rejected with clear error
- Unit tests with mock transport for all state transitions and edge cases
- Integration test with a simple test agent subprocess (echo server)
- Code passes
bun run quality:fix
Technical Specifications
New Module
packages/desktop-app/src-tauri/src/acp/session.rs
State Machine
Idle -> Initializing -> Active -> Completing -> Completed
\ \-> Failed
\-> Failed
- Enforce valid transitions at the type level or with runtime checks
- Reject operations invalid for current state (e.g., send message while Initializing)
- Store reason string when transitioning to Failed
Session Initialization
- Verify agent is available via
AgentRegistry - Spawn transport via
StdioTransportwith agent's binary/args/env - Send ACP
initializemessage:{ jsonrpc: "2.0", method: "initialize", params: { protocolVersion: "1", capabilities: {...} } } - Wait for
initializedresponse (30s timeout) - Send
session/newwith MCP server config:{ mcpServers: [{ name: "nodespace", url: "http://localhost:3100/mcp" }] } - Transition to Active
Message Routing (Active State)
- Forward user messages to agent via transport
- Receive agent responses and forward to frontend via Tauri events
- Agent tool-call requests happen out-of-band (agent -> MCP HTTP server)
- Track message count for session metadata
Completion
- Send completion signal
- Wait for agent's final response (configurable timeout)
- Transition to Completed
- Tear down transport gracefully
Multi-Session Management
- HashMap of active sessions keyed by session ID
- One active session per
AgentKind(reject duplicates) - Allow concurrent sessions with different agent types
- Session cleanup on completion or failure
Error Handling
- Transport failure -> immediate transition to Failed
- Timeout on any operation -> retry once, then Failed
- Agent process crash -> Failed with stderr output
- All errors include diagnostic info for frontend display
Reference Files
packages/desktop-app/src-tauri/src/acp/transport.rs— transport layer (ACP stdio NDJSON transport layer #1001)packages/desktop-app/src-tauri/src/acp/registry.rs— agent registry (ACP agent registry with binary detection and health checking #1002)packages/core/src/mcp/server.rs— MCP server (external agents connect here)
Exports
AcpSessionstructAcpClientServicefacade for managing multiple sessions
Dependencies
- Shared types, traits, and interface contracts for agent subsystems #998 (types/traits)
- ACP stdio NDJSON transport layer #1001 (ACP transport)
Related Issues
- ACP Integration and Local LLM Capability #997 (parent epic)
- ACP agent registry with binary detection and health checking #1002 (ACP registry — consumed but not blocking)
Activity
malibio commentedon Apr 3, 2026
Baseline: Frontend tests have a pre-existing Vitest startup error (TypeError in error handler). This is a known issue on the worktree, not introduced by this change. Rust backend is the focus of this issue.
feat: ACP session state machine and orchestration (closes #1004)
feat: ACP session state machine and orchestration (closes #1004)
feat: ACP session state machine and orchestration (closes #1004) (#1029)