Skip to content

Commit 2e3d419

Browse files
authored
fix: invalid references to http client & cli (#259)
Each environment holds a reference to the http client and the cli mainly for operations like start, stop, update, etc... performed by either one or the other. In the past we recreated the environment instances each time we polled, effectively updating the references to the cli and http client. This was really important for the cases where Coder Toolbox was already running and a URI was executed. In this case we recreate new instances of the http client and cli that are the used by the poller to create a new list of environments. However, not too long we discovered that recreating the environments instances each time has unwanted effects. The obvious fix was to update the existing env. instances instead of creating new ones. But the update failed to take into account that the cli and http client references also need to a refresh after a URI execution. As a result, environment actions stopped working after new instances were created by the URI handler. This fix ensures those references are properly refreshed.
1 parent b3c9bd8 commit 2e3d419

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- support for configuring the SSH connection timeout, defaults to 10 seconds
88

9+
### Fixed
10+
11+
- environment actions failing after URI execution by refreshing http client and CLI references
12+
913
## 0.8.4 - 2026-01-20
1014

1115
### Fixed

src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ private val POLL_INTERVAL = 5.seconds
4949
*/
5050
class CoderRemoteEnvironment(
5151
private val context: CoderToolboxContext,
52-
private val client: CoderRestClient,
53-
private val cli: CoderCLIManager,
52+
internal var client: CoderRestClient,
53+
internal var cli: CoderCLIManager,
5454
private var workspace: Workspace,
5555
private var agent: WorkspaceAgent,
5656
) : RemoteProviderEnvironment("${workspace.name}.${agent.name}"), BeforeConnectionHook, AfterDisconnectHook {
@@ -351,8 +351,6 @@ class CoderRemoteEnvironment(
351351
}
352352
}
353353

354-
fun isConnected(): Boolean = isConnected.value
355-
356354
/**
357355
* An environment is equal if it has the same ID.
358356
*/
@@ -371,4 +369,12 @@ class CoderRemoteEnvironment(
371369
override fun toString(): String {
372370
return "CoderRemoteEnvironment(name='$name')"
373371
}
372+
373+
/**
374+
* Update the client and CLI manager for this environment.
375+
*/
376+
fun updateClientAndCli(client: CoderRestClient, cli: CoderCLIManager) {
377+
this.client = client
378+
this.cli = cli
379+
}
374380
}

src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ class CoderRemoteProvider(
441441
}
442442
this.client = newRestClient
443443
this.cli = newCli
444+
lastEnvironments.forEach { it.updateClientAndCli(newRestClient, newCli) }
444445
pollJob = poll(newRestClient, newCli)
445446
context.logger.info("Workspace poll job with name ${pollJob.toString()} was created while handling URI")
446447
return newRestClient to newCli
@@ -521,6 +522,7 @@ class CoderRemoteProvider(
521522
}
522523
this.client = client
523524
this.cli = cli
525+
lastEnvironments.forEach { it.updateClientAndCli(client, cli) }
524526
environments.showLoadingMessage()
525527
if (context.settingsStore.useAppNameAsTitle) {
526528
context.logger.info("Displaying ${client.appName} as main page title")

0 commit comments

Comments
 (0)