Repository navigation
Commit 69cc714
authored
fix: send x-opencode-session for OpenCode Go requests (#349)
## Requirement or Bug
OpenCode Go models fail in the desktop app and the CLI with `400 Request
is missing x-opencode-session and cannot be routed efficiently`.
## Bug Reproduction Steps
1. Configure an OpenCode Go provider (base URL
`https://opencode.ai/zen/go/v1`) with an API key.
2. Send any message in a session.
3. The model request fails with the 400 above.
## Root Cause
OpenCode Go requires a stable session id in the `x-opencode-session`
header for each conversation
([docs](https://opencode.ai/docs/go/#where-can-i-use-it)). The engine
only built this header in the legacy `kosong/model` requester. Requests
now go through the `llm-adapter` requester, which never sent it. Even
the legacy path read `conversationId`, which no turn sets; turns set
only `cacheKey` (the session id). This is a fundamental fix.
## Code Changes
- `llm-adapter/model/model-requester-impl.ts`: merge
`x-opencode-session: <cacheKey>` into the model default headers when the
base URL is an `https://` `opencode.ai` host.
- `llm-adapter/model/catalog-service.ts`: the connectivity ping sends a
random session id, so the settings "test connection" works against
OpenCode.
- Move `opencodeSession.ts` into
`llm-adapter/model/opencode-session.ts`; the legacy requester imports it
from there and falls back to `cacheKey`.
## Behavior Changes and Affected Users
| Behavior | Before | After | Who relies on the old behavior | Escape
hatch |
| --- | --- | --- | --- | --- |
| Requests to `https://*.opencode.ai` | No session header; Go rejects
them with 400 | `x-opencode-session` is the session id (a header the
user set in provider config wins); the ping probe uses a random id |
Nobody (requests failed) | None needed |
| Requests to every other provider | Unchanged | Unchanged (the helper
returns no header for other hosts) | n/a | n/a |
Tests: `test/llm-adapter/model/modelRequester.test.ts` adds two cases
(header sent to OpenCode; not sent to other hosts or without a session
id). The first case fails without the fix.
## Checklist
- [x] I have read the
[CONTRIBUTING](https://github.com/PyModel/pythinker-code/blob/main/CONTRIBUTING.md)
document.
- [ ] I have linked a related issue (external PRs: issue must have a
maintainer's `/approve`).
- [x] I have added tests that prove my feature works.
- [x] The behavior-change table above is complete, and every removed
behavior or flipped default is named in the changeset and either has an
escape hatch or was explicitly approved by a maintainer in this PR.
- [x] Ran `gen-changesets` skill, or this PR needs no changeset.
- [x] Ran `gen-docs` skill, or this PR needs no doc update.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Fixed OpenCode Go requests that could fail when the required session
header was missing.
* Requests now include a session header when applicable, while
preserving an existing session header.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent bca1910 commit 69cc714
6 files changed
Lines changed: 75 additions & 4 deletions
File tree
- .changeset
- packages/agent-core-v2
- src
- kosong/model
- llm-adapter/model
- test/llm-adapter/model
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
96 | 99 | | |
97 | 100 | | |
98 | 101 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
171 | 173 | | |
172 | 174 | | |
173 | 175 | | |
174 | | - | |
| 176 | + | |
175 | 177 | | |
176 | 178 | | |
177 | 179 | | |
| |||
Lines changed: 18 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
159 | 161 | | |
160 | 162 | | |
161 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
162 | 170 | | |
163 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
164 | 181 | | |
165 | 182 | | |
166 | 183 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
Lines changed: 39 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
467 | 467 | | |
468 | 468 | | |
469 | 469 | | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
0 commit comments