oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1# S5 progress: OpenCode on OpenCode Go
2
3Branch `connections-s5-opencode` from main f5d1d677 (S1 to S4 merged).
4Spec: `docs/superpowers/specs/2026-11-12-equipo-connectors-and-token-scheduling.md`
5revision 3.2, §11 row S5: §0 decision 7 (Go stays metered), §2.1 to
6§2.3 (S1's guard; the Go row of the limit table), §3 (isolation,
7containment, pinning, mapping, families, acceptance), §4.2, §4.4's
8OpenCode row, and round 3 findings 5, 8 and 9. The controller's
92026-11-12 note: keep S1's single-model pick; S5b generalises models.
10
11No real key, no sign-in, no real provider. The real pinned OpenCode
122.2.7 ran only against a fake OpenCode Go on 127.0.0.1 (TLS as
13opencode.ai under a test authority), through the real relay, in the real
14bubblewrap namespace.
15
16## Probes
17
18- **OC-P1, passed.** OpenCode runs a whole step with only `opencode.ai`
19 reachable: `TestOpenCodeP1OnlyOpenCodeReachable` (a Review through
20 Equipo's MCP tool; every request was Go's chat completions with the
21 key; the relay refused no connection during the step; another host is
22 refused). Bun honours `HTTPS_PROXY` and `NODE_EXTRA_CA_CERTS`. The
23 OpenAI-compatible provider is bundled in the binary: no npm fetch.
24 With `OPENCODE_DISABLE_MODELS_FETCH` left out, the catalogue fetch is
25 refused at the relay (mutation R2).
26- **OC-P2, a stdio mode exists, so the bridge is not built.** `opencode
27 acp` speaks the Agent Client Protocol (JSON-RPC, one message per line)
28 on stdio: `session/new`, `session/load` (replays history first),
29 `session/prompt` (answered at the turn's end with `stopReason` and the
30 turn's `usage`), `session/update` (text chunks, tool calls),
31 `session/request_permission`, `session/cancel`. `serve --stdio` is not
32 a transport: it prints the loopback URL and serves HTTP. Every OpenCode
33 test drives `acp`.
34- **OC-P3, the allowance does not reach OpenCode's events.** Go's
35 `opencode.allowance` (and `billing_source`) were in every fake answer
36 and in none of OpenCode's ACP messages
37 (`TestOpenCodeP3AllowanceNotInEvents`). Headroom is "not reported".
38- **OC-P4, the figure is the turn's own.** ACP's prompt answer carries
39 the turn's usage summed over its requests, not the session's running
40 total: one request 60/7/40, then a two-request turn 120/14/80
41 (`TestOpenCodeP4UsagePerTurn`). (The serve API's
42 `session.usage.updated` replaces the session's totals, so it is
43 cumulative; it is not used.) `inputTokens` is the uncached part;
44 `outputTokens` excludes reasoning, so the tally adds `thoughtTokens`
45 into output (Go bills reasoning as output).
46
47## Found on the way
48
49- OpenCode makes a hidden **title-generation request** per session whose
50 usage is not in the turn's. `agents.title.disabled: true` stops it
51 (`disable` does not: v2 reads `disabled`); the summary agent and
52 automatic compaction (`compaction.auto: false`) are off too; warming is
53 off unless configured. OC-P1 counts the requests (mutation R4).
54- Missing usage is **zero, not absent**: OpenCode coerces every figure a
55 provider did not give to 0. A turn whose input (uncached, cached and
56 written) is zero is counted as not reported, so the connection pauses.
57 A provider dropping usage on only some requests of a multi-request
58 turn would under-count undetected: stated, not mitigated (§12's
59 "reported usage can be wrong").
60- A rejected permission ends the turn `cancelled` (usage still
61 reported). No role's rules ever ask.
62- The host's `/etc/opencode` overrides user configuration: masked with a
63 tmpfs for OpenCode launches.
64
65## Done
66
671. Wire (3e722df7). Protocol 17, `ProtocolOpenCode`: provider
68 `opencode-go`, harness `opencode`. Below 17 Encode drops that
69 provider's held connections (hello, sync) and usage rows (usage, step,
70 answer, reply) and refuses a connect or connection report about it,
71 checked against the frozen protocol 16 provider and harness sets.
72 S5 first took 16; main's publishing took 16 first, so the merge
73 renumbered S5 to 17. Encode's chain runs OpenCode's step (below 17),
74 then publish's (below 16), then every older step in order.
75 `APIKeyProvider` gains `ModelsPath`, `BaseURL`, `CompletionsURL`,
76 `ModelsURL`. OpenCode Go is neither PerToken nor Overflow: always
77 metered, a pay-as-you-go confirmation refused.
782. Egress: `(opencode, opencode-go)` to `opencode.ai` only. Prices:
79 `opencode-go-2026-11-12`, the Go page's per-model prices
80 (opencode.ai/docs/console/go/, "Token prices", read 2026-11-12) for
81 its chat-completions models; cache writes priced only where Go states
82 a price; DeepSeek at its peak price; free, Responses, Messages and
83 Gemini models unpriced (spend unknown, not offered). Probe client:
84 models at `/inference/go/v1/models`, completions at
85 `/inference/go/openai/v1/chat/completions`. Capability matrix: opencode
86 for Engineering and Review, never the coordinator or Research.
873. Pinning (dba19e50), `internal/runner/provider/opencode`: the committed
88 `npm/package.json` and `package-lock.json` pin `@opencode/cli` 2.2.7 by
89 its integrity and every platform package by theirs. npm cannot install
90 it as pinned (`--ignore-scripts` pulls all four linux-x64 variants,
91 about 1 GB, as npm records no libc; `--omit=optional` gets no binary),
92 so the installer fetches exactly `@opencode/cli` and this platform's
93 binary package by the lockfile's URLs, checks each against the
94 lockfile's sha512 integrity before unpacking, unpacks regular files and
95 directories only, runs no script, seals, and holds the tree
96 (per-platform digest) and the binary (SHA-256, amd64
97 `589253d3…`, arm64 `c577783e…`) to the committed pins. `equipo-runner
98 install-opencode <root>` prints `EQUIPO_OPENCODE_ROOT`; install and
99 `verify-installed` hold it to its pins. CI's box installs the same at
100 `/opt/equipo-opencode` (Python, the same digests, held to the code by
101 `TestBoxOpenCodeMatchesTheCode`); testci fingerprints it.
1024. The policy (`opencode-v1`, `provider/opencode_policy.go`): argv
103 `/opt/opencode acp`; environment `XDG_*` in the runtime home and
104 `OPENCODE_DISABLE_PROJECT_CONFIG`, `_CLAUDE_CODE`, `_MODELS_FETCH`,
105 `_AUTOUPDATE`, `_FREE_MODELS`, `_FILEWATCHER`; `opencode.json`
106 rebuilt from provider, model, tools and role and accepted exactly (no
107 other file beside it): updates off, one provider under Equipo's own id
108 (`equipo`, never the catalogue's `opencode-go`) with the bundled
109 OpenAI-compatible package, the table's base URL and the key by its
110 variable, one model, title and summary off, compaction off, Equipo's
111 MCP server, and permissions that start with a deny of everything,
112 allow the role's tools and end with explicit denies (`subagent`,
113 `skill`, `question`, `webfetch`, `websearch`, `execute`,
114 `external_directory`, image generation; and `edit`, `shell` for a
115 read-only role). Only the binary is mounted; the tree is hashed when
116 the policy is built, the binary (streamed) at build, attestation and,
117 through the descriptor bubblewrap mounts, at the mount. The key reaches
118 the namespace as `OPENCODE_GO_API_KEY` through the `--args` pipe.
1195. The adapter: an ACP client (LF framing, 8 MiB message cap, 16 MiB
120 queue budget, writes that give up with their context), a decoder (text
121 chunks to `delta`; a tool call to `tool_call` at its first update that
122 carries its arguments, its end to `tool_result`; a permission request
123 to `ask`; the prompt's answer to `usage` and `done` with
124 completed/interrupted/failed and the class: `-32000` auth,
125 `provider.rate-limit` and Go's budget limits quota; updates before the
126 turn, such as a load's replay, and other sessions' dropped; unknown
127 kinds counted by name), Pi's tally, and a `provider.Launcher` that
128 checks the version (2.2.7) and the session's model option. Kept
129 sessions are OpenCode's database, copied without following links.
130 `fakeopencode` reproduces the recorded protocol
131 (`provider/opencode/testdata`, from the real binary); a fake Go serves
132 the real-binary tests.
1336. The runner (404c85b3): one metered step path for Pi and OpenCode; the
134 prepared launch is what differs. OpenCode names its own session (taken
135 from Open), resumed by `session/load`. A metered step whose harness is
136 not installed is refused before admission. OpenCode Go connections are
137 metered bindings, scheduled with OpenCode's capability; Review's
138 family is the model that ran (`glm-5.3` is glm).
1397. The instance (677e91a0): the Add page offers OpenCode Go with its
140 required confirmation, Go's limit wording and page, and no
141 pay-as-you-go confirmation; an OpenCode Go connection to a runner below
142 17 is refused (`runner_too_old`) and never sent. Names: "OpenCode Go",
143 harness "OpenCode".
144
145## Tests
146
147- `internal/wire`: `TestEncodeBelowProtocol17DropsOpenCode`, `TestEncodeMixedVersionsOpenCodeAndPublish`, `TestOpenCodeGoProvider`.
148- `internal/runner/egress`: `TestEgressTableKeyedByHarnessAndProvider` (OpenCode rows).
149- `internal/runner/metered`: `TestOpenCodeGoPrices`.
150- `internal/runner/connect`: `TestAPIClientModelsPath`, `TestCapableOpenCode`.
151- `internal/runner/provider`: `TestOpenCodePolicyIsolatedConfiguration`, `TestOpenCodePolicyRefusals`, `TestOpenCodePolicyAttestation`, `TestOpenCodeLaunchSecretEnv`.
152- `internal/runner/provider/opencode`: `TestLockfilePinsOpenCode`, `TestInstallFromArchives`, `TestPinnedInstallVerifies`, `TestDecodeRecordedRuns`, `TestDecodeOnlyTheTurn`, `TestDecodeUnknownMessages`, `TestDecodeUsage`, `TestDecodeClipsToolArguments`, `TestFamilyFromModel`, `TestClientWritesAreCancellable`, `TestClientQueueIsBounded`, `TestLauncherInterruptIsBounded`, `TestKeepSessionRefusesLinks`, `TestOpenCodeFakeReviewInNamespace`; the real pinned OpenCode: `TestOpenCodeP1OnlyOpenCodeReachable`, `TestOpenCodeP3AllowanceNotInEvents`, `TestOpenCodeP4UsagePerTurn`, `TestOpenCodeAcceptanceHostileRepository`, `TestOpenCodeAStepCanReadTheKey`, `TestOpenCodeDescendantTermination`, `TestOpenCodeKeptSessionResumes`.
153- `internal/runner/thin`: `TestOpenCodeReviewStep`, `TestOpenCodeReviewWithoutLeaveToSpend`, `TestOpenCodeBudgetHoldsTheNextStep`, `TestOpenCodeNoUsagePausesTheConnection`, `TestOpenCodeKeyRefused`, `TestOpenCodeAskKeptSession`, `TestOpenCodeEngineeringRun`, `TestOpenCodeRedactsTheKey`, `TestOpenCodeNotInstalled`, `TestAPIKeyOpenCodeGoConnect`, and the finish line `TestOpenCodeStepsRealOpenCode`; the Pi tests unchanged on the shared path.
154- `internal/thintest`: `TestContractOpenCodeGoConnection`.
155- `internal/testci`: `TestBoxOpenCodeMatchesTheCode`. `cmd/equipo-runner`: `TestVerifyInstalledHoldsEveryProgramToTheRelease` (OpenCode root), `TestInstallOpenCodeArguments`.
156- `internal/headless` (`-tags browser`, CI only): `TestBrowserConnectionsOpenCodeGoLimitRequired`.
157
158The §3 acceptance for the OpenCode cells: the hostile repository loads
159nothing (`TestOpenCodeAcceptanceHostileRepository`: project and
160`.opencode` configuration, plugins, agents, commands, skills in
161`.opencode`, `.claude`, `.agents` and a home-level `~/.claude`,
162`AGENTS.md`, `CLAUDE.md`); only the provider host is reachable (OC-P1);
163Review has no write or shell tool (the hostile test: shell and edit
164refused without an ask; the offered tools); killing the namespace ends
165every descendant (`TestOpenCodeDescendantTermination`); the budget stops
166the next step (`TestOpenCodeBudgetHoldsTheNextStep`); a step with no
167usage pauses the connection (`TestOpenCodeNoUsagePausesTheConnection`); a
168resent usage row charges once (`TestOpenCodeReviewStep`); and, stated as
169§2.1 says, a step can read the key (`TestOpenCodeAStepCanReadTheKey`).
170
171Local runs were targeted (`-run`), with `-tags testbuild` where the
172seams are needed and the real-binary tests against a local pinned
173install (`EQUIPO_OPENCODE_ROOT`, made by the installer from the
174registry's tarballs); plus gofmt, go vet, staticcheck on the changed
175packages, the darwin runner build, gitleaks on the staged changes,
176`rastrillo budget size` and the dead-reference scan. The browser test
177was not run locally (headless lane).
178
179## Mutations, each observed failing
180
181W1 to W5 were taken at protocol 16, before the renumbering to 17.
182
183- wire W1: hello's OpenCode Go connections kept below 16 -> TestEncodeBelowProtocol16DropsOpenCode (hello at 15 names provider "opencode-go")
184- wire W2: a step report's OpenCode Go usage rows kept below 16 -> TestEncodeBelowProtocol16DropsOpenCode (step at 15 names provider "opencode-go")
185- wire W3: an OpenCode Go connect encoded below 16 -> TestEncodeBelowProtocol16DropsOpenCode (connect encoded at 15)
186- wire W4: an OpenCode Go connection report encoded below 16 -> TestEncodeBelowProtocol16DropsOpenCode (connection encoded at 15)
187- wire W5: the protocol 16 step skipped -> TestEncodeBelowProtocol16DropsOpenCode (hello at 15)
188- wire W6: OpenCode Go as an overflow subscription (a pay-as-you-go confirmation makes it a subscription) -> TestOpenCodeGoProvider (not always metered)
189- egress E1: no (opencode, opencode-go) route -> TestEgressTableKeyedByHarnessAndProvider (failed before the row, observed first)
190- prices X1: no OpenCode Go table -> TestOpenCodeGoPrices (failed before the table, observed first)
191- connect A1: the model list read under the completions path -> TestAPIClientModelsPath (failed before ModelsPath, observed first)
192- choose C1: opencode not in the Engineering and Review rows -> TestCapableOpenCode (failed before the matrix row, observed first)
193- policy P1: a read-only role allowed edit or shell -> TestOpenCodePolicyRefusals (review with shell accepted)
194- policy P2: the config not compared with Equipo's rebuilt one -> TestOpenCodePolicyRefusals (a plugin accepted)
195- policy P3: other files beside opencode.json accepted -> TestOpenCodePolicyRefusals (a second config file accepted)
196- policy P4: attestation not reading the config again -> TestOpenCodePolicyAttestation (a changed config attested)
197- policy P5: attestation not hashing the binary again -> TestOpenCodePolicyAttestation (a replaced binary attested)
198- policy P6: the binary's digest not compared at build -> TestOpenCodePolicyRefusals (another binary accepted)
199- policy P7: OPENCODE_DISABLE_PROJECT_CONFIG left out -> TestOpenCodePolicyIsolatedConfiguration (env)
200- policy P8: the title agent left on -> TestOpenCodePolicyIsolatedConfiguration (agents), TestOpenCodePolicyRefusals (the title agent on accepted)
201- policy P9: no leading deny of everything -> TestOpenCodePolicyIsolatedConfiguration (an unnamed action asks)
202- policy P10: Review's explicit edit and shell denies dropped -> TestOpenCodePolicyIsolatedConfiguration (review's last rules). First version of the test MISSED it by reading effects only (the leading deny still denies); the explicit-rule check was added before the mutation run
203- policy P11: a binary outside the tree accepted -> TestOpenCodePolicyRefusals (a binary outside the tree accepted)
204- policy P13: the selection's model not compared -> TestOpenCodePolicyAttestation (another model attested)
205- policy P12: the session a launch resumes not compared -> TestOpenCodePolicyAttestation (a resumed session attested)
206- install I1: an install held to no tree pin left in place -> TestInstallFromArchives (an install that did not verify was left)
207- decode D1: tool-call updates parsed with content as an object (as first written) -> TestDecodeRecordedRuns (no tool_result: a real update's content is a list). A real bug, found by the recordings
208- containment N1: OpenCode's key variable not in the secret allowlist (as first written) -> TestOpenCodeFakeReviewInNamespace (namespace_mount_rejected). A real bug
209- containment N2: the binary hashed through the O_PATH descriptor directly (as first written) -> TestOpenCodeFakeReviewInNamespace (namespace_mount_rejected). A real bug, fixed by reading /proc/self/fd/N
210- real R1: OPENCODE_DISABLE_PROJECT_CONFIG left out -> TestOpenCodeAcceptanceHostileRepository (provider_identity_mismatch: the repository's opencode.json chose its own model)
211- real R2: OPENCODE_DISABLE_MODELS_FETCH left out -> TestOpenCodeP1OnlyOpenCodeReachable (the relay refused connections during the step). First version of the probe MISSED it (the fetch never reaches the fake Go); the relay's denial count was added, then caught
212- real R3: OPENCODE_DISABLE_CLAUDE_CODE left out -> MISSED, twice: neither the repository's .claude and CLAUDE.md nor a home-level ~/.claude planted in the runtime home is read by 2.2.7 once project configuration is off. Kept as defence in depth; no test can observe it today
213- real R4: the title agent left on -> TestOpenCodeP1OnlyOpenCodeReachable (3 requests: a title request whose usage the turn does not report)
214- real R5: Review allowed shell -> TestOpenCodeAcceptanceHostileRepository (shell in a Review ran)
215- real R6: updates decoded before the turn starts (session/load's replay) -> TestOpenCodeKeptSessionResumes (the replayed history taken as this turn's). First caught by a nil-map panic; the decoder was made robust so the assertion catches it
216- thin T1: the connect client without Go's models path -> TestAPIKeyOpenCodeGoConnect (no model card: the list was looked for under the completions path)
217- thin T2: OpenCode connections not among a person's metered bindings -> TestOpenCodeReviewStep (held, never run)
218- thin T3: the binding's family by Pi's rule -> TestOpenCodeEngineeringRun, TestAPIKeyOpenCodeGoConnect (family ""). First run against TestOpenCodeReviewStep MISSED it: the report's family is the model that ran's, by the harness's own rule
219- thin T4: OpenCode's own session id not taken from Open -> TestOpenCodeReviewStep, TestOpenCodeAskKeptSession (not kept, not askable)
220- thin T5: a resumed launch without its ResumeSessionID -> TestOpenCodeAskKeptSession (provider_policy_rejected at attestation)
221- thin T6: a metered step admitted with its harness absent -> TestOpenCodeNotInstalled (charged, slot claimed). A real bug, found by writing the test: the step was admitted, then failed
222- thin T7: the OpenCode branch of the launch preparation removed -> TestOpenCodeReviewStep (account_unavailable)
223- cmd V1: verify-installed not holding the OpenCode root to its pins -> TestVerifyInstalledHoldsEveryProgramToTheRelease (verified with an empty OpenCode root)
224- box B1: the box's arm64 tree pin not the code's -> TestBoxOpenCodeMatchesTheCode (the box installs another tree)
225- instance I1: an OpenCode Go connect accepted for a protocol 15 runner -> TestContractOpenCodeGoConnection (a protocol 15 runner accepted). The test failed before the instance check, observed first
226- instance I2: OpenCode Go not offered on the Add page -> TestContractOpenCodeGoConnection (the Add page does not offer OpenCode Go)
227- instance I3: no docs link for Go's limits -> TestContractOpenCodeGoConnection (the form lacks Go's page)
228- instance I4: OpenCode Go taking a pay-as-you-go confirmation (Overflow) -> TestContractOpenCodeGoConnection (pay-as-you-go off confirmed: accepted). First runs of I2 to I4 failed for the test's own reason (an Expect's cancelled context dropped the fake runner); the test was reordered and all four rerun
229- client K1: a write that waits for OpenCode however long -> TestClientWritesAreCancellable (hangs to the test timeout at the write)
230- client K2: the client's byte budget off -> TestClientQueueIsBounded (2420 bytes queued against 300)
231- interrupt K3: TestLauncherInterruptIsBounded first failed for the test's own reason (an unbuffered pipe blocked the prompt); the stuck process now reads the prompt, as a real pipe's buffer would
232
233## Decisions where the spec was open
234
235- **ACP, no bridge** (OC-P2), as §4.2 says when a stdio mode exists. The
236 serve API's per-step events would have let a zero be caught per
237 request; ACP gives the turn's sum. The gap is stated above.
238- **Hidden model calls off by configuration**, held by the exact-config
239 check: title and summary agents, automatic compaction. A session that
240 overflows its context then fails rather than compacting.
241- **Go is always metered** with no pay-as-you-go confirmation offered.
242 Note for Paul: Go's page now names an "Extra Usage" switch ("you can
243 turn it off or on again on the Go page", said for Go Teams; not said
244 for Go or Go Plus). If his plan has it, a later change could offer the
245 overflow-off confirmation (§0 decision 7); not built.
246- **The install runs no npm and no Node**: the lockfile is committed and
247 its integrities are what the installer checks; the tree is the two
248 packages, sealed.
249- **Only the binary is mounted** (`/opt/opencode`); the tree is held to
250 its digest when the policy is built.
251- **The x64 build needs AVX2**; the baseline and musl builds are not
252 pinned.
253- **Equipo's provider id is `equipo`**, so OpenCode's own catalogue entry
254 for Go can never merge in; models are named `equipo/<id>`.
255- **Prices**: list prices from the Go page; within its plan Go reports
256 `cost: 0`, so the larger-of rule charges the list price. DeepSeek at
257 peak. The free models, and models Go serves only on Responses,
258 Messages or Gemini's API, are unpriced and not offered.
259- **Review's file tools are confined to `/workspace`** by denying
260 `external_directory` (Engineering too; its shell is the namespace's).
261- **A refused permission ends OpenCode's turn**: no role's rules ask, so
262 a step never meets one.
263- **Families** from the model's name: glm, kimi, deepseek, qwen, minimax,
264 mimo, longcat, step, and hy3/hy4 as hunyuan.
265- **The key variable** is `OPENCODE_GO_API_KEY`.
266- **Protocol 17** for the new provider; usage rows of it are dropped, not
267 refused, below 17 (spend stays on the runner's ledger).
268
269## Copy: delegated review (Astra, 2026-11-12)
270
271The four strings went through Astra as the copy-review gate (Paul's
272delegation of 2026-10-25): two kept, two changed, applied verbatim, each
273now `COPY ACCEPTED BY DELEGATION (Astra, 2026-11-12)` in `copy.go` and in
274the Plan 3 inventory. No test quotes them.
275
276- `chat.connections.opencode-go`: OpenCode Go
277- `chat.connections.opencode-go_desc`: Open-weight models on your Go plan, billed per token.
278- `chat.connections.metered.limit_how.opencode-go`: At OpenCode Go, your plan sets limits for each model. With Extra Usage on, further use draws on your Console balance. Keep that balance at what you are willing to spend.
279- `chat.connections.metered.limit_docs.opencode-go`: How OpenCode Go limits work
280
281## Staging witness (Paul)
282
2831. On the staging runner: `equipo-runner install-opencode
284 /home/<runner>/.local/share/equipo-runner/opencode`, add the printed
285 `EQUIPO_OPENCODE_ROOT` to the service environment, `equipo-runner
286 verify-installed`, restart the unit.
2872. Paul adds OpenCode Go in Settings, Connections, Add a connection: ticks
288 "This key has a spending limit at OpenCode Go" (Extra Usage off, or a
289 small Console balance), keeps $1 and $10, pastes a key from
290 opencode.ai/console, picks `glm-5.3`; the one-token probe makes it
291 Ready and shows on its spend line.
2923. A small task on a test repository, marked urgent (or Run now on a held
293 step), with Claude and Codex limited or absent for Engineering: the
294 Engineering step runs on Go. Witness: its usage row with `cost_micros`
295 and the spend line moved by it; the runner log shows no egress denial
296 and no `opencode unknown events` line (or names them).
2974. A Review on a Go model: with Engineering on Claude, Review goes to
298 another family and runs on Go; family glm, label `other_family`.
2995. Ask the Review a question: it answers from its session, on Go,
300 charged. Check again on the connection, then sign out.
301
302## Open
303
304- The staging witness above (Paul's key, a release).
305- The browser test runs in CI only.
306- No full headless scenario runs an OpenCode step; the finish line runs
307 real steps in thin with real containment.
308- Mac runners: OpenCode stays parked, as Pi.
309
310## Security round (Astra, read-only, on 5aac73ca)
311
312Verdict NOT READY: eight mechanical findings, fixed here, each with a
313test written first and a mutation observed; one design finding (#3)
314left to the controller with facts, behaviour unchanged.
315
3161. Session copying followed parent links (`opencode/home.go`): the kept
317 database is read beneath the runtime home's own descriptor (openat2
318 `RESOLVE_BENEATH`, no link in any component; macOS `O_NOFOLLOW_ANY`),
319 and restoring reads the keep directory the same way.
320 `TestKeepSessionRefusesLinkedDirectories`.
3212. The binary lost S2's filesystem checks after the policy
322 (`opencode_policy.go`, `containment/mounts.go`): at the policy, the
323 attestation and the mount (through the descriptor bubblewrap mounts)
324 the binary is held to its seal as well as its bytes: a regular file
325 root or this user owns, one name, not writable, every ancestor safe.
326 `TestOpenCodeBinaryStaysSealed`,
327 `TestNamespaceOpenCodeBinaryAfterAttestation` (rewritten, made
328 writable, a second name, replaced with other sealed bytes).
3294. The reported cost was discarded (`opencode/decode.go`): the decoder
330 keeps the session's cumulative cost from `usage_update`, between turns
331 too; a turn's reported cost is what it added from its baseline, so the
332 larger-of rule charges it. `session/load` reports no cost (probed on
333 the real binary), so keeping a session records its cost so far beside
334 the database and a resumed launch starts from it; with none recorded
335 the whole session cost counts as the turn's, never less. A cost that is
336 not a finite, non-negative USD amount, or goes down, makes the turn's
337 usage uncountable. `TestDecodeReportedCost`,
338 `TestOpenCodeReportedCostCharged` (a step charged $0.50 reported over
339 the table's few micro-dollars; a question on its kept session charged
340 the $0.20 it added).
3415. Unbounded goroutines and retained bytes (`opencode/acp.go`,
342 `launcher.go`, `decode.go`): one writer goroutine and a queue of 32;
343 `Send` gives up with its context or the shutdown; unsupported requests
344 are refused through `TrySend`, or dropped and counted when the queue is
345 full; pending permission requests capped at 64; tool ids at 256 bytes;
346 kept calls at 1024 and their arguments at 4 MiB in total.
347 `TestClientWritesAreBounded`, `TestLauncherRequestsAreBounded`,
348 `TestDecodeBoundsRetainedCalls`.
3496. Startup ignored cancellation (`thin/pistep.go`): both launchers gain
350 `OpenWithin(lifetime, startup)`; the step passes its own context with
351 one deadline shared by the start and the run, so a start that never
352 answers ends as cancelled or step_timeout, the attempt's kill and proof
353 unchanged. `TestOpenCodeStartupCancellable`.
3547. Readers blocked forever after the consumer left (`launcher.go`,
355 `acp.go`): `Close` shuts the session down; its reader stops however
356 full its events are, the client's however full its queue or channel,
357 and the writer closes OpenCode's stdin so a blocked write ends.
358 `TestClientShutdownWithFullQueues`, `TestLauncherCloseFreesTheReader`.
3598. Stray traffic on opencode.ai was invisible (`fakeopencode/gofake.go`):
360 the fake Go records every request before routing; OC-P1 asserts every
361 one is a POST to Go's chat completions. Sharing: 2.2.7's config has
362 `share` (manual, auto, disabled), pinned to disabled and held by the
363 exact-config check. Telemetry: 2.2.7 has no telemetry setting; its
364 only exporter is OTLP, started only when `OTEL_EXPORTER_OTLP_ENDPOINT`
365 is set, which no launch can carry (the containment admits the
366 policy's variables only). `TestGoRecordsEveryRequest`.
3679. Hostile marks went to a host path (`opencode/real_test.go`): marks go
368 to `/home/runner`, the writable runtime home; a control proves a mark
369 left in the namespace is seen; each source of configuration has its
370 own subtest. `TestOpenCodeAcceptanceHostileRepository`.
371
372Mutations observed:
373
374- S1a: session files opened by path with O_NOFOLLOW on the last component only (as it was) -> TestKeepSessionRefusesLinkedDirectories (.local, share and opencode linked: a host database kept; restored through a linked kept directory). The test failed before the fix, observed first
375- S2a: the binary held to its bytes only (as it was), at attestation -> TestOpenCodeBinaryStaysSealed (made writable, a second name, an ancestor others can write: attested). Observed first
376- S2b: the same, at the mount through the descriptor -> TestNamespaceOpenCodeBinaryAfterAttestation (writable, second name: a binary changed after its attestation was mounted)
377- S4a: the turn's reported cost not taken (as it was) -> TestDecodeReportedCost (first turn: cost 0), TestOpenCodeReportedCostCharged (failed before the fix, observed first)
378- S4b: the turn's cost not measured from its baseline -> TestDecodeReportedCost (first turn: 0.35, the session's whole cost)
379- S4c: a cost that goes down accepted -> TestDecodeReportedCost (down: counted)
380- S4d: a resumed launch without its kept baseline -> TestOpenCodeReportedCostCharged (the question charged 0.70, the session's whole cost)
381- S4e: the session's cost not recorded when kept (read after Close, as first written) -> TestOpenCodeReportedCostCharged (charged 0.70). A real bug in the first fix, found by the test
382- S5a: a goroutine per write (TrySend as an unbounded spawn) -> TestClientWritesAreBounded (goroutines 4 then 9971). The test did not compile before the fix, observed first
383- S5b: pending permission requests unbounded -> TestLauncherRequestsAreBounded (5001 pending asks)
384- S5c: arguments kept without a total -> TestDecodeBoundsRetainedCalls (62928896 bytes in 1024 calls)
385- S5d: tool ids of any length kept -> TestDecodeBoundsRetainedCalls (a long id kept)
386- S7a: the session's event send without the shutdown escape -> TestLauncherCloseFreesTheReader (321 events after Close). First MISSED: the test read events after Close, which unblocks the reader; it now drains only after Close and holds the count to the channel's capacity
387- S7b: the client's message send without the shutdown escape -> TestClientShutdownWithFullQueues (the 1 MiB budget case: the reader never ends). First MISSED twice: the small budget blocks in take before the channel fills, and draining Messages unblocks the reader; a large-budget case nobody reads was added, checked by the goroutine count
388- S7c: the byte-budget wait without the shutdown check -> TestClientShutdownWithFullQueues (timed out)
389- S7d: Shutdown not closing stdin (the writer blocked forever) -> TestClientShutdownWithFullQueues (goroutines 4, before 3). First MISSED: the caller was freed but nothing checked the writer goroutine; the goroutine count was added
390- S6a: the start bounded only by the attempt's lifetime (as it was) -> TestOpenCodeStartupCancellable (cancelled and deadline: each waited the 90 s start bound; the test failed before the fix, observed first; under the mutation it hit the test timeout)
391- S8a: the fake Go recording only the paths it serves (as it was) -> TestGoRecordsEveryRequest (only the models list seen). The test failed before the fix, observed first; OC-P1 now asserts every recorded request is a POST to Go's chat completions
392- S8b: sharing not pinned off -> TestOpenCodePolicyIsolatedConfiguration (config keys), TestOpenCodePolicyRefusals (sharing left out: accepted). Observed first
393- S9a: OPENCODE_DISABLE_PROJECT_CONFIG left out -> TestOpenCodeAcceptanceHostileRepository: project config and .opencode directory (provider_identity_mismatch: the repository chose its own model), context files (AGENTS.md reached the model)
394- S9b: Review allowed edit and shell -> the same test's project config, .opencode directory and context files subtests (edit and shell offered)
395- S9c: the marks looked for outside the namespace's mounts (as the finding describes) -> the same test's control, "a mark is seen" (no mark seen)
396- S9d: OPENCODE_DISABLE_CLAUDE_CODE left out -> still MISSED with each source on its own: 2.2.7 reads neither the repository's nor the home's Claude Code files once project configuration is off. Kept as defence in depth
397
398### Finding 3: per-request usage, the facts (no behaviour changed)
399
400Probed on the real 2.2.7 with the fake Go answering one request of a
401two-request turn without usage (`TestOpenCodePartialUsageFacts` records
402it):
403
404- **ACP carries no per-request usage.** The prompt's answer has the
405 turn's sum: 60/7/40, `Complete`, for a turn whose second request had no
406 figure. `usage_update` gives the context size and the session's
407 cumulative cost only. 2.2.7 never sends ACP's `session_message` updates
408 (the schema is the SDK's; no code emits them), and
409 `opencode/child-session-updates` is about subagent sessions.
410- **The session database has it.** `session_message` holds one
411 `assistant` row per request, in `seq` order after the turn's `user`
412 row, each with `tokens {input, output, reasoning, cache {read, write}}`
413 and `finish`; the request without usage is stored with every token 0
414 (`input 0, cache.read 0`), beside its sibling's 60/7/40. The `event`
415 table is empty (events are not stored). `session_v2` keeps only
416 cumulative totals.
417- **Options and their cost:**
418 - **A. Read the database after termination** (about a day): copy
419 `opencode.db` and its journal out of the runtime home beneath its
420 descriptor (finding 1's way), size-capped, into runner scratch; open
421 the copy read-only with `modernc.org/sqlite` (already in go.mod, pure
422 Go); take the `assistant` rows after the turn's last `user` row; any
423 with input, cache read and cache write all 0 makes the turn's spend
424 unknown. One prompt per launch keeps the turn boundary simple. The
425 table and JSON shape are 2.2.7's internals (pinned; a real-binary test
426 would catch drift on a bump). The file is the model's to write in
427 Engineering; that is no new exposure, as a step can already spend the
428 key (§2.1), but parsing a hostile SQLite file wants a time and size
429 bound.
430 - **B. The serve API through the bridge** (several days): per-step
431 `session.step.ended` events carry the step's tokens and `native`
432 provider data; that is §4.2's bridge, not built since OC-P2 found ACP.
433 - **C. Count requests at the relay** (not viable): the relay sees TLS
434 tunnels, not requests (keep-alive and HTTP/2 multiplex them).
435 - **D. Infer the request count from tool calls** (heuristic only):
436 parallel tool calls share one request, so the count is not exact.
437
438## Controller follow-up (2026-11-12)
439
440### 1. Protocol 17
441
442Main took protocol 16 for website publishing (`ProtocolPublish`), so
443S5 takes 17: `ProtocolOpenCode = Protocol17`, with `ProtocolCurrent`
444moving to it. That renumber landed on main with S5's squash
445(5880ab10), along with its mixed-version tests:
446`TestEncodeBelowProtocol17DropsOpenCode` checks every frame at 16 and
44715, `TestEncodeMixedVersionsOpenCodeAndPublish`, and the contract test's
448older runners at 16 and 15. This follow-up branch
449(`connections-s5-undercount`) carries only items 2 and 3 and adds no
450wire change. The branch's own renumber was dropped, since main's covers
451everything it had: its hello test with the sites capability and an
452OpenCode Go connection is covered by the mixed-version test's hello at
45316 and at 15.
454
455### 2. Finding 3: the gap accepted and stated
456
457The controller's ruling: option 1, accept the stated gap; option A (read
458the per-request rows from `OPENCODE_DB` after the attempt) is the slice
459after S5b, not built here.
460
461- The spec says it: §2.3's OpenCode bullet, §4.2 ("Usage as built"),
462 §12 ("OpenCode can under-count a turn"), and a line in its history.
463- The Usage page's spend source line gains a line (below) for a connection whose harness has
464 the gap. It comes from data: `wire.Harnesses` holds each metered
465 harness's facts, `PartialUsageUnderCounts` true for OpenCode, false
466 for Pi, and the page reads the connection's harness, never its
467 provider. `TestUsageSpendUnderCountLine` (OpenCode Go shows it once;
468 TensorX does not; a connection on a harness with the gap shows it
469 whatever its provider).
470- **Why not Pi on TensorX:** Pi reports usage per request
471 (`message_end.usage`), and the tally (S2's security round, finding 3)
472 makes the whole attempt's figures unknown when any message has no
473 usage, no input or output, or a negative figure. A missing figure
474 there is spend unknown, which pauses the connection; it is never a
475 smaller sum. OpenCode's ACP gives only the turn's sum, in which
476 OpenCode has already turned a missing figure into zeros.
477
478Mutations observed:
479
480- U1: the line keyed on the provider -> TestUsageSpendUnderCountLine (the line follows the provider, not the harness)
481- U2: Pi given the gap -> TestUsageSpendUnderCountLine (TensorX shows the line)
482- U3: the line dropped from the page -> TestUsageSpendUnderCountLine (the line shows 0 times)
483
484### 3. Copy: delegated review (Astra, 2026-11-12)
485
486The new string went through Astra as the copy-review gate and was
487changed; applied verbatim, marked `COPY ACCEPTED BY DELEGATION (Astra,
4882026-11-12)` in `copy.go` and the Plan 3 inventory; the page test quotes
489it.
490
491- `usage.spend_undercount`: Spend may be higher than shown when usage is not reported for a request.
492