Symptom
On a reused terminal, send_input followed by wait_until_status(COMPLETED) can return immediately with the previous turn's output — the caller receives a stale result instead of waiting for the new turn.
Root cause pointer
src/cli_agent_orchestrator/services/terminal_service.py — send_input clears only the rolling byte buffer before send_keys (deliberately, to preserve the sticky-latch arm), but the cached _last_status = COMPLETED from the previous turn survives. The next wait_until_status(COMPLETED) is satisfied by the cached value before the new turn has produced anything.
Impact
Any handoff/reuse flow that waits for completion on a warm terminal can silently get the prior answer. Intermittent (depends on whether a fresh status probe lands before the wait), which makes it look like a flaky agent rather than an orchestrator bug.
Suggested direction
Invalidate/downgrade the cached status (e.g. to PROCESSING or None) at send_input time, in the same critical section that clears the byte buffer, so completion can only be re-satisfied by a post-input detection.
Symptom
On a reused terminal,
send_inputfollowed bywait_until_status(COMPLETED)can return immediately with the previous turn's output — the caller receives a stale result instead of waiting for the new turn.Root cause pointer
src/cli_agent_orchestrator/services/terminal_service.py—send_inputclears only the rolling byte buffer beforesend_keys(deliberately, to preserve the sticky-latch arm), but the cached_last_status = COMPLETEDfrom the previous turn survives. The nextwait_until_status(COMPLETED)is satisfied by the cached value before the new turn has produced anything.Impact
Any handoff/reuse flow that waits for completion on a warm terminal can silently get the prior answer. Intermittent (depends on whether a fresh status probe lands before the wait), which makes it look like a flaky agent rather than an orchestrator bug.
Suggested direction
Invalidate/downgrade the cached status (e.g. to PROCESSING or None) at
send_inputtime, in the same critical section that clears the byte buffer, so completion can only be re-satisfied by a post-input detection.