fix(opencode): send CLI identity + x-opencode-session on background calls - #13005
alvinveroy wants to merge 7 commits into
Conversation
|
Clean, well-scoped fix — I traced the two background call sites |
…alls Discovery (PROVIDER_MODELS_CONFIG) and quota-fetch background calls went out as bare 'Bun fetch' with no x-opencode-session, so opencode.ai hard-errors them (announced for 2026-09-06). Add buildOpencodeBackgroundHeaders() and use it from the discovery entries and the quota fetcher so background calls carry the stable conversation-scoped identity the operator sends.
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
…with connection-id fallback Discovery's readOpencodeBackgroundSeed only read 'opencodeGoWorkspaceId', but the providerSpecificData validator accepts three spellings (openCodeGoWorkspaceId / opencodeGoWorkspaceId / workspaceId). A connection using either of the other two silently fell through to the helper's randomUUID fallback — a fresh anonymous x-opencode-session per discovery call, exactly the shape the operator warning targets. Read all three spellings, then fall back to the connection id so a workspace-less connection still gets a deterministic per-connection session instead of a random one. Add id to ProviderModelsHeaderContext (the route spreads the full connection row, so it is already present). Tests fail on branch HEAD (2 of 8) and pass after the fix.
a768868 to
98bde55
Compare
|
Both asks answered on 1. The new authHeader: "Authorization",
authPrefix: "Bearer ",
headers: { "Content-Type": "application/json" },— a plain Bearer fetch with no 2. Changelog fragment — One correction for your records: the branch carries 8 tests, not 6 ( |
Resolves the two conflicts in providerModelsConfig.ts — independent additions at the same spots (this PR's OpenCode identity-header discovery entry; the base's xai-oauth live-discovery flag from the release); kept both. typecheck:core clean. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
The release added a lockstep set mirroring PROVIDER_MODELS_CONFIG's keys after this branch was cut; the new 'opencode' entry needs its twin there (discovery-class + xai-oauth-discovery lockstep tests). Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
|
Re-homed to |
Conflict in open-sse/utils/opencodeHeaders.ts: upstream canonicalized the x-opencode-request/x-opencode-session ids emitted by applyCliDefaults (msg_/ses_ shapes); this branch adds buildOpencodeBackgroundHeaders after it. Kept upstream's canonicalization and the background-headers helper below it; the helper's seed-based session override still wins.
…elper The base's applyCliDefaults now canonicalizes x-opencode-request/-session (msg_/ses_ shapes). Seed the session BEFORE calling it so the canonicalizer derives the deterministic ses_ id from the raw workspace/connection seed, instead of overwriting with a bare 16-hex fingerprint afterwards. The suite now asserts the canonical shapes on the request id, the seeded and seedless sessions, and the discovery headers.
|
Refreshed onto the latest |
What
OpenCode background calls — model discovery (
PROVIDER_MODELS_CONFIG) and the quota fetcher — went out as bareBun fetchwith nox-opencode-session, which is exactly the shape OpenCode's operator warning names (enforcement announced from 2026-09-06).Change
Add
buildOpencodeBackgroundHeaders()(User-Agent +x-opencode-session/request/client/project, stable per-workspace seed) and use it from the opencode-family discovery entries and the quota fetcher so background calls carry the same conversation-scoped identity the operator sends.open-sse/utils/opencodeHeaders.ts— addbuildOpencodeBackgroundHeaders.src/app/api/providers/[id]/models/discovery/providerModelsConfig.ts— build opencode/zen/go discovery entries with the identity headers.open-sse/services/opencodeQuotaFetcher.ts— attach the headers to quota calls.tests/unit/opencode-background-identity-headers.test.ts— regression.CI failures on this repo are pre-existing (not from this change)
The default branch
release/v3.8.51has failing CI independent of this PR:open-sse/handlers/chatCore.ts TS2339 (baseline 0, live 13)— a typecheck regression on the default branch, in a file this PR does not touch.test:unit:ci:shard(includes an expired Perplexity session cookie401), on unrelated PRs.This PR does not modify
open-sse/handlers/chatCore.tsand introduces no new typecheck diagnostics.