From 411632548c6a618e9728c25954df171374ac523f Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sat, 14 Nov 2026 21:59:42 +1100 Subject: [PATCH] fix(openshell): a sandbox that fails to start reports its last log lines (#1864) --- internal/infrastructure/openshell/runtime.go | 28 +++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/internal/infrastructure/openshell/runtime.go b/internal/infrastructure/openshell/runtime.go index ddacb7684..e5163a253 100644 --- a/internal/infrastructure/openshell/runtime.go +++ b/internal/infrastructure/openshell/runtime.go @@ -165,8 +165,11 @@ func (r *Runtime) Acquire(ctx context.Context, l Launch) (*Sandbox, error) { return nil, fmt.Errorf("create sandbox %s: %w", name, err) } if _, err := r.client.Sandboxes().WaitReady(ctx, r.workspace, name); err != nil { + // The sandbox's own log is the only record of why it failed, and + // removing the sandbox discards it. + tail := r.logTail(ctx, name) r.remove(ctx, name) - return nil, fmt.Errorf("sandbox %s not ready: %w", name, err) + return nil, fmt.Errorf("sandbox %s not ready: %w%s", name, err, tail) } watchCtx, stop := context.WithCancel(context.WithoutCancel(ctx)) s := &Sandbox{name: name, exited: make(chan struct{}), stop: stop, done: make(chan struct{})} @@ -175,6 +178,29 @@ func (r *Runtime) Acquire(ctx context.Context, l Launch) (*Sandbox, error) { return s, nil } +// logTail returns the sandbox's last log lines, prefixed for appending to an +// error, or "" when there are none or they cannot be read. +func (r *Runtime) logTail(ctx context.Context, name string) string { + res, err := r.client.Sandboxes().GetLogs(ctx, r.workspace, name, v1.WithLogLines(15)) + if err != nil { + r.log.WarnContext(ctx, "read failed sandbox log", "sandbox", name, "err", err) + return "" + } + var b strings.Builder + for _, l := range res.Lines { + b.WriteString("\n") + b.WriteString(l.Source) + b.WriteString(" ") + b.WriteString(l.Level) + b.WriteString(" ") + b.WriteString(l.Message) + } + if b.Len() == 0 { + return "" + } + return "\nsandbox log:" + b.String() +} + // sandboxName is a short random name: the gateway rejects names much longer // than 19 characters, and the instance is carried by the sandbox's label. func sandboxName() (string, error) {