Skip to content

fix(opencode): send x-opencode-session header to OpenCode Go provider - #15

Closed
Usman0220 wants to merge 1 commit into
s0ld13rr:mainfrom
Usman0220:fix/opencode-go-session-header
Closed

Usman0220 wants to merge 1 commit into
s0ld13rr:mainfrom
Usman0220:fix/opencode-go-session-header

Conversation

@Usman0220

Copy link
Copy Markdown

Summary

OpenCode Go began enforcing the x-opencode-session header on 2026-09-05 to optimize routing and prompt caching. Every request made through the built-in opencode-go provider is now rejected:

AI_APICallError: Request is missing x-opencode-session and cannot be routed efficiently.

Upstream OpenCode (v1.18.x) works against the same endpoint because it sends the header natively per session. This PR ports those send points into pentestcode.

Changes

  • packages/opencode/src/session/llm/request.ts — replace the x-pentestcode-* headers with the canonical x-opencode-* headers (x-opencode-session, x-opencode-request, x-opencode-client, x-opencode-project) for all opencode* providers, and apply x-parent-session-id uniformly across both provider branches (matches upstream anomalyco/opencode behavior).
  • packages/core/src/session/runner/llm.ts — add the missing http.headers send point (x-session-affinity, X-Session-Id, x-parent-session-id) so auxiliary/runner requests carry the session too, including x-opencode-session when the model provider is opencode*.

Why not keep x-pentestcode-*?

The x-pentestcode-* headers were only produced in request.ts and consumed nowhere in this repo — swapping them for the upstream x-opencode-* names is safe and fixes routing to https://opencode.ai/zen/go/v1.

Testing

  • Built from source (bun run build --single --skip-embed-web-ui), smoke test passed.
  • Requests to opencode-go/* models now carry a stable per-conversation session ID in x-opencode-session.

s0ld13rr added a commit that referenced this pull request Oct 2, 2026
…d binary

- Rename x-pentestcode-* headers to x-opencode-* in request.ts (the old
  names were never consumed by any server)
- Add session/affinity headers to core runner LLM path (auxiliary requests
  now carry x-opencode-session for OpenCode Go provider routing)
- Move x-parent-session-id to apply to both opencode and non-opencode
  provider branches
- Break circular import between filesystem/search.ts and filesystem.ts
  by importing Entry/FindInput/Match directly from @pentestcode/schema;
  fixes "Unexpected server error" crash in compiled binaries where the
  cycle left FileSystemSearch.node undefined

Closes #13
Based on contributions from PR #14 (devilarch) and PR #15 (Usman0220)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@s0ld13rr

s0ld13rr commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Thanks for the thorough fix, @Usman0220! Your approach of renaming all headers to x-opencode-* and adding the core runner headers was the right call.

I've merged a combined fix in 6cfd111 that takes your header approach plus the circular import fix from PR #14. Both contributors credited in the commit message.

@s0ld13rr s0ld13rr closed this Oct 2, 2026
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.

2 participants