oficina / equipo Public

security: a kept Pi session stays put; progress records the round

Astra's S2 round, finding 7. With leave to spend, a usable kept
metered connection is chosen before subscription precedence, so a Pi
Engineering fix round stays on TensorX when Claude is usable again,
and the guard holds it there (busy, budget) rather than moving it; a
fix round finds a kept Pi transcript. S2-PI-PROGRESS.md records the
round's nine findings, fixes and mutations.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev f8ecce9971ac90d4867eab6192cc7fe8eb8ede04 parent 934e847
6 files changed, +206 −12
  • .rastrillo/budgets.txt +1 −1
  • docs/superpowers/plans/S2-PI-PROGRESS.md +97 −0
  • internal/runner/connect/choose.go +8 −0
  • internal/runner/connect/choose_test.go +15 −10
  • internal/runner/thin/engineer.go +4 −1
  • internal/runner/thin/pistep_test.go +81 −0

CI passed — run details

diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index c3786429..c665256b 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -35,7 +35,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 19799 11256 The thin runner: steps, link, coordinator, Mac worker, previews, publication, merges, metered connections and Pi steps. Measured 19799 source and 11256 test lines.
+size internal/runner/thin 19846 11393 The thin runner: steps, link, coordinator, Mac worker, previews, publication, merges, metered connections and Pi steps. Measured 19846 source and 11393 test lines.
time internal/thintest 180s Contract tests for Mac runners, transitions and the thin core share one instance harness; loaded CI needs 180s.
time internal/runner/mac 30s Mac runners (Darwin worker): real process groups killed after a grace and proven gone (SIGTERM, SIGKILL, the marker sweep), and the probes run end to end with fake srt and xcodebuild, P6 killing.
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).
diff --git a/docs/superpowers/plans/S2-PI-PROGRESS.md b/docs/superpowers/plans/S2-PI-PROGRESS.md
index 2824a365..6091721e 100644
--- a/docs/superpowers/plans/S2-PI-PROGRESS.md
+++ b/docs/superpowers/plans/S2-PI-PROGRESS.md
@@ -221,6 +221,103 @@ build), `rastrillo budget size` and the dead-reference scan.
- decode D5: system and user messages' usage counted -> TestDecodeRecordedRuns, TestTallyUsage
- decode D6: Pi's unpriced zero cost recorded as a reported cost -> TestTallyUsage
+## Security round (Astra, read-only, on ca3e7bb0)
+
+Verdict NOT READY, nine findings, all mechanical; each fixed with a test
+written first and a mutation observed. Nothing was found against the
+relay's Host change, the gitleaks entry or the leave-to-spend seam.
+
+1. The Pi tree hashed by path, then mounted by a fresh open
+ (`containment/mounts.go`): the containment now hashes the tree again
+ through the very descriptor it mounts and refuses a mismatch; an
+ install root anyone else could write (other-writable without the
+ sticky bit, or group-writable for a group that is not this user's own),
+ an entry another user owns, and a file with a second name (a hard link
+ another path could write through) are refused at the policy, the
+ attestation and `pi.Verify`. `TestNamespacePiTreeSwapAfterAttestation`
+ swaps a file and the whole directory after the attestation.
+2. A Pi that stops reading its stdin held the runner (`pi/rpc.go`): writes
+ take their own lock, never held by a waiting caller, and give up with
+ their context; Interrupt is bounded by its context, cancelling pending
+ dialogs first; a cancelled step asks Pi to stop aside while the
+ namespace is killed regardless. `TestClientWritesAreCancellable`,
+ `TestLauncherInterruptIsBounded`.
+3. Missing usage counted as zero (`pi/decode.go`): a message without
+ usage, without input or output, with a negative figure, a run with no
+ message at all, and a sum that overflows (checked addition) leave the
+ attempt's figures null, so the spend is unknown however the run ends.
+ `TestTallyUnknownUsage`, `TestPiEndWithoutUsagePausesTheConnection`.
+4. Configuration accepted by secret-shaped names only (`check_policy.go`):
+ the policy rebuilds models.json, settings.json and mcp.json from the
+ provider and model and accepts exactly those (no other MCP server,
+ command, argument or exposure, no other setting, no other field, the
+ provider table's base URL), and pins the extension's digest; the
+ extension moved into the provider package. New cases in
+ `TestPiPolicyRefusals`, `TestPiBaseURLsAreTheProviders`.
+5. The key in logs and reports (`thin/pistep.go`): the runner reads the
+ launch's key once and redacts it (as itself and as JSON text) from every
+ delta, as a stream so a key split across deltas is caught, the step
+ log, the tail, activity subjects, provider errors, unknown event names
+ and the arguments Pi gives Equipo's tools. `TestPiRedactsTheKey`,
+ `TestRedactorStream`.
+6. Unbounded text and queues (`thin/pistep.go`, `pi/rpc.go`): the client
+ keeps at most 16 MiB of records (Pi waits for the rest), a record over
+ 8 MiB ends the stream, events carry no tool arguments over 64 KiB,
+ the events channel holds 64, and a reply over 1 MiB ends the run with
+ its usage incomplete (spend unknown). `TestClientQueueIsBounded`,
+ `TestDecodeClipsToolArguments`, `TestPiOversizedReply`.
+7. A kept Pi session moved to a recovered subscription
+ (`connect/choose.go`): with leave to spend, a usable kept metered
+ connection is chosen first, before subscription precedence; the guard
+ then holds the round there (busy, budget), it does not move; an
+ Engineering fix round now finds a kept Pi transcript.
+ `TestPiKeptSessionStaysPut`, new `TestChooseMetered` cases.
+8. Lexical link containment (`provider/tree.go`): links are followed
+ link by link under the root, refusing escapes, dangling links, absolute
+ targets and chains over 40 (cycles); the CI installer does the same.
+ New `TestTreeDigest` cases.
+9. The leave-to-spend release check untested on its own
+ (`release_guard_test.go`): `TestReleaseCheckRefusesEachMarker` hands
+ the script one marker at a time.
+
+Decisions within the findings: group write on an install root is allowed
+only for this user's own group (Debian's user private groups make
+`~/.cache` group-writable); a kept metered session without leave to spend
+is not kept (no leave, no metered run: decision 5), which no release build
+meets before S3; a Review whose verdict was already recorded through
+Equipo's tool keeps it when its reply is then cut for length.
+
+Mutations observed:
+
+- S8a: link containment lexical again (the old prefix check) -> TestTreeDigest (a chain out of the tree, a dangling link, a cycle: accepted)
+- S8b: a link to nothing accepted -> TestTreeDigest (a dangling link)
+- S8c: the hop limit removed -> TestTreeDigest (a cycle: the walk never ends; the run fails at its 20s timeout). Raising the limit to 100000 instead was MISSED: the cycle is still refused, only later, so that change is not observable
+- S1a: a file with a second name accepted -> TestTreeDigest (a second name for a file)
+- S1b: the mount not hashing the tree through its retained descriptor -> TestNamespacePiTreeSwapAfterAttestation (file, directory: a tree changed after its attestation was mounted)
+- S1c: an install root others can write accepted -> TestPiPolicyRefusals (an install root others can write)
+- S9: the release script not refusing the leave-to-spend marker -> TestReleaseCheckRefusesEachMarker (a binary with only that marker was accepted). Before the fix, TestReleaseRunnerHasNoFakeWorker alone passed with this change, as the finding says
+- S3a: a run with no assistant message counted as zero -> TestTallyUnknownUsage (no message at all)
+- S3b: a message without countable usage counted as zero -> TestTallyUnknownUsage (without usage, negative, not an object, without input, one good and one without)
+- S3c: unchecked sums -> TestTallyUnknownUsage (a sum that overflows)
+- S3d: missing input or output read as zero -> TestTallyUnknownUsage (usage without input, without output)
+- S3e: as S3a, through a whole step on fakepi -> TestPiEndWithoutUsagePausesTheConnection (charged zero, spend not unknown)
+- S4a: the configuration checked by secret-shaped names only (as it was) -> TestPiPolicyRefusals (an MCP server running a shell, a second MCP server, a field in a model, a command for the key, a token in settings: accepted)
+- S4b: the extension's digest not pinned -> TestPiPolicyRefusals (another extension)
+- S4c: a base URL that is not the provider table's -> TestPiBaseURLsAreTheProviders
+- S2a: a write that waits for Pi however long (as it was) -> TestClientWritesAreCancellable, TestLauncherInterruptIsBounded (both hang to the 30s test timeout)
+- S2b: the interrupt's dialog cancellation ignoring its context -> TestLauncherInterruptIsBounded (hangs to the timeout). First run MISSED: the test's Pi had no pending question, so no cancellation was sent; the stuck Pi now asks one first, then caught
+- S6a: the reply text not capped -> TestPiOversizedReply (no cut, spend not unknown)
+- S6b: the client's byte budget off -> TestClientQueueIsBounded (2020 bytes queued in 20 records against 300)
+- S6c: tool arguments not clipped in events -> TestDecodeClipsToolArguments (a 200047-byte payload)
+- S6d: no record size limit -> TestClientQueueIsBounded (the oversized record is taken and the test hangs to its timeout)
+- S5a: Equipo's tools given Pi's arguments unredacted -> TestPiRedactsTheKey (the report holds the key: the verdict's headline and summary)
+- S5b: deltas redacted one by one, not as a stream -> TestPiRedactsTheKey (the key split across two deltas reached the report's tail)
+- S5c: the step log written unredacted -> TestPiRedactsTheKey (the step log holds the key)
+- S5d: the stream holding nothing back -> TestRedactorStream (pieces of 1: the key passed)
+- S7a: a kept metered session not resolved first (as it was) -> TestChooseMetered (kept on metered, a subscription usable: chose c1), TestPiKeptSessionStaysPut (the round moved to claude-a)
+- S7b: a kept metered connection kept even when it cannot run (refused) -> TestChooseMetered (kept on metered, refused)
+- S7c: a fix round not finding a kept Pi transcript -> TestPiKeptSessionStaysPut (the kept Pi session was not found)
+
## Decisions where the spec was open
- Leave to spend (controller, 2026-11-12, option A): `connect.Choose`
diff --git a/internal/runner/connect/choose.go b/internal/runner/connect/choose.go
index 27b38f34..c507b2a4 100644
--- a/internal/runner/connect/choose.go
+++ b/internal/runner/connect/choose.go
@@ -106,6 +106,14 @@ type Choice struct {
// metered connection is never a candidate; with it, one is chosen only
// when no subscription connection can run the role.
func Choose(cs []Candidate, role, current, prefer string, avoid []string, now time.Time, spend bool) (Choice, bool) {
+ // A kept session on a metered connection stays there (connectors
+ // spec §7, rule 1) while it can run, whatever a subscription offers:
+ // the metered guard then holds it there, never moves it.
+ for _, c := range cs {
+ if current != "" && c.ID == current && c.Metered && spend && Capable(c.harness(), role) && c.Usable(now) && !slices.Contains(avoid, c.ID) {
+ return Choice{ID: c.ID, Reason: ReasonHeadroom}, true
+ }
+ }
var usable, metered []Candidate
for _, c := range cs {
if !Capable(c.harness(), role) || !c.Usable(now) || slices.Contains(avoid, c.ID) {
diff --git a/internal/runner/connect/choose_test.go b/internal/runner/connect/choose_test.go
index 0f3b140b..2e0221cc 100644
--- a/internal/runner/connect/choose_test.go
+++ b/internal/runner/connect/choose_test.go
@@ -142,19 +142,24 @@ func TestChooseMetered(t *testing.T) {
spend bool
avoid []string
want string
+ current string
}{
- {"no leave: never chosen", RoleReview, []Candidate{pi}, false, nil, ""},
- {"no leave, alongside a subscription", RoleReview, []Candidate{pi, claude}, false, nil, "c1"},
- {"leave, only option", RoleReview, []Candidate{pi}, true, nil, "tensorx-a"},
- {"leave, Engineering", RoleEngineering, []Candidate{pi}, true, nil, "tensorx-a"},
- {"leave, never the coordinator", RoleCoordinator, []Candidate{pi}, true, nil, ""},
- {"leave, a subscription first", RoleReview, []Candidate{pi, claude}, true, nil, "c1"},
- {"leave, a subscription first even with less room", RoleReview, []Candidate{{ID: "tensorx-a", Provider: "tensorx", Harness: "pi", Metered: true, State: StateHealthy, Known: true}, claude}, true, nil, "c1"},
- {"leave, the subscription avoided", RoleReview, []Candidate{claude, pi}, true, []string{"c1"}, "tensorx-a"},
- {"capability is the harness's, not the provider's", RoleReview, []Candidate{{ID: "x", Provider: "tensorx", Metered: true, State: StateHealthy}}, true, nil, ""},
+ // A kept session on the metered connection stays there, even
+ // with a subscription usable; unless it cannot run.
+ {"kept on metered, a subscription usable", RoleEngineering, []Candidate{claude, pi}, true, nil, "tensorx-a", "tensorx-a"},
+ {"kept on metered, refused", RoleEngineering, []Candidate{claude, {ID: "tensorx-a", Provider: "tensorx", Harness: "pi", Metered: true, State: "sign_in_again"}}, true, nil, "c1", "tensorx-a"},
+ {"no leave: never chosen", RoleReview, []Candidate{pi}, false, nil, "", ""},
+ {"no leave, alongside a subscription", RoleReview, []Candidate{pi, claude}, false, nil, "c1", ""},
+ {"leave, only option", RoleReview, []Candidate{pi}, true, nil, "tensorx-a", ""},
+ {"leave, Engineering", RoleEngineering, []Candidate{pi}, true, nil, "tensorx-a", ""},
+ {"leave, never the coordinator", RoleCoordinator, []Candidate{pi}, true, nil, "", ""},
+ {"leave, a subscription first", RoleReview, []Candidate{pi, claude}, true, nil, "c1", ""},
+ {"leave, a subscription first even with less room", RoleReview, []Candidate{{ID: "tensorx-a", Provider: "tensorx", Harness: "pi", Metered: true, State: StateHealthy, Known: true}, claude}, true, nil, "c1", ""},
+ {"leave, the subscription avoided", RoleReview, []Candidate{claude, pi}, true, []string{"c1"}, "tensorx-a", ""},
+ {"capability is the harness's, not the provider's", RoleReview, []Candidate{{ID: "x", Provider: "tensorx", Metered: true, State: StateHealthy}}, true, nil, "", ""},
} {
t.Run(tc.name, func(t *testing.T) {
- got, ok := Choose(tc.cs, tc.role, "", "", tc.avoid, now, tc.spend)
+ got, ok := Choose(tc.cs, tc.role, tc.current, "", tc.avoid, now, tc.spend)
if got.ID != tc.want || ok != (tc.want != "") {
t.Fatalf("chose %+v %v, want %q", got, ok, tc.want)
}
diff --git a/internal/runner/thin/engineer.go b/internal/runner/thin/engineer.go
index 834bdb26..9cd2b967 100644
--- a/internal/runner/thin/engineer.go
+++ b/internal/runner/thin/engineer.go
@@ -22,6 +22,7 @@ import (
"amadan.net/oficina/equipo/internal/runner/forge"
"amadan.net/oficina/equipo/internal/runner/provider"
"amadan.net/oficina/equipo/internal/runner/provider/claude"
+ "amadan.net/oficina/equipo/internal/runner/provider/pi"
"amadan.net/oficina/equipo/internal/runner/workspace"
"amadan.net/oficina/equipo/internal/runnerproto"
"amadan.net/oficina/equipo/internal/wire"
@@ -704,7 +705,9 @@ func (e *Engineer) fixSession(ctx context.Context, r stepRow, base string) (kept
if !found {
return keptSession{}, false
}
- if _, err := os.Stat(transcriptPath(k.Dir, k.SessionID)); err != nil {
+ // Claude's transcript, or Pi's (a session kept on a metered
+ // connection).
+ if _, err := os.Stat(transcriptPath(k.Dir, k.SessionID)); err != nil && !pi.HasSession(k.Dir, k.SessionID) {
return keptSession{}, false
}
return k, true
diff --git a/internal/runner/thin/pistep_test.go b/internal/runner/thin/pistep_test.go
index 95d78d4b..07f9f843 100644
--- a/internal/runner/thin/pistep_test.go
+++ b/internal/runner/thin/pistep_test.go
@@ -526,3 +526,84 @@ func TestPiRedactsTheKey(t *testing.T) {
t.Fatalf("nothing was redacted: summary %q headline %q", rep.Summary, rep.Headline)
}
}
+
+// A kept Pi Engineering session stays put (spec §7, rule 1): its fix
+// round resumes on the metered connection even when a subscription is
+// usable again; when the guard bars spending there (a busy slot, the
+// budget), the round is held on it, never moved.
+func TestPiKeptSessionStaysPut(t *testing.T) {
+ r := newPiRig(t, fakePiInstall(t), wire.Budget{Day: 1, Month: 1_000, Revision: 1})
+ leave(t)
+ // Round 0 ran on TensorX and kept its Pi session.
+ dir := filepath.Join(t.TempDir(), "kept")
+ os.MkdirAll(dir, 0700)
+ session := pi.NewSessionID()
+ if err := os.WriteFile(filepath.Join(dir, "2026-11-12T00-00-00-000Z_"+session+".jsonl"), []byte(`{"type":"session"}`+"\n"), 0600); err != nil {
+ t.Fatal(err)
+ }
+ base := r.review.CandidateSHA
+ round0 := stepRow{DispatchCommand: wire.DispatchCommand{Person: connPerson, TaskID: "tk7", StepID: "e0", Attempt: 1, Specialist: wire.SpecialistEngineering}}
+ if err := r.state.keepSession(r.ctx, round0, wire.SpecialistEngineering, piLocal, session, dir, base, 10); err != nil {
+ t.Fatal(err)
+ }
+ // Claude is usable again: its limit's reset (an hour on) has passed.
+ r.conns.now = func() time.Time { return time.Now().Add(2 * time.Hour) }
+ if _, _, err := r.conns.Choose(r.ctx, connPerson, connect.RoleEngineering, "", nil); err != nil {
+ t.Fatalf("Claude is not usable: %v", err)
+ }
+ row := stepRow{DispatchCommand: wire.DispatchCommand{Person: connPerson, TaskID: "tk7", StepID: "e1", Attempt: 1, Specialist: wire.SpecialistEngineering, Repo: r.review.Repo, Branch: "equipo/tk7-x", BaseSHA: base, Round: 1, Feedback: "Fix round 1 of 2. Review asked for changes.", Findings: []wire.Finding{}}, Base: base}
+ plan := func() (string, bool) {
+ t.Helper()
+ kept, ok := r.e.fixSession(r.ctx, row, base)
+ if !ok {
+ t.Fatal("the kept Pi session was not found")
+ }
+ b, resume, err := r.e.fixPlan(r.ctx, row, nil, kept, ok)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return b.ID, resume
+ }
+ if id, resume := plan(); id != piLocal || !resume {
+ t.Fatalf("the round moved: %s resume %v", id, resume)
+ }
+ // Busy: another attempt holds the slot. The round is held there.
+ err := r.state.tx(r.ctx, func(tx *sql.Tx) error {
+ _, err := metered.Admit(r.ctx, tx, piLocal, metered.Holder{Step: "other", Attempt: 1, Role: metered.RoleReview}, time.Now())
+ return err
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := r.state.AcceptDispatch(r.ctx, "f-e1", row.DispatchCommand); err != nil {
+ t.Fatal(err)
+ }
+ if rep := r.e.Exec(r.ctx, row, func(wire.StepReport) {}); rep.State != stepDeferred {
+ t.Fatalf("busy: %+v", rep)
+ }
+ if id, _ := plan(); id != piLocal {
+ t.Fatalf("after a hold the round moved to %s", id)
+ }
+ // The budget: the slot free again, today's spend past the budget. Held
+ // there again.
+ other := metered.Holder{Step: "other", Attempt: 1, Role: metered.RoleReview}
+ in, out := int64(1_000_000), int64(1_000)
+ err = r.state.tx(r.ctx, func(tx *sql.Tx) error {
+ if _, err := metered.Charge(r.ctx, tx, piLocal, other, []wire.Usage{{Provider: wire.ProviderTensorX, Connection: piLocal, Model: "z-ai/glm-5.3", Attempt: 1, Complete: true, InputTokens: &in, OutputTokens: &out}}, time.Now()); err != nil {
+ return err
+ }
+ return metered.Settle(r.ctx, tx, piLocal, other, metered.Ending{Proven: true})
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !r.slotFree() || r.charges() != 1 {
+ t.Fatalf("slot free %v charges %d", r.slotFree(), r.charges())
+ }
+ if rep := r.e.Exec(r.ctx, row, func(wire.StepReport) {}); rep.State != stepDeferred {
+ t.Fatalf("budget: %+v", rep)
+ }
+ if id, _ := plan(); id != piLocal {
+ t.Fatalf("after the budget hold the round moved to %s", id)
+ }
+}