oficina / equipo Public

Abilities phase 2: Astra round 2 fixes (2 P1, 1 P2)

P1: the Oficina provider checks apps_read again right before every
authenticated request, after its token (and any refresh) is ready, so a
switch turned off meanwhile sends nothing. P1: a legacy hand-off's turn
in the shared Coordinator lane is held like a job thread's: its
work-changing tools and card answers find the hand-off through the turn.
P2: the build hold applies to steps of unfinished tasks only; a finished
task's Publish is going live, which go_live and its last checks govern,
so resuming can't strand one. Budgets re-measured.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 02ff954cdf52554f380d1c5e3685aa7eb45c946c parent 15734e4
8 files changed, +110 −6
  • .rastrillo/budgets.txt +2 −2
  • internal/equipo/assist/gate_test.go +34 −0
  • internal/equipo/assist/http.go +9 −0
  • internal/equipo/assist/oficina.go +5 −1
  • internal/equipo/chat/ability_hold.go +28 −1
  • internal/equipo/chat/projects.go +1 −1
  • internal/equipo/chat/tools.go +1 −1
  • internal/thintest/build_off_contract_test.go +30 −0
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 0755f40e..08b4f316 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -56,7 +56,7 @@ perf GET /api/v1/tasks/{id} skip Thin v1 person API: bearer-only JSON for device
perf GET /api/v1/assistant/snapshot skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen.
perf GET /api/v1/assistant/messages skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen.
perf GET /api/v1/assistant/events skip Assistant event stream (Server-Sent Events), bearer-only and long-lived; not a screen.
-size internal/equipo/chat 39488 13248 File facts/diffs, previews, merge authority, unfinished work, CI feedback, notification receipts, Assistant files, places and where their cards land, waiting cards, the Assistant's abilities (board fetch, switches, send gate, holds, go-live checks); measured 39488/13248.
+size internal/equipo/chat 39515 13248 File facts/diffs, previews, merge authority, unfinished work, CI feedback, notification receipts, Assistant files, places and where their cards land, waiting cards, the Assistant's abilities (board fetch, switches, send gate, holds, go-live checks); measured 39515/13248.
perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}.
perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}.
perf GET /api/v1/connections/preference skip Connections slice 1 person API: bearer-only JSON for devices; the browser shows the preference on /conversation/connections.
@@ -71,7 +71,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 - 11873 Grant scenarios (#48); sign-in email at 1280 and 390; Assistant files end to end; the restart wait; the live site waits for a place; a card answer settles at the bottom; measured 11873 test lines.
-size internal/thintest - 37687 Protocol 31 contracts, 35 diffs, stuck tasks, no-access merges, held retries, unfinished work, free rounds, previews, Assistant files, places and where their cards land, the Assistant's abilities; measured 37687 test lines.
+size internal/thintest - 37717 Protocol 31 contracts, 35 diffs, stuck tasks, no-access merges, held retries, unfinished work, free rounds, previews, Assistant files, places and where their cards land, the Assistant's abilities; measured 37717 test lines.
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/equipo/assist/gate_test.go b/internal/equipo/assist/gate_test.go
index 3c5cbf8e..259c5f29 100644
--- a/internal/equipo/assist/gate_test.go
+++ b/internal/equipo/assist/gate_test.go
@@ -158,3 +158,37 @@ func TestProviderCannotSpeakAsInstance(t *testing.T) {
}
}
}
+
+// flipConn turns reading off while it hands out a token, as a refresh
+// that took long enough might.
+type flipConn struct {
+ conn
+ off *bool
+}
+
+func (c *flipConn) Host(ctx context.Context, person string) (string, string, bool, error) {
+ *c.off = true
+ return c.conn.Host(ctx, person)
+}
+
+// Reading turned off while the token is refreshed: the read that would
+// follow is never sent (Astra phase 2 round 2, P1).
+func TestReadingOffDuringRefreshSendsNothing(t *testing.T) {
+ tr := &trace{}
+ client := &http.Client{Transport: traceTransport{tr, http.DefaultTransport}}
+ off := false
+ c := &flipConn{conn: conn{origin: "https://connect.invalid", tokens: []string{"token-0123456789"}}, off: &off}
+ allowed := func(context.Context, string) error {
+ if off {
+ return Refusal{Code: "ability_off"}
+ }
+ return nil
+ }
+ p := NewOficinaProvider("oficina", c, client, allowed)
+ if _, err := p.List(allowAll(context.Background()), "p"); err == nil {
+ t.Error("listed with reading off")
+ }
+ if n := len(tr.all()); n != 0 {
+ t.Errorf("%d requests sent after reading went off", n)
+ }
+}
diff --git a/internal/equipo/assist/http.go b/internal/equipo/assist/http.go
index cc3dc148..94fe6de4 100644
--- a/internal/equipo/assist/http.go
+++ b/internal/equipo/assist/http.go
@@ -21,6 +21,10 @@ type httpProvider struct {
name string
host func(ctx context.Context, person string) (origin, token string, ok bool, err error)
client *http.Client
+ // beforeSend, when set, runs right before every request is sent,
+ // after its host and token are ready (the Oficina provider's
+ // apps_read): a refusal sends nothing.
+ beforeSend func(ctx context.Context, person string) error
}
// NewHTTPProvider speaks agent-access's operations contract to the origin
@@ -105,6 +109,11 @@ func (p *httpProvider) do(ctx context.Context, person, method, path string, in [
if key != "" {
req.Header.Set("Idempotency-Key", key)
}
+ if p.beforeSend != nil {
+ if err := p.beforeSend(ctx, person); err != nil {
+ return nil, err
+ }
+ }
if gate != nil {
if err := gate(); err != nil {
return nil, err
diff --git a/internal/equipo/assist/oficina.go b/internal/equipo/assist/oficina.go
index 5b259a10..5eadc50f 100644
--- a/internal/equipo/assist/oficina.go
+++ b/internal/equipo/assist/oficina.go
@@ -59,7 +59,11 @@ func NewOficinaProvider(name string, conn Connection, client *http.Client, allow
return conn.Host(ctx, person)
}
}
- return &oficinaProvider{http: newHTTPProvider(name, host, client), conn: conn}
+ h := newHTTPProvider(name, host, client)
+ // Checked again right before each request: a token refresh may
+ // have taken long enough for the switch to go off.
+ h.beforeSend = allowed
+ return &oficinaProvider{http: h, conn: conn}
}
func (p *oficinaProvider) Name() string { return p.http.name }
diff --git a/internal/equipo/chat/ability_hold.go b/internal/equipo/chat/ability_hold.go
index 1275cb65..7fc3ccbf 100644
--- a/internal/equipo/chat/ability_hold.go
+++ b/internal/equipo/chat/ability_hold.go
@@ -77,11 +77,22 @@ func (t *txn) laneHeld(lane string) (bool, error) {
return t.abilityHeld(h)
}
-// taskHeld reports whether task is followed by a held job.
+// taskHeld reports whether task is followed by a held job. A finished
+// task's steps (its Publish) are going live, which go_live and its own
+// last checks govern, not building.
func (t *txn) taskHeld(task string) (bool, error) {
if task == "" {
return false, nil
}
+ k, err := t.loadTask(task)
+ if errors.Is(err, ErrNotFound) {
+ return false, nil
+ } else if err != nil {
+ return false, err
+ }
+ if wire.FinalStage(k.Stage) {
+ return false, nil
+ }
h, ok, err := t.handoffOf("", task)
if err != nil || !ok {
return false, err
@@ -258,3 +269,19 @@ func (t *txn) goLiveOptions(v *wire.AssistantCard, person string) error {
})
return nil
}
+
+// turnHeld reports whether turn belongs to a held job: a job thread's
+// turn, or a legacy hand-off's turn in the shared Coordinator lane.
+func (t *txn) turnHeld(turn, lane string) (bool, error) {
+ if held, err := t.laneHeld(lane); err != nil || held {
+ return held, err
+ }
+ if turn == "" {
+ return false, nil
+ }
+ h, ok, err := t.handoffOf(turn, "")
+ if err != nil || !ok {
+ return false, err
+ }
+ return t.abilityHeld(h)
+}
diff --git a/internal/equipo/chat/projects.go b/internal/equipo/chat/projects.go
index 07d11d1c..f1d71674 100644
--- a/internal/equipo/chat/projects.go
+++ b/internal/equipo/chat/projects.go
@@ -718,7 +718,7 @@ func (s *Store) AnswerDevice(ctx context.Context, person, credential, id string,
// A card in a held job's thread that would start or change
// work can't be answered; dropping the job still can.
if in.Choice != "drop" {
- if held, err := t.laneHeld(c.Lane); err != nil || held {
+ if held, err := t.turnHeld(c.TurnID, c.Lane); err != nil || held {
if held {
return ErrAbilityOff
}
diff --git a/internal/equipo/chat/tools.go b/internal/equipo/chat/tools.go
index eef6d8f2..8be96d5b 100644
--- a/internal/equipo/chat/tools.go
+++ b/internal/equipo/chat/tools.go
@@ -566,7 +566,7 @@ func (t *txn) runTool(l Lease, v *wire.ToolCall) (wire.ToolResult, error) {
return refused("request_cancelled", toolRequestCancelled), err
}
if slices.Contains(buildOffTools, v.Name) {
- if held, err := t.laneHeld(r.Lane); err != nil || held {
+ if held, err := t.turnHeld(r.ID, r.Lane); err != nil || held {
return refused(wire.CodeAbilityOff, buildOffCoordinatorText), err
}
}
diff --git a/internal/thintest/build_off_contract_test.go b/internal/thintest/build_off_contract_test.go
index 2b13a2c9..67786797 100644
--- a/internal/thintest/build_off_contract_test.go
+++ b/internal/thintest/build_off_contract_test.go
@@ -171,3 +171,33 @@ func TestResearchNeedsWeb(t *testing.T) {
}
})
}
+
+// A legacy hand-off's turn in the shared Coordinator lane is held as a
+// job thread's is: with building off, its work-changing tools are refused
+// (Astra phase 2 round 2, P1).
+func TestLegacyHandoffBuildOff(t *testing.T) {
+ o := newTeamRig(t)
+ o.ask("Fix the README.")
+ _, turn := o.legacyHandoff("lg", "Fix the README.")
+ o.setBoard(wire.AbilityBuild)
+ o.in(turn, func() {
+ refusedOff(t, "record_task", o.call("lg-rt", wire.ToolRecordTask, map[string]any{"repo": "oficina/sample", "title": "Fix", "brief": "Fix it.", "separate": true}))
+ })
+}
+
+// A finished task's Publish is going live, which putting live governs:
+// building off doesn't stop it (Astra phase 2 round 2, P2).
+func TestPublishNotHeldByBuild(t *testing.T) {
+ o := newTeamRigAt(t, wire.ProtocolCurrent)
+ _, id, merge := o.paulsWebsite(false)
+ publish := o.paulsPublish(id, merge)
+ o.setBoard(wire.AbilityBuild)
+ // Whatever else the publish start waits for, building being off isn't
+ // it, and the attempt isn't settled for a hold.
+ if refused := o.lease(o.runner, "pb-pub", wire.LeaseCheck{StepID: publish.StepID, Attempt: publish.Attempt, Purpose: wire.LeasePurposePublish}); refused == wire.CodeAbilityOff {
+ t.Errorf("publish refused for building off")
+ }
+ if n := o.rows("SELECT count(*) FROM chat_handoffs WHERE ability_held_at IS NOT NULL"); n != 0 {
+ t.Errorf("the job was held for a publish")
+ }
+}