oficina / equipo Public

Mac slice F wb fix 3 #4: screen whole text before any bound

Whole-branch review round 3, finding 4. On a Mac worker every stdout
frame of the CLI has each known secret form replaced before it is
parsed, clipped or kept (redactForms, forms only, so the frame stays
valid JSON): the tail's 160-byte lines and the reply see no secret.
The reply is redacted whole (known forms and the generic patterns)
before splitHeadline and the summary's clip, the commit message is
built from that text, and the clipped message is screened again
before the commit. A secret cut by a bound can no longer leave a
fragment that matches nothing.

The object scan's "in the commit message" case now checks that the
candidate commits with "***" in its message (the token never reaches
the commit). The fake CLI gains headsay: for the headline, and say:
no longer matches inside it.

Regressions: TestWorkerSecretAcrossEveryBound (a hex-encoded secret
across the 120-byte headline, the 160-byte tail line, the commit's
1,500 and the summary's 2,000), TestWorkerGenericTokenAcrossTheCommitBound.

Also, from hosted CI on 6f21c002: the thintest and thin budget
records' reasons shortened under 200 bytes (TestBudgetRecordsAreShort),
and TestOutboundPackOversizeIsWorkspaceTooLarge no longer assigns the
restarted peer it never uses (staticcheck SA4006); its assertion after
the restart stays.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 8c71000e419b435b628a6cb6a46ae1f81140d505 parent 9478490
7 files changed, +121 −10
  • .rastrillo/budgets.txt +2 −2
  • internal/fakeclaude/fake.go +9 −2
  • internal/runner/thin/wbfix3_secret_test.go +74 −0
  • internal/runner/thin/worker_engineering.go +7 −3
  • internal/runner/thin/worker_engineering_test.go +15 −1
  • internal/runner/thin/worker_launch.go +13 −1
  • internal/thintest/wbfix1_oversize_contract_test.go +1 −1

CI cancelled — superseded by a newer push — run details

diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 50786f6b..3c6df8d2 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -38,7 +38,7 @@ time internal/runner/provider 15s Plan 3 CI repair measured 10.346s for the full
perf GET /releases/* skip Verified runner release file downloads, not browser GET screens.
perf GET /install.sh skip Mac runners: the one-line bootstrap a terminal pipes to sh, not a browser screen.
time internal/runner/containment 15s Plan 3 loaded CI measured 10.817s;
-size internal/runner/thin 34715 31928 Protocols 31 to 35, merge credential, publication guards, kept work, scans, 36 lookups; Mac pin, Engineering, asks, F probes, D1, pack bound, P2 readiness; 34715/31928.
+size internal/runner/thin 34760 32185 Protocols 31 to 35, merge credential, publication guards, kept work, scans, 36 lookups; Mac pin, Engineering, asks, F probes, D1, pack bound, P2, held reports, screening; 34760/32185.
time internal/thintest 240s Thin contract and page tests, the Assistant's and the models' included, share one harness. Measured 202s on a shared 16 CPU box (2026-11-13); CI runs two lanes.
time internal/runner/mac 45s Real processes killed and proven gone: groups, sessions, the runner-user sweep, turns, restarts; probes end to end. Measured 29.3s locally.
time internal/runner/thin 45s Thin v1 slice 4 review: real git repositories for the merge and squash checks, a stalled fetch, and a 16 MiB candidate streamed through the review diff and the checks pack (about 5s).
@@ -72,7 +72,7 @@ perf GET /tasks/{id}/files/{file} skip Research kept images: the bytes of one im
perf GET /api/v1/runners skip Mac runners person API: bearer-only JSON for devices; the browser shows runners in the Team section.
time cmd/equipo-runner 60s TestReleaseRunnerHasNoFakeWorker builds the release runner and the thin package under testbuild (about 12s locally).
size internal/headless - 13400 Grant scenarios (#48); sign-in email at 1280 and 390; Assistant files; restart wait; live site waits; card answer; scenario 7; Mac M9, mixed versions; 13400.
-size internal/thintest - 41998 Protocol 31 contracts, 35 diffs, stuck tasks, merges, retries, unfinished work, previews, places, abilities, lookups, go-aheads, Mac Engineering, conns, D1, held reports, commits between primaries; 41998.
+size internal/thintest - 41998 Protocol 31 contracts, 35 diffs, stuck tasks, merges, retries, unfinished work, previews, places, abilities, lookups, go-aheads, Mac Engineering, conns, D1, held reports; 41998.
perf GET /api/v1/projects/{id}/merge-policy skip Merge authority person API: bearer-only JSON for devices; the browser reads the policy on /projects/{id}.
perf GET /api/v1/usage skip Thin v1 person API: bearer-only JSON for devices; the browser reads usage through /usage.
diff --git a/internal/fakeclaude/fake.go b/internal/fakeclaude/fake.go
index 3aa00ff1..39a9a8ef 100644
--- a/internal/fakeclaude/fake.go
+++ b/internal/fakeclaude/fake.go
@@ -77,7 +77,8 @@
// minutes each); "bytes:<path>|<base64>"
// asks for Write and writes the decoded bytes (a binary file);
// "symlink:<path>|<target>" asks for Write and makes a symbolic link;
-// "say:<text>" (to ";" or the line's end) adds the text to the reply;
+// "say:<text>" (to ";" or the line's end) adds the text to the reply,
+// "headsay:<text>" is its headline's words;
// "move:<from>|<to>" asks for Write on <to> and renames the file;
// with "steplimit:<email>", "limitleave:<path>" writes the file before
// the refusal (a refused attempt that changed its tree). On a darwin
@@ -585,7 +586,10 @@ var createWord = regexp.MustCompile(`create:([^|\s]+)\|([^;\n]*)`)
var stepSleep = regexp.MustCompile(`stepsleep:([0-9]+)`)
var bytesWord = regexp.MustCompile(`bytes:([^|\s]+)\|([A-Za-z0-9+/=]+)`)
var symlinkWord = regexp.MustCompile(`symlink:([^|\s]+)\|([^;\s]+)`)
-var sayWord = regexp.MustCompile(`say:([^;\n]*)`)
+var sayWord = regexp.MustCompile(`\bsay:([^;\n]*)`)
+
+// headWord ("headsay:<text>") replaces the headline's words.
+var headWord = regexp.MustCompile(`headsay:([^;\n]*)`)
var moveWord = regexp.MustCompile(`move:([^|\s]+)\|([^;\s]+)`)
var limitLeave = regexp.MustCompile(`limitleave:([^;\s]+)`)
var stepWait = regexp.MustCompile(`stepwait:(/[^;\s]+)`)
@@ -843,6 +847,9 @@ func (f *fake) engineer(prompt string, turn int, emit func(any)) string {
if len(done) == 0 {
headline = "Headline: Nothing needed changing.\n\n"
}
+ if m := headWord.FindStringSubmatch(prompt); m != nil {
+ headline = "Headline: " + strings.TrimSpace(m[1]) + "\n\n"
+ }
}
if len(done) == 0 {
return headline + "I looked and changed nothing."
diff --git a/internal/runner/thin/wbfix3_secret_test.go b/internal/runner/thin/wbfix3_secret_test.go
new file mode 100644
index 00000000..dced42d8
--- /dev/null
+++ b/internal/runner/thin/wbfix3_secret_test.go
@@ -0,0 +1,74 @@
+//go:build testbuild
+
+package thin
+
+import (
+ "encoding/hex"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+// Whole-branch fix 3, #4: a known secret, hex-encoded, written where
+// every bound cuts it (the headline's 120 bytes, a tail line's 160, the
+// commit message's 1,500 bytes of summary, the summary's 2,000) is
+// redacted whole before anything is clipped: no fragment long enough to
+// matter reaches the headline, the summary, the tail, the step log or
+// the commit message.
+func TestWorkerSecretAcrossEveryBound(t *testing.T) {
+ x := newEngRig(t)
+ h := hex.EncodeToString([]byte(engBearer))
+ pad := func(n int) string { return strings.Repeat("w", n) }
+ // The summary is "Wrote Notes.txt. " and the said text: one copy of
+ // the secret straddles the commit message's 1,500 bytes, another the
+ // summary's 2,000; the headline's copy straddles its 120 bytes and,
+ // in the reply's first line, the tail line's 160. No whole copy
+ // reaches the commit, so the object scan alone would not see it.
+ prefix := len("Wrote Notes.txt. ")
+ first := 1500 - 36 - prefix
+ second := 2000 - 36 - (prefix + first + len(h))
+ x.note("create:Notes.txt|hello\nheadsay:" + pad(90) + h + "\nsay:" + pad(first) + h + pad(second) + h)
+ rep := x.run(t)
+ if rep.CandidateSHA == "" {
+ t.Fatalf("no commit: %+v", rep)
+ }
+ msg, err := x.store(t, "log", "-1", "--format=%B", rep.CandidateSHA)
+ if err != nil {
+ t.Fatal(err)
+ }
+ logged, _ := os.ReadFile(filepath.Join(x.w.Engine.root(), stepKey(x.r), "log.jsonl"))
+ for name, text := range map[string]string{"headline": rep.Headline, "summary": rep.Summary, "tail": rep.LogTail, "commit message": msg, "step log": string(logged)} {
+ for i := 0; i+16 <= len(h); i++ {
+ if strings.Contains(strings.ToLower(text), h[i:i+16]) {
+ t.Fatalf("%s carries part of the secret (%q at %d)", name, h[i:i+16], i)
+ }
+ }
+ }
+ // Redacted where it was written (the headline's trailing *** is
+ // trimmed with its markdown).
+ if !strings.Contains(msg, "***") || !strings.Contains(rep.Summary, "***") || rep.Headline != pad(90) {
+ t.Fatalf("not redacted where written: headline %q, message %q", rep.Headline, msg[:min(len(msg), 200)])
+ }
+}
+
+// Whole-branch fix 3, #4: what only the generic patterns take for a
+// secret (a GitHub token) is also redacted from the whole reply before
+// the commit message's 1,500 bytes cut it.
+func TestWorkerGenericTokenAcrossTheCommitBound(t *testing.T) {
+ x := newEngRig(t)
+ token := "ghp_" + "R4nd0mT0k3nW1thH1ghEntr0pyXyZ987654321"
+ pad := 1500 - 20 - len("Created Notes.txt. ")
+ x.note("create:Notes.txt|hello\nsay:" + strings.Repeat("w", pad) + " " + token)
+ rep := x.run(t)
+ if rep.CandidateSHA == "" {
+ t.Fatalf("no commit: %+v", rep)
+ }
+ msg, err := x.store(t, "log", "-1", "--format=%B", rep.CandidateSHA)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if strings.Contains(msg, token[:12]) {
+ t.Fatalf("the commit message carries part of the token: %q", msg[len(msg)-120:])
+ }
+}
diff --git a/internal/runner/thin/worker_engineering.go b/internal/runner/thin/worker_engineering.go
index 51383439..e79fda4f 100644
--- a/internal/runner/thin/worker_engineering.go
+++ b/internal/runner/thin/worker_engineering.go
@@ -307,8 +307,10 @@ func (w *Worker) engineering(ctx context.Context, r stepRow, progress func(wire.
rep.Switched.To = b.Provider
}
rep.Usage = append(rep.Usage, res.usage(b, r.Attempt)...)
- headline, summary := splitHeadline(res.summary)
- rep.Headline, rep.Summary, rep.LogTail = headline, clip(summary, wire.MaxStepSummary), res.tail
+ // Screened whole before any of it is clipped (the frames were too):
+ // a secret cut by a bound would match nothing afterwards.
+ headline, summary := splitHeadline(redactText(res.summary, known))
+ rep.Headline, rep.Summary, rep.LogTail = headline, clip(summary, wire.MaxStepSummary), redactText(res.tail, known)
kept := e.recordKept(ctx, r, b, res, "")
if kept {
rep.SessionID = res.session
@@ -331,7 +333,9 @@ func (w *Worker) engineering(ctx context.Context, r stepRow, progress func(wire.
case res.noShell && r.Round >= 1 && !r.Rebase:
outcome = wire.OutcomeNoShell
}
- sha, err := tree.Commit(ctx, message, commitName, commitEmail)
+ // The clipped message is screened again (the object scan reads it
+ // too, whole).
+ sha, err := tree.Commit(ctx, redactText(message, known), commitName, commitEmail)
switch {
case unfinished && err != nil:
if !errors.Is(err, workspace.ErrNoChanges) {
diff --git a/internal/runner/thin/worker_engineering_test.go b/internal/runner/thin/worker_engineering_test.go
index 64b948d9..814e5b00 100644
--- a/internal/runner/thin/worker_engineering_test.go
+++ b/internal/runner/thin/worker_engineering_test.go
@@ -556,7 +556,6 @@ func TestWorkerObjectScan(t *testing.T) {
"base64 in a binary file": {note: "bytes:blob.bin|" + base64.StdEncoding.EncodeToString(binary), names: []string{"blob.bin"}},
"in a file name": {note: "create:" + token + ".txt|hello"},
"in a symlink target": {note: "symlink:planted-link|/tmp/" + token, names: []string{"planted-link"}},
- "in the commit message": {note: "edit:Swipe.swift|false|true\nsay:" + token},
"hex-encoded": {note: "create:hex.txt|" + hex.EncodeToString([]byte(token)), names: []string{"hex.txt"}},
"the runner credential, URL": {note: "create:cred.txt|" + urlForm, names: []string{"cred.txt"}},
"gitleaks finds a key": {note: "create:keys.txt|token = \"ghp_" + "R4nd0mT0k3nW1thH1ghEntr0pyXyZ987654321\"", names: []string{"keys.txt"}},
@@ -623,6 +622,21 @@ func TestWorkerObjectScan(t *testing.T) {
}
x.clean(t, token, engBearer, hex.EncodeToString([]byte(token)))
})
+ // Whole-branch fix 3, #4: a known secret the CLI writes into what
+ // becomes the commit message is redacted before the commit is made,
+ // so the candidate goes with "***" in its message.
+ t.Run("in the commit message", func(t *testing.T) {
+ x := newEngRig(t)
+ x.note("edit:Swipe.swift|false|true\nsay:" + token)
+ rep := x.run(t)
+ if rep.State != wire.StepDone || rep.CandidateSHA == "" {
+ t.Fatalf("report %+v", rep)
+ }
+ msg, err := x.store(t, "log", "-1", "--format=%B", rep.CandidateSHA)
+ if err != nil || strings.Contains(msg, token) || !strings.Contains(msg, "***") {
+ t.Fatalf("message %q %v", msg, err)
+ }
+ })
}
// The candidate is retained in the store: with the attempt's directory
diff --git a/internal/runner/thin/worker_launch.go b/internal/runner/thin/worker_launch.go
index 9d5a83d2..4aaf4c22 100644
--- a/internal/runner/thin/worker_launch.go
+++ b/internal/runner/thin/worker_launch.go
@@ -199,7 +199,9 @@ func (w *Worker) launch(ctx context.Context, r stepRow, tree workspace.TaskTree,
if spec.tap != nil {
spec.tap(line)
}
- frames <- append([]byte(nil), line...)
+ // Every known secret goes from the whole frame before any of
+ // it is parsed, clipped or kept (whole-branch fix 3, #4).
+ frames <- redactForms(line, forms)
}
}
}()
@@ -249,6 +251,16 @@ func (w *Worker) readyNow(ctx context.Context, r stepRow) string {
return ""
}
+// redactForms is a copy of b with every known secret form replaced by
+// *** (only the forms: a frame stays valid JSON).
+func redactForms(b []byte, forms [][]byte) []byte {
+ out := append([]byte(nil), b...)
+ for _, f := range forms {
+ out = bytes.ReplaceAll(out, f, []byte("***"))
+ }
+ return out
+}
+
// redactingWriter writes each frame with every known secret redacted.
type redactingWriter struct {
w io.Writer
diff --git a/internal/thintest/wbfix1_oversize_contract_test.go b/internal/thintest/wbfix1_oversize_contract_test.go
index 553f0892..24d742fb 100644
--- a/internal/thintest/wbfix1_oversize_contract_test.go
+++ b/internal/thintest/wbfix1_oversize_contract_test.go
@@ -50,7 +50,7 @@ func TestOutboundPackOversizeIsWorkspaceTooLarge(t *testing.T) {
t.Fatalf("%d chunks reached the primary", n)
}
// A restart keeps it.
- w = r.restartMac(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))
}