Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

fix(runner): omit normal peer close errors after an exec exit (#3197)

kekxy74bba8f8d8b3
diff --git a/apps/runner/README.md b/apps/runner/README.md
index 169f21049..a25336695 100644
--- a/apps/runner/README.md
+++ b/apps/runner/README.md
@@ -465,7 +465,11 @@ The session-end line carries `boxId`, `execId`, `reason`, the first
error's text, the client's Close status code when there was one, how long
the socket was up, per-stream replayed / sent / dropped bytes, whether the
exit frame was sent, whether the exec had finished, and how many sessions
-the exec has had. `reason` is one of:
+the exec has had. On `exec_done`, a normal peer Close (1000) paired with a
+successfully sent exit frame produces no `firstError` or `clientCloseCode`.
+A client Close that ends a running exec still includes its close details.
+
+`reason` is one of:
| Reason | Meaning |
| --- | --- |
diff --git a/apps/runner/pkg/api/controllers/boxlite_exec_attach.go b/apps/runner/pkg/api/controllers/boxlite_exec_attach.go
index cea45a1e9..eae8b1a8f 100644
--- a/apps/runner/pkg/api/controllers/boxlite_exec_attach.go
+++ b/apps/runner/pkg/api/controllers/boxlite_exec_attach.go
@@ -613,8 +613,7 @@ func runAttachLoop(parentCtx context.Context, conn *websocket.Conn, exec attachE
type attachSessionReport struct {
boxId, execId string
reason attachEndReason
- // firstErr is the first failure any goroutine reported, nil when the
- // exec finished normally.
+ // firstErr can include the peer's normal Close if the reader beat cancellation.
firstErr error
connectedFor time.Duration
outputs [2]*attachOutput
@@ -648,10 +647,12 @@ func logAttachSessionEnd(r attachSessionReport) {
"execDone", r.execDone,
"exitFrameSent", r.exitFrameSent,
}
- if r.firstErr != nil {
+ closeCode := clientCloseCode(r.firstErr)
+ normalExitClose := r.reason == attachEndExecDone && r.exitFrameSent && closeCode == websocket.CloseNormalClosure
+ if r.firstErr != nil && !normalExitClose {
args = append(args, "firstError", r.firstErr.Error())
- if code := clientCloseCode(r.firstErr); code != 0 {
- args = append(args, "clientCloseCode", code)
+ if closeCode != 0 {
+ args = append(args, "clientCloseCode", closeCode)
}
}
for _, o := range r.outputs {
diff --git a/apps/runner/pkg/api/controllers/boxlite_exec_attach_test.go b/apps/runner/pkg/api/controllers/boxlite_exec_attach_test.go
index 92fe49d7a..76e0cbaa8 100644
--- a/apps/runner/pkg/api/controllers/boxlite_exec_attach_test.go
+++ b/apps/runner/pkg/api/controllers/boxlite_exec_attach_test.go
@@ -1368,6 +1368,40 @@ func TestBoxliteExecAttach_SessionEndLog_ExecDone(t *testing.T) {
}
}
+func TestBoxliteExecAttach_SessionEndLog_PeerCloseAtExit(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ exitSent bool
+ peerCode int
+ wantFailure bool
+ }{
+ {"normal close after exit", true, websocket.CloseNormalClosure, false},
+ {"exit frame unsent", false, websocket.CloseNormalClosure, true},
+ {"protocol error after exit", true, websocket.CloseProtocolError, true},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ logs := captureAttachLogs(t)
+ logAttachSessionEnd(attachSessionReport{
+ execId: tc.name,
+ reason: attachEndExecDone,
+ execDone: true,
+ exitFrameSent: tc.exitSent,
+ firstErr: fmt.Errorf("read client frame: %w", &websocket.CloseError{Code: tc.peerCode}),
+ outputs: [2]*attachOutput{
+ {stream: &stubStream{}, channel: chanStdout},
+ {stream: &stubStream{}, channel: chanStderr},
+ },
+ })
+ match := []string{`"reason":"exec_done"`, fmt.Sprintf(`"execId":%q`, tc.name)}
+ if tc.wantFailure {
+ assertLogHas(t, logs, match, []string{`"firstError":`, fmt.Sprintf(`"clientCloseCode":%d`, tc.peerCode)})
+ } else {
+ assertLogHas(t, logs, match, nil, `"firstError":`, `"clientCloseCode":`)
+ }
+ })
+ }
+}
+
// A client Close frame is the normal end of a session that the client ends
// itself — what the SDK does before it reconnects.
func TestBoxliteExecAttach_SessionEndLog_ClientClose(t *testing.T) {