From 9f659c28f9d7f395d39b4891de1689ce7a25e9f3 Mon Sep 17 00:00:00 2001 From: Robert Otting Date: Tue, 24 Nov 2026 19:27:08 +0000 Subject: [PATCH 1/9] feat: surface critical dockerd and sysbox output in startup logs dockerd and sysbox failures were only written to the envbox container's logs. For example, when dockerd ran out of disk at startup, the workspace startup logs only showed a later, misleading error. Child process lines that match a short list of actionable failures (no space left on device, dockerd and sysbox startup failures, logrus fatal) are now logged at error level and forwarded to the workspace startup logs. Forwarding runs off the output path so it never blocks the child, is deduplicated and capped per process run, and completes before the process exit is reported so the cause appears before envbox's own failure message. Co-Authored-By: Claude Opus 5.5 --- background/process.go | 134 ++++++++++++++++++++- background/process_test.go | 166 +++++++++++++++++++++++++++ cli/docker.go | 21 +++- integration/docker_test.go | 59 ++++++++++ integration/integrationtest/coder.go | 8 ++ 5 files changed, 383 insertions(+), 5 deletions(-) create mode 100644 background/process_test.go diff --git a/background/process.go b/background/process.go index 9f30e0f..1c14467 100644 --- a/background/process.go +++ b/background/process.go @@ -32,6 +32,48 @@ type Process struct { userKilled *int64 waitCh chan error mu sync.Mutex + + onCriticalOutput func(line string) +} + +const ( + // maxCriticalLines caps how many critical lines a single run of a + // process forwards to its OnCriticalOutput handler. + maxCriticalLines = 10 + // criticalFlushTimeout bounds how long reporting a process exit waits for + // the OnCriticalOutput handler to finish with already forwarded lines. + criticalFlushTimeout = 5 * time.Second +) + +// criticalOutputPatterns are lowercase substrings of child output that point +// at an actionable startup failure. Keep this list short: every match is +// shown to the user in the workspace startup logs. +var criticalOutputPatterns = []string{ + // Disk exhaustion, from dockerd or sysbox. + "no space left on device", + // dockerd prints this to stderr before its logger is set up, so the + // line has no level= field. + "failed to start daemon", + // sysbox-mgr and sysbox-fs startup errors. + "failed to create sysbox-mgr", + "failed to start sysbox-mgr", + "failed to start sysbox-fs", + // logrus fatal level, used by dockerd, sysbox-mgr, and sysbox-fs right + // before they exit. + "level=fatal", +} + +// IsCriticalOutput reports whether a line of child process output describes +// a failure that should be shown to the user, rather than only written to the +// envbox container's logs. +func IsCriticalOutput(line string) bool { + line = strings.ToLower(line) + for _, pattern := range criticalOutputPatterns { + if strings.Contains(line, pattern) { + return true + } + } + return false } // New returns an instantiated daemon. binName is the expected @@ -51,6 +93,21 @@ func New(ctx context.Context, log slog.Logger, binName, cmd string, args ...stri } } +// OnCriticalOutput registers fn to receive lines of the process's output for +// which IsCriticalOutput is true. Each run of the process forwards a line at +// most once and at most maxCriticalLines lines in total. fn runs on its own +// goroutine so a slow fn never blocks the process. The channel returned by +// Wait does not report an exit until fn has returned for every forwarded +// line, or until criticalFlushTimeout passes. Call it before Start or Run; +// the handler also applies after Restart. +func (d *Process) OnCriticalOutput(fn func(line string)) *Process { + d.mu.Lock() + defer d.mu.Unlock() + + d.onCriticalOutput = fn + return d +} + // Start starts the daemon. It functions akin to ox/exec.Command.Start(). func (d *Process) Start() error { d.mu.Lock() @@ -126,7 +183,11 @@ func (d *Process) startProcess() error { cmd.SetStdout(mw) cmd.SetStderr(mw) - go scanIntoLog(d.ctx, d.log, bufio.NewScanner(pr), d.binName) + scanDone := make(chan struct{}) + go func() { + defer close(scanDone) + scanIntoLog(d.ctx, d.log, bufio.NewScanner(pr), d.binName, d.onCriticalOutput) + }() err := d.cmd.Start() if err != nil { @@ -142,6 +203,16 @@ func (d *Process) startProcess() error { err := cmd.Wait() _ = psw.Flush() + // Wait returns only after all output has been copied into the + // pipe. Closing it lets scanIntoLog finish, so critical lines + // reach the handler before the exit is reported to callers. + _ = pw.Close() + select { + case <-scanDone: + case <-time.After(criticalFlushTimeout): + d.log.Warn(d.ctx, "timed out forwarding critical output", slog.F("process", d.binName)) + } + // If the user killed the application the actual error returned // from wait doesn't really matter. if atomic.LoadInt64(userKilled) == 1 { @@ -223,7 +294,10 @@ func isProcExited(fs afero.Fs, pid int, cmd string) (bool, error) { return cmd != string(args[0]), nil } -func scanIntoLog(ctx context.Context, log slog.Logger, scanner *bufio.Scanner, binaryName string) { +func scanIntoLog(ctx context.Context, log slog.Logger, scanner *bufio.Scanner, binaryName string, onCritical func(line string)) { + fwd := newCriticalForwarder(onCritical) + defer fwd.close() + for scanner.Scan() { select { case <-ctx.Done(): @@ -249,6 +323,11 @@ func scanIntoLog(ctx context.Context, log slog.Logger, scanner *bufio.Scanner, b logFn = log.Error } + if IsCriticalOutput(line) { + logFn = log.Error + fwd.forward(line) + } + logFn(ctx, "child log", slog.F("process", binaryName), slog.F("content", line), @@ -256,6 +335,57 @@ func scanIntoLog(ctx context.Context, log slog.Logger, scanner *bufio.Scanner, b } } +// criticalForwarder delivers critical lines to a handler on a separate +// goroutine. forward and close must be called from a single goroutine. +type criticalForwarder struct { + lines chan string + seen map[string]struct{} + done chan struct{} +} + +// newCriticalForwarder returns nil when fn is nil. The nil forwarder's +// methods are no-ops. +func newCriticalForwarder(fn func(line string)) *criticalForwarder { + if fn == nil { + return nil + } + + f := &criticalForwarder{ + lines: make(chan string, maxCriticalLines), + seen: make(map[string]struct{}), + done: make(chan struct{}), + } + go func() { + defer close(f.done) + for line := range f.lines { + fn(line) + } + }() + return f +} + +func (f *criticalForwarder) forward(line string) { + if f == nil { + return + } + if _, ok := f.seen[line]; ok || len(f.seen) >= maxCriticalLines { + return + } + f.seen[line] = struct{}{} + // Never blocks: the buffer holds maxCriticalLines and no more than that + // are ever sent. + f.lines <- line +} + +// close waits for the handler to finish with every forwarded line. +func (f *criticalForwarder) close() { + if f == nil { + return + } + close(f.lines) + <-f.done +} + var ErrUserKilled = xerrors.Errorf("daemon killed by user") func i64ptr(i int64) *int64 { diff --git a/background/process_test.go b/background/process_test.go new file mode 100644 index 0000000..ce6962c --- /dev/null +++ b/background/process_test.go @@ -0,0 +1,166 @@ +package background_test + +import ( + "context" + "os" + "path/filepath" + "strconv" + "sync" + "testing" + "time" + + "github.com/stretchr/testify/require" + + "cdr.dev/slog/v3" + "cdr.dev/slog/v3/sloggers/slogtest" + "github.com/coder/envbox/background" +) + +func TestIsCriticalOutput(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + line string + want bool + }{ + { + // The line from the original report, emitted before dockerd's + // logger starts. + name: "DockerdNoSpace", + line: "failed to start daemon: Unable to get the TempDir under /var/lib/docker/100000.100000: mkdir /var/lib/docker/100000.100000/tmp: no space left on device", + want: true, + }, + { + name: "SysboxFatal", + line: `time="2026-11-24 18:00:00" level=fatal msg="failed to start sysbox-mgr: some error"`, + want: true, + }, + { + name: "SysboxFsStartError", + line: `level=error msg="failed to start sysbox-fs: ipc init"`, + want: true, + }, + { + name: "CaseInsensitive", + line: "No Space Left On Device", + want: true, + }, + { + name: "DockerdInfo", + line: `level=info msg="API listen on /var/run/docker.sock"`, + want: false, + }, + { + name: "DockerdError", + line: `level=error msg="Handler for GET /v1.47/containers/foo/json returned error: No such container: foo"`, + want: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + require.Equal(t, tt.want, background.IsCriticalOutput(tt.line)) + }) + } +} + +// testLogger ignores error logs, since critical child output is logged at the +// error level. +func testLogger(t *testing.T) slog.Logger { + return slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}) +} + +// lineRecorder is a thread-safe OnCriticalOutput handler. +type lineRecorder struct { + mu sync.Mutex + lines []string +} + +func (r *lineRecorder) record(line string) { + r.mu.Lock() + defer r.mu.Unlock() + r.lines = append(r.lines, line) +} + +func (r *lineRecorder) get() []string { + r.mu.Lock() + defer r.mu.Unlock() + return append([]string(nil), r.lines...) +} + +func TestProcessOnCriticalOutput(t *testing.T) { + t.Parallel() + + t.Run("ForwardsCriticalLinesBeforeExit", func(t *testing.T) { + t.Parallel() + + var rec lineRecorder + script := ` +echo 'level=info msg="starting up"' +echo 'failed to start daemon: mkdir /var/lib/docker/tmp: no space left on device' >&2 +echo 'regular output' +exit 1` + err := <-background.New(context.Background(), testLogger(t), "sh", "sh", "-c", script). + OnCriticalOutput(rec.record). + Run() + require.Error(t, err) + + // Checked without waiting: the exit is only reported after the + // handler has received every forwarded line. + require.Equal(t, []string{ + "failed to start daemon: mkdir /var/lib/docker/tmp: no space left on device", + }, rec.get()) + }) + + t.Run("DedupesAndCaps", func(t *testing.T) { + t.Parallel() + + var rec lineRecorder + script := ` +for i in 1 2 3; do echo 'level=fatal msg="repeated"'; done +for i in $(seq 1 20); do echo "level=fatal msg=\"line $i\""; done` + err := <-background.New(context.Background(), testLogger(t), "sh", "sh", "-c", script). + OnCriticalOutput(rec.record). + Run() + require.NoError(t, err) + + want := []string{`level=fatal msg="repeated"`} + for i := 1; len(want) < 10; i++ { + want = append(want, `level=fatal msg="line `+strconv.Itoa(i)+`"`) + } + require.Equal(t, want, rec.get()) + }) + + t.Run("SlowHandlerDoesNotBlockProcess", func(t *testing.T) { + t.Parallel() + + marker := filepath.Join(t.TempDir(), "done") + release := make(chan struct{}) + var rec lineRecorder + + // The process writes far more than a pipe buffer after the + // critical line, then creates the marker file. If the handler + // blocked output, the marker would never appear. + script := ` +echo 'level=fatal msg="boom"' +head -c 1048576 /dev/zero | tr '\0' 'a' | fold -w 1024 +touch "$1"` + p := background.New(context.Background(), testLogger(t), "sh", "sh", "-c", script, "sh", marker). + OnCriticalOutput(func(line string) { + <-release + rec.record(line) + }) + require.NoError(t, p.Start()) + + require.Eventually(t, func() bool { + _, err := os.Stat(marker) + return err == nil + }, 10*time.Second, 10*time.Millisecond) + + close(release) + require.NoError(t, <-p.Wait()) + require.Equal(t, []string{`level=fatal msg="boom"`}, rec.get()) + }) +} diff --git a/cli/docker.go b/cli/docker.go index 469bc69..1920162 100644 --- a/cli/docker.go +++ b/cli/docker.go @@ -226,14 +226,18 @@ func dockerCmd() *cobra.Command { select { // Start sysbox-mgr and sysbox-fs in order to run // sysbox containers. - case err := <-background.New(ctx, log, "sysbox-mgr", "sysbox-mgr", sysboxArgs...).Run(): + case err := <-background.New(ctx, log, "sysbox-mgr", "sysbox-mgr", sysboxArgs...). + OnCriticalOutput(startupLogCriticalOutput(blog, "sysbox-mgr")). + Run(): if ctx.Err() == nil { blog.Info(sysboxErrMsg) //nolint log.Critical(ctx, "sysbox-mgr exited", slog.Error(err)) panic(err) } - case err := <-background.New(ctx, log, "sysbox-fs", "sysbox-fs").Run(): + case err := <-background.New(ctx, log, "sysbox-fs", "sysbox-fs"). + OnCriticalOutput(startupLogCriticalOutput(blog, "sysbox-fs")). + Run(): if ctx.Err() == nil { blog.Info(sysboxErrMsg) //nolint @@ -258,7 +262,8 @@ func dockerCmd() *cobra.Command { blog.Info("Waiting for sysbox processes to startup...") wrapCmd, wrapArgs := wrapDockerdCmd(dargs) - dockerd := background.New(ctx, log, dockerdBinName, wrapCmd, wrapArgs...) + dockerd := background.New(ctx, log, dockerdBinName, wrapCmd, wrapArgs...). + OnCriticalOutput(startupLogCriticalOutput(blog, "dockerd")) err = dockerd.Start() if err != nil { return xerrors.Errorf("start dockerd: %w", err) @@ -456,6 +461,16 @@ func dockerCmd() *cobra.Command { return cmd } +// startupLogCriticalOutput returns a handler that writes critical output of a +// background process to the workspace startup logs. Without it, failures such +// as dockerd running out of disk are only visible in the envbox container's +// logs. +func startupLogCriticalOutput(blog buildlog.Logger, process string) func(line string) { + return func(line string) { + blog.Errorf("%s: %s", process, line) + } +} + func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.Client, blog buildlog.Logger, flags flags) (string, error) { fs := xunix.GetFS(ctx) err := xunix.SetOOMScore(ctx, "self", "-1000") diff --git a/integration/docker_test.go b/integration/docker_test.go index 61c961d..0836fbe 100644 --- a/integration/docker_test.go +++ b/integration/docker_test.go @@ -1,17 +1,20 @@ package integration_test import ( + "crypto/tls" "encoding/json" "fmt" "net" "os" "path/filepath" + "slices" "strconv" "strings" "testing" "time" dockertest "github.com/ory/dockertest/v3" + "github.com/ory/dockertest/v3/docker" "github.com/stretchr/testify/require" "github.com/coder/envbox/cli" @@ -73,6 +76,62 @@ func TestDocker(t *testing.T) { _ = runEnvbox() }) + // CriticalOutputInStartupLogs asserts that a dockerd startup failure that + // is only printed by dockerd itself reaches the workspace startup logs. + t.Run("CriticalOutputInStartupLogs", func(t *testing.T) { + t.Parallel() + + pool, err := dockertest.NewPool("") + require.NoError(t, err) + + coderListener, err := net.Listen("tcp", fmt.Sprintf("%s:0", integrationtest.DockerBridgeIP(t))) + require.NoError(t, err) + defer coderListener.Close() + coderAddr := tcpAddr(t, coderListener) + recorder := integrationtest.FakeBuildLogRecorder(t, coderListener, tls.Certificate{}) + + // Give dockerd a data root too small to start in. + var binds []docker.HostMount + for _, bind := range integrationtest.DefaultBinds(t, integrationtest.TmpDir(t)) { + if bind.Target != "/var/lib/docker" { + binds = append(binds, bind) + } + } + binds = append(binds, docker.HostMount{ + Target: "/var/lib/docker", + Type: "tmpfs", + TempfsOptions: &docker.TempfsOptions{SizeBytes: 64 << 10}, + }) + + _ = integrationtest.RunEnvbox(t, pool, &integrationtest.CreateDockerCVMConfig{ + Image: integrationtest.DockerdImage, + Username: "root", + Envs: []string{ + integrationtest.EnvVar(cli.EnvAgentToken, "faketoken"), + integrationtest.EnvVar(cli.EnvAgentURL, fmt.Sprintf("http://host.docker.internal:%d", coderAddr.Port)), + }, + OuterMounts: binds, + ExpectFailure: true, + }) + + isCritical := func(log string) bool { + return strings.HasPrefix(log, "dockerd: ") && strings.Contains(log, "no space left on device") + } + require.Eventually(t, func() bool { + return slices.ContainsFunc(recorder.Logs(), isCritical) + }, 30*time.Second, 100*time.Millisecond, "startup logs: %q", recorder.Logs()) + + // The dockerd output must arrive before envbox reports the failure. + logs := recorder.Logs() + criticalIdx := slices.IndexFunc(logs, isCritical) + failedIdx := slices.IndexFunc(logs, func(log string) bool { + return strings.HasPrefix(log, "Failed to create Container-based Virtual Machine") + }) + if failedIdx != -1 { + require.Less(t, criticalIdx, failedIdx, "startup logs: %q", logs) + } + }) + // EnvboxArgs validates that arguments passed to envbox function correctly. // Most cases should be covered with unit tests, the intent with this is to // test cases that do not garner a high degree of confidence from mocking diff --git a/integration/integrationtest/coder.go b/integration/integrationtest/coder.go index 326232e..7de9f66 100644 --- a/integration/integrationtest/coder.go +++ b/integration/integrationtest/coder.go @@ -31,6 +31,14 @@ func (b *BuildLogRecorder) ContainsLog(l string) bool { return false } +// Logs returns a copy of the recorded build logs in the order they were +// received. +func (b *BuildLogRecorder) Logs() []string { + b.mu.Lock() + defer b.mu.Unlock() + return append([]string(nil), b.logs...) +} + func (b *BuildLogRecorder) Len() int { b.mu.Lock() defer b.mu.Unlock() From 23f2e943a063daebbe850f36024dbe44032ca55f Mon Sep 17 00:00:00 2001 From: Robert Otting Date: Wed, 25 Nov 2026 19:33:53 +0000 Subject: [PATCH 2/9] DO NOT MERGE: ci: run TestDocker in the integration job Temporary commit so CI exercises the new integration test. The job never sets CODER_TEST_INTEGRATION, so TestDocker and TestDocker_Nvidia skip. Drop before marking the PR ready. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c97e610..ef2c852 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -171,6 +171,8 @@ jobs: - name: Run integration tests id: test shell: bash + env: + CODER_TEST_INTEGRATION: "1" run: go test -tags=integration ./... build: From 8ad76dcc00217c34043e598df3f614014d1a0392 Mon Sep 17 00:00:00 2001 From: Robert Otting Date: Wed, 25 Nov 2026 19:43:14 +0000 Subject: [PATCH 3/9] test(integration): enforce the tmpfs size limit in CriticalOutputInStartupLogs docker.TempfsOptions serializes as "TempfsOptions", but the Docker API expects "TmpfsOptions", so the 64 KiB limit was dropped and dockerd started normally. Add CreateDockerCVMConfig.OuterTmpfs, which sets HostConfig.Tmpfs, and use it for /var/lib/docker. Co-Authored-By: Claude Opus 5.5 --- integration/docker_test.go | 8 ++------ integration/integrationtest/docker.go | 8 +++++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/integration/docker_test.go b/integration/docker_test.go index 0836fbe..7b8d264 100644 --- a/integration/docker_test.go +++ b/integration/docker_test.go @@ -90,18 +90,13 @@ func TestDocker(t *testing.T) { coderAddr := tcpAddr(t, coderListener) recorder := integrationtest.FakeBuildLogRecorder(t, coderListener, tls.Certificate{}) - // Give dockerd a data root too small to start in. + // Replace dockerd's data root with a tmpfs too small to start in. var binds []docker.HostMount for _, bind := range integrationtest.DefaultBinds(t, integrationtest.TmpDir(t)) { if bind.Target != "/var/lib/docker" { binds = append(binds, bind) } } - binds = append(binds, docker.HostMount{ - Target: "/var/lib/docker", - Type: "tmpfs", - TempfsOptions: &docker.TempfsOptions{SizeBytes: 64 << 10}, - }) _ = integrationtest.RunEnvbox(t, pool, &integrationtest.CreateDockerCVMConfig{ Image: integrationtest.DockerdImage, @@ -111,6 +106,7 @@ func TestDocker(t *testing.T) { integrationtest.EnvVar(cli.EnvAgentURL, fmt.Sprintf("http://host.docker.internal:%d", coderAddr.Port)), }, OuterMounts: binds, + OuterTmpfs: map[string]string{"/var/lib/docker": "size=64k"}, ExpectFailure: true, }) diff --git a/integration/integrationtest/docker.go b/integration/integrationtest/docker.go index b6f5ce4..14142e9 100644 --- a/integration/integrationtest/docker.go +++ b/integration/integrationtest/docker.go @@ -62,7 +62,12 @@ type CreateDockerCVMConfig struct { InnerEnvFilter []string Envs []string - OuterMounts []docker.HostMount + OuterMounts []docker.HostMount + // OuterTmpfs mounts tmpfs filesystems in the envbox container, keyed by + // path, with mount options such as "size=64k" as values. Use it instead + // of a tmpfs HostMount: docker.TempfsOptions has the wrong JSON key, so + // Docker ignores its size limit. + OuterTmpfs map[string]string AddFUSE bool AddTUN bool CPUs int @@ -104,6 +109,7 @@ func RunEnvbox(t *testing.T, pool *dockertest.Pool, conf *CreateDockerCVMConfig) Env: conf.Envs, }, func(host *docker.HostConfig) { host.Mounts = conf.OuterMounts + host.Tmpfs = conf.OuterTmpfs host.Privileged = true host.CPUPeriod = int64(dockerutil.DefaultCPUPeriod) host.CPUQuota = int64(conf.CPUs) * int64(dockerutil.DefaultCPUPeriod) From d315a4035a4f1e962e79fc1552634b0536db57f2 Mon Sep 17 00:00:00 2001 From: Robert Otting Date: Wed, 25 Nov 2026 19:47:39 +0000 Subject: [PATCH 4/9] Revert "DO NOT MERGE: ci: run TestDocker in the integration job" CI passed with TestDocker enabled (run 45687984937), so the temporary change is no longer needed. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ef2c852..c97e610 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -171,8 +171,6 @@ jobs: - name: Run integration tests id: test shell: bash - env: - CODER_TEST_INTEGRATION: "1" run: go test -tags=integration ./... build: From e9ec287f02139474fbff92e1133a9def1acaaab5 Mon Sep 17 00:00:00 2001 From: Robert Otting Date: Tue, 1 Dec 2026 17:51:28 +0000 Subject: [PATCH 5/9] fix: forward critical output at info level and fix review findings A matched dockerd or sysbox line does not mean envbox failed, since envbox can recover by restarting dockerd with the vfs driver. Writing it with blog.Errorf emitted JSON error records, which until now meant envbox gave up. Write it at info level instead. Copy ctx, binName, and the handler into locals in startProcess so its goroutines no longer race with Restart reassigning those fields. Make the integration test wait for both the dockerd line and the failure message, then always assert their order. Previously the check was skipped when the failure message had not arrived yet. waitForCVM now reports failure when envbox exits without a done or error record, since this failure path ends in log.Fatal after info-level messages only. Co-Authored-By: Claude Opus 5.5 --- background/process.go | 10 ++++++++-- cli/docker.go | 6 ++++-- integration/docker_test.go | 14 ++++++-------- integration/integrationtest/docker.go | 8 ++++++-- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/background/process.go b/background/process.go index 1c14467..71a2449 100644 --- a/background/process.go +++ b/background/process.go @@ -178,6 +178,12 @@ func (d *Process) startProcess() error { mw = io.MultiWriter(w, out) cmd = d.cmd + + // Restart reassigns these fields under d.mu, so the goroutines + // below must not read them directly. + ctx = d.ctx + binName = d.binName + onCritical = d.onCriticalOutput ) cmd.SetStdout(mw) @@ -186,7 +192,7 @@ func (d *Process) startProcess() error { scanDone := make(chan struct{}) go func() { defer close(scanDone) - scanIntoLog(d.ctx, d.log, bufio.NewScanner(pr), d.binName, d.onCriticalOutput) + scanIntoLog(ctx, d.log, bufio.NewScanner(pr), binName, onCritical) }() err := d.cmd.Start() @@ -210,7 +216,7 @@ func (d *Process) startProcess() error { select { case <-scanDone: case <-time.After(criticalFlushTimeout): - d.log.Warn(d.ctx, "timed out forwarding critical output", slog.F("process", d.binName)) + d.log.Warn(ctx, "timed out forwarding critical output", slog.F("process", binName)) } // If the user killed the application the actual error returned diff --git a/cli/docker.go b/cli/docker.go index 1920162..e65de04 100644 --- a/cli/docker.go +++ b/cli/docker.go @@ -464,10 +464,12 @@ func dockerCmd() *cobra.Command { // startupLogCriticalOutput returns a handler that writes critical output of a // background process to the workspace startup logs. Without it, failures such // as dockerd running out of disk are only visible in the envbox container's -// logs. +// logs. The lines are written at info level because a matching line does not +// mean envbox failed: envbox can recover, for example by restarting dockerd +// with the vfs storage driver. Error is reserved for envbox's own failures. func startupLogCriticalOutput(blog buildlog.Logger, process string) func(line string) { return func(line string) { - blog.Errorf("%s: %s", process, line) + blog.Infof("%s: %s", process, line) } } diff --git a/integration/docker_test.go b/integration/docker_test.go index 7b8d264..83f0b35 100644 --- a/integration/docker_test.go +++ b/integration/docker_test.go @@ -113,19 +113,17 @@ func TestDocker(t *testing.T) { isCritical := func(log string) bool { return strings.HasPrefix(log, "dockerd: ") && strings.Contains(log, "no space left on device") } + isFailure := func(log string) bool { + return strings.HasPrefix(log, "Failed to create Container-based Virtual Machine") + } require.Eventually(t, func() bool { - return slices.ContainsFunc(recorder.Logs(), isCritical) + logs := recorder.Logs() + return slices.ContainsFunc(logs, isCritical) && slices.ContainsFunc(logs, isFailure) }, 30*time.Second, 100*time.Millisecond, "startup logs: %q", recorder.Logs()) // The dockerd output must arrive before envbox reports the failure. logs := recorder.Logs() - criticalIdx := slices.IndexFunc(logs, isCritical) - failedIdx := slices.IndexFunc(logs, func(log string) bool { - return strings.HasPrefix(log, "Failed to create Container-based Virtual Machine") - }) - if failedIdx != -1 { - require.Less(t, criticalIdx, failedIdx, "startup logs: %q", logs) - } + require.Less(t, slices.IndexFunc(logs, isCritical), slices.IndexFunc(logs, isFailure), "startup logs: %q", logs) }) // EnvboxArgs validates that arguments passed to envbox function correctly. diff --git a/integration/integrationtest/docker.go b/integration/integrationtest/docker.go index 14142e9..4f63914 100644 --- a/integration/integrationtest/docker.go +++ b/integration/integrationtest/docker.go @@ -263,8 +263,12 @@ func waitForCVM(t *testing.T, pool *dockertest.Pool, resource *dockertest.Resour } } require.NoError(t, scanner.Err()) - require.True(t, finished, "unexpected logger exit") - return true + if !finished { + // envbox can exit without an error record, for example when a + // background process calls log.Fatal. + t.Log("envbox exited before reporting success") + } + return finished } type ExecConfig struct { From 0438845e0cb8baf585b837011ea0b1c4b30394e0 Mon Sep 17 00:00:00 2001 From: Robert Otting Date: Wed, 25 Nov 2026 19:33:53 +0000 Subject: [PATCH 6/9] DO NOT MERGE: ci: run TestDocker in the integration job Temporary commit so CI exercises the new integration test. The job never sets CODER_TEST_INTEGRATION, so TestDocker and TestDocker_Nvidia skip. Drop before marking the PR ready. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 677b90a..e5672f7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -171,6 +171,8 @@ jobs: - name: Run integration tests id: test shell: bash + env: + CODER_TEST_INTEGRATION: "1" run: go test -tags=integration ./... build: From 7cf53eb8ceabd082a305715600db10dd60ed0726 Mon Sep 17 00:00:00 2001 From: Robert Otting Date: Tue, 1 Dec 2026 18:36:06 +0000 Subject: [PATCH 7/9] DO NOT MERGE: ci: run integration tests verbosely Temporary, to confirm which TestDocker subtests run. Reverted with the CODER_TEST_INTEGRATION commit. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e5672f7..e0877b5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -173,7 +173,7 @@ jobs: shell: bash env: CODER_TEST_INTEGRATION: "1" - run: go test -tags=integration ./... + run: go test -v -tags=integration ./... build: runs-on: ubuntu-22.04 From 71a54ca6a520cee00f448d7440f892646cf2797a Mon Sep 17 00:00:00 2001 From: Robert Otting Date: Tue, 1 Dec 2026 18:40:32 +0000 Subject: [PATCH 8/9] Revert "DO NOT MERGE: ci: run integration tests verbosely" This reverts commit 7cf53eb8ceabd082a305715600db10dd60ed0726. --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e0877b5..e5672f7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -173,7 +173,7 @@ jobs: shell: bash env: CODER_TEST_INTEGRATION: "1" - run: go test -v -tags=integration ./... + run: go test -tags=integration ./... build: runs-on: ubuntu-22.04 From fff2016c3d539fc161262fe5b5478d96a3a9ba09 Mon Sep 17 00:00:00 2001 From: Robert Otting Date: Tue, 1 Dec 2026 18:40:32 +0000 Subject: [PATCH 9/9] Revert "DO NOT MERGE: ci: run TestDocker in the integration job" This reverts commit 0438845e0cb8baf585b837011ea0b1c4b30394e0. --- .github/workflows/ci.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e5672f7..677b90a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -171,8 +171,6 @@ jobs: - name: Run integration tests id: test shell: bash - env: - CODER_TEST_INTEGRATION: "1" run: go test -tags=integration ./... build: