Agent Identity and Status Tracking
1. Context & Motivation
Wardian currently manages Agent Identity (session_name) and Agent Status (current_status) as mutable fields in memory (AppState). This creates several issues:
- Duplicate Names: Agents can have the same
session_name, making them impossible to uniquely identify via CLI. - Volatile Status Tracking: Status is tracked by parsing stdout and updating an in-memory
HashMap. If Wardian restarts, it cannot recover the true state of background processes. - Process Lifecycle Coupling: The UI assumes the agent process is tied to the Tauri application lifecycle.
2. Agent Identity: Globally Unique CLI-Friendly Names
The UUID (session_id) remains the internal primary key and folder identifier (~/.wardian/agents/<uuid>). The session_name becomes a globally unique CLI-friendly alias.
2.1. Naming Constraints
- Regex:
^[a-zA-Z0-9_-]+$(No whitespace, no special characters). - Uniqueness: The Rust backend enforces uniqueness upon creation and mutation.
- Auto-Generation: Collisions result in unique suffixes (e.g.,
coder-a1b2).
2.2. Folder Stability
- Folder paths remain tied to UUIDs. Renaming an agent is a metadata-only change, ensuring no broken paths or file locks.
3. Status Tracking: SQLite Event Database
A local SQLite Database (~/.wardian/state.db) acts as the source of truth, enabling process recovery and event auditing.
3.1. Schema & Performance
- WAL Mode: SQLite will use Write-Ahead Logging (WAL) to prevent blocking concurrent UI reads during high-frequency parser writes.
agentstable: Addedlast_statusandlast_pidcolumns for O(1) status retrieval.eventstable: Audit log of status changes and tool calls.- Pruning: A background task will prune the
eventstable (e.g., keep last 1000 events or 30 days of history).
3.2. Status Lifecycle & Deduplication
- Deduplication: Status updates are only written to SQLite if
new_status != last_known_statusto prevent write amplification. - Event Source: PTY parsers emit
status_changeevents.
3.3. Process Recovery & "Headless" Reality
- Forensic ID Injection: Every agent is spawned with
WARDIAN_SESSION_ID=<uuid>in its environment. - Recovery: On startup, Wardian reconciles the DB with the OS process list. It verifies process identity by checking the environment block (via
sysinfo). - Headless Capability: If a process is alive but Wardian lacks the Master PTY handle (destroyed on restart), the status is
Headless.- Constraint: "Headless" agents are unreachable for interactive input until a PTY daemon (e.g., tmux-style persistence) is implemented. They continue executing tasks but cannot be commanded via the terminal grid.
4. Implementation Phasing
Phase 1: Strict Identity
- Update UI to enforce CLI-friendly name regex.
- Update Rust backend to reject duplicate names.
- Migration to sanitize existing names in
projects.json.
Phase 2: SQLite Infrastructure
- Add
rusqlitewith WAL mode. - Implement
dbmodule for migrations andWARDIAN_SESSION_IDinjection. - Hook parsers into the DB with a deduplication layer.
Phase 3: State Decoupling
- Derive telemetry and status from DB +
sysinfo. - Implement event pruning logic.