bug(kimi): no TerminalActivityDetector, so a Kimi turn whose end hook never reaches AO stays Working
What went wrong?
A Kimi session's activity state is driven only by hooks. If the hook that ends a turn never reaches the daemon, the session reads Working indefinitely, and nothing recovers it.
#7433 (for #3387) installs Kimi's StopFailure hook, so a turn that ends on a provider error now reports idle. That fixes the reported 401 case, but there is still no backup when the end-of-turn hook (Stop or StopFailure) is lost, for example:
- the daemon is restarting or unreachable when
ao hooks kimi stopruns (postActivityHookretries onlyACTIVITY_PROJECTION_BUSY, never a transport error, and Kimi doesn't re-run a failed hook); - the hook command hits its 5 s timeout;
- Kimi is killed while the hook is running.
Why nothing recovers it
The stale-activity observer (backend/internal/observe/activity/observer.go) only reconciles sessions whose adapter implements ports.TerminalActivityDetector. Kimi doesn't, so the observer returns early for every Kimi session:
detector, ok := agent.(ports.TerminalActivityDetector)
if !ok {
return
}
AO has no other path that demotes a stale active for Kimi.
Proposed fix
Add DetectTerminalActivity to the Kimi adapter (backend/internal/adapters/agent/kimi/), in the same way as claudecode and codex. It should report authoritative idle only when Kimi's idle composer is on screen (PromptReadinessHints already uses │ >), and return non-authoritative for anything it can't prove.
This was left out of #7433 on purpose, because the detector is more than an observer fallback:
WaitForMessageDeliveryReady(session_manager/message_delivery.go) switches to screen-proven readiness once an adapter has a detector. A detector that never proves idle would hold every queued message for Kimi, and it also drops the 5 s idle fallback.- The TUI→Chat handoff (
session_manager/interface_transition.go) consults it too.
So it needs to be built and tested from real Kimi Code terminal frames: the idle prompt, a running turn, a permission prompt, and the provider.auth_error screen. It should not be guessed from the source.
Done when
- Kimi implements
TerminalActivityDetector, with tests built from captured Kimi frames. - A Kimi session whose end hook was dropped returns to Idle through the observer.
- Message delivery and TUI→Chat handoff to Kimi still work: covered by tests and one live check.
Related: #3387, #7433, #4142 (the same fix for claude-code), #6131.