Keep kelos logs -f open after empty streams
What type of PR is this?
/kind bug
What this PR does / why we need it:
Kubernetes can successfully open an agent log stream and immediately return EOF while the Task and Pod are still Pending. The CLI previously treated that empty stream as successful completion, so kelos logs <task> -f could exit before the Task produced any output.
This change probes successful agent follow streams before returning them to the log parser. If a stream is empty, the CLI checks the current Task, Pod, and container state and reconnects while the Task remains active. Terminal Tasks end promptly, while failed Tasks and non-transient container startup failures return actionable errors. Non-empty streams continue through the existing parser without replaying output.
Which issue(s) this PR is related to:
Fixes #1653
Special notes for your reviewer:
The retry path applies only to empty agent follow streams. Init-container and non-follow log behavior remain unchanged.
Validation:
env -u CODEX_HOME -u CODEX_AUTH_JSON make testmake verifymake buildgit diff --check
The E2E suite is left to PR CI as directed by the project guidance.
Does this PR introduce a user-facing change?
`kelos logs -f` now reconnects when Kubernetes closes an empty agent log stream before the Task completes.
Summary by cubic
Keep kelos logs -f open when Kubernetes returns an empty agent log stream so the CLI does not exit before Task output appears. Previously an empty stream meant success; now the CLI reconnects while the Task remains active and returns actionable errors for terminal or non-transient startup failures.
Reviewer notes
- Applies only to empty follow streams from the agent container; non-follow and init-container behavior is unchanged.
- Peeks one byte with a buffered reader and wraps the stream in a
bufferedReadCloserto avoid replaying or dropping data when the stream is non-empty. - Reconnect decisions come from
shouldRetryEmptyTaskLogStream(...), which inspects Task, Pod, and container state; it retries for active states and fails with clear messages for TaskFailed, container waiting reasons (e.g., ImagePullBackOff), or PodFailed/Unknown. - Updates
docs/reference.mdto describe the reconnection behavior and adds tests for retry, terminal, and failure paths.