oficina / equipo Public

Merge branch 'connections-s5-undercount' into main

Merge connections-s5-undercount: say OpenCode's spend may be higher

The Usage page tells the person, for OpenCode only, that spend may be
higher than shown when a request's usage is not reported; the spec
notes the gap. No wire change, no migration. Hosted CI passed on
7ce28e1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev e8e7dd28ead0fc1dd7ea78860a74ffa2fa23892f parent 5880ab1parent 7ce28e1
9 files changed, +146 −4
  • .rastrillo/budgets.txt +2 −2
  • docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md +1 −0
  • docs/superpowers/plans/S5-OPENCODE-PROGRESS.md +55 −0
  • docs/superpowers/specs/2026-11-12-equipo-connectors-and-token-scheduling.md +26 −1
  • internal/equipo/copy.go +1 −0
  • internal/equipo/templates/usage.html +1 −1
  • internal/equipo/usage_page.go +6 −0
  • internal/equipo/usage_page_test.go +39 −0
  • internal/wire/metered.go +15 −0

CI passed — run details

diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 04814bc7..672e54d4 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -14,8 +14,8 @@ perf GET /* skip Unknown private paths render 404; this fallback contains no scr
time internal/equipo/team 60s Plan 3 loaded CI measured 45.985s; niced serial reruns measured 18.079s and 22.031s. Keep migration, recovery, accounting and concurrency assertions; 60s leaves 30 percent headroom above loaded CI.
time internal/equipotest 300s Final fix package rerun measured 187.035s (review 172.4s); 300s gives 60 percent headroom for HTTP, sandbox, authority and final regression coverage.
-size internal/equipo 19148 - The instance web layer: pages, handlers, templates and copy for every screen, the Usage page included. Measured 19148 source lines.
-size internal/wire 5533 - The runner and person API protocol: every frame, resource and its downgrade up to protocol 17 (16 publishing, 17 OpenCode Go), one package so Encode sees every type. Measured 5533 source lines.
+size internal/equipo 19155 - The instance web layer: pages, handlers, templates and copy for every screen, the Usage page included. Measured 19155 source lines.
+size internal/wire 5548 - The runner and person API protocol: every frame, resource and its downgrade up to protocol 17 (16 publishing, 17 OpenCode Go), one package so Encode sees every type. Measured 5548 source lines.
size internal/equipotest - 13400 Task 21 repairs historical migration and conversation fixtures after Plan 3. Measured 13024 test lines; the 300s time ceiling is unchanged.
time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded);
time internal/runner 330s Plan 3 CI repair measured 292.120s for the full package (controller CI 472.184s).
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
index b96ea52c..879d58a6 100644
--- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
+++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
@@ -6174,6 +6174,7 @@ records remain unchanged.
| `usage.connect` | Add a connection | Usage S4: link to Add a connection when nothing is connected | Runtime; COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12) |
| `usage.spend` | Spend this month | Usage S4: heading of the spend part (metered connections and subscriptions' plans) | Runtime; COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12) |
| `usage.price_source` | %s prices taken from the public page on %s. | Usage S4, controller's price note: where prices come from, read from the price table's version; %s the provider (TensorX), %s the day its public page was read (12 Nov 2026) | Runtime; COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12) |
+| `usage.spend_undercount` | Spend may be higher than shown when usage is not reported for a request. | OpenCode on OpenCode Go S5 (security round finding 3, accepted gap): on the Usage page beside the spend source line, for a connection whose harness counts a request without usage as zero (OpenCode); not on Pi (TensorX), whose missing usage makes spend unknown | Runtime; COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12) |
| `usage.plan_tokens` | %s tokens this month | Usage S4: a subscription's tokens this month (never a money figure); %s is a token count (1.2M) | Runtime; COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12) |
| `usage.plan` | %s plan | Usage S4: a subscription's plan as its provider names it; %s is the plan (Pro) | Runtime; COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12) |
| `usage.spend_none` | Every connection uses a subscription. There are no separate token charges. | Usage S4: the spend part when no connection is metered | Runtime; COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12) |
diff --git a/docs/superpowers/plans/S5-OPENCODE-PROGRESS.md b/docs/superpowers/plans/S5-OPENCODE-PROGRESS.md
index 1ba241d9..22a7ade9 100644
--- a/docs/superpowers/plans/S5-OPENCODE-PROGRESS.md
+++ b/docs/superpowers/plans/S5-OPENCODE-PROGRESS.md
@@ -434,3 +434,58 @@ it):
tunnels, not requests (keep-alive and HTTP/2 multiplex them).
- **D. Infer the request count from tool calls** (heuristic only):
parallel tool calls share one request, so the count is not exact.
+
+## Controller follow-up (2026-11-12)
+
+### 1. Protocol 17
+
+Main took protocol 16 for website publishing (`ProtocolPublish`), so
+S5 takes 17: `ProtocolOpenCode = Protocol17`, with `ProtocolCurrent`
+moving to it. That renumber landed on main with S5's squash
+(5880ab10), along with its mixed-version tests:
+`TestEncodeBelowProtocol17DropsOpenCode` checks every frame at 16 and
+15, `TestEncodeMixedVersionsOpenCodeAndPublish`, and the contract test's
+older runners at 16 and 15. This follow-up branch
+(`connections-s5-undercount`) carries only items 2 and 3 and adds no
+wire change. The branch's own renumber was dropped, since main's covers
+everything it had: its hello test with the sites capability and an
+OpenCode Go connection is covered by the mixed-version test's hello at
+16 and at 15.
+
+### 2. Finding 3: the gap accepted and stated
+
+The controller's ruling: option 1, accept the stated gap; option A (read
+the per-request rows from `OPENCODE_DB` after the attempt) is the slice
+after S5b, not built here.
+
+- The spec says it: §2.3's OpenCode bullet, §4.2 ("Usage as built"),
+ §12 ("OpenCode can under-count a turn"), and a line in its history.
+- The Usage page's spend source line gains a line (below) for a connection whose harness has
+ the gap. It comes from data: `wire.Harnesses` holds each metered
+ harness's facts, `PartialUsageUnderCounts` true for OpenCode, false
+ for Pi, and the page reads the connection's harness, never its
+ provider. `TestUsageSpendUnderCountLine` (OpenCode Go shows it once;
+ TensorX does not; a connection on a harness with the gap shows it
+ whatever its provider).
+- **Why not Pi on TensorX:** Pi reports usage per request
+ (`message_end.usage`), and the tally (S2's security round, finding 3)
+ makes the whole attempt's figures unknown when any message has no
+ usage, no input or output, or a negative figure. A missing figure
+ there is spend unknown, which pauses the connection; it is never a
+ smaller sum. OpenCode's ACP gives only the turn's sum, in which
+ OpenCode has already turned a missing figure into zeros.
+
+Mutations observed:
+
+- U1: the line keyed on the provider -> TestUsageSpendUnderCountLine (the line follows the provider, not the harness)
+- U2: Pi given the gap -> TestUsageSpendUnderCountLine (TensorX shows the line)
+- U3: the line dropped from the page -> TestUsageSpendUnderCountLine (the line shows 0 times)
+
+### 3. Copy: delegated review (Astra, 2026-11-12)
+
+The new string went through Astra as the copy-review gate and was
+changed; applied verbatim, marked `COPY ACCEPTED BY DELEGATION (Astra,
+2026-11-12)` in `copy.go` and the Plan 3 inventory; the page test quotes
+it.
+
+- `usage.spend_undercount`: Spend may be higher than shown when usage is not reported for a request.
diff --git a/docs/superpowers/specs/2026-11-12-equipo-connectors-and-token-scheduling.md b/docs/superpowers/specs/2026-11-12-equipo-connectors-and-token-scheduling.md
index a15e0a44..7cd2fc29 100644
--- a/docs/superpowers/specs/2026-11-12-equipo-connectors-and-token-scheduling.md
+++ b/docs/superpowers/specs/2026-11-12-equipo-connectors-and-token-scheduling.md
@@ -33,6 +33,10 @@ Claude (Opus 5.5) on `connections-slice2-design` from main 1d7b4e4.
- Revision 3.2 (2026-11-12) records the controller's two rulings on
S3's security review (#7 reading freshness, #8 a kept metered session
moving) and that S1 to S3 are built. Nothing else changes.
+- S5 (OpenCode on Go, 2026-11-12) records the controller's ruling on
+ its security round's finding 3: OpenCode's usage gap is accepted and
+ stated (§2.3, §4.2, §12); reading OpenCode's own per-request rows is a
+ follow-up slice.
§15 maps all three rounds' findings.
@@ -213,7 +217,12 @@ gateway, which is later (§5).
incremental is probe OC-P4. If cumulative, the attempt is the last
total less the total at the attempt's start, as `CodexTally` does;
if incremental, the sum. It is `complete` when the session went
- idle.
+ idle. As built (S5, over ACP, §4.2): the prompt's answer carries the
+ turn's own sum over its requests (OC-P4), complete at that answer;
+ a turn whose figure has no input at all is spend unknown. A request
+ inside a turn that the provider answers without usage counts as
+ zero in that sum, so a turn of several requests can be
+ under-counted, and Equipo cannot see it through ACP (§12).
- **Vibe:** one attempt is one run. It is `export.json`'s totals,
`complete` when the file is present and parses.
@@ -378,6 +387,17 @@ fall back to Console credit. [OC2]
answered at the reply endpoint. Usage comes from
`session.usage.updated`. [OC4] If probe OC-P2 finds a stdio mode in
OpenCode v2 (`acp`, unconfirmed), the bridge is not built.
+- **Usage as built (S5).** OC-P2 found `opencode acp`, so S5 drives ACP
+ and builds no bridge. ACP gives each turn's usage summed over its
+ requests, with no per-request figure. In a turn with several
+ requests, OpenCode reports a request without usage as zero, so the
+ turn's spend can be under-counted, and Equipo cannot see this through
+ ACP. The gap is accepted (the controller's ruling on S5's security
+ round, finding 3) and stated on the Usage page for OpenCode's
+ connections. The follow-up slice reads the per-request rows from
+ `OPENCODE_DB` after the attempt (each request is one `assistant` row
+ with its own tokens; one without usage has every token 0), and makes
+ such a turn spend unknown.
- **Billing:** metered (§0 decision 7), unless Paul confirms a standing
Console setting that disables overflow, which is undocumented today.
Headroom is "not reported" unless probe OC-P3 finds the Go allowance
@@ -765,6 +785,11 @@ needs its own Astra round on its branch.
the remedy.
- **Reported usage can be wrong or missing.** Wrong usage misleads the
soft budget. Missing usage pauses the connection.
+- **OpenCode can under-count a turn (S5).** In a turn with several
+ requests, OpenCode reports a request without usage as zero, so the
+ turn's spend can be under-counted; Equipo cannot see this through ACP.
+ The Usage page says so for OpenCode's connections. The follow-up slice
+ reads the per-request rows from `OPENCODE_DB` after the attempt (§4.2).
- **The confirmations are Paul's word.** Equipo cannot check a provider
limit or a pay-as-you-go setting.
- **Thresholds are not predictions.** Concurrent steps can run a window
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go
index d9bf959b..34b8dca8 100644
--- a/internal/equipo/copy.go
+++ b/internal/equipo/copy.go
@@ -1003,6 +1003,7 @@ var pageCopy = map[string]string{
"usage.connect": "Add a connection", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12)
"usage.spend": "Spend this month", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12)
"usage.price_source": "%s prices taken from the public page on %s.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12)
+ "usage.spend_undercount": "Spend may be higher than shown when usage is not reported for a request.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12)
"usage.plan_tokens": "%s tokens this month", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12)
"usage.plan": "%s plan", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12)
"usage.spend_none": "Every connection uses a subscription. There are no separate token charges.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12)
diff --git a/internal/equipo/templates/usage.html b/internal/equipo/templates/usage.html
index d9b9cc70..c17c2c63 100644
--- a/internal/equipo/templates/usage.html
+++ b/internal/equipo/templates/usage.html
@@ -6,7 +6,7 @@
<section equipo-usage-part aria-labelledby="usage-now"><h2 id="usage-now">{{copy "usage.now"}}</h2>
{{if .NoConnections}}<p data-empty-state="usage.no_connections">{{copy "usage.no_connections"}} <a href="/conversation/settings/connections/add">{{copy "usage.connect"}}</a></p>{{else}}<ul equipo-usage-list role="list">{{range .Available}}<li equipo-usage-conn data-available="{{.ID}}" data-provider="{{.Provider}}" data-state="{{.State}}"><span equipo-usage-name><b>{{template "conn-label" .Tag}}</b> <span equipo-conn-state data-s="{{.State}}">{{.Words}}</span>{{template "conn-add-email" .Tag}}</span><span equipo-usage-facts>{{range .Meters}}<span equipo-conn-meter data-level="{{.Level}}"{{with .At}} title="{{.}}"{{end}}><span equipo-conn-bar><i data-w="{{.Used}}"></i></span><span>{{.Name}} <b>{{.Used}}%</b>{{with .Resets}}, {{.}}{{end}}</span></span>{{end}}{{with .Spend}}<span data-available-spend>{{.}}</span>{{end}}{{with .Age}}<span equipo-usage-age data-reading-age>{{.}}</span>{{end}}{{with .Note}}<span equipo-usage-age data-reading-none>{{.}}</span>{{end}}</span></li>{{end}}</ul>{{end}}</section>
<section equipo-usage-part aria-labelledby="usage-spend"><h2 id="usage-spend">{{copy "usage.spend"}}</h2>
-<ul equipo-usage-list role="list">{{range .Spend}}<li equipo-usage-spend data-spend="{{.ID}}"><span equipo-usage-name><b>{{template "conn-label" .Tag}}</b>{{with .Paused}} <span equipo-conn-state data-s="limited">{{.}}</span>{{end}}</span><span equipo-usage-facts>{{with .Line}}<span data-spend-line>{{.}}</span>{{end}}{{with .Tail}}<span equipo-usage-age>{{.}}</span>{{end}}{{with .Source}}<span equipo-usage-age data-price-source>{{.}}</span>{{end}}</span></li>{{end}}{{range .Plans}}<li equipo-usage-spend data-plan="{{.ID}}"><span equipo-usage-name><b>{{template "conn-label" .Tag}}</b>{{with .Plan}} <span equipo-usage-age>{{.}}</span>{{end}}</span><span equipo-usage-facts><span data-plan-tokens>{{.Tokens}}</span></span></li>{{end}}</ul>
+<ul equipo-usage-list role="list">{{range .Spend}}<li equipo-usage-spend data-spend="{{.ID}}"><span equipo-usage-name><b>{{template "conn-label" .Tag}}</b>{{with .Paused}} <span equipo-conn-state data-s="limited">{{.}}</span>{{end}}</span><span equipo-usage-facts>{{with .Line}}<span data-spend-line>{{.}}</span>{{end}}{{with .Tail}}<span equipo-usage-age>{{.}}</span>{{end}}{{with .Source}}<span equipo-usage-age data-price-source>{{.}}</span>{{end}}{{with .UnderCount}}<span equipo-usage-age data-spend-undercount>{{.}}</span>{{end}}</span></li>{{end}}{{range .Plans}}<li equipo-usage-spend data-plan="{{.ID}}"><span equipo-usage-name><b>{{template "conn-label" .Tag}}</b>{{with .Plan}} <span equipo-usage-age>{{.}}</span>{{end}}</span><span equipo-usage-facts><span data-plan-tokens>{{.Tokens}}</span></span></li>{{end}}</ul>
{{if not .Spend}}<p equipo-usage-age data-empty-state="usage.spend_none">{{copy "usage.spend_none"}}</p>{{end}}</section>
<section equipo-usage-part aria-labelledby="usage-tokens"><h2 id="usage-tokens">{{copy "usage.tokens"}}</h2>
<nav equipo-usage-tabs aria-label="{{copy "usage.tokens"}}"><span role="list">{{range .Periods}}<a role="listitem" href="{{.Href}}" data-period="{{.Key}}"{{if .On}} aria-current="true"{{end}}>{{.Label}}</a>{{end}}</span><span role="list">{{range .By}}<a role="listitem" href="{{.Href}}" data-by="{{.Key}}"{{if .On}} aria-current="true"{{end}}>{{.Label}}</a>{{end}}</span></nav>
diff --git a/internal/equipo/usage_page.go b/internal/equipo/usage_page.go
index 2baa747d..0244dacf 100644
--- a/internal/equipo/usage_page.go
+++ b/internal/equipo/usage_page.go
@@ -54,6 +54,9 @@ type usageConn struct {
type usageSpend struct {
Tag chat.ConnLabel
ID, Name, Line, Tail, Paused, Source string
+ // UnderCount says the connection's harness can under-count a turn's
+ // spend (wire.Harnesses), beside where its prices come from.
+ UnderCount string
}
// usagePlan is a subscription: its plan and its tokens this month, never
@@ -194,6 +197,9 @@ func usagePage(conns []wire.Connection, labels map[string]chat.ConnLabel, totals
u.Words = row.Unknown
}
s := usageSpend{Tag: tag, ID: c.ID, Name: tag.Text, Line: row.Spend, Tail: row.SpendTail, Paused: row.Paused + row.Unknown, Source: priceSource(c.Provider, prices[c.ID])}
+ if wire.Harnesses[c.Harness].PartialUsageUnderCounts {
+ s.UnderCount = copyText("usage.spend_undercount")
+ }
v.Spend = append(v.Spend, s)
case u.State != wire.ConnSignedOut:
if len(u.Meters) > 0 {
diff --git a/internal/equipo/usage_page_test.go b/internal/equipo/usage_page_test.go
index 17f8f215..36681455 100644
--- a/internal/equipo/usage_page_test.go
+++ b/internal/equipo/usage_page_test.go
@@ -163,3 +163,42 @@ func TestHoldLineSaysTheReadingsAge(t *testing.T) {
t.Fatalf("a reading with no time: %q", v.Hold.Line)
}
}
+
+// Spend can be under-counted on a harness that reports a request without
+// usage as zero inside a turn's sum (OpenCode, security round finding 3,
+// accepted as a stated gap): the spend source line says so for such a
+// harness's connections, from the harness table, never per provider.
+// Pi's missing usage already makes spend unknown, so TensorX says
+// nothing.
+func TestUsageSpendUnderCountLine(t *testing.T) {
+ conns := append(usageConns(), wire.Connection{ID: "cn_go", LocalID: "opencode-go-1", RunnerID: "r1", Provider: wire.ProviderOpenCodeGo, Kind: wire.KindAPIKey, Harness: wire.HarnessOpenCode, Billing: wire.BillingMetered, State: wire.ConnHealthy, Budget: &wire.Budget{Day: 1_000_000, Month: 10_000_000, Currency: "USD", Revision: 1}, Spend: &wire.Spend{Day: 10_000, Month: 20_000, Currency: "USD"}})
+ byRole, month := usageTotals()
+ month.Prices = append(month.Prices, wire.PriceSource{Connection: "cn_go", PriceVersion: "opencode-go-2026-11-12"})
+ v := usagePage(conns, connLabels(conns, nil), byRole, month, nil, usageNow)
+ spend := map[string]usageSpend{}
+ for _, s := range v.Spend {
+ spend[s.ID] = s
+ }
+ if spend["cn_go"].UnderCount != "Spend may be higher than shown when usage is not reported for a request." || spend["cn_tx"].UnderCount != "" {
+ t.Fatalf("spend %+v", v.Spend)
+ }
+ if !wire.Harnesses[wire.HarnessOpenCode].PartialUsageUnderCounts || wire.Harnesses[wire.HarnessPi].PartialUsageUnderCounts {
+ t.Fatal("the harness table")
+ }
+ var buf bytes.Buffer
+ if err := pages["usage"].ExecuteTemplate(&buf, "content", pageData{Usage: v}); err != nil {
+ t.Fatal(err)
+ }
+ if n := strings.Count(buf.String(), `data-spend-undercount>Spend may be higher than shown`); n != 1 {
+ t.Fatalf("the line shows %d times", n)
+ }
+ // From the harness's facts, whatever the provider: a TensorX
+ // connection on a harness with the gap would say it too.
+ conns[len(conns)-1].Provider, conns[len(conns)-1].Harness = wire.ProviderTensorX, wire.HarnessOpenCode
+ again := usagePage(conns, connLabels(conns, nil), byRole, month, nil, usageNow)
+ for _, s := range again.Spend {
+ if s.ID == "cn_go" && s.UnderCount == "" {
+ t.Fatal("the line follows the provider, not the harness")
+ }
+ }
+}
diff --git a/internal/wire/metered.go b/internal/wire/metered.go
index 8a1152ae..a386e55f 100644
--- a/internal/wire/metered.go
+++ b/internal/wire/metered.go
@@ -73,6 +73,21 @@ var APIKeyProviders = map[string]APIKeyProvider{
ProviderOpenCodeGo: {Name: "OpenCode Go", Harness: HarnessOpenCode, Upstream: "https://opencode.ai", APIPath: "/inference/go/openai/v1", ModelsPath: "/inference/go/v1/models", Endpoint: "https://opencode.ai:443", Currency: "USD"},
}
+// HarnessFacts are what a person is told about a metered harness's
+// reporting. PartialUsageUnderCounts: a request inside a turn that the
+// provider answers without usage counts as zero in the turn's figure, so
+// spend can be under-counted (OpenCode: connectors spec §4.2 and §12).
+// Pi's missing per-message usage makes the spend unknown instead.
+type HarnessFacts struct {
+ PartialUsageUnderCounts bool
+}
+
+// Harnesses are the metered harnesses' facts, by name.
+var Harnesses = map[string]HarnessFacts{
+ HarnessPi: {},
+ HarnessOpenCode: {PartialUsageUnderCounts: true},
+}
+
// BaseURL is the provider's OpenAI-compatible base URL (a harness's
// configuration names it).
func (p APIKeyProvider) BaseURL() string { return p.Upstream + p.APIPath }