{"record":{"id":"6fe19f1d269fbb63","repo":"vxcontrol/pentagi","slug":"listing-output-exceeded-d-bytes","errorCode":null,"errorMessage":"listing output exceeded %d bytes","messagePattern":"listing output exceeded (.+?) bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/docker/client.go","lineNumber":1083,"sourceCode":"\t\t\tif err == io.EOF {\n\t\t\t\tbreak // clean end at a frame boundary\n\t\t\t}\n\t\t\t// A header cut short (ErrUnexpectedEOF) means the stream was truncated\n\t\t\t// mid-frame — the listing is incomplete, so fail rather than silently\n\t\t\t// dropping the tail.\n\t\t\treturn nil, fmt.Errorf(\"truncated exec stream: %w\", err)\n\t\t}\n\t\tsize := int64(binary.BigEndian.Uint32(header[4:8]))\n\t\tif size == 0 {\n\t\t\tcontinue\n\t\t}\n\t\tswitch header[0] {\n\t\tcase 1: // stdout\n\t\t\tif _, err := io.CopyN(&stdout, r, size); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif stdout.Len() > maxStdout {\n\t\t\t\treturn nil, fmt.Errorf(\"listing output exceeded %d bytes\", maxStdout)\n\t\t\t}\n\t\tcase 3: // systemerr — a daemon-level error injected mid-stream; surface it\n\t\t\tvar msg bytes.Buffer\n\t\t\t_, _ = io.CopyN(&msg, r, size)\n\t\t\treturn nil, fmt.Errorf(\"docker exec systemerr: %s\", strings.TrimSpace(msg.String()))\n\t\tdefault: // stderr and anything else — discard\n\t\t\tif _, err := io.CopyN(io.Discard, r, size); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t}\n\t}\n\treturn stdout.Bytes(), nil\n}\n\ntype statFailure struct {\n\tname string\n\terr  error\n}","sourceCodeStart":1065,"sourceCodeEnd":1101,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/docker/client.go#L1065-L1101","documentation":"demuxExecStdout enforces a hard cap (maxListStdoutBytes) on accumulated stdout so a compromised or noisy sandbox cannot stream unbounded output into memory. As soon as the stdout buffer exceeds the cap, it aborts with this error. The listing is discarded entirely — the cap is a safety limit, not a truncation mechanism (truncation of entry COUNT is handled separately via Truncated).","triggerScenarios":"Listing a directory whose `find -maxdepth 1 -print0` output exceeds maxListStdoutBytes — i.e., a very large number of children or extremely long path names (deeply nested container paths).","commonSituations":"Pointing the listing at /, /usr, /proc, node_modules, or container-internal dirs with tens of thousands of entries; paths near PATH_MAX multiplied by thousands of entries.","solutions":["List a more specific subdirectory instead of a huge parent","If large listings are legitimate for your workload, raise maxListStdoutBytes","Handle the error in the caller by suggesting the user navigate deeper rather than listing everything at once","Pre-aggregate: enumerate subdirs of interest rather than the root"],"exampleFix":"// before\nlisting, err := dc.ListContainerDir(ctx, id, \"/usr\")\n// after: target the relevant subtree\nlisting, err := dc.ListContainerDir(ctx, id, \"/usr/local/bin\")","handlingStrategy":"validation","validationCode":"// estimate listing size first via a cheap exec\nout, _ := runInContainer(ctx, containerID,\n    []string{\"sh\", \"-c\", \"find \" + dir + \" -maxdepth 1 -mindepth 1 | wc -l\"})\nif n, _ := strconv.Atoi(strings.TrimSpace(out)); n > 50000 {\n    return fmt.Errorf(\"directory %s too large to list in one call\", dir)\n}","typeGuard":null,"tryCatchPattern":"listing, err := client.ListContainerDir(ctx, containerID, dir)\nif err != nil && strings.Contains(err.Error(), \"listing output exceeded\") {\n    // fall back to listing subdirectories incrementally\n    return listInChunks(ctx, containerID, dir)\n}","preventionTips":["Never point listings at /, /usr, /proc or dependency trees like node_modules","Split very large directories into per-subdir listings","Raise maxListStdoutBytes only with awareness of memory impact","Surface the cap to users in UI flows so they navigate deeper"],"tags":["docker","output-limit","memory-safety"],"backgroundTag":"output-size-limit-exceeded","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}