Skip to content

feat(plugin): let http.request hooks answer a request - #67635

Open
nv-nedelman-1 wants to merge 1 commit into
anomalyco:devfrom
nv-nedelman-1:nedelman/http-request-response
Open

nv-nedelman-1 wants to merge 1 commit into
anomalyco:devfrom
nv-nedelman-1:nedelman/http-request-response

Conversation

@nv-nedelman-1

@nv-nedelman-1 nv-nedelman-1 commented Dec 2, 2026 •

Copy link
Copy Markdown

Issue for this PR

Addresses #65198

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Plugins can block a tool call (execute.before can fail with Tool.Error), but there's no analogous way to block or
locally answer a model request. An http.request hook can only throw, ending the turn with an unknown error and
skipping the retry handling.

To that end, this PR adds an optional response to the http.request event. If a hook sets it, the request is not sent and the provided response is used directly.

Implementation details:

  • http.response hooks still run/the response then gets normal handling, so OpenCode and other plugins treat it like a provider's response
  • The event starts with response: undefined so plugins can detect support via "response" in event
  • When no hook sets it, behavior remains the same

How did you verify your code works?

  • Local pre-push checks
  • New test in packages/core/test/session-model-request-hooks.test.ts passes locally. checks that the hook's response comes back, the request is never sent, and http.response hooks see the answer.
  • Wrote a plugin that uses the new field to short-circuit model requests; tested it out locally and OpenCode reports a provider error.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.


Added by the opencode bot (AI-generated).

Fixes #65198

Public API: adds optional response to the http.request session hook event in the Promise and Effect plugin APIs (backwards compatible)

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change works as described. I set a 429 as event.response from an http.request hook and streamed through the real LLM client. Nothing was sent over the network, and the stream failed with a RateLimit AI.Error, the same as a real provider 429. That is what lets the retry hook fall back to another provider, as #65198 asks. The hook runs inside the HTTP layer, before status codes are turned into errors, so a local answer gets the same error handling and x-should-retry checks as a real response. session-model-request-hooks.test.ts passes, and tsc --noEmit is clean for packages/core and packages/plugin.

Public API: it adds an optional response?: Response to SessionHttpRequest (http.request hook event) in both @opencode/plugin (Promise) and @opencode/plugin/effect. This is additive, so existing plugins are unaffected.

One thing worth adding: the plugin docs (services/site/src/docs/content/build/plugins/server.mdx, the "Native HTTP" section and the hook type listing) don't mention the new field yet. They should say that setting it skips the request and that http.response hooks still run. They should also note it has no effect for providers that stream over a WebSocket, since http.request never sees that traffic.

Fixes #65198

@dhaern

dhaern commented Dec 2, 2026

Copy link
Copy Markdown

Dont forget auto thumbs up your initial comment or this will get closed in 1 month because devs here ignores 99% things... you need 2 votes

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugins: http.request quota refusals bypass session.retry

2 participants