OpenCode 2.4.4 lets plugins mock model replies for repeatable agent tests
OpenCode server plugins can now supply a model HTTP response before a request leaves the process. That gives plugin authors a repeatable way to test how the coding agent handles rate limits and tool calls.
OpenCode 2.4.4, released December 3, lets a server plugin answer a model HTTP request before OpenCode sends it to the provider. For plugin authors and teams testing coding workflows in CI, that means a test can produce the same rate limit on every run and check what OpenCode does next. The new capability is part of the existing request hook. Set event.response on the outgoing request event, and OpenCode uses that response locally. OpenCode v2.4.4 release notes

The mock goes through OpenCode’s response handling
The implementation pull request explains the difference between supplying a response and throwing from the request hook. A thrown error previously ended the turn with an unknown error and skipped retry handling. A supplied response still goes through http.response hooks and normal response handling. The contributor reported a regression test that checks whether OpenCode returns the supplied response, skips sending the original request, and passes the supplied response to response hooks. When no request hook supplies a response, the usual request path continues. OpenCode pull request #67635
That placement makes an HTTP 429 a useful first fixture. A bot review comment on the merged pull request reports that a local 429 went through the model client’s streaming path and surfaced as a rate-limit error. The plugin docs put the retry hook after error classification and before retry scheduling. A test can therefore assert that rate-limit classification happened and then check the retry decision separately. If the test expects a second attempt or a fallback, record that outcome explicitly. Seeing a 429 alone establishes only what the first attempt received. Implementation discussion · OpenCode server plugin docs
What to assert in CI
Start with one session, one HTTP model route, and one expected request. Scope the mock to that case and count how often it supplies the fixture. For a rate-limit test, also record the classified error and retry decision. A failed assertion can then distinguish a fixture that never matched from a retry hook that was reached and made the wrong decision. Track outbound calls to the mocked provider too, so a live response cannot accidentally satisfy the test.
| Case | Fixture | Assertion |
|---|---|---|
| Rate limit ends the turn | HTTP 429 on the first attempt | OpenCode classifies the response as a rate limit and the test’s retry policy stops the turn. |
| Retry recovers | HTTP 429, then a valid response for the selected protocol | The expected follow-up attempt consumes the second fixture and the turn completes. |
| Agent handles a tool call | A provider-format stream containing one call to a test tool, followed by a completion fixture | The tool receives the expected arguments and the session consumes its result before completing. |
The release changelog lists mocks as a use for the hook. The tool-call case above is a proposed test design. Use a read-only test tool with a fixed result, such as one that returns a value from an in-memory fixture. Create a fresh response for each matching request because the docs describe HTTP bodies as one-shot streams. Keep the fixture in the selected provider’s format, including its streaming events if the route streams. The supplied response controls what OpenCode receives, so the test can establish how OpenCode handles that tool call. A live-model evaluation can separately measure whether the model chooses the tool on its own. OpenCode changelog · Guide to replaying an LLM stream through two adapters
Check which transport the test actually exercises
The server docs say native WebSocket traffic bypasses the HTTP request and response hooks. If a WebSocket route falls back to HTTP, the resulting HTTP request can reach the hook. For a test intended to exercise HTTP response handling, verify that the fixture was consumed on the expected attempt. This matters when the same server also issues auxiliary requests such as title generation or compaction. The HTTP hook’s event.kind distinguishes those requests from primary agent-loop traffic, so a test for a coding turn can target the request it intends to exercise. OpenCode server plugin docs