:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(devbox): pin workspace_region on coder update (#60483)
Raúl Negrón-Otero9a5c65c66e68
diff --git a/tools/hogli-commands/hogli_commands/devbox/cli.py b/tools/hogli-commands/hogli_commands/devbox/cli.pyindex f84021a1409c..6fbc9f0594e8 100644--- a/tools/hogli-commands/hogli_commands/devbox/cli.py+++ b/tools/hogli-commands/hogli_commands/devbox/cli.py@@ -31,6 +31,7 @@ from .coder import (GIT_NAME_PARAMETER,GIT_SIGNING_KEY_SECRET,REGIONS,+ WORKSPACE_REGION_PARAMETER,_diagnose_unreachable_coder,_fail,coder_authenticated,@@ -266,7 +267,21 @@ def _workspace_status_color(status: str) -> str:return WORKSPACE_STATUS_COLORS.get(status, "white")-def _sync_workspace_parameters(name: str) -> None:+def _pinned_region_param(workspace: dict[str, Any]) -> dict[str, str]:+ """Pin `workspace_region` to the workspace's current value for `coder update`.++ Coder re-prompts for any parameter whose template-declared option set has+ changed since the workspace was created (see coder.com docs on rich+ parameters). The recent addition of `eu-central-1` did exactly that, so+ every update path now forwards the current value to suppress the picker.+ Boxes predating region metadata default to us-east-1 — the only region+ that existed before the metadata item was added.+ """+ region = get_workspace_region(workspace) or DEFAULT_REGION+ return {WORKSPACE_REGION_PARAMETER: region}+++def _sync_workspace_parameters(name: str, workspace: dict[str, Any]) -> None:"""Push local config (git identity, dotfiles) to workspace parameters before start."""config = load_config()params: dict[str, str] = {}@@ -281,8 +296,10 @@ def _sync_workspace_parameters(name: str) -> None:if dotfiles_uri:params[DOTFILES_URI_PARAMETER] = dotfiles_uri- if params:- update_workspace_parameters(name, params)+ if not params:+ return+ params.update(_pinned_region_param(workspace))+ update_workspace_parameters(name, params)def _start_existing_workspace(name: str, workspace: dict[str, Any], *, verbose: bool) -> None:@@ -298,7 +315,7 @@ def _start_existing_workspace(name: str, workspace: dict[str, Any], *, verbose:click.echo("Wait for the current operation to complete.")return- _sync_workspace_parameters(name)+ _sync_workspace_parameters(name, workspace)if status == "stopped":click.echo(f"Starting devbox '{name}'...")@@ -1315,7 +1332,7 @@ def devbox_update(workspace: str | None, verbose: bool) -> None:click.echo(f"Devbox '{name}' is already up to date.")returnconfig = load_config()- params: dict[str, str] = {}+ params: dict[str, str] = _pinned_region_param(ws)if dotfiles_uri := config.get("dotfiles_uri"):params[DOTFILES_URI_PARAMETER] = dotfiles_uriclick.echo(f"Updating '{name}' to the latest template...")diff --git a/tools/hogli-commands/hogli_commands/devbox/coder.py b/tools/hogli-commands/hogli_commands/devbox/coder.pyindex e86da009f78e..f70bd94524d3 100644--- a/tools/hogli-commands/hogli_commands/devbox/coder.py+++ b/tools/hogli-commands/hogli_commands/devbox/coder.py@@ -45,10 +45,13 @@ DOTFILES_URI_PARAMETER = "dotfiles_uri"DOTFILES_BRANCH_PARAMETER = "dotfiles_branch"JETBRAINS_IDES_PARAMETER = "jetbrains_ides"-# Create-time region selector. The template defines `workspace_region` with a-# us-east-1 default; eu-central-1 only becomes a valid option once the EU-# infrastructure is live. The chosen value is immutable after creation, so it-# is forwarded on `coder create` only -- never on update or the parameter sync.+# Region selector. The template defines `workspace_region` with a us-east-1+# default; eu-central-1 became a valid option when the EU infrastructure went+# live. The value is immutable after creation, but it must still be forwarded+# on `coder update` and the parameter sync -- when a template author changes a+# parameter's allowed values, Coder re-prompts existing workspaces for that+# parameter regardless of `--use-parameter-defaults`, and the prompt is not+# bypassable by any flag. Pinning the current value short-circuits the picker.# Valid values match the template contract exactly.WORKSPACE_REGION_PARAMETER = "workspace_region"REGIONS = ("us-east-1", "eu-central-1")diff --git a/tools/hogli-commands/hogli_commands/tests/test_devbox.py b/tools/hogli-commands/hogli_commands/tests/test_devbox.pyindex f9be7a0ce7c0..5bd2a8ef6002 100644--- a/tools/hogli-commands/hogli_commands/tests/test_devbox.py+++ b/tools/hogli-commands/hogli_commands/tests/test_devbox.py@@ -1678,7 +1678,10 @@ class TestDevboxCommands:assert result.exit_code == 0assert "Updating" in result.outputassert captured["name"] == "devbox-test-user"- assert captured["parameters"] == {"dotfiles_uri": "https://github.com/user/dotfiles"}+ assert captured["parameters"] == {+ "dotfiles_uri": "https://github.com/user/dotfiles",+ "workspace_region": coder.DEFAULT_REGION,+ }def test_devbox_update_skips_when_up_to_date(self, monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.setattr(devbox_cli, "ensure_runtime_ready", lambda: None)@@ -2168,6 +2171,7 @@ class TestStartExistingWorkspace:"git_name": "PostHog Engineer","git_email": "[email protected]","dotfiles_uri": "https://github.com/user/dotfiles",+ "workspace_region": coder.DEFAULT_REGION,},}@@ -2192,6 +2196,43 @@ class TestStartExistingWorkspace:assert calls == ["start"]+ def test_sync_pins_workspace_region_from_metadata_to_suppress_picker(self, monkeypatch: pytest.MonkeyPatch) -> None:+ """When a `coder update` actually fires, pin the current region.++ Coder re-prompts for any parameter whose template-declared option set+ changed since workspace creation. Forwarding the workspace's current+ region as `--parameter workspace_region=<value>` short-circuits that+ picker -- the prompt is otherwise unanswerable from environments that+ can't deliver stdin (e.g. an IDE's read-only output channel).+ """+ captured: dict[str, object] = {}+ monkeypatch.setattr(devbox_cli, "get_workspace_status", lambda ws: "stopped")+ monkeypatch.setattr(+ devbox_cli,+ "load_config",+ lambda: {"dotfiles_uri": "https://github.com/user/dotfiles"},+ )+ monkeypatch.setattr(+ devbox_cli,+ "update_workspace_parameters",+ lambda name, params: captured.update({"name": name, "params": params}),+ )+ monkeypatch.setattr(devbox_cli, "start_workspace", lambda name, verbose=False: None)+ monkeypatch.setattr(devbox_cli, "extract_workspace_label", lambda name: None)++ workspace = {+ "latest_build": {+ "status": "stopped",+ "resources": [{"metadata": [{"key": coder.REGION_METADATA_KEY, "value": "eu-central-1"}]}],+ },+ }+ devbox_cli._start_existing_workspace("devbox-test-user", workspace, verbose=False)++ assert captured["params"] == {+ "dotfiles_uri": "https://github.com/user/dotfiles",+ "workspace_region": "eu-central-1",+ }+def test_skips_sync_for_running_workspace(self, monkeypatch: pytest.MonkeyPatch) -> None:calls: list[str] = []