Skip to content

Conversation

@mafredri
Copy link
Member

@mafredri mafredri commented Dec 4, 2025

When users pass --wait=no or set CODER_SSH_WAIT=no, startup logs are no longer dumped to stderr. The stage indicator is still shown, just not the log content.

This addresses the issue where SSH operations like rsync and scp would dump hundreds of lines of startup logs, breaking scriptability.

Depends on #21104

Fixes #13580


Examples of output when using no wait:

Early attach:

❯ CODER_SSH_WAIT=no ssh foo.coder
=== ✔ Starting workspace [3583ms]
==> ⧗ Cleaning Up
=== ✔ Cleaning Up [19ms]
==> ⧗ Waiting for the workspace agent to connect
=== ✔ Waiting for the workspace agent to connect [955ms]
==> ⧗ Running workspace agent startup scripts (non-blocking)
Notice: The startup scripts are still running and your workspace may be incomplete.
For more information and troubleshooting, see https://coder.com/docs/@v2.29.0/admin/templates/troubleshooting#your-workspace-may-be-incomplete and https://coder.com/docs/admin/templates/troubleshooting
coder@foo:~/coder$

During startup:

❯ CODER_SSH_WAIT=no ssh foo.coder
==> ⧗ Running workspace agent startup scripts (non-blocking)
Notice: The startup scripts are still running and your workspace may be incomplete.
For more information and troubleshooting, see https://coder.com/docs/@v2.29.0/admin/templates/troubleshooting#your-workspace-may-be-incomplete and https://coder.com/docs/admin/templates/troubleshooting
coder@foo:~/coder$

After startup (still shows warning, but no logs):

❯ CODER_SSH_WAIT=no ssh foo.coder
==> ⧗ Running workspace agent startup scripts (non-blocking)
=== ✘ Running workspace agent startup scripts (non-blocking) [18303ms]
Warning: A startup script exited with an error and your workspace may be incomplete.
For more information and troubleshooting, see https://coder.com/docs/@v2.29.0/admin/templates/troubleshooting#startup-script-exited-with-an-error and https://coder.com/docs/admin/templates/troubleshooting
coder@foo:~/coder$

@mafredri mafredri force-pushed the mafredri/refactor-agent-waiter branch from a05caf2 to 92fa5b1 Compare December 4, 2025 17:37
@mafredri mafredri force-pushed the mafredri/fix-cliui-agent-logs branch from 3ce5d2a to 38d9973 Compare December 4, 2025 17:38
@mafredri mafredri force-pushed the mafredri/refactor-agent-waiter branch from 92fa5b1 to 73bd961 Compare December 4, 2025 17:43
@mafredri mafredri force-pushed the mafredri/fix-cliui-agent-logs branch from 38d9973 to 65329a5 Compare December 4, 2025 17:44
@mafredri mafredri force-pushed the mafredri/refactor-agent-waiter branch from 73bd961 to 380b15b Compare December 4, 2025 17:44
@mafredri mafredri force-pushed the mafredri/fix-cliui-agent-logs branch from 65329a5 to 9c77fcd Compare December 4, 2025 17:44
@mafredri mafredri force-pushed the mafredri/refactor-agent-waiter branch from 380b15b to 4ffc13f Compare December 4, 2025 17:46
@mafredri mafredri force-pushed the mafredri/fix-cliui-agent-logs branch from 9c77fcd to cc5cf9a Compare December 4, 2025 17:46
@mafredri mafredri force-pushed the mafredri/refactor-agent-waiter branch from 4ffc13f to 1463cd8 Compare December 4, 2025 18:05
@mafredri mafredri force-pushed the mafredri/fix-cliui-agent-logs branch from cc5cf9a to 48a735a Compare December 4, 2025 18:06
@mafredri mafredri requested a review from Copilot December 4, 2025 18:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #13580 by suppressing startup script logs when users explicitly set Wait=false (via --wait=no or CODER_SSH_WAIT=no). This prevents SSH operations like rsync and scp from dumping hundreds of lines of logs to stderr, which was breaking scriptability.

Key Changes:

  • Modified handleConnected to only call streamLogs when Wait=true, preventing log output in non-blocking mode
  • Stage indicators and warning messages are still displayed, only the log content is suppressed
  • Added comprehensive test coverage for the new non-blocking behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
cli/cliui/agent.go Added conditional logic to skip streamLogs when Wait=false, suppressing log output while maintaining stage indicators and warnings
cli/cliui/agent_test.go Added two new test cases verifying logs are suppressed in non-blocking mode, both when agent is already connected and after waiting for connection

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bpmct bpmct added the doc-check Assign this label to PRs to check for any doc changes. label Dec 4, 2025
@github-actions
Copy link

github-actions bot commented Dec 4, 2025

Copy link
Member

bpmct commented Dec 4, 2025

📚 Documentation Check

✨ No Changes Needed

This PR is an internal refactoring that improves code organization without changing user-facing behavior. The changes:

  • Extract agent waiting logic into a dedicated agentWaiter struct with clearer state transitions
  • Rename showStartupLogswaitedForConnection for clarity
  • Add helper methods (pollWhile, waitForConnection, handleConnected, waitForReconnection, streamLogs) to organize the state machine
  • Improve code comments and maintainability

User-facing behavior remains unchanged:

  • The --wait flag behavior is identical (already documented in docs/reference/cli/ssh.md)
  • Agent connection flow and messaging unchanged
  • Startup script handling unchanged
  • The troubleshooting message mentioning --wait=no is preserved

The existing documentation in docs/reference/cli/ssh.md and docs/admin/templates/troubleshooting.md already covers the --wait flag functionality and remains accurate.


This comment was generated by an AI Agent through Coder Tasks

return agent.LifecycleState.Starting()
})
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we will call pollWhite in a few places, should wrap these errors?

@mtojek mtojek self-requested a review December 5, 2025 15:14
Base automatically changed from mafredri/refactor-agent-waiter to main December 8, 2025 14:00
When users pass --wait=no or set CODER_SSH_WAIT=no, startup logs are no
longer dumped to stderr. The stage indicator is still shown, just not
the log content.

Fixes #13580
@mafredri mafredri force-pushed the mafredri/fix-cliui-agent-logs branch from 48a735a to 6d43efd Compare December 8, 2025 14:00
@mafredri mafredri enabled auto-merge (squash) December 8, 2025 14:02
@mafredri mafredri merged commit d351821 into main Dec 8, 2025
30 checks passed
@mafredri mafredri deleted the mafredri/fix-cliui-agent-logs branch December 8, 2025 14:11
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

doc-check Assign this label to PRs to check for any doc changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Startup script error message is obnoxious on SSH

4 participants