Mac slice F wb fix 1 #5: an oversized outbound pack fails the step
Whole-branch review round 1, finding 5. The worker builds the thin pack its outbound transfer would carry and measures it against the 64 MB bound (workerPackBound) after the object scan and before it records committed. Past the bound the candidate ref goes and the step ends workspace_too_large, terminated: Needs you with Retry, nothing committed, nothing uploaded. candidatePack and the measure share thinPack. The instance also fails the step durably if an oversized outbound close ever reaches it (an older worker): a running attempt is withdrawn and ends workspace_too_large once its termination is reported; a done, unpublished one fails at once. Before, the step stayed done and unpushed with no publication and no Retry. Regressions: TestWorkerEngineeringPackTooLarge (two incompressible 12 KiB files, each under a 14 KiB object bound, against a 16 KiB pack bound), TestOutboundPackOversizeIsWorkspaceTooLarge (done first, running; kept across a restart). Mutations: no measure, the outbound branch dropped, the done case not failed, the running case not withdrawn; each fails a named test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+171
−6
internal/equipo/chat/transfers.go+27 −0internal/runner/thin/wbfix1_pack_test.go+44 −0internal/runner/thin/worker_engineering.go+11 −0internal/runner/thin/worker_scan.go+4 −0internal/runner/thin/worker_store.go+26 −6internal/thintest/wbfix1_oversize_contract_test.go+59 −0
diff --git a/internal/equipo/chat/transfers.go b/internal/equipo/chat/transfers.go| index fd7adf7e..f6f1b078 100644 |
| --- a/internal/equipo/chat/transfers.go |
| +++ b/internal/equipo/chat/transfers.go |
| @@ -148,6 +148,8 @@ func (t *txn) blob(l Lease, v *wire.Blob) error { |
| // tooLarge closes a transfer past the bound; inbound, its checks end as |
| // not run (checks_unavailable), and Engineering on a Mac ends |
| // workspace_too_large with Needs you (it never runs on Linux instead). |
| +// Outbound, a worker's commit that cannot reach the primary ends its |
| +// step workspace_too_large too, with Needs you and Retry. |
| func (t *txn) tooLarge(k *taskRecord, s *stepRecord, tr transferRecord) error { |
| if err := t.dropChunks(tr); err != nil { |
| return err |
| @@ -155,6 +157,9 @@ func (t *txn) tooLarge(k *taskRecord, s *stepRecord, tr transferRecord) error { |
| if err := t.db.Model(&transferRecord{}).Where("id = ?", tr.ID).Update("state", transferClosed).Error; err != nil { |
| return err |
| } |
| + if tr.Direction == wire.TransferOutbound { |
| + return t.outboundTooLarge(k, s) |
| + } |
| if tr.Direction != wire.TransferInbound || wire.StepTerminal(s.State) { |
| return nil |
| } |
| @@ -164,6 +169,28 @@ func (t *txn) tooLarge(k *taskRecord, s *stepRecord, tr transferRecord) error { |
| return t.withdrawResolving(k, s, "checks_unavailable") |
| } |
| +// outboundTooLarge ends a worker's Engineering attempt whose commit is |
| +// past the transfer bound: workspace_too_large, never published. Still |
| +// running, it is withdrawn and ends once its termination is reported; |
| +// already done (unpublished), it fails now. |
| +func (t *txn) outboundTooLarge(k *taskRecord, s *stepRecord) error { |
| + if k.MoveProject != "" || s.Retired || s.Withdrawn || s.Pushed || wire.FinalStage(k.Stage) { |
| + return nil |
| + } |
| + if !wire.StepTerminal(s.State) { |
| + return t.withdrawFailing(k, s, wire.ReasonWorkspaceTooLarge) |
| + } |
| + if s.State != wire.StepDone { |
| + return nil |
| + } |
| + now := t.now() |
| + s.State, s.Reason, s.FinishedAt, s.Publication, s.PublicationID, s.PublicationRunner = wire.StepFailed, wire.ReasonWorkspaceTooLarge, &now, "", "", "" |
| + if err := t.saveStep(s, k); err != nil { |
| + return err |
| + } |
| + return t.advance(k) |
| +} |
| + |
| // withdrawFailing withdraws an Engineering attempt that will end failed |
| // for reason: at once when it never started, else once its termination |
| // is reported (withdrawnSettle). |
diff --git a/internal/runner/thin/wbfix1_pack_test.go b/internal/runner/thin/wbfix1_pack_test.go| new file mode 100644 |
| index 00000000..77b2345f |
| --- /dev/null |
| +++ b/internal/runner/thin/wbfix1_pack_test.go |
| @@ -0,0 +1,44 @@ |
| +//go:build testbuild |
| + |
| +package thin |
| + |
| +import ( |
| + "encoding/base64" |
| + "math/rand/v2" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// Whole-branch fix 1, #5: two incompressible files, each within the |
| +// object scan's bound, make an outbound pack past the transfer bound. |
| +// The worker measures the pack before it records committed: the step |
| +// ends workspace_too_large (terminated, so Retry is offered), nothing |
| +// is committed and nothing is uploaded. |
| +func TestWorkerEngineeringPackTooLarge(t *testing.T) { |
| + scan, pack := workerScanBound, workerPackBound |
| + workerScanBound, workerPackBound = 14<<10, 16<<10 |
| + t.Cleanup(func() { workerScanBound, workerPackBound = scan, pack }) |
| + x := newEngRig(t) |
| + rng := rand.New(rand.NewPCG(5, 37)) |
| + noise := func() string { |
| + b := make([]byte, 12<<10) |
| + for i := range b { |
| + b[i] = byte(rng.Uint32()) |
| + } |
| + return base64.StdEncoding.EncodeToString(b) |
| + } |
| + x.note("bytes:Assets/one.bin|" + noise() + "\nbytes:Assets/two.bin|" + noise()) |
| + rep := x.run(t) |
| + if rep.State != wire.StepFailed || rep.Reason != wire.ReasonWorkspaceTooLarge || !rep.Termination || rep.CandidateSHA != "" { |
| + t.Fatalf("report %+v", rep) |
| + } |
| + if c := x.committed(); c.CandidateSHA != "" { |
| + t.Fatalf("committed %+v", c) |
| + } |
| + for _, f := range x.outbox(t) { |
| + if f.Type == wire.FrameBlob { |
| + t.Fatalf("uploaded %s", f.ID) |
| + } |
| + } |
| +} |
diff --git a/internal/runner/thin/worker_engineering.go b/internal/runner/thin/worker_engineering.go| index 4f5402aa..51383439 100644 |
| --- a/internal/runner/thin/worker_engineering.go |
| +++ b/internal/runner/thin/worker_engineering.go |
| @@ -373,6 +373,17 @@ func (w *Worker) engineering(ctx context.Context, r stepRow, progress func(wire. |
| rep.Headline, rep.Summary, rep.LogTail, rep.Apple, rep.SessionID = "", "", "", false, "" |
| return fail(wire.ReasonSecretInCandidate, !hit.unproven) |
| } |
| + // The pack that leaves, measured before anything is committed: a |
| + // candidate past the transfer bound can never reach the primary, so |
| + // the step ends now, workspace_too_large, with Retry. |
| + if size, err := w.packSize(ctx, store, base, sha); err != nil || size > workerPackBound { |
| + e.log("worker candidate ref", w.dropCandidate(context.WithoutCancel(ctx), r.Repo, ref)) |
| + if err != nil { |
| + e.log("worker pack", err) |
| + return fail("workspace_refused", true) |
| + } |
| + return fail(wire.ReasonWorkspaceTooLarge, true) |
| + } |
| rep.CandidateSHA, rep.Phase, rep.OutcomePhase, rep.Askable = sha, wire.OutcomeCommitted, outcome, kept |
| final := redactReport(workerDone(rep, outcome), known) |
| // One transition: committed, the outcome, the final report a restart |
diff --git a/internal/runner/thin/worker_scan.go b/internal/runner/thin/worker_scan.go| index 78fd0f12..730434b1 100644 |
| --- a/internal/runner/thin/worker_scan.go |
| +++ b/internal/runner/thin/worker_scan.go |
| @@ -40,6 +40,10 @@ import ( |
| // one past it refuses the candidate. |
| var workerScanBound = int64(wire.MaxTransferBytes) |
| +// workerPackBound is the largest outbound pack (the transfer bound): |
| +// objects each within workerScanBound can still make a larger one. |
| +var workerPackBound = int64(wire.MaxTransferBytes) |
| + |
| // minSecret is the shortest known secret searched for: shorter ones |
| // would match ordinary text. |
| const minSecret = 16 |
diff --git a/internal/runner/thin/worker_store.go b/internal/runner/thin/worker_store.go| index 246342c6..1d1d6060 100644 |
| --- a/internal/runner/thin/worker_store.go |
| +++ b/internal/runner/thin/worker_store.go |
| @@ -6,6 +6,7 @@ import ( |
| "database/sql" |
| "errors" |
| "fmt" |
| + "io" |
| "io/fs" |
| "os" |
| "os/exec" |
| @@ -243,17 +244,36 @@ func (w *Worker) candidatePack(ctx context.Context, h wire.TransferHeader) ([]by |
| return nil, errPackRefused |
| } |
| var out bytes.Buffer |
| - cmd := exec.CommandContext(ctx, w.Engine.O.Runner.GitPath, "--git-dir="+store, "pack-objects", "--revs", "--thin", "--stdout", "-q") |
| - cmd.Stdin, cmd.Stdout, cmd.Env = strings.NewReader(cand+"\n^"+base+"\n"), &limitWriter{w: &out, n: wire.MaxTransferBytes + 1}, w.gitEnv() |
| - if err := mac.StartOwn(cmd); err != nil { |
| - return nil, err |
| - } |
| - if err := cmd.Wait(); err != nil { |
| + if err := w.thinPack(ctx, store, base, cand, &limitWriter{w: &out, n: wire.MaxTransferBytes + 1}); err != nil { |
| return nil, err |
| } |
| return out.Bytes(), nil |
| } |
| +// thinPack writes the thin pack of cand against base from store to out: |
| +// what an outbound transfer carries. |
| +func (w *Worker) thinPack(ctx context.Context, store, base, cand string, out io.Writer) error { |
| + cmd := exec.CommandContext(ctx, w.Engine.O.Runner.GitPath, "--git-dir="+store, "pack-objects", "--revs", "--thin", "--stdout", "-q") |
| + cmd.Stdin, cmd.Stdout, cmd.Env = strings.NewReader(cand+"\n^"+base+"\n"), out, w.gitEnv() |
| + if err := mac.StartOwn(cmd); err != nil { |
| + return err |
| + } |
| + return cmd.Wait() |
| +} |
| + |
| +// packSize is the size of the thin pack an outbound transfer of cand |
| +// would carry. |
| +func (w *Worker) packSize(ctx context.Context, store, base, cand string) (int64, error) { |
| + var n counter |
| + err := w.thinPack(ctx, store, base, cand, &n) |
| + return int64(n), err |
| +} |
| + |
| +// counter counts what is written to it. |
| +type counter int64 |
| + |
| +func (c *counter) Write(p []byte) (int, error) { *c += counter(len(p)); return len(p), nil } |
| + |
| // forget is the worker's forget_task: the kept sessions it released go, |
| // and so do the task's candidates whose keep (none, or passed) is over; |
| // the next keep's end is swept when it comes. |
diff --git a/internal/thintest/wbfix1_oversize_contract_test.go b/internal/thintest/wbfix1_oversize_contract_test.go| new file mode 100644 |
| index 00000000..553f0892 |
| --- /dev/null |
| +++ b/internal/thintest/wbfix1_oversize_contract_test.go |
| @@ -0,0 +1,59 @@ |
| +package thintest |
| + |
| +import ( |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// Whole-branch fix 1, #5: an outbound pack declared past the bound (an |
| +// older worker, which does not measure it first) fails the step |
| +// durably, workspace_too_large with Needs you and Retry, whether the |
| +// worker's done came first or not; nothing is published. |
| +func TestOutboundPackOversizeIsWorkspaceTooLarge(t *testing.T) { |
| + for _, doneFirst := range []bool{true, false} { |
| + name := "running" |
| + if doneFirst { |
| + name = "done first" |
| + } |
| + t.Run(name, func(t *testing.T) { |
| + r := newMacRig(t) |
| + w := r.newMacEngineer("Mac A", wire.EngineeringReady) |
| + base, cand := sha(1), sha(0xb6) |
| + task, d := r.macDispatch(w, "iOS huge commit", base) |
| + if !w.lease(d.StepID, d.Attempt) { |
| + t.Fatal("start refused") |
| + } |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepRunning, CandidateSHA: cand, Phase: wire.OutcomeCommitted, OutcomePhase: wire.OutcomeCommitted, Findings: []wire.Finding{}}) |
| + _, body := w.expect(wire.FrameSendPack) |
| + h := body.(*wire.SendPackCommand).Transfer |
| + if doneFirst { |
| + w.send(wire.FrameStep, workerDone(d, cand, wire.OutcomeCommitted)) |
| + } |
| + big := chunk(h, []byte("PACK huge")) |
| + big.Total = wire.MaxTransferChunks + 1 |
| + w.send(wire.FrameBlob, big) |
| + if !doneFirst { |
| + _, body = w.expect(wire.FrameCancelStep) |
| + if c := body.(*wire.CancelStepCommand); c.StepID != d.StepID || c.Attempt != d.Attempt { |
| + t.Fatalf("cancel %+v", c) |
| + } |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepCancelled, Reason: "withdrawn", Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) |
| + } |
| + s := r.engineeringStep(task) |
| + if s.State != wire.StepFailed || s.Reason != wire.ReasonWorkspaceTooLarge || !s.Terminated || s.Pushed || r.needsYou(task) != wire.NeedsRetry { |
| + t.Fatalf("oversize %+v needs %q", s, r.needsYou(task)) |
| + } |
| + r.primary.none(wire.FramePublish, 50*time.Millisecond) |
| + if n := r.relayed(r.primary); n != 0 { |
| + t.Fatalf("%d chunks reached the primary", n) |
| + } |
| + // A restart keeps it. |
| + w = r.restartMac(w) |
| + if s := r.engineeringStep(task); s.State != wire.StepFailed || s.Reason != wire.ReasonWorkspaceTooLarge || r.needsYou(task) != wire.NeedsRetry { |
| + t.Fatalf("after a restart %+v needs %q", s, r.needsYou(task)) |
| + } |
| + }) |
| + } |
| +} |