Skip to main content

flush_barrier

Function flush_barrier 

Source
async fn flush_barrier(
    tx: &Sender<PtyReadChunk>,
    timeout: Duration,
) -> Result<(), ()>
Expand description

Ask the output flusher to confirm that everything enqueued so far has been committed, bounded by timeout.

This is the ordering guarantee the post-exit wait actually needs: clients must not observe STATUS_DONE before the output that preceded it is readable. PtyShellStatus → PtyShellRead is the sharpest case — an agent polls until running: false and then reads the file, so a STATUS_DONE that outran the final flush hands it truncated command output (Codex P1 on PR #3261).

Waiting on the flusher TASK was the previous way to get that, and it is a much blunter instrument: the task only ends when the channel closes, which on Windows never happens (ConPTY’s console host outlives the child, so the read loop stays blocked in a read that never returns and never drops its sender). Every ordinary exit therefore paid the full FLUSHER_DRAIN_TIMEOUT while the flusher sat idle — a visible second of dead UI, and the reason exit in a shell felt stuck.

Err(()) means the barrier could not be confirmed within timeout (or the flusher is already gone). Callers fall back to the old bounded wait.