Skip to content

CLI commands report incorrect status (error/idle) for live sessions #325

@shanesavoie

Description

@shanesavoie

Bug Description

CLI commands (agent-deck list --json, agent-deck status --json) report incorrect status for live tmux sessions. Sessions that are alive and waiting for input show as error or idle instead of waiting.

Root Causes

1. CLI never reads hook status files from disk

The TUI uses StatusFileWatcher (fsnotify) to populate hookStatus on each instance, enabling the hook fast path in UpdateStatus(). CLI commands don't start a StatusFileWatcher, so hookStatus is always empty and the hook fast path is always skipped. This forces all CLI status detection through the slower tmux polling path.

2. ReconnectSessionLazy restores acknowledged flag from SQLite status

When loading from SQLite with previousStatus="idle", ReconnectSessionLazy creates a StateTracker with acknowledged=true. The tmux polling path in GetStatus() then detects a prompt indicator but sees acknowledged=true and returns "idle" instead of "waiting". This means sessions that transitioned from idle→waiting (e.g., Claude finished work and is waiting for input) get stuck reporting idle in CLI.

3. Restart() doesn't write .sid sidecar file

After RespawnPane() in Restart(), no .sid file is written. Hook events fired after restart can't be correlated with the instance because the .sid anchor is missing. This causes the hook handler to write status files without a session ID, and UpdateHookStatus() can't resolve the session.

Reproduction

  1. Start several Claude sessions via agent-deck TUI
  2. Wait for sessions to complete their work (status → waiting)
  3. Run agent-deck list --json or agent-deck status --json
  4. Observe sessions reported as error or idle instead of waiting
  5. The TUI shows correct status because it has the StatusFileWatcher

Expected Behavior

CLI commands should report the same status as the TUI for all sessions.

Proposed Fix

  1. Add cold hook file loading in UpdateStatus(): When hookStatus is empty and the tool supports hooks, read the .json hook file from disk once. This gives CLI the same hook fast path without needing a persistent filesystem watcher.

  2. Write .sid file in Restart(): After successful RespawnPane(), call WriteHookSessionAnchor() to persist the session ID mapping.

Environment

  • agent-deck v0.25.1
  • macOS (Darwin 24.6.0)
  • tmux 3.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions