Skip to content

Commit f59bd1f

Browse files
committed
Allow connecting when lifecycle is created
If the agent status is "connected" but the lifecycle state is "created", still allow connecting. Fixes coder#450.
1 parent 1ea0cb8 commit f59bd1f

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
## Unreleased
66

7+
### Changed
8+
9+
- Allow connecting when the agent state is "connected" but the lifecycle state
10+
is "created". This may resolve issues when trying to connect to an updated
11+
workspace where the agent has restarted but lifecycle scripts have not been
12+
ran again.
13+
714
## 2.12.0 - 2024-07-02
815

916
### Added

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pluginGroup=com.coder.gateway
44
# Zip file name.
55
pluginName=coder-gateway
66
# SemVer format -> https://semver.org
7-
pluginVersion=2.12.0
7+
pluginVersion=2.12.1
88
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
99
# for insight into build numbers and IntelliJ Platform versions.
1010
pluginSinceBuild=233.6745

src/main/kotlin/com/coder/gateway/models/WorkspaceAndAgentStatus.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ enum class WorkspaceAndAgentStatus(val icon: Icon, val label: String, val descri
5454
fun statusColor(): JBColor =
5555
when (this) {
5656
READY, AGENT_STARTING_READY, START_TIMEOUT_READY -> JBColor.GREEN
57-
START_ERROR, START_TIMEOUT, SHUTDOWN_TIMEOUT -> JBColor.YELLOW
57+
CREATED, START_ERROR, START_TIMEOUT, SHUTDOWN_TIMEOUT -> JBColor.YELLOW
5858
FAILED, DISCONNECTED, TIMEOUT, SHUTDOWN_ERROR -> JBColor.RED
5959
else -> if (JBColor.isBright()) JBColor.LIGHT_GRAY else JBColor.DARK_GRAY
6060
}
@@ -63,15 +63,21 @@ enum class WorkspaceAndAgentStatus(val icon: Icon, val label: String, val descri
6363
* Return true if the agent is in a connectable state.
6464
*/
6565
fun ready(): Boolean {
66-
return listOf(READY, START_ERROR, AGENT_STARTING_READY, START_TIMEOUT_READY)
66+
// It seems that the agent can get stuck in a `created` state if the
67+
// workspace is updated and the agent is restarted (presumably because
68+
// lifecycle scripts are not running again). This feels like either a
69+
// Coder or template bug, but `coder ssh` and the VS Code plugin will
70+
// still connect so do the same here to not be the odd one out.
71+
return listOf(READY, START_ERROR, AGENT_STARTING_READY, START_TIMEOUT_READY, CREATED)
6772
.contains(this)
6873
}
6974

7075
/**
7176
* Return true if the agent might soon be in a connectable state.
7277
*/
7378
fun pending(): Boolean {
74-
return listOf(CONNECTING, TIMEOUT, CREATED, AGENT_STARTING, START_TIMEOUT)
79+
// See ready() for why `CREATED` is not in this list.
80+
return listOf(CONNECTING, TIMEOUT, AGENT_STARTING, START_TIMEOUT)
7581
.contains(this)
7682
}
7783

src/main/kotlin/com/coder/gateway/util/LinkHandler.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ fun handleLink(
8080
if (status.pending()) {
8181
// TODO: Wait for the agent to be ready.
8282
throw IllegalArgumentException(
83-
"The agent \"${agent.name}\" is ${status.toString().lowercase()}; please wait then try again",
83+
"The agent \"${agent.name}\" has a status of \"${status.toString().lowercase()}\"; please wait then try again",
8484
)
8585
} else if (!status.ready()) {
86-
throw IllegalArgumentException("The agent \"${agent.name}\" is ${status.toString().lowercase()}; unable to connect")
86+
throw IllegalArgumentException("The agent \"${agent.name}\" has a status of \"${status.toString().lowercase()}\"; unable to connect")
8787
}
8888

8989
val cli =

0 commit comments

Comments
 (0)