ai-devkit icon indicating copy to clipboard operation
ai-devkit copied to clipboard

fix(agent-console): new session file takes ~60s to appear in preview after daemon subscribe

Open codeaholicguy opened this issue 1 month ago • 0 comments

Symptom

Starting a new agent session from the console: messages sent to the agent reach the process and the agent responds quickly, but the console preview shows nothing for ~60+ seconds. The preview starts working only after the slow list-poll picks up the session file.

Root cause

Not a devkitd delay — a regression from the daemon event-stream subscription in useAgentList:

  1. New agent appears → daemon sweep emits agent.appeared → immediate refresh() → agent listed, but sessionFilePath is null (the agent hasn't written its session file yet).
  2. The session file materializes a few seconds later, but no daemon event fires — the daemon only observes process lifecycle (ps), not session-file attribution.
  3. Meanwhile the daemon-subscribed path relaxes the list poll to LIST_FALLBACK_INTERVAL_MS = 60_000 (useAgentList.ts), so sessionFilePath stays null until the next blind poll.
  4. useAgentConversation polls every 3s correctly, but agent.sessionFilePath is null → no-session-file state — nothing to read.

Before the daemon subscription existed, the 3s blind poll incidentally picked up session files within seconds, masking this gap.

Evidence

  • useAgentList.ts: fast poll → LIST_FALLBACK_INTERVAL_MS relax on successful attachDaemonRefresh; comment already notes fallback covers "attribution drift (status text, session files) the daemon can't see"
  • useAgentConversation.ts: PREVIEW_POLL_INTERVAL_MS = 3000 — preview is fast once sessionFilePath is populated
  • Related: #398 (preview refresh timing around session files)

Proposed fix (not started)

Warm-up refreshes after lifecycle events: when a daemon appeared/agent.started event triggers refresh, also schedule 2–3 delayed refreshes (~+4s, +10s, +25s) to cover session-file/status attribution materializing after the appear — without re-tightening the steady-state poll.

Alternative: have useAgentConversation trigger a list refresh() while in no-session-file state (self-healing, but couples the two hooks).

codeaholicguy avatar Oct 23 '26 06:10 codeaholicguy