Skip to content

refactor(core): share oauth loopback server and provider attribution table - #67216

Merged
kitlangton merged 1 commit into
devfrom
share-oauth-providers
Nov 30, 2026
Merged

kitlangton merged 1 commit into
devfrom
share-oauth-providers

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Provider sign-in callback servers and attribution headers each live in one place now.
Five browser logins built their own copy of the same loopback HTTP server; six provider plugins repeated the same header transform. Nothing changes for users.

❌ Before

  1. MCP, GitLab, Poe, Snowflake and DigitalOcean each created a node:http server, listened on their own port, turned EADDRINUSE into their own message, closed the server when the login ended, and — except DigitalOcean — hashed their own PKCE challenge.
  2. Cerebras, Kilo, LLM Gateway, NVIDIA, OpenRouter and Zenmux each matched an endpoint and stamped attribution headers in a separate near-identical plugin.

✅ After

  1. oauth/loopback.ts owns the listener, the preferred/fallback port rules, the taken-port message, PKCE, and the callback answer page.
  2. provider/attribution.ts describes each provider as a table row (match, headers, userWins, plus the LLM Gateway and OpenRouter extras) and builds the same six plugins, with the same ids and registration slots.
  3. 🟰 Behavior change: none. Every provider keeps its port, its taken-port message, its callback status codes, its header precedence, and its model-alias rule.
- createServer(handler) + listen(port) + addFinalizer(close)   ×5 providers
+ listenLoopback({ port, fallbackPort, inUse, handler })        ×5 providers

- six plugins, each: for each provider -> if package/baseURL match -> stamp headers
+ one table: { match, headers, userWins, configuredOnly, disabledModels }
+ the same six plugins built from its rows

📊 Numbers (against origin/dev)

Area Added Deleted Net
packages/core/src 342 359 −17
packages/core/test 7 9 −2
modules 2 shared 6 deleted −4 files

No tests were added: the existing suites pin the moved behavior, and their only change is the import path of the six provider plugins.

👀 Read: loopback.ts — its port fallback (preferred → port from an earlier registration → ephemeral, with fallback only for the middle case), and the finalizer registered before listening so cancelling between listen and listening still releases the port. Then the userWins merge in attribution.ts. Those are the places a provider could drift. Azure keeps its own refresh loop on purpose: ProviderRefresh.start applies state only after a load finishes and takes a single reload, so it cannot drop the previous resource's deployments and reload providers before discovery runs, which the Azure tests observe. The rest is routine.

Found in a structural cleanup pass · no user reports · line counts from git diff --numstat origin/dev...HEAD

Checks run
  • bun run test test/mcp in packages/core: 146 pass
  • targeted provider suites (gitlab, gitlab-oauth, poe, snowflake-cortex, kilo, zenmux, nvidia, cerebras, llmgateway, openrouter, azure): 147 pass across 13 files
  • bun run test test/plugin/provider-digitalocean.test.ts: 6 fail on this machine, exactly as at origin/dev (Bun binds localhost to ::1 while fetch resolves it to 127.0.0.1); all 13 pass when the test listener is pointed at 127.0.0.1
  • bun typecheck and bun run typecheck:tsc in packages/core: clean
  • bun run check from the repo root: 37/37 tasks
  • prettier --check on every changed file: clean

@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.

I found no problems with this refactor. I compared each removed attribution plugin with its row in the new table: matching, header precedence (Zenmux fills headers in, NVIDIA keeps only the user's billing header, the rest overwrite), the LLM Gateway active/configured checks and OpenRouter's hidden aliases are all unchanged. The five login servers keep their host, port rules, taken-port message and connection closing. A small script against listenLoopback confirmed the custom taken-port message, the raw error without one, the ephemeral fallback, the server being closed once the login ends, and the PKCE lengths. The MCP and provider suites give the same results as on dev: 234 pass and the same 12 environment-related failures (port 8080 is already in use on this machine, plus one unrelated process-kill test). typecheck:tsc is clean.

The public API is unchanged: only internal @opencode/core modules move, and the plugin ids and registration order stay the same.

@kitlangton
kitlangton merged commit f12235c into dev Nov 30, 2026
11 checks passed
@kitlangton
kitlangton deleted the share-oauth-providers branch November 30, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant