From dd21f27bfac5aa28ed4d011617b8e7624a785249 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Fri, 30 Oct 2026 14:20:23 -0600 Subject: [PATCH 01/11] fix: configure SSH timeout and preserve agent mounts --- pkg/devcontainer/capabilities_test.go | 2 +- pkg/devcontainer/single.go | 24 +++---- pkg/devcontainer/single_delivery_test.go | 70 +++++++++++++++++++ pkg/ide/ideparse/parse_test.go | 18 +++++ pkg/ide/opener/opener.go | 14 ++-- pkg/ide/vscode/open.go | 17 +++-- pkg/ide/vscode/settings.go | 25 ++++++- pkg/ide/vscode/settings_test.go | 61 +++++++++++++--- pkg/ide/vscode/vscode.go | 10 ++- .../connect-to-a-workspace.mdx | 8 +++ .../troubleshooting/linux-troubleshooting.mdx | 10 +++ 11 files changed, 223 insertions(+), 36 deletions(-) diff --git a/pkg/devcontainer/capabilities_test.go b/pkg/devcontainer/capabilities_test.go index fd40dcdebe..fa7e8aba99 100644 --- a/pkg/devcontainer/capabilities_test.go +++ b/pkg/devcontainer/capabilities_test.go @@ -227,7 +227,7 @@ func TestImageRuntimeDoesNotNeedImageBackend(t *testing.T) { } require.NoError( t, - r.runContainer(context.Background(), params, &config.MergedDevContainerConfig{}, info), + r.runContainer(context.Background(), params, &config.MergedDevContainerConfig{}, info, nil), ) require.NotNil(t, d.params) assert.Equal(t, r.id, d.params.WorkspaceID) diff --git a/pkg/devcontainer/single.go b/pkg/devcontainer/single.go index 282f65951e..cf296ea805 100644 --- a/pkg/devcontainer/single.go +++ b/pkg/devcontainer/single.go @@ -412,13 +412,13 @@ func (r *runner) resolveNewContainer( return nil, err } - r.attemptPreStartDelivery(ctx, mergedConfig, p, buildInfo) + runOptions := r.attemptPreStartDelivery(ctx, mergedConfig, p, buildInfo) if seedErr := r.seedWorkspaceVolume(ctx, p); seedErr != nil { return nil, fmt.Errorf("seed workspace volume: %w", seedErr) } - err = r.runContainer(ctx, p, mergedConfig, buildInfo) + err = r.runContainer(ctx, p, mergedConfig, buildInfo, runOptions) if err != nil { return nil, fmt.Errorf("runner run container: %w", err) } @@ -442,26 +442,24 @@ func (r *runner) resolveNewContainer( }, nil } -// attemptPreStartDelivery builds run options and attempts pre-start agent -// delivery. Failures are non-fatal: the caller falls back to post-start. func (r *runner) attemptPreStartDelivery( ctx context.Context, mergedConfig *config.MergedDevContainerConfig, p *resolveParams, buildInfo *config.BuildInfo, -) { +) *driver.RunOptions { strategy := r.newAgentDelivery() switch strategy.Phase() { case delivery.PhasePostStart: log.Debug("agent delivery scheduled for post-start") - return + return nil case delivery.PhasePreStart: default: log.Debugf( "pre-start agent delivery skipped for unsupported phase %s", strategy.Phase(), ) - return + return nil } runOptions, err := r.buildRunOptionsForDelivery( @@ -475,11 +473,14 @@ func (r *runner) attemptPreStartDelivery( "pre-start agent delivery could not prepare run options; will use post-start: %v", err, ) - return + return nil } + runOptions.Env = maps.Clone(runOptions.Env) if preStartErr := r.deliverPreStart(ctx, strategy, runOptions); preStartErr != nil { log.Debugf("pre-start agent delivery failed; will use post-start: %v", preStartErr) + return nil } + return runOptions } func (r *runner) lingerWarning(ctx context.Context) string { @@ -912,12 +913,11 @@ func (r *runner) runContainer( p *resolveParams, mergedConfig *config.MergedDevContainerConfig, buildInfo *config.BuildInfo, + runOptions *driver.RunOptions, ) error { var err error - // build run options for dockerless mode - var runOptions *driver.RunOptions - if buildInfo.Dockerless != nil { + if runOptions == nil && buildInfo.Dockerless != nil { runOptions, err = r.getDockerlessRunOptions( mergedConfig, p.substitutionContext, @@ -927,7 +927,7 @@ func (r *runner) runContainer( if err != nil { return fmt.Errorf("build dockerless run options: %w", err) } - } else { + } else if runOptions == nil { // build run options runOptions, err = r.getRunOptions( mergedConfig, diff --git a/pkg/devcontainer/single_delivery_test.go b/pkg/devcontainer/single_delivery_test.go index 4bc63cf4f0..b4a2d89092 100644 --- a/pkg/devcontainer/single_delivery_test.go +++ b/pkg/devcontainer/single_delivery_test.go @@ -3,11 +3,20 @@ package devcontainer import ( "context" "errors" + "os" + "os/exec" + "path/filepath" + "runtime" "testing" + pkgconfig "github.com/devsy-org/devsy/pkg/config" "github.com/devsy-org/devsy/pkg/devcontainer/config" "github.com/devsy-org/devsy/pkg/log" "github.com/devsy-org/devsy/pkg/provider" + "github.com/devsy-org/devsy/pkg/status" + "github.com/devsy-org/devsy/pkg/version" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" ) @@ -60,3 +69,64 @@ func TestAttemptPreStartDeliveryLogsFailureAndContinues(t *testing.T) { t.Fatal("pre-start failure was misreported as a planned post-start strategy") } } + +func TestResolveNewContainerPreStartDelivery(t *testing.T) { + const baseImageName = "alpine" + if runtime.GOOS == goosWindows { + t.Skip("requires a shell executable") + } + + for _, failDelivery := range []bool{false, true} { + name := "success" + script := "#!/bin/sh\ncase \"$1\" in\nvolume) exit 0 ;;\n" + + "run) printf '%s\\n' \"$TEST_AGENT_VERSION\" ;;\n*) exit 1 ;;\nesac\n" + if failDelivery { + name = "failure" + script = "#!/bin/sh\nexit 1\n" + } + t.Run(name, func(t *testing.T) { + dir := t.TempDir() + docker := filepath.Join(dir, "docker") + require.NoError(t, os.WriteFile(docker, []byte(script), 0o600)) + chmod := exec.Command("chmod", "u+x", "docker") + chmod.Dir = dir + require.NoError(t, chmod.Run()) + d := &imageOnlyRuntime{mockDriver: mockDriver{findResult: runningContainerDetails()}} + r := newTestRunner(d) + r.workspaceConfig.Agent.Driver = provider.DockerDriver + r.workspaceConfig.Agent.Docker.Path = docker + r.workspaceConfig.Agent.Docker.Env = map[string]string{ + "TEST_AGENT_VERSION": version.GetVersion(), + } + r.workspaceConfig.Workspace = &provider.Workspace{ + ID: r.id, + UID: composeUpTestWorkspaceUID, + } + r.imageBackend = &separateImages{details: &config.ImageDetails{ID: overlayImageField}} + r.reporter = status.Nop() + + p := recreateResolveParams() + p.options.Recreate = false + p.parsedConfig.Config.Image = baseImageName + p.parsedConfig.Config.ContainerEnv = map[string]string{"USER_VALUE": "preserved"} + p.parsedConfig.Raw = config.CloneDevContainerConfig(p.parsedConfig.Config) + p.substitutionContext = &config.SubstitutionContext{} + + resolved, err := r.resolveNewContainer(context.Background(), p) + require.NoError(t, err) + require.NotNil(t, d.params) + assert.Equal(t, "preserved", d.params.Options.Env["USER_VALUE"]) + assert.NotContains(t, resolved.mergedConfig.ContainerEnv, pkgconfig.EnvAgentPath) + if failDelivery { + assert.NotContains(t, d.params.Options.Env, pkgconfig.EnvAgentPath) + assert.Empty(t, d.params.Options.Mounts) + } else { + assert.Equal(t, "/opt/devsy/devsy", d.params.Options.Env[pkgconfig.EnvAgentPath]) + require.Len(t, d.params.Options.Mounts, 1) + assert.Equal(t, "devsy-agent-"+r.id, d.params.Options.Mounts[0].Source) + assert.Equal(t, "/opt/devsy", d.params.Options.Mounts[0].Target) + assert.Equal(t, "volume", d.params.Options.Mounts[0].Type) + } + }) + } +} diff --git a/pkg/ide/ideparse/parse_test.go b/pkg/ide/ideparse/parse_test.go index cf11181ed9..8807df1852 100644 --- a/pkg/ide/ideparse/parse_test.go +++ b/pkg/ide/ideparse/parse_test.go @@ -8,6 +8,7 @@ import ( "github.com/devsy-org/devsy/pkg/config" "github.com/devsy-org/devsy/pkg/ide" + "github.com/devsy-org/devsy/pkg/ide/vscode" "github.com/devsy-org/devsy/pkg/provider" ) @@ -16,6 +17,23 @@ const ( ideVSCode = "vscode" ) +func TestVSCodeSSHConnectTimeoutValidation(t *testing.T) { + for _, value := range []string{"1", "60", "999999999"} { + values, err := ParseOptions([]string{"SSH_CONNECT_TIMEOUT=" + value}, vscode.Options) + if err != nil || values[vscode.SSHConnectTimeout].Value != value { + t.Errorf("value %q: got %v, error %v", value, values, err) + } + } + for _, value := range []string{"", "0", "-1", "1.5", "abc", "1000000000"} { + if _, err := ParseOptions( + []string{"SSH_CONNECT_TIMEOUT=" + value}, + vscode.Options, + ); err == nil { + t.Errorf("value %q should be rejected", value) + } + } +} + // setupTempHome redirects the path manager to a temp HOME so // SaveWorkspaceConfig writes under the test's tempdir. func setupTempHome(t *testing.T) { diff --git a/pkg/ide/opener/opener.go b/pkg/ide/opener/opener.go index 38a5966e1b..7e074819b1 100644 --- a/pkg/ide/opener/opener.go +++ b/pkg/ide/opener/opener.go @@ -212,11 +212,15 @@ func openVSCodeFlavor( params IDEParams, ) error { return vscode.Open(ctx, vscode.OpenParams{ - Workspace: params.Client.Workspace(), - Folder: params.Result.SubstitutionContext.ContainerWorkspaceFolder, - NewWindow: vscode.Options.GetValue(ideOptions, vscode.OpenNewWindow) == config.BoolTrue, - Flavor: vsCodeFlavorMap[ideName], - TunnelMode: params.TunnelMode, + Workspace: params.Client.Workspace(), + Folder: params.Result.SubstitutionContext.ContainerWorkspaceFolder, + NewWindow: vscode.Options.GetValue( + ideOptions, + vscode.OpenNewWindow, + ) == config.BoolTrue, + Flavor: vsCodeFlavorMap[ideName], + TunnelMode: params.TunnelMode, + SSHConnectTimeout: vscode.Options.GetValue(ideOptions, vscode.SSHConnectTimeout), }) } diff --git a/pkg/ide/vscode/open.go b/pkg/ide/vscode/open.go index 16752a239e..8faba7529f 100644 --- a/pkg/ide/vscode/open.go +++ b/pkg/ide/vscode/open.go @@ -28,11 +28,12 @@ const containersExtension = "ms-vscode-remote.remote-containers" const remoteFolderScheme = "vscode-remote" type OpenParams struct { - Workspace string - Folder string - NewWindow bool - Flavor Flavor - TunnelMode bool + Workspace string + Folder string + NewWindow bool + Flavor Flavor + TunnelMode bool + SSHConnectTimeout string } type openConfig struct { @@ -246,7 +247,11 @@ func classifyFailure(err error) string { } func Open(ctx context.Context, params OpenParams) error { - EnsureHostSettings(params.Flavor) + if params.SSHConnectTimeout == "" { + EnsureHostSettings(params.Flavor) + } else if err := ensureHostSettingsWithTimeout(params.Flavor, params.SSHConnectTimeout); err != nil { + return fmt.Errorf("configure host Remote SSH timeout: %w", err) + } return newHostLauncher().open(ctx, params) } diff --git a/pkg/ide/vscode/settings.go b/pkg/ide/vscode/settings.go index 3abf748440..9c5522fe1d 100644 --- a/pkg/ide/vscode/settings.go +++ b/pkg/ide/vscode/settings.go @@ -5,14 +5,19 @@ import ( "fmt" "os" "path/filepath" + "regexp" "runtime" + "strconv" "github.com/devsy-org/devsy/pkg/log" "github.com/devsy-org/devsy/pkg/util" "github.com/tailscale/hujson" ) -const settingUseExecServer = "remote.SSH.useExecServer" +const ( + settingUseExecServer = "remote.SSH.useExecServer" + settingConnectTimeout = "remote.SSH.connectTimeout" +) var userSettingsDirNames = map[Flavor]string{ FlavorStable: "Code", @@ -45,6 +50,24 @@ func EnsureHostSettings(flavor Flavor) { } } +func ensureHostSettingsWithTimeout(flavor Flavor, value string) error { + if !regexp.MustCompile(Options[SSHConnectTimeout].ValidationPattern).MatchString(value) { + return fmt.Errorf("%s", Options[SSHConnectTimeout].ValidationMessage) + } + timeout, err := strconv.Atoi(value) + if err != nil { + return fmt.Errorf("invalid SSH_CONNECT_TIMEOUT: %w", err) + } + path, err := userSettingsPath(flavor) + if err != nil { + return err + } + return mergeUserSettings(path, map[string]any{ + settingUseExecServer: false, + settingConnectTimeout: float64(timeout), + }) +} + // removeUserSetting removes a single key from the VS Code user settings file. // It is a no-op if the file does not exist or the key is not present. func removeUserSetting(path string, key string) { diff --git a/pkg/ide/vscode/settings_test.go b/pkg/ide/vscode/settings_test.go index 2bee592af2..1ff9c68ff4 100644 --- a/pkg/ide/vscode/settings_test.go +++ b/pkg/ide/vscode/settings_test.go @@ -9,6 +9,8 @@ import ( "github.com/stretchr/testify/suite" ) +const editorFontSize = "editor.fontSize" + type SettingsSuite struct { suite.Suite tmpDir string @@ -22,6 +24,45 @@ func (s *SettingsSuite) SetupTest() { s.tmpDir = s.T().TempDir() } +func (s *SettingsSuite) TestHostTimeoutPreservesSettingsAndTargetsFlavor() { + s.T().Setenv("HOME", s.tmpDir) + s.T().Setenv("APPDATA", s.tmpDir) + path, err := userSettingsPath(FlavorCursor) + s.Require().NoError(err) + s.writeJSON(path, map[string]any{ + settingConnectTimeout: float64(15), + editorFontSize: float64(14), + }) + stablePath, err := userSettingsPath(FlavorStable) + s.Require().NoError(err) + s.writeJSON(stablePath, map[string]any{settingConnectTimeout: float64(22)}) + + s.Require().NoError(ensureHostSettingsWithTimeout(FlavorCursor, "60")) + settings, err := readSettingsFile(path) + s.Require().NoError(err) + s.Equal(float64(60), settings[settingConnectTimeout]) + s.Equal(float64(14), settings[editorFontSize]) + s.Equal(false, settings[settingUseExecServer]) + stable, err := readSettingsFile(stablePath) + s.Require().NoError(err) + s.Equal(float64(22), stable[settingConnectTimeout]) + + EnsureHostSettings(FlavorCursor) + settings, err = readSettingsFile(path) + s.Require().NoError(err) + s.Equal(float64(60), settings[settingConnectTimeout]) +} + +func (s *SettingsSuite) TestHostTimeoutReportsInvalidSettings() { + s.T().Setenv("HOME", s.tmpDir) + s.T().Setenv("APPDATA", s.tmpDir) + path, err := userSettingsPath(FlavorStable) + s.Require().NoError(err) + s.writeRaw(path, "{ invalid") + s.Error(ensureHostSettingsWithTimeout(FlavorStable, "60")) + s.Error(ensureHostSettingsWithTimeout(FlavorStable, "0")) +} + func (s *SettingsSuite) TestMergeUserSettings_CreatesNewFile() { path := filepath.Join(s.tmpDir, "User", "settings.json") err := mergeUserSettings(path, map[string]any{ @@ -40,7 +81,7 @@ func (s *SettingsSuite) TestMergeUserSettings_CreatesNewFile() { func (s *SettingsSuite) TestMergeUserSettings_PreservesExistingSettings() { path := filepath.Join(s.tmpDir, "settings.json") existing := map[string]any{ - "editor.fontSize": float64(14), + editorFontSize: float64(14), "workbench.colorTheme": "One Dark Pro", } s.writeJSON(path, existing) @@ -55,7 +96,7 @@ func (s *SettingsSuite) TestMergeUserSettings_PreservesExistingSettings() { var settings map[string]any s.Require().NoError(json.Unmarshal(data, &settings)) - s.Equal(float64(14), settings["editor.fontSize"]) + s.Equal(float64(14), settings[editorFontSize]) s.Equal("One Dark Pro", settings["workbench.colorTheme"]) s.Equal(false, settings[settingUseExecServer]) } @@ -102,7 +143,7 @@ func (s *SettingsSuite) TestRemoveUserSetting_RemovesKey() { path := filepath.Join(s.tmpDir, "settings.json") initial := map[string]any{ settingUseExecServer: false, - "editor.fontSize": float64(14), + editorFontSize: float64(14), } s.writeJSON(path, initial) @@ -111,7 +152,7 @@ func (s *SettingsSuite) TestRemoveUserSetting_RemovesKey() { settings, err := readSettingsFile(path) s.Require().NoError(err) s.NotContains(settings, settingUseExecServer, "useExecServer should have been removed") - s.Equal(float64(14), settings["editor.fontSize"], "other settings should be preserved") + s.Equal(float64(14), settings[editorFontSize], "other settings should be preserved") } func (s *SettingsSuite) TestRemoveUserSetting_NoFile() { @@ -120,7 +161,7 @@ func (s *SettingsSuite) TestRemoveUserSetting_NoFile() { func (s *SettingsSuite) TestRemoveUserSetting_KeyNotPresent() { path := filepath.Join(s.tmpDir, "settings.json") - initial := map[string]any{"editor.fontSize": float64(14)} + initial := map[string]any{editorFontSize: float64(14)} s.writeJSON(path, initial) removeUserSetting(path, "nonexistent.key") @@ -149,7 +190,7 @@ func (s *SettingsSuite) TestMergeUserSettings_HandlesLineComments() { var settings map[string]any s.Require().NoError(json.Unmarshal(data, &settings)) - s.Equal(float64(14), settings["editor.fontSize"]) + s.Equal(float64(14), settings[editorFontSize]) s.Equal("Monokai", settings["workbench.colorTheme"]) s.Equal(false, settings[settingUseExecServer]) } @@ -176,7 +217,7 @@ func (s *SettingsSuite) TestMergeUserSettings_HandlesBlockComments() { var settings map[string]any s.Require().NoError(json.Unmarshal(data, &settings)) - s.Equal(float64(16), settings["editor.fontSize"]) + s.Equal(float64(16), settings[editorFontSize]) s.Equal("Solarized Dark", settings["workbench.colorTheme"]) s.Equal(false, settings[settingUseExecServer]) } @@ -199,7 +240,7 @@ func (s *SettingsSuite) TestMergeUserSettings_HandlesTrailingCommas() { var settings map[string]any s.Require().NoError(json.Unmarshal(data, &settings)) - s.Equal(float64(12), settings["editor.fontSize"]) + s.Equal(float64(12), settings[editorFontSize]) s.Equal("Nord", settings["workbench.colorTheme"]) s.Equal(float64(4), settings["editor.tabSize"]) s.Equal(false, settings[settingUseExecServer]) @@ -229,7 +270,7 @@ func (s *SettingsSuite) TestMergeUserSettings_HandlesMixedJSONC() { var settings map[string]any s.Require().NoError(json.Unmarshal(data, &settings)) - s.Equal(float64(14), settings["editor.fontSize"]) + s.Equal(float64(14), settings[editorFontSize]) s.Equal("One Dark Pro", settings["workbench.colorTheme"]) s.Equal("on", settings["editor.wordWrap"]) s.Equal("afterDelay", settings["files.autoSave"]) @@ -256,7 +297,7 @@ func (s *SettingsSuite) TestMergeUserSettings_HandlesCommentsAroundTargetSetting var settings map[string]any s.Require().NoError(json.Unmarshal(data, &settings)) - s.Equal(float64(14), settings["editor.fontSize"]) + s.Equal(float64(14), settings[editorFontSize]) s.Equal("Monokai", settings["workbench.colorTheme"]) s.Equal(false, settings[settingUseExecServer]) } diff --git a/pkg/ide/vscode/vscode.go b/pkg/ide/vscode/vscode.go index 4bb7c972bf..d4804094bb 100644 --- a/pkg/ide/vscode/vscode.go +++ b/pkg/ide/vscode/vscode.go @@ -21,7 +21,8 @@ import ( ) const ( - OpenNewWindow = "OPEN_NEW_WINDOW" + OpenNewWindow = "OPEN_NEW_WINDOW" + SSHConnectTimeout = "SSH_CONNECT_TIMEOUT" ) type Flavor string @@ -101,6 +102,13 @@ var Options = ide.Options{ "true", }, }, + SSHConnectTimeout: { + Name: SSHConnectTimeout, + Description: "Remote SSH connection timeout in positive seconds; " + + "applies globally to this editor flavor's host settings", + ValidationPattern: `^[1-9][0-9]{0,8}$`, + ValidationMessage: "SSH_CONNECT_TIMEOUT must be a positive whole number of seconds (at most 999999999)", + }, } func NewVSCodeServer(opts ServerOptions) *VsCodeServer { diff --git a/sites/docs-devsy-sh/content/docs/developing-in-workspaces/connect-to-a-workspace.mdx b/sites/docs-devsy-sh/content/docs/developing-in-workspaces/connect-to-a-workspace.mdx index c118739074..28ca7fafbb 100644 --- a/sites/docs-devsy-sh/content/docs/developing-in-workspaces/connect-to-a-workspace.mdx +++ b/sites/docs-devsy-sh/content/docs/developing-in-workspaces/connect-to-a-workspace.mdx @@ -32,6 +32,14 @@ devsy workspace up my-workspace --ide vscode If that fails, connect VS Code to `WORKSPACE_NAME.devsy` over SSH. +For a slow SSH connection, set the Remote - SSH connection timeout in seconds: + +```sh +devsy workspace up my-workspace --ide vscode --ide-option SSH_CONNECT_TIMEOUT=60 +``` + +Alternatively, set the option for all VS Code workspaces with `devsy ide set vscode -o SSH_CONNECT_TIMEOUT=60`. The value must be a positive whole number of seconds, up to 999999999. When specified, Devsy writes `remote.SSH.connectTimeout` to the host user settings for the selected editor flavor. This setting applies globally to all Remote - SSH hosts in that editor, including non-Devsy hosts. If the option is not set, Devsy leaves the existing timeout unchanged. For other VS Code-based editors, use their IDE name in place of `vscode`. + ### JetBrains IDEs Install [JetBrains Gateway](https://www.jetbrains.com/remote-development/gateway/). You need a license for the IDE you use. Start the workspace with the IDE name, for example: diff --git a/sites/docs-devsy-sh/content/docs/troubleshooting/linux-troubleshooting.mdx b/sites/docs-devsy-sh/content/docs/troubleshooting/linux-troubleshooting.mdx index 364d2cd905..e53248638b 100644 --- a/sites/docs-devsy-sh/content/docs/troubleshooting/linux-troubleshooting.mdx +++ b/sites/docs-devsy-sh/content/docs/troubleshooting/linux-troubleshooting.mdx @@ -27,6 +27,16 @@ Both the external OpenSSH client and the built-in SSH transport use the same boo For locked-down accounts, ask the administrator to permit `/bin/sh` and the required tools, provide a writable executable agent directory, and check forced-command restrictions. Keep noninteractive shell startup output off stdout: it carries the bootstrap protocol and the live SSH tunnel. Send diagnostics to stderr and limit banners and prompts to interactive sessions. +### VS Code SSH connection timeout + +If Remote - SSH reports `Connection timed out during banner exchange`, a slow provider connection can exceed its default timeout. Increase `remote.SSH.connectTimeout` in VS Code user settings, for example to `60` seconds, and reconnect. This applies to all Remote - SSH hosts. + +### Workspace waits for the Devsy agent + +If container logs repeatedly report `waiting for devsy agent to be available`, check whether the container's `DEVSY_AGENT_PATH` exists and whether its agent volume is mounted. A container created without the agent mount must be recreated after updating Devsy; restarting it cannot change its mounts. + +Recreating a container discards changes in its writable layer. Back up any data outside persistent workspace mounts before recreating it. + ### Fish startup configuration Anything in `config.fish` runs on every `fish -c` call, which can interfere with `devsy internal agent workspace up`. Move your customizations inside the `if status is-interactive` block: From c96137e350b4d3bf35b66f8e842c5af9145703c6 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Fri, 30 Oct 2026 15:45:53 -0600 Subject: [PATCH 02/11] test: expose detached launch failure diagnostics --- e2e/tests/ssh/detached_validation.go | 52 +++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/e2e/tests/ssh/detached_validation.go b/e2e/tests/ssh/detached_validation.go index e88b77f9a3..1b88fcc9cf 100644 --- a/e2e/tests/ssh/detached_validation.go +++ b/e2e/tests/ssh/detached_validation.go @@ -13,6 +13,7 @@ import ( "github.com/devsy-org/devsy/e2e/framework" "github.com/devsy-org/devsy/pkg/command" "github.com/devsy-org/devsy/pkg/config" + "github.com/devsy-org/devsy/pkg/secrets" "github.com/devsy-org/devsy/pkg/task" "github.com/devsy-org/devsy/pkg/workspace" "github.com/onsi/ginkgo/v2" @@ -75,7 +76,8 @@ var _ = ginkgo.Describe("detached workspace input validation", ginkgo.Label("tas "--provider=missing-provider-1471", source, ) - framework.ExpectNoError(err) + gomega.Expect(err).NotTo(gomega.HaveOccurred(), "CLI output: %s", + secrets.NewEnvironmentRedactor(detachedValidationEnvironment(home)).Redact(out)) var envelope struct { Kind string `json:"kind"` ID string `json:"id"` @@ -236,11 +238,59 @@ func (cli detachedValidationCLI) launchWorker( return worker, nil }) if err != nil { + redactor := secrets.NewEnvironmentRedactor(detachedValidationEnvironment(cli.home)) + store, storeErr := task.NewStoreAt(filepath.Join(cli.home, "state", "tasks")) + if storeErr != nil { + ginkgo.GinkgoWriter.Printf("task store: %s\n", redactor.Redact(storeErr.Error())) + } else { + state, stateErr := store.Get(tk.ID()) + if stateErr != nil { + ginkgo.GinkgoWriter.Printf("task state: %s\n", redactor.Redact(stateErr.Error())) + } else { + data, marshalErr := json.Marshal(state) + if marshalErr != nil { + ginkgo.GinkgoWriter.Printf( + "task state: %s\n", + redactor.Redact(marshalErr.Error()), + ) + } else { + ginkgo.GinkgoWriter.Printf("task state: %s\n", redactor.Redact(string(data))) + } + } + } + streamsPath, pathErr := config.DefaultPathManager(). + ProcessStreamsFile(task.WorkerProcessName(tk.ID())) + if pathErr != nil { + ginkgo.GinkgoWriter.Printf( + "worker streams path: %s\n", + redactor.Redact(pathErr.Error()), + ) + } else { + streams, readErr := readDiagnosticStreams(cli.home, streamsPath) + if readErr != nil { + ginkgo.GinkgoWriter.Printf("worker streams: %s\n", redactor.Redact(readErr.Error())) + } else { + ginkgo.GinkgoWriter.Printf("worker streams: %s\n", redactor.Redact(string(streams))) + } + } return ref, errors.Join(err, tk.FailLaunch(err)) } return ref, nil } +func readDiagnosticStreams(home, path string) ([]byte, error) { + root, err := os.OpenRoot(home) + if err != nil { + return nil, err + } + defer func() { _ = root.Close() }() + relative, err := filepath.Rel(home, path) + if err != nil { + return nil, err + } + return root.ReadFile(relative) +} + func (cli detachedValidationCLI) expectFailureEnvelope(ctx context.Context, id, diagnostic string) { followCtx, cancel := context.WithTimeout(ctx, 10*time.Second) defer cancel() From d36e6d364c9aca474210c1d90b0aa2f81647080b Mon Sep 17 00:00:00 2001 From: Samuel K Date: Fri, 30 Oct 2026 16:43:52 -0600 Subject: [PATCH 03/11] test: trace detached worker admission --- cmd/workspace/up/detach.go | 11 +++++++++++ e2e/tests/ssh/detached_validation.go | 1 + 2 files changed, 12 insertions(+) diff --git a/cmd/workspace/up/detach.go b/cmd/workspace/up/detach.go index e12c0a052e..5ee532b82e 100644 --- a/cmd/workspace/up/detach.go +++ b/cmd/workspace/up/detach.go @@ -14,6 +14,7 @@ import ( config2 "github.com/devsy-org/devsy/pkg/devcontainer/config" "github.com/devsy-org/devsy/pkg/file" "github.com/devsy-org/devsy/pkg/flags/names" + "github.com/devsy-org/devsy/pkg/log" "github.com/devsy-org/devsy/pkg/output" "github.com/devsy-org/devsy/pkg/secrets" "github.com/devsy-org/devsy/pkg/task" @@ -154,9 +155,11 @@ func (cmd *UpCmd) openTask() (*task.Task, error) { return nil, err } t := store.Open(cmd.taskID) + log.Debugf("detached worker admission: acquiring worker lock") if err := t.HoldWorkerLock(); err != nil { return nil, err } + log.Debugf("detached worker admission: waiting for launch metadata") verifiedOwner, err := waitForTaskLaunch(t, store) if err != nil { if verifiedOwner { @@ -182,14 +185,17 @@ func waitForTaskLaunch(t *task.Task, store *task.Store) (bool, error) { defer ticker.Stop() progress := workerLaunchProgress{} for { + log.Debugf("detached worker admission: reading launch state") state, err := readWorkerLaunchState(t, store) if err != nil { return progress.verifiedOwner, err } + log.Debugf("detached worker admission: advancing launch state") ready, err := advanceTaskLaunch(t, store, state, &progress) if err != nil { return progress.verifiedOwner, err } + log.Debugf("detached worker admission: launch state advanced") if ready { return progress.verifiedOwner, nil } @@ -220,6 +226,7 @@ func advanceTaskLaunch( state *task.State, progress *workerLaunchProgress, ) (bool, error) { + log.Debugf("detached worker admission: verifying owner") owner, err := verifyWorkerTaskOwner(state) progress.verifiedOwner = owner if err != nil { @@ -232,13 +239,17 @@ func advanceTaskLaunch( progress.verifiedOwner = false return false, nil } + log.Debugf("detached worker admission: retaining launch lease") if err := retainWorkerLaunchLease(&progress.leaseRetained); err != nil { return false, err } + log.Debugf("detached worker admission: checking launcher") if err := checkWorkerLauncher(t, store); err != nil { return false, err } + log.Debugf("detached worker admission: checking worker acknowledgement") if state.PID != 0 && !state.WorkerReady { + log.Debugf("detached worker admission: acknowledging worker") return false, t.WorkerLaunchReady(os.Getpid()) } return false, nil diff --git a/e2e/tests/ssh/detached_validation.go b/e2e/tests/ssh/detached_validation.go index 1b88fcc9cf..ff322704d9 100644 --- a/e2e/tests/ssh/detached_validation.go +++ b/e2e/tests/ssh/detached_validation.go @@ -178,6 +178,7 @@ var _ = ginkgo.Describe( "up", "--task-id", tk.ID(), + "--debug", "--result-format=json", "--id=Backend", } From 95ad70846c82850542586aeb89721bd9a3cf2511 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Fri, 30 Oct 2026 17:37:53 -0600 Subject: [PATCH 04/11] test: isolate detached failure diagnostics --- cmd/workspace/up/detach.go | 22 +++++++++++----------- e2e/tests/ssh/detached_task.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/cmd/workspace/up/detach.go b/cmd/workspace/up/detach.go index 5ee532b82e..f3099ca8ad 100644 --- a/cmd/workspace/up/detach.go +++ b/cmd/workspace/up/detach.go @@ -155,11 +155,10 @@ func (cmd *UpCmd) openTask() (*task.Task, error) { return nil, err } t := store.Open(cmd.taskID) - log.Debugf("detached worker admission: acquiring worker lock") if err := t.HoldWorkerLock(); err != nil { + log.Debugf("detached worker admission failed: worker lock") return nil, err } - log.Debugf("detached worker admission: waiting for launch metadata") verifiedOwner, err := waitForTaskLaunch(t, store) if err != nil { if verifiedOwner { @@ -185,22 +184,21 @@ func waitForTaskLaunch(t *task.Task, store *task.Store) (bool, error) { defer ticker.Stop() progress := workerLaunchProgress{} for { - log.Debugf("detached worker admission: reading launch state") state, err := readWorkerLaunchState(t, store) if err != nil { + log.Debugf("detached worker admission failed: reading launch state") return progress.verifiedOwner, err } - log.Debugf("detached worker admission: advancing launch state") ready, err := advanceTaskLaunch(t, store, state, &progress) if err != nil { return progress.verifiedOwner, err } - log.Debugf("detached worker admission: launch state advanced") if ready { return progress.verifiedOwner, nil } select { case <-deadline.C: + log.Debugf("detached worker admission failed: waiting for launch commit") return progress.verifiedOwner, errors.New( "timed out waiting for detached worker launch metadata", ) @@ -226,10 +224,10 @@ func advanceTaskLaunch( state *task.State, progress *workerLaunchProgress, ) (bool, error) { - log.Debugf("detached worker admission: verifying owner") owner, err := verifyWorkerTaskOwner(state) progress.verifiedOwner = owner if err != nil { + log.Debugf("detached worker admission failed: verifying owner") return false, err } if !state.LaunchPending { @@ -239,18 +237,20 @@ func advanceTaskLaunch( progress.verifiedOwner = false return false, nil } - log.Debugf("detached worker admission: retaining launch lease") if err := retainWorkerLaunchLease(&progress.leaseRetained); err != nil { + log.Debugf("detached worker admission failed: retaining launch lease") return false, err } - log.Debugf("detached worker admission: checking launcher") if err := checkWorkerLauncher(t, store); err != nil { + log.Debugf("detached worker admission failed: checking launcher") return false, err } - log.Debugf("detached worker admission: checking worker acknowledgement") if state.PID != 0 && !state.WorkerReady { - log.Debugf("detached worker admission: acknowledging worker") - return false, t.WorkerLaunchReady(os.Getpid()) + if err := t.WorkerLaunchReady(os.Getpid()); err != nil { + log.Debugf("detached worker admission failed: acknowledging worker") + return false, err + } + return false, nil } return false, nil } diff --git a/e2e/tests/ssh/detached_task.go b/e2e/tests/ssh/detached_task.go index 2456a6d92b..214cd990ec 100644 --- a/e2e/tests/ssh/detached_task.go +++ b/e2e/tests/ssh/detached_task.go @@ -4,12 +4,18 @@ import ( "context" "encoding/json" "fmt" + "os" + "path/filepath" "runtime" "strings" "time" "github.com/devsy-org/devsy/e2e/framework" + "github.com/devsy-org/devsy/pkg/config" "github.com/devsy-org/devsy/pkg/flags/names" + "github.com/devsy-org/devsy/pkg/secrets" + "github.com/devsy-org/devsy/pkg/task" + "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" ) @@ -58,6 +64,7 @@ func startDetachedTunnelUp( out, err := f.ExecCommandOutput(ctx, args) if err != nil { + reportDetachedLaunchFailure() return "", err } var env struct { @@ -74,6 +81,33 @@ func startDetachedTunnelUp( return env.ID, nil } +func reportDetachedLaunchFailure() { + store, err := task.NewStore() + if err != nil { + return + } + states, err := store.List() + if err != nil || len(states) == 0 { + return + } + state := states[0] + data, err := json.Marshal(state) + if err != nil { + return + } + redactor := secrets.NewEnvironmentRedactor(os.Environ()) + ginkgo.GinkgoWriter.Printf("detached launch state: %s\n", redactor.Redact(string(data))) + path, err := config.DefaultPathManager().ProcessStreamsFile(task.WorkerProcessName(state.ID)) + if err != nil { + return + } + streams, err := readDiagnosticStreams(filepath.Dir(path), path) + if err != nil { + return + } + ginkgo.GinkgoWriter.Printf("detached worker streams: %s\n", redactor.Redact(string(streams))) +} + func findDetachedUpTask( ctx context.Context, f *framework.Framework, From 05d3b4446d49a2b6fec57afef4bdab761981f358 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Fri, 30 Oct 2026 18:34:30 -0600 Subject: [PATCH 05/11] test: trace isolated detached launch failures --- cmd/workspace/up/detach.go | 21 +++++++++++++-------- e2e/tests/ssh/detached_validation.go | 10 ++++++++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/cmd/workspace/up/detach.go b/cmd/workspace/up/detach.go index f3099ca8ad..16556c24d1 100644 --- a/cmd/workspace/up/detach.go +++ b/cmd/workspace/up/detach.go @@ -14,7 +14,6 @@ import ( config2 "github.com/devsy-org/devsy/pkg/devcontainer/config" "github.com/devsy-org/devsy/pkg/file" "github.com/devsy-org/devsy/pkg/flags/names" - "github.com/devsy-org/devsy/pkg/log" "github.com/devsy-org/devsy/pkg/output" "github.com/devsy-org/devsy/pkg/secrets" "github.com/devsy-org/devsy/pkg/task" @@ -156,7 +155,7 @@ func (cmd *UpCmd) openTask() (*task.Task, error) { } t := store.Open(cmd.taskID) if err := t.HoldWorkerLock(); err != nil { - log.Debugf("detached worker admission failed: worker lock") + traceDetachedAdmission("worker lock") return nil, err } verifiedOwner, err := waitForTaskLaunch(t, store) @@ -186,7 +185,7 @@ func waitForTaskLaunch(t *task.Task, store *task.Store) (bool, error) { for { state, err := readWorkerLaunchState(t, store) if err != nil { - log.Debugf("detached worker admission failed: reading launch state") + traceDetachedAdmission("reading launch state") return progress.verifiedOwner, err } ready, err := advanceTaskLaunch(t, store, state, &progress) @@ -198,7 +197,7 @@ func waitForTaskLaunch(t *task.Task, store *task.Store) (bool, error) { } select { case <-deadline.C: - log.Debugf("detached worker admission failed: waiting for launch commit") + traceDetachedAdmission("waiting for launch commit") return progress.verifiedOwner, errors.New( "timed out waiting for detached worker launch metadata", ) @@ -227,7 +226,7 @@ func advanceTaskLaunch( owner, err := verifyWorkerTaskOwner(state) progress.verifiedOwner = owner if err != nil { - log.Debugf("detached worker admission failed: verifying owner") + traceDetachedAdmission("verifying owner") return false, err } if !state.LaunchPending { @@ -238,16 +237,16 @@ func advanceTaskLaunch( return false, nil } if err := retainWorkerLaunchLease(&progress.leaseRetained); err != nil { - log.Debugf("detached worker admission failed: retaining launch lease") + traceDetachedAdmission("retaining launch lease") return false, err } if err := checkWorkerLauncher(t, store); err != nil { - log.Debugf("detached worker admission failed: checking launcher") + traceDetachedAdmission("checking launcher") return false, err } if state.PID != 0 && !state.WorkerReady { if err := t.WorkerLaunchReady(os.Getpid()); err != nil { - log.Debugf("detached worker admission failed: acknowledging worker") + traceDetachedAdmission("acknowledging worker") return false, err } return false, nil @@ -255,6 +254,12 @@ func advanceTaskLaunch( return false, nil } +func traceDetachedAdmission(stage string) { + if os.Getenv("DEVSY_DETACHED_DIAGNOSTICS") == "1" { + fmt.Fprintln(os.Stderr, "detached worker admission failed:", stage) + } +} + // The worker lock excludes concurrent invocations; only the saved kernel identity // authorizes this invocation to acknowledge launch or persist startup failures. func verifyWorkerTaskOwner(state *task.State) (bool, error) { diff --git a/e2e/tests/ssh/detached_validation.go b/e2e/tests/ssh/detached_validation.go index ff322704d9..77bb771374 100644 --- a/e2e/tests/ssh/detached_validation.go +++ b/e2e/tests/ssh/detached_validation.go @@ -63,6 +63,9 @@ var _ = ginkgo.Describe("detached workspace input validation", ginkgo.Label("tas home, err := os.MkdirTemp("", "devsy-early-worker-") framework.ExpectNoError(err) ginkgo.DeferCleanup(os.RemoveAll, home) + ginkgo.GinkgoT().Setenv(config.EnvHome, home) + config.ResetPathManager() + ginkgo.DeferCleanup(config.ResetPathManager) cli := detachedValidationCLI{framework: f, home: home} source := filepath.Join(home, "Backend.API") framework.ExpectNoError(os.MkdirAll(source, 0o700)) @@ -76,6 +79,9 @@ var _ = ginkgo.Describe("detached workspace input validation", ginkgo.Label("tas "--provider=missing-provider-1471", source, ) + if err != nil { + reportDetachedLaunchFailure() + } gomega.Expect(err).NotTo(gomega.HaveOccurred(), "CLI output: %s", secrets.NewEnvironmentRedactor(detachedValidationEnvironment(home)).Redact(out)) var envelope struct { @@ -178,7 +184,6 @@ var _ = ginkgo.Describe( "up", "--task-id", tk.ID(), - "--debug", "--result-format=json", "--id=Backend", } @@ -316,5 +321,6 @@ func (cli detachedValidationCLI) expectFailureEnvelope(ctx context.Context, id, } func detachedValidationEnvironment(home string) []string { - return append(os.Environ(), "DEVSY_HOME="+home, "DEVSY_TEST_TOKEN=missing-provider-1471") + return append(os.Environ(), "DEVSY_HOME="+home, "DEVSY_TEST_TOKEN=missing-provider-1471", + "DEVSY_DETACHED_DIAGNOSTICS=1") } From 8532aaa87026156db1b3a829d086912281439c42 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Fri, 30 Oct 2026 19:47:37 -0600 Subject: [PATCH 06/11] test: synchronize pod readiness check --- pkg/driver/kubernetes/pod_lifecycle_test.go | 55 +++++++++++++++------ 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/pkg/driver/kubernetes/pod_lifecycle_test.go b/pkg/driver/kubernetes/pod_lifecycle_test.go index 519838efa8..594e7de48b 100644 --- a/pkg/driver/kubernetes/pod_lifecycle_test.go +++ b/pkg/driver/kubernetes/pod_lifecycle_test.go @@ -224,23 +224,48 @@ func TestReconcileReplacesPodWhenOptionsChanged(t *testing.T) { func TestReconcilePendingPodWaitsForReadiness(t *testing.T) { c := newFakeCluster(t) c.putPod(t, c.pod(t, podSpec{uid: "u1", phase: corev1.PodPending})) - var ready atomic.Bool + observed := make(chan struct{}, 1) + c.cs.PrependReactor( + "get", podResourceName, func(clienttesting.Action) (bool, runtime.Object, error) { + select { + case observed <- struct{}{}: + default: + } + return false, nil, nil + }, + ) + type result struct { + reused bool + err error + } + done := make(chan result, 1) go func() { - time.Sleep(40 * time.Millisecond) - running := c.pod(t, podSpec{uid: "u1", phase: corev1.PodRunning}) - running.Status.ContainerStatuses = []corev1.ContainerStatus{{ - Name: DevContainerName, Ready: true, - State: corev1.ContainerState{Running: &corev1.ContainerStateRunning{}}, - }} - c.putPod(t, running) - ready.Store(true) + reused, err := c.reconcile(t.Context()) + done <- result{reused: reused, err: err} }() - - reused, err := c.reconcile(context.Background()) - - require.NoError(t, err) - assert.True(t, reused) - assert.True(t, ready.Load(), "success must wait for the pod, not just its object") + select { + case <-observed: + case <-time.After(time.Second): + t.Fatal("reconcile did not inspect the pending pod") + } + select { + case got := <-done: + t.Fatalf("reconcile returned before the pod was ready: %+v", got) + case <-time.After(40 * time.Millisecond): + } + running := c.pod(t, podSpec{uid: "u1", phase: corev1.PodRunning}) + running.Status.ContainerStatuses = []corev1.ContainerStatus{{ + Name: DevContainerName, Ready: true, + State: corev1.ContainerState{Running: &corev1.ContainerStateRunning{}}, + }} + c.putPod(t, running) + select { + case got := <-done: + require.NoError(t, got.err) + assert.True(t, got.reused) + case <-time.After(time.Second): + t.Fatal("reconcile did not return after the pod became ready") + } } func TestReconcileTerminatingPodWaitsForDeletionThenAllowsCreate(t *testing.T) { From 7047af1b26d54816dcd1e68045bc1681f7d4d144 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Fri, 30 Oct 2026 20:52:15 -0600 Subject: [PATCH 07/11] fix: preserve existing agent path mounts --- pkg/agent/delivery/local_docker.go | 10 ++ pkg/agent/delivery/local_docker_test.go | 24 +++++ pkg/devcontainer/single.go | 12 +++ pkg/devcontainer/single_delivery_test.go | 98 ++++++++++++------- .../troubleshooting/linux-troubleshooting.mdx | 2 + 5 files changed, 112 insertions(+), 34 deletions(-) diff --git a/pkg/agent/delivery/local_docker.go b/pkg/agent/delivery/local_docker.go index 96620c1df2..52b4432750 100644 --- a/pkg/agent/delivery/local_docker.go +++ b/pkg/agent/delivery/local_docker.go @@ -8,6 +8,7 @@ import ( "io" "os" "os/exec" + "path" "path/filepath" "slices" "strings" @@ -48,6 +49,15 @@ func (d *LocalDockerDelivery) DeliverPreStart(ctx context.Context, opts PreStart if opts.BinarySource == nil { return fmt.Errorf("binary source is required for local docker delivery") } + if mount := opts.RunOptions.WorkspaceMount; mount != nil && + path.Clean(mount.Target) == volumeMountPath { + return fmt.Errorf("agent mount target %s is already in use", volumeMountPath) + } + for _, mount := range opts.RunOptions.Mounts { + if mount != nil && path.Clean(mount.Target) == volumeMountPath { + return fmt.Errorf("agent mount target %s is already in use", volumeMountPath) + } + } volumeName := volumePrefix + opts.WorkspaceID diff --git a/pkg/agent/delivery/local_docker_test.go b/pkg/agent/delivery/local_docker_test.go index edadf52af6..178d9125fe 100644 --- a/pkg/agent/delivery/local_docker_test.go +++ b/pkg/agent/delivery/local_docker_test.go @@ -3,11 +3,13 @@ package delivery import ( "bytes" "context" + "fmt" "io" "os" "path/filepath" "testing" + "github.com/devsy-org/devsy/pkg/devcontainer/config" "github.com/devsy-org/devsy/pkg/docker" "github.com/devsy-org/devsy/pkg/driver" "github.com/devsy-org/devsy/pkg/provider" @@ -35,6 +37,28 @@ func TestLocalDockerDelivery_DeliverPreStart_RequiresBinarySource(t *testing.T) assert.Contains(t, err.Error(), "binary source is required") } +func TestLocalDockerDeliveryRejectsOccupiedAgentMount(t *testing.T) { + for _, workspaceMount := range []bool{false, true} { + t.Run(fmt.Sprintf("workspace=%t", workspaceMount), func(t *testing.T) { + mount := &config.Mount{Type: "volume", Source: "user-data", Target: "/opt/devsy/"} + options := &driver.RunOptions{Env: map[string]string{"USER_VALUE": "preserved"}} + if workspaceMount { + options.WorkspaceMount = mount + } else { + options.Mounts = []*config.Mount{mount} + } + err := (&LocalDockerDelivery{DockerCommand: "not-a-docker-command"}).DeliverPreStart( + context.Background(), + PreStartOptions{RunOptions: options, BinarySource: fakeBinarySource}, + ) + require.ErrorContains(t, err, "/opt/devsy") + assert.Equal(t, "preserved", options.Env["USER_VALUE"]) + assert.NotContains(t, options.Env, "DEVSY_AGENT_PATH") + assert.Equal(t, "user-data", mount.Source) + }) + } +} + func TestLocalDockerDelivery_DeliverPostStart_ReturnsError(t *testing.T) { d := &LocalDockerDelivery{} err := d.DeliverPostStart(context.Background(), PostStartOptions{}) diff --git a/pkg/devcontainer/single.go b/pkg/devcontainer/single.go index cf296ea805..5bfc93a0c8 100644 --- a/pkg/devcontainer/single.go +++ b/pkg/devcontainer/single.go @@ -461,6 +461,18 @@ func (r *runner) attemptPreStartDelivery( ) return nil } + if _, local := strategy.(*delivery.LocalDockerDelivery); local { + for _, arg := range mergedConfig.RunArgs { + if arg == "--mount" || strings.HasPrefix(arg, "--mount=") || + arg == "--volume" || strings.HasPrefix(arg, "--volume=") || + arg == "--tmpfs" || strings.HasPrefix(arg, "--tmpfs=") || + arg == "--volumes-from" || strings.HasPrefix(arg, "--volumes-from=") || + arg == "-v" || strings.HasPrefix(arg, "-v=") || + (strings.HasPrefix(arg, "-v") && len(arg) > 2) { + return nil + } + } + } runOptions, err := r.buildRunOptionsForDelivery( mergedConfig, diff --git a/pkg/devcontainer/single_delivery_test.go b/pkg/devcontainer/single_delivery_test.go index b4a2d89092..8072bd2da5 100644 --- a/pkg/devcontainer/single_delivery_test.go +++ b/pkg/devcontainer/single_delivery_test.go @@ -11,6 +11,7 @@ import ( pkgconfig "github.com/devsy-org/devsy/pkg/config" "github.com/devsy-org/devsy/pkg/devcontainer/config" + "github.com/devsy-org/devsy/pkg/driver" "github.com/devsy-org/devsy/pkg/log" "github.com/devsy-org/devsy/pkg/provider" "github.com/devsy-org/devsy/pkg/status" @@ -76,39 +77,37 @@ func TestResolveNewContainerPreStartDelivery(t *testing.T) { t.Skip("requires a shell executable") } - for _, failDelivery := range []bool{false, true} { - name := "success" + for _, tc := range []struct { + name string + fail bool + mount bool + rawMount bool + }{ + {name: "success"}, + {name: "failure", fail: true}, + {name: "occupied mount", mount: true}, + {name: "raw mount", rawMount: true}, + } { script := "#!/bin/sh\ncase \"$1\" in\nvolume) exit 0 ;;\n" + "run) printf '%s\\n' \"$TEST_AGENT_VERSION\" ;;\n*) exit 1 ;;\nesac\n" - if failDelivery { - name = "failure" + if tc.fail { script = "#!/bin/sh\nexit 1\n" } - t.Run(name, func(t *testing.T) { - dir := t.TempDir() - docker := filepath.Join(dir, "docker") - require.NoError(t, os.WriteFile(docker, []byte(script), 0o600)) - chmod := exec.Command("chmod", "u+x", "docker") - chmod.Dir = dir - require.NoError(t, chmod.Run()) - d := &imageOnlyRuntime{mockDriver: mockDriver{findResult: runningContainerDetails()}} - r := newTestRunner(d) - r.workspaceConfig.Agent.Driver = provider.DockerDriver - r.workspaceConfig.Agent.Docker.Path = docker - r.workspaceConfig.Agent.Docker.Env = map[string]string{ - "TEST_AGENT_VERSION": version.GetVersion(), - } - r.workspaceConfig.Workspace = &provider.Workspace{ - ID: r.id, - UID: composeUpTestWorkspaceUID, - } - r.imageBackend = &separateImages{details: &config.ImageDetails{ID: overlayImageField}} - r.reporter = status.Nop() + t.Run(tc.name, func(t *testing.T) { + r, d := newPreStartTestRunner(t, script) p := recreateResolveParams() p.options.Recreate = false p.parsedConfig.Config.Image = baseImageName p.parsedConfig.Config.ContainerEnv = map[string]string{"USER_VALUE": "preserved"} + if tc.mount { + p.parsedConfig.Config.Mounts = []*config.Mount{{ + Type: "volume", Source: "user-data", Target: "/opt/devsy", + }} + } + if tc.rawMount { + p.parsedConfig.Config.RunArgs = []string{"--volume=user-data:/opt/devsy"} + } p.parsedConfig.Raw = config.CloneDevContainerConfig(p.parsedConfig.Config) p.substitutionContext = &config.SubstitutionContext{} @@ -117,16 +116,47 @@ func TestResolveNewContainerPreStartDelivery(t *testing.T) { require.NotNil(t, d.params) assert.Equal(t, "preserved", d.params.Options.Env["USER_VALUE"]) assert.NotContains(t, resolved.mergedConfig.ContainerEnv, pkgconfig.EnvAgentPath) - if failDelivery { - assert.NotContains(t, d.params.Options.Env, pkgconfig.EnvAgentPath) - assert.Empty(t, d.params.Options.Mounts) - } else { - assert.Equal(t, "/opt/devsy/devsy", d.params.Options.Env[pkgconfig.EnvAgentPath]) - require.Len(t, d.params.Options.Mounts, 1) - assert.Equal(t, "devsy-agent-"+r.id, d.params.Options.Mounts[0].Source) - assert.Equal(t, "/opt/devsy", d.params.Options.Mounts[0].Target) - assert.Equal(t, "volume", d.params.Options.Mounts[0].Type) - } + assertPreStartDeliveryOptions(t, d.params.Options, r.id, tc.name) }) } } + +func newPreStartTestRunner(t *testing.T, script string) (*runner, *imageOnlyRuntime) { + t.Helper() + dir := t.TempDir() + docker := filepath.Join(dir, "docker") + require.NoError(t, os.WriteFile(docker, []byte(script), 0o600)) + chmod := exec.Command("chmod", "u+x", "docker") + chmod.Dir = dir + require.NoError(t, chmod.Run()) + d := &imageOnlyRuntime{mockDriver: mockDriver{findResult: runningContainerDetails()}} + r := newTestRunner(d) + r.workspaceConfig.Agent.Driver = provider.DockerDriver + r.workspaceConfig.Agent.Docker.Path = docker + r.workspaceConfig.Agent.Docker.Env = map[string]string{ + "TEST_AGENT_VERSION": version.GetVersion(), + } + r.workspaceConfig.Workspace = &provider.Workspace{ID: r.id, UID: composeUpTestWorkspaceUID} + r.imageBackend = &separateImages{details: &config.ImageDetails{ID: overlayImageField}} + r.reporter = status.Nop() + return r, d +} + +func assertPreStartDeliveryOptions(t *testing.T, options *driver.RunOptions, id, scenario string) { + t.Helper() + if scenario != "success" { + assert.NotContains(t, options.Env, pkgconfig.EnvAgentPath) + if scenario == "occupied mount" { + require.Len(t, options.Mounts, 1) + assert.Equal(t, "user-data", options.Mounts[0].Source) + } else { + assert.Empty(t, options.Mounts) + } + return + } + assert.Equal(t, "/opt/devsy/devsy", options.Env[pkgconfig.EnvAgentPath]) + require.Len(t, options.Mounts, 1) + assert.Equal(t, "devsy-agent-"+id, options.Mounts[0].Source) + assert.Equal(t, "/opt/devsy", options.Mounts[0].Target) + assert.Equal(t, "volume", options.Mounts[0].Type) +} diff --git a/sites/docs-devsy-sh/content/docs/troubleshooting/linux-troubleshooting.mdx b/sites/docs-devsy-sh/content/docs/troubleshooting/linux-troubleshooting.mdx index e53248638b..dab982dfa6 100644 --- a/sites/docs-devsy-sh/content/docs/troubleshooting/linux-troubleshooting.mdx +++ b/sites/docs-devsy-sh/content/docs/troubleshooting/linux-troubleshooting.mdx @@ -35,6 +35,8 @@ If Remote - SSH reports `Connection timed out during banner exchange`, a slow pr If container logs repeatedly report `waiting for devsy agent to be available`, check whether the container's `DEVSY_AGENT_PATH` exists and whether its agent volume is mounted. A container created without the agent mount must be recreated after updating Devsy; restarting it cannot change its mounts. +If a configured mount uses `/opt/devsy`, Devsy preserves that mount and installs the agent after the container starts. Docker mount flags in `runArgs` also use post-start installation. + Recreating a container discards changes in its writable layer. Back up any data outside persistent workspace mounts before recreating it. ### Fish startup configuration From 8a9631d41b17f2870d407233c9ce988f8534b0b4 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Fri, 30 Oct 2026 22:27:06 -0600 Subject: [PATCH 08/11] fix: harden mount and launch diagnostics --- e2e/tests/ssh/detached_diagnostics_test.go | 52 ++++++++++++++++ e2e/tests/ssh/detached_task.go | 60 +++++++++++++++++-- e2e/tests/ssh/detached_validation.go | 16 ++++- pkg/agent/delivery/local_docker.go | 9 ++- pkg/agent/delivery/local_docker_test.go | 16 +++-- pkg/driver/kubernetes/pod_lifecycle_test.go | 2 +- .../troubleshooting/linux-troubleshooting.mdx | 2 +- 7 files changed, 142 insertions(+), 15 deletions(-) create mode 100644 e2e/tests/ssh/detached_diagnostics_test.go diff --git a/e2e/tests/ssh/detached_diagnostics_test.go b/e2e/tests/ssh/detached_diagnostics_test.go new file mode 100644 index 0000000000..eaddc7d124 --- /dev/null +++ b/e2e/tests/ssh/detached_diagnostics_test.go @@ -0,0 +1,52 @@ +package ssh + +import ( + "os" + "path/filepath" + "strings" + "testing" + + "github.com/devsy-org/devsy/pkg/config" + "github.com/devsy-org/devsy/pkg/task" + "github.com/devsy-org/devsy/pkg/workspace" + "github.com/stretchr/testify/require" +) + +func TestReadDiagnosticStreamsLimitsOutput(t *testing.T) { + home := t.TempDir() + path := filepath.Join(home, "worker.streams") + content := "complete line\n" + strings.Repeat("x", 64*1024) + require.NoError(t, os.WriteFile(path, []byte(content), 0o600)) + got, err := readDiagnosticStreams(home, path) + require.NoError(t, err) + require.Equal(t, "complete line\n", string(got)) + _, err = readDiagnosticStreams(home, filepath.Join(t.TempDir(), "outside")) + require.Error(t, err) +} + +func TestNewDetachedTaskExcludesExistingAndAmbiguousTasks(t *testing.T) { + home := t.TempDir() + t.Setenv(config.EnvHome, home) + config.ResetPathManager() + t.Cleanup(config.ResetPathManager) + source := filepath.Join(home, "project") + store, err := task.NewStore() + require.NoError(t, err) + existing, err := store.Create( + task.CreateOptions{Command: "up", WorkspaceID: workspace.ToID(source)}, + ) + require.NoError(t, err) + before := map[string]struct{}{existing.ID(): {}} + _, err = store.Create(task.CreateOptions{Command: "up", WorkspaceID: "unrelated"}) + require.NoError(t, err) + created, err := store.Create( + task.CreateOptions{Command: "up", WorkspaceID: workspace.ToID(source)}, + ) + require.NoError(t, err) + got := newDetachedTask(before, source) + require.NotNil(t, got) + require.Equal(t, created.ID(), got.ID) + _, err = store.Create(task.CreateOptions{Command: "up", WorkspaceID: workspace.ToID(source)}) + require.NoError(t, err) + require.Nil(t, newDetachedTask(before, source)) +} diff --git a/e2e/tests/ssh/detached_task.go b/e2e/tests/ssh/detached_task.go index 214cd990ec..613a6c4bfd 100644 --- a/e2e/tests/ssh/detached_task.go +++ b/e2e/tests/ssh/detached_task.go @@ -15,6 +15,7 @@ import ( "github.com/devsy-org/devsy/pkg/flags/names" "github.com/devsy-org/devsy/pkg/secrets" "github.com/devsy-org/devsy/pkg/task" + workspacepkg "github.com/devsy-org/devsy/pkg/workspace" "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" ) @@ -61,10 +62,11 @@ func startDetachedTunnelUp( } args = append(args, extraArgs...) args = append(args, workspace) + before := detachedTaskIDs() out, err := f.ExecCommandOutput(ctx, args) if err != nil { - reportDetachedLaunchFailure() + reportDetachedLaunchFailure(before, workspace) return "", err } var env struct { @@ -81,16 +83,27 @@ func startDetachedTunnelUp( return env.ID, nil } -func reportDetachedLaunchFailure() { +func detachedTaskIDs() map[string]struct{} { store, err := task.NewStore() if err != nil { - return + return nil } states, err := store.List() - if err != nil || len(states) == 0 { + if err != nil { + return nil + } + ids := make(map[string]struct{}, len(states)) + for _, state := range states { + ids[state.ID] = struct{}{} + } + return ids +} + +func reportDetachedLaunchFailure(before map[string]struct{}, source string) { + state := newDetachedTask(before, source) + if state == nil { return } - state := states[0] data, err := json.Marshal(state) if err != nil { return @@ -108,6 +121,43 @@ func reportDetachedLaunchFailure() { ginkgo.GinkgoWriter.Printf("detached worker streams: %s\n", redactor.Redact(string(streams))) } +func newDetachedTask(before map[string]struct{}, source string) *task.State { + if before == nil { + return nil + } + absolute, err := filepath.Abs(source) + if err != nil { + return nil + } + workspaceID := workspacepkg.ToID(absolute) + store, err := task.NewStore() + if err != nil { + return nil + } + states, err := store.List() + if err != nil { + return nil + } + return selectNewDetachedTask(states, before, workspaceID) +} + +func selectNewDetachedTask( + states []*task.State, before map[string]struct{}, workspaceID string, +) *task.State { + var state *task.State + for _, candidate := range states { + if _, existed := before[candidate.ID]; existed || candidate.Command != "up" || + candidate.WorkspaceID != workspaceID { + continue + } + if state != nil { + return nil + } + state = candidate + } + return state +} + func findDetachedUpTask( ctx context.Context, f *framework.Framework, diff --git a/e2e/tests/ssh/detached_validation.go b/e2e/tests/ssh/detached_validation.go index 77bb771374..32a84f33dd 100644 --- a/e2e/tests/ssh/detached_validation.go +++ b/e2e/tests/ssh/detached_validation.go @@ -1,9 +1,11 @@ package ssh import ( + "bytes" "context" "encoding/json" "errors" + "io" "os" "os/exec" "path/filepath" @@ -70,6 +72,7 @@ var _ = ginkgo.Describe("detached workspace input validation", ginkgo.Label("tas source := filepath.Join(home, "Backend.API") framework.ExpectNoError(os.MkdirAll(source, 0o700)) sentinel := filepath.Join(source, "KeepCase.txt") + before := detachedTaskIDs() framework.ExpectNoError(os.WriteFile(sentinel, []byte("original source"), 0o600)) out, err := cli.command(ctx, cmdWorkspace, @@ -80,7 +83,7 @@ var _ = ginkgo.Describe("detached workspace input validation", ginkgo.Label("tas source, ) if err != nil { - reportDetachedLaunchFailure() + reportDetachedLaunchFailure(before, source) } gomega.Expect(err).NotTo(gomega.HaveOccurred(), "CLI output: %s", secrets.NewEnvironmentRedactor(detachedValidationEnvironment(home)).Redact(out)) @@ -294,7 +297,16 @@ func readDiagnosticStreams(home, path string) ([]byte, error) { if err != nil { return nil, err } - return root.ReadFile(relative) + file, err := root.Open(relative) + if err != nil { + return nil, err + } + defer func() { _ = file.Close() }() + data, err := io.ReadAll(io.LimitReader(file, 64*1024+1)) + if err != nil || len(data) <= 64*1024 { + return data, err + } + return data[:bytes.LastIndexByte(data[:64*1024], '\n')+1], nil } func (cli detachedValidationCLI) expectFailureEnvelope(ctx context.Context, id, diagnostic string) { diff --git a/pkg/agent/delivery/local_docker.go b/pkg/agent/delivery/local_docker.go index 52b4432750..a202573082 100644 --- a/pkg/agent/delivery/local_docker.go +++ b/pkg/agent/delivery/local_docker.go @@ -50,11 +50,11 @@ func (d *LocalDockerDelivery) DeliverPreStart(ctx context.Context, opts PreStart return fmt.Errorf("binary source is required for local docker delivery") } if mount := opts.RunOptions.WorkspaceMount; mount != nil && - path.Clean(mount.Target) == volumeMountPath { + isAgentMountTarget(mount.Target) { return fmt.Errorf("agent mount target %s is already in use", volumeMountPath) } for _, mount := range opts.RunOptions.Mounts { - if mount != nil && path.Clean(mount.Target) == volumeMountPath { + if mount != nil && isAgentMountTarget(mount.Target) { return fmt.Errorf("agent mount target %s is already in use", volumeMountPath) } } @@ -84,6 +84,11 @@ func (d *LocalDockerDelivery) DeliverPreStart(ctx context.Context, opts PreStart return nil } +func isAgentMountTarget(target string) bool { + cleaned := path.Clean(target) + return cleaned == volumeMountPath || strings.HasPrefix(cleaned, volumeMountPath+"/") +} + func (d *LocalDockerDelivery) DeliverPostStart(_ context.Context, _ PostStartOptions) error { return fmt.Errorf("LocalDockerDelivery does not support post-start delivery") } diff --git a/pkg/agent/delivery/local_docker_test.go b/pkg/agent/delivery/local_docker_test.go index 178d9125fe..91e9b9e84d 100644 --- a/pkg/agent/delivery/local_docker_test.go +++ b/pkg/agent/delivery/local_docker_test.go @@ -38,11 +38,19 @@ func TestLocalDockerDelivery_DeliverPreStart_RequiresBinarySource(t *testing.T) } func TestLocalDockerDeliveryRejectsOccupiedAgentMount(t *testing.T) { - for _, workspaceMount := range []bool{false, true} { - t.Run(fmt.Sprintf("workspace=%t", workspaceMount), func(t *testing.T) { - mount := &config.Mount{Type: "volume", Source: "user-data", Target: "/opt/devsy/"} + for _, tc := range []struct { + workspace bool + target string + }{ + {target: "/opt/devsy/"}, + {workspace: true, target: "/opt/devsy/"}, + {target: "/opt/devsy/devsy"}, + {workspace: true, target: "/opt/devsy/devsy"}, + } { + t.Run(fmt.Sprintf("workspace=%t target=%s", tc.workspace, tc.target), func(t *testing.T) { + mount := &config.Mount{Type: "volume", Source: "user-data", Target: tc.target} options := &driver.RunOptions{Env: map[string]string{"USER_VALUE": "preserved"}} - if workspaceMount { + if tc.workspace { options.WorkspaceMount = mount } else { options.Mounts = []*config.Mount{mount} diff --git a/pkg/driver/kubernetes/pod_lifecycle_test.go b/pkg/driver/kubernetes/pod_lifecycle_test.go index 594e7de48b..b93b568c12 100644 --- a/pkg/driver/kubernetes/pod_lifecycle_test.go +++ b/pkg/driver/kubernetes/pod_lifecycle_test.go @@ -263,7 +263,7 @@ func TestReconcilePendingPodWaitsForReadiness(t *testing.T) { case got := <-done: require.NoError(t, got.err) assert.True(t, got.reused) - case <-time.After(time.Second): + case <-time.After(2 * time.Second): t.Fatal("reconcile did not return after the pod became ready") } } diff --git a/sites/docs-devsy-sh/content/docs/troubleshooting/linux-troubleshooting.mdx b/sites/docs-devsy-sh/content/docs/troubleshooting/linux-troubleshooting.mdx index dab982dfa6..88c58f7b2f 100644 --- a/sites/docs-devsy-sh/content/docs/troubleshooting/linux-troubleshooting.mdx +++ b/sites/docs-devsy-sh/content/docs/troubleshooting/linux-troubleshooting.mdx @@ -35,7 +35,7 @@ If Remote - SSH reports `Connection timed out during banner exchange`, a slow pr If container logs repeatedly report `waiting for devsy agent to be available`, check whether the container's `DEVSY_AGENT_PATH` exists and whether its agent volume is mounted. A container created without the agent mount must be recreated after updating Devsy; restarting it cannot change its mounts. -If a configured mount uses `/opt/devsy`, Devsy preserves that mount and installs the agent after the container starts. Docker mount flags in `runArgs` also use post-start installation. +If a configured mount uses `/opt/devsy` or a path inside it, Devsy preserves that mount and installs the agent after the container starts. Docker mount flags in `runArgs` also use post-start installation. Recreating a container discards changes in its writable layer. Back up any data outside persistent workspace mounts before recreating it. From 57491d7642930d166fd41bfb4fdbc887e246aa40 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Fri, 30 Oct 2026 23:55:54 -0600 Subject: [PATCH 09/11] fix: target Linux editor settings safely --- e2e/tests/ssh/detached_diagnostics_test.go | 13 +++- e2e/tests/ssh/detached_task.go | 22 ++++--- e2e/tests/ssh/detached_validation.go | 64 ++++++++++--------- pkg/ide/vscode/settings.go | 25 +++++--- pkg/ide/vscode/settings_test.go | 16 +++++ .../connect-to-a-workspace.mdx | 2 + 6 files changed, 91 insertions(+), 51 deletions(-) diff --git a/e2e/tests/ssh/detached_diagnostics_test.go b/e2e/tests/ssh/detached_diagnostics_test.go index eaddc7d124..518ed92a44 100644 --- a/e2e/tests/ssh/detached_diagnostics_test.go +++ b/e2e/tests/ssh/detached_diagnostics_test.go @@ -15,11 +15,20 @@ import ( func TestReadDiagnosticStreamsLimitsOutput(t *testing.T) { home := t.TempDir() path := filepath.Join(home, "worker.streams") - content := "complete line\n" + strings.Repeat("x", 64*1024) + marker := "detached worker admission failed: reading launch state\n" + content := "private credential\n" + marker + strings.Repeat("x", 64*1024) require.NoError(t, os.WriteFile(path, []byte(content), 0o600)) got, err := readDiagnosticStreams(home, path) require.NoError(t, err) - require.Equal(t, "complete line\n", string(got)) + require.Equal(t, marker+"[worker stream truncated at 65536 bytes]\n", string(got)) + require.NoError(t, os.WriteFile(path, []byte(strings.Repeat("x", 64*1024+1)), 0o600)) + got, err = readDiagnosticStreams(home, path) + require.NoError(t, err) + require.Equal(t, "[worker stream truncated at 65536 bytes]\n", string(got)) + require.NoError(t, os.WriteFile(path, []byte(strings.Repeat("x", 64*1024)), 0o600)) + got, err = readDiagnosticStreams(home, path) + require.NoError(t, err) + require.Empty(t, got) _, err = readDiagnosticStreams(home, filepath.Join(t.TempDir(), "outside")) require.Error(t, err) } diff --git a/e2e/tests/ssh/detached_task.go b/e2e/tests/ssh/detached_task.go index 613a6c4bfd..31ca9086bd 100644 --- a/e2e/tests/ssh/detached_task.go +++ b/e2e/tests/ssh/detached_task.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "os" "path/filepath" "runtime" "strings" @@ -13,7 +12,6 @@ import ( "github.com/devsy-org/devsy/e2e/framework" "github.com/devsy-org/devsy/pkg/config" "github.com/devsy-org/devsy/pkg/flags/names" - "github.com/devsy-org/devsy/pkg/secrets" "github.com/devsy-org/devsy/pkg/task" workspacepkg "github.com/devsy-org/devsy/pkg/workspace" "github.com/onsi/ginkgo/v2" @@ -104,12 +102,7 @@ func reportDetachedLaunchFailure(before map[string]struct{}, source string) { if state == nil { return } - data, err := json.Marshal(state) - if err != nil { - return - } - redactor := secrets.NewEnvironmentRedactor(os.Environ()) - ginkgo.GinkgoWriter.Printf("detached launch state: %s\n", redactor.Redact(string(data))) + reportDiagnosticState(state) path, err := config.DefaultPathManager().ProcessStreamsFile(task.WorkerProcessName(state.ID)) if err != nil { return @@ -118,7 +111,18 @@ func reportDetachedLaunchFailure(before map[string]struct{}, source string) { if err != nil { return } - ginkgo.GinkgoWriter.Printf("detached worker streams: %s\n", redactor.Redact(string(streams))) + ginkgo.GinkgoWriter.Printf("detached worker streams: %s\n", streams) +} + +func reportDiagnosticState(state *task.State) { + ginkgo.GinkgoWriter.Printf( + "detached launch state: pidPublished=%t launchPending=%t launchOwned=%t workerReady=%t cleanupComplete=%t\n", + state.PID != 0, + state.LaunchPending, + state.LaunchOwned, + state.WorkerReady, + state.ProcessCleanupComplete, + ) } func newDetachedTask(before map[string]struct{}, source string) *task.State { diff --git a/e2e/tests/ssh/detached_validation.go b/e2e/tests/ssh/detached_validation.go index 32a84f33dd..1a4d7db15d 100644 --- a/e2e/tests/ssh/detached_validation.go +++ b/e2e/tests/ssh/detached_validation.go @@ -1,7 +1,6 @@ package ssh import ( - "bytes" "context" "encoding/json" "errors" @@ -247,39 +246,19 @@ func (cli detachedValidationCLI) launchWorker( return worker, nil }) if err != nil { - redactor := secrets.NewEnvironmentRedactor(detachedValidationEnvironment(cli.home)) store, storeErr := task.NewStoreAt(filepath.Join(cli.home, "state", "tasks")) - if storeErr != nil { - ginkgo.GinkgoWriter.Printf("task store: %s\n", redactor.Redact(storeErr.Error())) - } else { + if storeErr == nil { state, stateErr := store.Get(tk.ID()) - if stateErr != nil { - ginkgo.GinkgoWriter.Printf("task state: %s\n", redactor.Redact(stateErr.Error())) - } else { - data, marshalErr := json.Marshal(state) - if marshalErr != nil { - ginkgo.GinkgoWriter.Printf( - "task state: %s\n", - redactor.Redact(marshalErr.Error()), - ) - } else { - ginkgo.GinkgoWriter.Printf("task state: %s\n", redactor.Redact(string(data))) - } + if stateErr == nil { + reportDiagnosticState(state) } } streamsPath, pathErr := config.DefaultPathManager(). ProcessStreamsFile(task.WorkerProcessName(tk.ID())) - if pathErr != nil { - ginkgo.GinkgoWriter.Printf( - "worker streams path: %s\n", - redactor.Redact(pathErr.Error()), - ) - } else { + if pathErr == nil { streams, readErr := readDiagnosticStreams(cli.home, streamsPath) - if readErr != nil { - ginkgo.GinkgoWriter.Printf("worker streams: %s\n", redactor.Redact(readErr.Error())) - } else { - ginkgo.GinkgoWriter.Printf("worker streams: %s\n", redactor.Redact(string(streams))) + if readErr == nil { + ginkgo.GinkgoWriter.Printf("worker streams: %s\n", streams) } } return ref, errors.Join(err, tk.FailLaunch(err)) @@ -303,10 +282,35 @@ func readDiagnosticStreams(home, path string) ([]byte, error) { } defer func() { _ = file.Close() }() data, err := io.ReadAll(io.LimitReader(file, 64*1024+1)) - if err != nil || len(data) <= 64*1024 { - return data, err + if err != nil { + return nil, err + } + return filterDiagnosticStreams(data), nil +} + +func filterDiagnosticStreams(data []byte) []byte { + truncated := len(data) > 64*1024 + if truncated { + data = data[:64*1024] + } + var result strings.Builder + for line := range strings.SplitSeq(string(data), "\n") { + switch strings.TrimSuffix(line, "\r") { + case "detached worker admission failed: worker lock", + "detached worker admission failed: reading launch state", + "detached worker admission failed: waiting for launch commit", + "detached worker admission failed: verifying owner", + "detached worker admission failed: retaining launch lease", + "detached worker admission failed: checking launcher", + "detached worker admission failed: acknowledging worker": + result.WriteString(strings.TrimSuffix(line, "\r")) + result.WriteByte('\n') + } + } + if truncated { + result.WriteString("[worker stream truncated at 65536 bytes]\n") } - return data[:bytes.LastIndexByte(data[:64*1024], '\n')+1], nil + return []byte(result.String()) } func (cli detachedValidationCLI) expectFailureEnvelope(ctx context.Context, id, diagnostic string) { diff --git a/pkg/ide/vscode/settings.go b/pkg/ide/vscode/settings.go index 9c5522fe1d..d167942753 100644 --- a/pkg/ide/vscode/settings.go +++ b/pkg/ide/vscode/settings.go @@ -105,20 +105,25 @@ func userSettingsPath(flavor Flavor) (string, error) { return "", err } - var base string - switch runtime.GOOS { + base := userSettingsBaseDir(homeDir, runtime.GOOS) + return filepath.Join(base, dirName, "User", "settings.json"), nil +} + +func userSettingsBaseDir(homeDir, goos string) string { + switch goos { case "darwin": - base = filepath.Join(homeDir, "Library", "Application Support") + return filepath.Join(homeDir, "Library", "Application Support") case "windows": - base = os.Getenv("APPDATA") - if base == "" { - base = filepath.Join(homeDir, "AppData", "Roaming") + if base := os.Getenv("APPDATA"); base != "" { + return base + } + return filepath.Join(homeDir, "AppData", "Roaming") + case "linux": + if base := os.Getenv("XDG_CONFIG_HOME"); base != "" { + return base } - default: - base = filepath.Join(homeDir, ".config") } - - return filepath.Join(base, dirName, "User", "settings.json"), nil + return filepath.Join(homeDir, ".config") } func readSettingsFile(path string) (map[string]any, error) { diff --git a/pkg/ide/vscode/settings_test.go b/pkg/ide/vscode/settings_test.go index 1ff9c68ff4..9e3ab99adc 100644 --- a/pkg/ide/vscode/settings_test.go +++ b/pkg/ide/vscode/settings_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "os" "path/filepath" + "runtime" "testing" "github.com/stretchr/testify/suite" @@ -24,6 +25,21 @@ func (s *SettingsSuite) SetupTest() { s.tmpDir = s.T().TempDir() } +func (s *SettingsSuite) TestLinuxSettingsRespectXDGConfigHome() { + xdg := filepath.Join(s.tmpDir, "xdg") + s.T().Setenv("XDG_CONFIG_HOME", xdg) + s.Equal(xdg, userSettingsBaseDir(s.tmpDir, "linux")) + if runtime.GOOS == "linux" { + s.T().Setenv("HOME", s.tmpDir) + s.Require().NoError(ensureHostSettingsWithTimeout(FlavorStable, "60")) + settings, err := readSettingsFile(filepath.Join(xdg, "Code", "User", "settings.json")) + s.Require().NoError(err) + s.Equal(float64(60), settings[settingConnectTimeout]) + } + s.T().Setenv("XDG_CONFIG_HOME", "") + s.Equal(filepath.Join(s.tmpDir, ".config"), userSettingsBaseDir(s.tmpDir, "linux")) +} + func (s *SettingsSuite) TestHostTimeoutPreservesSettingsAndTargetsFlavor() { s.T().Setenv("HOME", s.tmpDir) s.T().Setenv("APPDATA", s.tmpDir) diff --git a/sites/docs-devsy-sh/content/docs/developing-in-workspaces/connect-to-a-workspace.mdx b/sites/docs-devsy-sh/content/docs/developing-in-workspaces/connect-to-a-workspace.mdx index 28ca7fafbb..d842340ac0 100644 --- a/sites/docs-devsy-sh/content/docs/developing-in-workspaces/connect-to-a-workspace.mdx +++ b/sites/docs-devsy-sh/content/docs/developing-in-workspaces/connect-to-a-workspace.mdx @@ -40,6 +40,8 @@ devsy workspace up my-workspace --ide vscode --ide-option SSH_CONNECT_TIMEOUT=60 Alternatively, set the option for all VS Code workspaces with `devsy ide set vscode -o SSH_CONNECT_TIMEOUT=60`. The value must be a positive whole number of seconds, up to 999999999. When specified, Devsy writes `remote.SSH.connectTimeout` to the host user settings for the selected editor flavor. This setting applies globally to all Remote - SSH hosts in that editor, including non-Devsy hosts. If the option is not set, Devsy leaves the existing timeout unchanged. For other VS Code-based editors, use their IDE name in place of `vscode`. +On Linux, Devsy uses `XDG_CONFIG_HOME` for editor settings when it is set. Otherwise, it uses `~/.config`. + ### JetBrains IDEs Install [JetBrains Gateway](https://www.jetbrains.com/remote-development/gateway/). You need a license for the IDE you use. Start the workspace with the IDE name, for example: From 5499881cbcc07267f53bad4584ed767e57bf0c29 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Sat, 31 Oct 2026 01:51:16 -0600 Subject: [PATCH 10/11] test: isolate Linux editor settings path --- e2e/tests/ide/vscode_settings.go | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e/tests/ide/vscode_settings.go b/e2e/tests/ide/vscode_settings.go index 67c277d5de..671ca36d88 100644 --- a/e2e/tests/ide/vscode_settings.go +++ b/e2e/tests/ide/vscode_settings.go @@ -30,6 +30,7 @@ var _ = ginkgo.Describe("VS Code Settings JSONC Handling", ginkgo.Label("ide"), err = os.MkdirAll(settingsDir, 0o750) framework.ExpectNoError(err) + framework.SetEnvForSpec("XDG_CONFIG_HOME", filepath.Join(tmpHome, ".config")) framework.SetEnvForSpec("HOME", tmpHome) }) From 80404a582d4bdbbe3ebe25ca978f80deb56420a2 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Sat, 31 Oct 2026 09:55:43 -0600 Subject: [PATCH 11/11] test: isolate settings paths and verify raw mounts --- pkg/driver/docker/runargs_test.go | 20 ++++++++++++++++++++ pkg/ide/vscode/settings_test.go | 2 ++ 2 files changed, 22 insertions(+) diff --git a/pkg/driver/docker/runargs_test.go b/pkg/driver/docker/runargs_test.go index 4a7b25c236..9241f81e66 100644 --- a/pkg/driver/docker/runargs_test.go +++ b/pkg/driver/docker/runargs_test.go @@ -5,6 +5,7 @@ import ( "path/filepath" "github.com/devsy-org/devsy/pkg/devcontainer/config" + "github.com/devsy-org/devsy/pkg/docker" "github.com/devsy-org/devsy/pkg/driver" ) @@ -247,6 +248,25 @@ func (s *DockerDriverTestSuite) TestAddMountArgs_DoesNotModifySourceOrOptions() } } +func (s *DockerDriverTestSuite) TestRunArgsBuilderPreservesRawMountFlags() { + const rawMount = "--volume=user-data:/opt/devsy" + rt, err := docker.RuntimeFromName(string(docker.RuntimeDocker)) + s.Require().NoError(err) + helper := &docker.DockerHelper{DockerCommand: "docker", Runtime: rt} + s.driver.Docker = helper + args, err := s.driver.buildRunArgs( + &driver.RunImageDevContainerParams{ + ParsedConfig: &config.DevContainerConfig{ + NonComposeBase: config.NonComposeBase{RunArgs: []string{rawMount}}, + }, + Options: &driver.RunOptions{Image: "alpine"}, + }, + helper, + ) + s.Require().NoError(err) + s.Contains(args, rawMount) +} + func (s *DockerDriverTestSuite) TestRunArgsBuilder_AdditionalMountReachesArgs() { source := filepath.Join(s.T().TempDir(), "engine.sock") b := &runArgsBuilder{ diff --git a/pkg/ide/vscode/settings_test.go b/pkg/ide/vscode/settings_test.go index 9e3ab99adc..e237a1a5cc 100644 --- a/pkg/ide/vscode/settings_test.go +++ b/pkg/ide/vscode/settings_test.go @@ -23,6 +23,7 @@ func TestSettingsSuite(t *testing.T) { func (s *SettingsSuite) SetupTest() { s.tmpDir = s.T().TempDir() + s.T().Setenv("XDG_CONFIG_HOME", filepath.Join(s.tmpDir, ".config")) } func (s *SettingsSuite) TestLinuxSettingsRespectXDGConfigHome() { @@ -76,6 +77,7 @@ func (s *SettingsSuite) TestHostTimeoutReportsInvalidSettings() { s.Require().NoError(err) s.writeRaw(path, "{ invalid") s.Error(ensureHostSettingsWithTimeout(FlavorStable, "60")) + s.writeJSON(path, map[string]any{}) s.Error(ensureHostSettingsWithTimeout(FlavorStable, "0")) }