better-auth-fix-resolve-dynamic-baseurl

Based on#9113
SegmentInvestigate-and-fix
Typebug
## Task

Multi-tenant customers running on our dynamic baseURL config
(allowedHosts + protocol) are reporting wrong origins baked into URLs
constructed inside endpoint handlers (ex: verification emails, OAuth
redirects) but only on the server-side code
paths that call our API methods directly instead of going through the
HTTP handler. The HTTP handler resolves the per-tenant origin fine.
The direct programmatic path treats every call like no host info was
provided. Make both paths consistent so the resolved origin follows
the request's host headers either way.

## General instructions

- The code repo is at /repo/better-auth.
- You are inside of a Docker container. You may not be able to perform all operations you would normally be able to do on a local machine. Dependencies have not been pre-installed, and you may need to install them yourself.
- You are expected to act autonomously as a software engineer to complete tasks you are given.
- Do not stop until you feel you have completed the task and your code changes can be merged.
- You may need to use software engineering skills like analyzing the codebase, researching technologies, running services, analyzing logs, etc. to complete the task. Not all tasks will be solvable by reading source code alone.

Agent Results

AgentTastefulBasicVerifierValidationRubricBloatPractTasteCheated
Oracle
7/71.0x5.04.0
Gemini 3.1 Pro
7/70.8x2.02.0
GPT-5.4
7/71.4x3.02.0
GPT-5.5
7/71.4x2.02.0
Gemini 3.5 Flash
6/70.3x3.02.0
Opus 4.7
6/70.6x4.03.0
Opus 4.8
6/70.8x3.02.0
Sonnet 4.6
6/70.2x3.02.0
Sonnet 5
6/70.4x3.02.0
GLM-5.2
3/70.2x3.02.0
Kimi K2.6
2/70.2x3.02.0
No-Op
2/7
Agent details

Verifier Tests

Gemini 3.1 Pro7/7

Taste Scores

Patch Bloat0.8x
154 agent / 192 oracle SLOC, 3 / 4 files(raw: 1.5x)
Practice Alignment — 2.0/5
2
style consistency
2
pattern adherence
3
library usage
2
abstraction level
3
documentation fit
Relative Taste — 2.0/5
2
minimality
2
approach quality
2
hygiene
3
fluency
2
craftsmanship

Agent Patch