oficina / equipo Public

checks: a failed or stalled index-pack never holds the step worker

Astra round 2: streaming the candidate into the checks tree's .git
waited on pack-objects after index-pack failed early, and pack-objects
blocked writing into a pipe nobody drained. Now any downstream failure
(index-pack, the pack bound, the deadline) cancels every command's
process group and closes both pipes before each started command is
reaped, a start failure reaps what started, and the whole preparation
has the judge tree's deadline. TestCheckRepositoryPackFailureNeverHangs
(an injected index-pack failure and a stall) hung before the fix.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 3cede55cd0108f708988d13020ac460cb2e2389d parent 28cbe50
2 files changed, +90 −5
  • internal/runner/thin/judge.go +27 −5
  • internal/runner/thin/pack_failure_test.go +63 −0

CI cancelled — superseded by a newer push — run details

diff --git a/internal/runner/thin/judge.go b/internal/runner/thin/judge.go
index 83498938..8ccc9da5 100644
--- a/internal/runner/thin/judge.go
+++ b/internal/runner/thin/judge.go
@@ -274,6 +274,10 @@ var offline = regexp.MustCompile(`GOPROXY=off|module lookup disabled|Could not r
// asks git about its files sees the commit it judges. The namespace may
// change it; the tree is thrown away after.
func (e *Engineer) checkRepository(ctx context.Context, tree workspace.TaskTree, sha string) error {
+ // Preparation has the same deadline as the judge tree's: the serial
+ // step worker is never held by it.
+ ctx, cancel := context.WithTimeout(ctx, prepTimeout)
+ defer cancel()
env := workspace.GitEnvironment()
env["HOME"] = "/nonexistent"
git := func(stdin io.Reader, stdout io.Writer, extra map[string]string, args ...string) error {
@@ -331,21 +335,39 @@ func (e *Engineer) streamObjects(ctx context.Context, env map[string]string, tre
}
limited := &limitReader{r: packed, n: maxCheckPack}
index.Stdin = limited
+ // stop cancels every command's process group and closes both pipes,
+ // so nothing upstream can block writing into a pipe nobody drains.
+ stop := func() {
+ cancel()
+ objects.Close()
+ packed.Close()
+ }
+ var started []*exec.Cmd
for _, c := range []*exec.Cmd{list, pack, index} {
if err := c.Start(); err != nil {
- cancel()
+ stop()
+ for _, s := range started {
+ _ = s.Wait()
+ }
return err
}
+ started = append(started, c)
}
+ // Downstream first: any failure (index-pack refusing, the pack bound,
+ // the deadline) stops the commands above it before they are reaped.
errIndex := index.Wait()
- if limited.over {
- cancel()
+ if errIndex != nil || limited.over {
+ stop()
+ }
+ errPack := pack.Wait()
+ if errPack != nil {
+ stop()
}
- errPack, errList := pack.Wait(), list.Wait()
+ errList := list.Wait()
if limited.over {
return errors.New("checks repository too large")
}
- if err := errors.Join(errList, errPack, errIndex); err != nil {
+ if err := errors.Join(errList, errPack, errIndex, ctx.Err()); err != nil {
return err
}
in := map[string]string{"GIT_DIR": dot, "GIT_WORK_TREE": tree.Dir}
diff --git a/internal/runner/thin/pack_failure_test.go b/internal/runner/thin/pack_failure_test.go
new file mode 100644
index 00000000..8c3b5d6e
--- /dev/null
+++ b/internal/runner/thin/pack_failure_test.go
@@ -0,0 +1,63 @@
+package thin
+
+import (
+ "context"
+ "crypto/rand"
+ "encoding/hex"
+ "os"
+ "path/filepath"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/runner/workspace"
+)
+
+// Astra round 2: streaming the candidate into the checks tree's .git
+// never holds the serial step worker. If index-pack fails early (a full
+// disk) the upstream commands are cancelled and reaped instead of
+// blocking on an undrained pipe; if it stalls, the preparation deadline
+// ends it. Either way checkRepository returns an error promptly.
+func TestCheckRepositoryPackFailureNeverHangs(t *testing.T) {
+ root := t.TempDir()
+ work := filepath.Join(root, "work")
+ gitT(t, root, "init", "-q", "-b", "main", work)
+ // 4 MiB that does not compress: far beyond any pipe buffer.
+ raw := make([]byte, 2<<20)
+ rand.Read(raw)
+ os.WriteFile(filepath.Join(work, "noise.txt"), []byte(hex.EncodeToString(raw)), 0644)
+ gitT(t, work, "add", "-A")
+ gitT(t, work, "commit", "-qm", "noise")
+ cand := gitT(t, work, "rev-parse", "HEAD")
+ for _, tc := range []struct{ name, indexPack string }{
+ {"fails", "exit 1"},
+ {"stalls", "exec sleep 600"},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ dir := t.TempDir()
+ wrapper := filepath.Join(dir, "git")
+ script := "#!/bin/sh\nfor a in \"$@\"; do [ \"$a\" = index-pack ] && { " + tc.indexPack + "; }; done\nexec /usr/bin/git \"$@\"\n"
+ if err := os.WriteFile(wrapper, []byte(script), 0700); err != nil {
+ t.Fatal(err)
+ }
+ old := prepTimeout
+ prepTimeout = 3 * time.Second
+ t.Cleanup(func() { prepTimeout = old })
+ tree := workspace.TaskTree{Dir: filepath.Join(dir, "tree"), GitDir: filepath.Join(work, ".git"), Git: wrapper, Branch: "equipo/tk1-x", Base: cand}
+ os.MkdirAll(tree.Dir, 0700)
+ e := &Engineer{}
+ e.O.Runner.GitPath = wrapper
+ done := make(chan error, 1)
+ start := time.Now()
+ go func() { done <- e.checkRepository(context.Background(), tree, cand) }()
+ select {
+ case err := <-done:
+ if err == nil {
+ t.Fatal("a failed index-pack was taken for a checks repository")
+ }
+ t.Logf("refused after %s: %v", time.Since(start).Round(time.Millisecond), err)
+ case <-time.After(30 * time.Second):
+ t.Fatal("checkRepository hung on a failed index-pack")
+ }
+ })
+ }
+}