Skip to content

fix(core): honor request hook baseURL for AI SDK models - #55996

Open
HootRock wants to merge 3 commits into
anomalyco:devfrom
HootRock:sdk-hook-url
Open

HootRock wants to merge 3 commits into
anomalyco:devfrom
HootRock:sdk-hook-url

Conversation

@HootRock

@HootRock HootRock commented Oct 16, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #55984.

Type of change

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

What does this PR do?

AI SDK routes currently discard route.with({ endpoint: { baseURL } }), so a session model.request hook cannot redirect a request. Clone the route with the requested setting and resolve its SDK model through the existing cache. Expose the configured endpoint to hooks, while retaining SDK defaults when none is configured. Original models and their cached endpoints remain reusable.

How did you verify your code works?

Native Windows / Bun 1.4.2, against dev at 37e3912d8 using an existing dependency runtime:

  • Two focused regressions (166 lines total): one real AI SDK adapter request verifies that route.with({ endpoint: { baseURL } }) changes the URL received by SDK fetch while the original model keeps its URL; one PluginHooks → SessionModelRequest.primary → AI SDK request verifies that a model.request hook redirects the request. Responses are scripted; no provider calls.
  • Both regressions fail on the original aisdk.ts from 37e3912d8 and pass with the fix. Ten randomized repetitions give 20 pass / 0 fail; five nearby AI SDK/model/session test files give 64 pass / 0 fail. These controls use the existing frozen dependency runtime and the repository's core test runner; only aisdk.ts is reversed for the failure control.
  • Core source/test typecheck, scoped oxlint, Prettier and diff checks pass in the existing checkout dependency runtime. Independent review of the test reduction found no actionable defects. Production code is unchanged from f64a7fd; the reduction removes the extra adapter cases, four-kind session matrix, and header/authentication/session-ID/HTTP-hook assertions requested by review.
  • A separate source-CLI end-to-end check at f64a7fd uses frozen dependencies, a private stdio-owned server, a disk-loaded Promise plugin, the real AI SDK bridge and a loopback fake provider. Reversing only aisdk.ts to 37e3912d8 leaves the request at /original/v1/chat/completions; restoring the fix sends it to /replacement/v2/chat/completions. Both controls execute the hook and preserve model/HTTP/session headers; the fixed run renders the fixture reply. The source is restored after the control.

Broader validation at f64a7fd: all 264 core test files were covered in eight bounded, separate-process batches (48 AI SDK/model/provider/session-request files: 560 pass / 0 fail; total: 5,184 pass / 1,220 skip / 277 fail, with no batch timeout). Every tracked core source/test blob matched this head after CRLF normalization. Replaying all 12 failing files on the same source/dependencies, first with only aisdk.ts reversed to 37e3912d8 and then with the fix restored, produced the same 277 failure occurrences in both controls (1,182 pass / 413 skip each). This is a single-module reversal, not a complete base checkout. The failures cover Windows shell/symlink/socket fixtures, snapshot fixtures and the external harness's XDG layout; correcting that layout separately gives 2 passes for the preload contract. No application/test changes were made for these environment failures.

Core source/test typecheck passes. Root bun run check completes lint with 0 errors and SDK documentation checks with 0 problems, then stops on missing Astro and @tsconfig/node22 dependencies in other workspace packages. The partitioned checks do not establish a green single-process full suite, a packaged CLI build or live-provider compatibility.

AI-assisted implementation and review; reviewed and tested locally.

Screenshots / recordings

Not applicable; core request routing.

Checklist

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

Added by the opencode bot (AI-generated).

Public API: the model.request hook's baseURL for AI SDK models is now the configured settings.baseURL (was the placeholder https://ai-sdk.local) and setting it takes effect (backwards compatible)

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@HootRock
HootRock marked this pull request as ready for review October 18, 2026 13:59

@opencode-agent opencode-agent 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 fix works. I ran the #55984 reproduction from source: on the base, the AI SDK request still goes to the original baseURL. With this PR it goes to the baseURL set in the model.request hook, and models without the override keep their original endpoint. The new tests pass here and fail on the base, the nearby AI SDK, session model request and model resolver tests pass, and packages/core type-checks cleanly.

Public API: the model.request session hook's baseURL value changes for AI SDK models. It used to be the placeholder https://ai-sdk.local; it is now the configured settings.baseURL, or undefined if none is set. Setting it now takes effect. This is backwards compatible: no plugin could usefully rely on the placeholder.

The only thing worth changing is the size of the tests: 354 lines for a 26-line fix (see the inline comment).

const chunk =
'data: {"id":"r","object":"chat.completion.chunk","created":0,"model":"api-model","choices":[{"index":0,"delta":{"content":"ok"},"finish_reason":"stop"}]}\n\ndata: [DONE]\n\n'

// Returning the original route from AISDK.route.with must fail the overridden cases.

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.

These two new files add 354 lines of tests for a 26-line fix: three parameterised adapter cases, three more adapter scenarios, and a four-way session test that checks headers, auth, session IDs and HTTP hooks the fix doesn't touch. Could you cut this down to the core cases? One adapter test showing that route.with({ endpoint: { baseURL } }) changes the URL the SDK fetch receives while the original model keeps its URL, plus one session test showing a model.request hook redirecting an AI SDK request. The rest can be dropped, so the change stays small and easy to maintain.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in c92fa95. Reduced the two files from 354 to 166 lines, keeping one adapter URL-override/original-model control and one real session model.request redirect. Removed the extra adapter scenarios, four-kind matrix and unrelated header/auth/session-ID/HTTP-hook assertions; production code is unchanged.

Both retained tests fail with the original aisdk.ts and pass with the fix. Ten randomized repetitions pass (20/20), the five-file nearby set passes (64/64), and core source/test typecheck, scoped lint and formatting pass. Independent review found no actionable defects. The PR description now distinguishes these results from the broader validation on the previous head.

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.

Thanks, this addresses it. I read c92fa95: aisdk.ts is unchanged, and the tests are down to the two core cases. One checks that route.with({ endpoint: { baseURL } }) changes the SDK fetch URL while the original model keeps its URL. The other checks that a session model.request hook redirects an AI SDK request and sees the configured baseURL. Nothing else from my review is outstanding.

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.

model.request hook baseURL is ignored for models loaded through the AI SDK adapter

1 participant