Repository navigation
fix(plugin): support stateless generation HTTP hooks - #53990
peeyush-ciridae wants to merge 1 commit into
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 72 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
Companion OAuth plugin registration: ex-machina-co/opencode-anthropic-auth#288. Both changes were verified together against real Haiku 5.5 and 4.5 stateless requests. |
|
The following comment was made by an LLM, it may be inaccurate: |
|
I'm still triaging this pull request; I'll answer here when that's done. |
There was a problem hiding this comment.
I couldn't run this end to end: the Anthropic OAuth case needs real credentials and your companion plugin change. The closest Core, plugin and server tests pass, and Core, plugin and server type-check. The new Core test shows the request and response rewrites reach the wire, and that hooks are scoped to their provider and kept apart from session hooks.
Concerns:
- Built-in providers that add auth in session HTTP hooks still don't work through
ctx.generate.text. Azure Entra (packages/core/src/plugin/provider/azure.ts), Snowflake Cortex and GitHub Copilot add auth or required headers only inctx.session.hook("http.request"). With a separategeneratehook domain, stateless generation for those providers is still sent without those headers, the same failure this PR fixes for Anthropic. Every auth plugin also has to register the same callback twice. Please either register the built-in providers' HTTP hooks forgeneratetoo, or say whether a separate domain is meant to be the design. That choice is the maintainers' call. - The HTTP hook wrapper is copied from the session code (see the inline comment).
- The
Plugin.awaitActivationline inpackages/server/src/handlers/generate.tsduplicates open PR #52887, which fixes #52881 with the same two lines. Leaving it out of this PR, or coordinating with #52887, would keep this PR focused on the hook feature.
| }) | ||
| const requestID = SessionID.create() | ||
| const scope = { requestID, model: resolved.ref } | ||
| const hasHttpHooks = |
There was a problem hiding this comment.
This has/trigger/body-rebuild/response-wrapping block is a line-for-line copy of the session HTTP hook wrapper in packages/core/src/session/model-request.ts (around lines 337–364). The only difference is the hook domain and the scope fields. Two copies of this tricky conversion (body re-encoding, content type, the 204/205/304 null-body statuses, error mapping) will drift apart over time. Could you move it into one shared helper that takes the domain and scope, and use it from both places?
|
Thanks for linking the companion plugin PR and for testing both together against Haiku 5.5 and 4.5. That covers what I couldn't run here. The head commit hasn't changed, so the review's points still apply:
|
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 72-hour window. Feel free to open a new pull request that follows our guidelines. |
Issue for this PR
Reproduced on 2.0.25: Anthropic OAuth Haiku 5.5 works in sessions but fails through
ctx.generate.text//api/experimental/generatebecause stateless generation has no native HTTP hook surface. The provider returns 429Error; OpenCode reports 503. Haiku 4.5 accepts the same untransformed request.Type of change
What does this PR do?
Adds provider-scoped
ctx.generate.hook("http.request" | "http.response", ...)in both plugin APIs and applies them to stateless native HTTP calls. Events expose a request ID and model, without inventing a session or agent. The endpoint also waits for plugin activation before selecting a model, fixing cold-start “Model unavailable” failures.The Anthropic auth plugin must register these hooks separately; this PR does not bake provider-specific authentication into Core.
How did you verify your code works?
bun run check: passed (repository-wide lint warnings remain).bun test test/generate.test.ts test/session-generate.test.ts: 7 passed; verifies request/body and response rewriting, provider scoping, session-hook isolation, and distinct request IDs.bun test: 9 passed. Serverbun test test/generate.test.ts: 1 passed.OKthrough/api/experimental/generate, including the first request after startup. Used a private database snapshot; installed setup unchanged.test attempted network request: POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2022-10-01. Not addressed here.Screenshots / recordings
Not a UI change.
Checklist