PTY Daemon Architecture
The PTY Daemon (pty-daemon-rust) is a standalone Rust binary that manages PTY sessions. It survives app crashes and enables session recovery.
Overview
Key Features
Crash Resilience
The daemon runs as a separate process from the main app:- App crashes don’t kill the daemon
- Terminal sessions continue running
- Sessions can be recovered on app restart
Unix Socket Communication
Each session has its own Unix socket:Pure Rust PTY
Usesportable-pty crate for cross-platform PTY management:
- No node-pty (native module issues)
- Pure Rust implementation
- macOS, Linux, Windows support
Protocol
Control Socket Commands
| Command | Description |
|---|---|
CREATE | Create new PTY session |
LIST | List active sessions |
KILL | Terminate a session |
SHUTDOWN | Graceful daemon shutdown |
Session Socket Protocol
Binary protocol for data transfer:Lifecycle
Startup
Session Creation
Crash Recovery
Configuration
Binary Location
| Environment | Path |
|---|---|
| Development | src-tauri/binaries/pty-daemon-rust-{triple} |
| Production | MacOS/pty-daemon-rust |
Tauri Configuration
Target Triple Suffix
| Platform | Suffix |
|---|---|
| macOS ARM | aarch64-apple-darwin |
| macOS Intel | x86_64-apple-darwin |
| Linux | x86_64-unknown-linux-gnu |
| Windows | x86_64-pc-windows-msvc.exe |
Logging
Daemon logs to/tmp/pty-daemon.log:
Troubleshooting
Check Daemon Status
Kill Stale Daemon
Code Signing (macOS)
Daemon binary MUST be signed or macOS will SIGKILL it:Characteristics
| Metric | Value |
|---|---|
| Binary size | ~953KB |
| Startup | Fast |
| Memory per session | Low |
| Communication | Unix sockets |
SMPC/OFAC Applied
| Principle | Application |
|---|---|
| SMPC | Single responsibility: PTY management only |
| Simple protocol: length-prefixed binary | |
| One socket per session: clear isolation | |
| OFAC | Crash resilience emerged from separate process |
| Recovery pattern emerged from socket persistence |