Skip to content

Share SSH commands between remote agent session stats - #600

Open
thiblahute wants to merge 1 commit into
powerfooI:mainfrom
thiblahute:upstream/remote-session-reads
Open

thiblahute wants to merge 1 commit into
powerfooI:mainfrom
thiblahute:upstream/remote-session-reads

Conversation

@thiblahute

Copy link
Copy Markdown
Collaborator

Summary

Remote agent session stats share SSH commands: stats asked together go out as one command, and the agent list reuses an agent's activity time for 30 seconds while its state stays. A follow-up to #563 and #564.

Why

Each stat of a session file on an SSH host ran its own SSH command. agent.list, polled every few seconds, stat'ed every agent's session each time to fill last_activity_at, and a session's subagents are stat'ed one by one. With many agent panes on one host, these commands held the host's session slots, so opening a chat or reading a long transcript on that connection waited behind them.

What changed

  • session-file-access.ts: a remote statFile waits 25 ms for others and goes out with them as one bash -c script over SSH (up to 64 paths per command). The script answers a line per path: - for no file, ! for an unreadable one, else the same metadata as before (GNU stat, else BSD stat). A stat only joins a batch that has not been sent, so its answer is never older than the call; the same path asked twice in a batch shares one answer. A failed command rejects every stat in it.
  • agent-activity.ts: over SSH, an agent's activity time is reused for 30 seconds while its pane, session and state (agent_status, state_change_seq) stay; any state change stats again. Local connections stat as before.
  • docs/ARCHITECTURE.md: the Agent activity section says both.

Verification

  • bun test server/src/agent/: 147 pass. New: "stats asked together share one SSH command" (five concurrent stats, a missing file and a directory, one command; a later stat runs a new one), "a failed stat batch fails each of its stats", and "over SSH, reuses an agent's activity time while its state stays". All three fail on main, as do the transcript tests whose SSH stub now answers in the batch format.
  • bun run format:check, bun run lint (only the existing TerminalView.tsx warning), bun run typecheck:bun.
  • bun run test:quick with an isolated HOME/TMPDIR: the only failures are the two zsh tests (no zsh here), the worktree-removal process-scan timeout, and timeouts under load that pass when rerun alone.
  • Server only; no asset change.

Manual checks

  • On an SSH connection with several agent panes, the agent list still sorts by recent activity, and a working agent moves up within 30 seconds.
  • Chats and Session Inspect still load on that connection, on a Linux and a macOS host (GNU and BSD stat).

Compatibility

No stored format changes. The remote stat script now runs in bash -c instead of a login shell (bash -lc); it needs only stat, base64 and tr, as before.

Also adds a regression test: a Pi pane skips a session file named without an id (the behaviour already on main since #565).

Every remote session stat ran its own SSH command, and Herdr's agent
list, polled every few seconds, stat'ed each agent's session each time.
With many panes on one host these commands held the host's session
slots, which slowed every other read on that connection, transcripts
included.

- Stats of remote session files asked together (a poll over every pane,
  a session's subagents) go out as one SSH command, up to 64 paths. A
  stat only joins a batch not sent yet, so its answer is never older
  than the call.
- Over SSH, the activity time the agent list is sorted by is reused for
  30 seconds while an agent's state stays.

Also test that a Pi pane skips a session file named without an id.
@github-actions github-actions Bot added the enhancement New feature or request label Nov 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant