Confine subprocess diagnostics and retain redacted tails

This commit is contained in:
2026-08-11 03:11:27 +00:00
parent 801adb385d
commit 80be8be4d6
6 changed files with 568 additions and 1063 deletions

View File

@@ -3,7 +3,6 @@ package subprocess
import (
"context"
"fmt"
"io"
"os"
"os/exec"
"strings"
@@ -124,7 +123,7 @@ func Run(ctx context.Context, req RunRequest) (RunResult, error) {
return result, nil
}
stderrTail := readDiagnosticTail(req.StderrLogPath, 2048)
stderrTail := logs.stderr.Tail()
diagnostics := buildDiagnostics(req, result, stderrTail)
if captureLimit != nil {
@@ -208,36 +207,3 @@ func fdDiagnosticsHint(exitCode int, stderrTail string) string {
}
return ""
}
func readDiagnosticTail(path string, maxBytes int64) string {
if strings.TrimSpace(path) == "" || maxBytes <= 0 {
return ""
}
f, err := os.Open(path)
if err != nil {
return ""
}
defer f.Close()
info, err := f.Stat()
if err != nil {
return ""
}
size := info.Size()
start := int64(0)
if size > maxBytes {
start = size - maxBytes
}
if _, err := f.Seek(start, io.SeekStart); err != nil {
return ""
}
data, err := io.ReadAll(f)
if err != nil {
return ""
}
tail := strings.TrimSpace(string(data))
if tail == "" {
return ""
}
return tail
}