diff --git a/cmd/workspace/up/detach.go b/cmd/workspace/up/detach.go index e12c0a052e..16556c24d1 100644 --- a/cmd/workspace/up/detach.go +++ b/cmd/workspace/up/detach.go @@ -155,6 +155,7 @@ func (cmd *UpCmd) openTask() (*task.Task, error) { } t := store.Open(cmd.taskID) if err := t.HoldWorkerLock(); err != nil { + traceDetachedAdmission("worker lock") return nil, err } verifiedOwner, err := waitForTaskLaunch(t, store) @@ -184,6 +185,7 @@ func waitForTaskLaunch(t *task.Task, store *task.Store) (bool, error) { for { state, err := readWorkerLaunchState(t, store) if err != nil { + traceDetachedAdmission("reading launch state") return progress.verifiedOwner, err } ready, err := advanceTaskLaunch(t, store, state, &progress) @@ -195,6 +197,7 @@ func waitForTaskLaunch(t *task.Task, store *task.Store) (bool, error) { } select { case <-deadline.C: + traceDetachedAdmission("waiting for launch commit") return progress.verifiedOwner, errors.New( "timed out waiting for detached worker launch metadata", ) @@ -223,6 +226,7 @@ func advanceTaskLaunch( owner, err := verifyWorkerTaskOwner(state) progress.verifiedOwner = owner if err != nil { + traceDetachedAdmission("verifying owner") return false, err } if !state.LaunchPending { @@ -233,17 +237,29 @@ func advanceTaskLaunch( return false, nil } if err := retainWorkerLaunchLease(&progress.leaseRetained); err != nil { + traceDetachedAdmission("retaining launch lease") return false, err } if err := checkWorkerLauncher(t, store); err != nil { + traceDetachedAdmission("checking launcher") return false, err } if state.PID != 0 && !state.WorkerReady { - return false, t.WorkerLaunchReady(os.Getpid()) + if err := t.WorkerLaunchReady(os.Getpid()); err != nil { + traceDetachedAdmission("acknowledging worker") + return false, err + } + return false, nil } 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/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) }) diff --git a/e2e/tests/ssh/detached_diagnostics_test.go b/e2e/tests/ssh/detached_diagnostics_test.go new file mode 100644 index 0000000000..518ed92a44 --- /dev/null +++ b/e2e/tests/ssh/detached_diagnostics_test.go @@ -0,0 +1,61 @@ +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") + 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, 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) +} + +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 2456a6d92b..31ca9086bd 100644 --- a/e2e/tests/ssh/detached_task.go +++ b/e2e/tests/ssh/detached_task.go @@ -4,12 +4,17 @@ import ( "context" "encoding/json" "fmt" + "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/task" + workspacepkg "github.com/devsy-org/devsy/pkg/workspace" + "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" ) @@ -55,9 +60,11 @@ func startDetachedTunnelUp( } args = append(args, extraArgs...) args = append(args, workspace) + before := detachedTaskIDs() out, err := f.ExecCommandOutput(ctx, args) if err != nil { + reportDetachedLaunchFailure(before, workspace) return "", err } var env struct { @@ -74,6 +81,87 @@ func startDetachedTunnelUp( return env.ID, nil } +func detachedTaskIDs() map[string]struct{} { + store, err := task.NewStore() + if err != nil { + return nil + } + states, err := store.List() + 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 + } + reportDiagnosticState(state) + 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", 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 { + 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 e88b77f9a3..1a4d7db15d 100644 --- a/e2e/tests/ssh/detached_validation.go +++ b/e2e/tests/ssh/detached_validation.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "io" "os" "os/exec" "path/filepath" @@ -13,6 +14,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" @@ -62,10 +64,14 @@ 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)) sentinel := filepath.Join(source, "KeepCase.txt") + before := detachedTaskIDs() framework.ExpectNoError(os.WriteFile(sentinel, []byte("original source"), 0o600)) out, err := cli.command(ctx, cmdWorkspace, @@ -75,7 +81,11 @@ var _ = ginkgo.Describe("detached workspace input validation", ginkgo.Label("tas "--provider=missing-provider-1471", source, ) - framework.ExpectNoError(err) + if err != nil { + reportDetachedLaunchFailure(before, source) + } + 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 +246,73 @@ func (cli detachedValidationCLI) launchWorker( return worker, nil }) if err != nil { + store, storeErr := task.NewStoreAt(filepath.Join(cli.home, "state", "tasks")) + if storeErr == nil { + state, stateErr := store.Get(tk.ID()) + if stateErr == nil { + reportDiagnosticState(state) + } + } + streamsPath, pathErr := config.DefaultPathManager(). + ProcessStreamsFile(task.WorkerProcessName(tk.ID())) + if pathErr == nil { + streams, readErr := readDiagnosticStreams(cli.home, streamsPath) + if readErr == nil { + ginkgo.GinkgoWriter.Printf("worker streams: %s\n", 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 + } + 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 { + 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 []byte(result.String()) +} + func (cli detachedValidationCLI) expectFailureEnvelope(ctx context.Context, id, diagnostic string) { followCtx, cancel := context.WithTimeout(ctx, 10*time.Second) defer cancel() @@ -265,5 +337,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") } diff --git a/pkg/agent/delivery/local_docker.go b/pkg/agent/delivery/local_docker.go index 96620c1df2..a202573082 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 && + isAgentMountTarget(mount.Target) { + return fmt.Errorf("agent mount target %s is already in use", volumeMountPath) + } + for _, mount := range opts.RunOptions.Mounts { + if mount != nil && isAgentMountTarget(mount.Target) { + return fmt.Errorf("agent mount target %s is already in use", volumeMountPath) + } + } volumeName := volumePrefix + opts.WorkspaceID @@ -74,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 edadf52af6..91e9b9e84d 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,36 @@ func TestLocalDockerDelivery_DeliverPreStart_RequiresBinarySource(t *testing.T) assert.Contains(t, err.Error(), "binary source is required") } +func TestLocalDockerDeliveryRejectsOccupiedAgentMount(t *testing.T) { + 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 tc.workspace { + 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/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..5bfc93a0c8 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,36 @@ 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 + } + 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( @@ -475,11 +485,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 +925,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 +939,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..8072bd2da5 100644 --- a/pkg/devcontainer/single_delivery_test.go +++ b/pkg/devcontainer/single_delivery_test.go @@ -3,11 +3,21 @@ 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/driver" "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 +70,93 @@ 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 _, 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 tc.fail { + script = "#!/bin/sh\nexit 1\n" + } + 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{} + + 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) + 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/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/driver/kubernetes/pod_lifecycle_test.go b/pkg/driver/kubernetes/pod_lifecycle_test.go index 737c09f716..b93b568c12 100644 --- a/pkg/driver/kubernetes/pod_lifecycle_test.go +++ b/pkg/driver/kubernetes/pod_lifecycle_test.go @@ -224,24 +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{}}, - }} - // Set before publishing: reconcile can return as soon as the pod is visible. - ready.Store(true) - c.putPod(t, running) + 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(2 * time.Second): + t.Fatal("reconcile did not return after the pod became ready") + } } func TestReconcileTerminatingPodWaitsForDeletionThenAllowsCreate(t *testing.T) { 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..d167942753 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) { @@ -82,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 2bee592af2..e237a1a5cc 100644 --- a/pkg/ide/vscode/settings_test.go +++ b/pkg/ide/vscode/settings_test.go @@ -4,11 +4,14 @@ import ( "encoding/json" "os" "path/filepath" + "runtime" "testing" "github.com/stretchr/testify/suite" ) +const editorFontSize = "editor.fontSize" + type SettingsSuite struct { suite.Suite tmpDir string @@ -20,6 +23,62 @@ 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() { + 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) + 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.writeJSON(path, map[string]any{}) + s.Error(ensureHostSettingsWithTimeout(FlavorStable, "0")) } func (s *SettingsSuite) TestMergeUserSettings_CreatesNewFile() { @@ -40,7 +99,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 +114,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 +161,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 +170,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 +179,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 +208,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 +235,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 +258,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 +288,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 +315,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..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 @@ -32,6 +32,16 @@ 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`. + +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: 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..88c58f7b2f 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,18 @@ 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. + +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. + ### 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: