Skip to content

[Bug] terminal_service.send_input: stale cached COMPLETED satisfies the next wait_until_status immediately (returns previous turn's output) #407

Description

@chaogebaba

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.pysend_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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions