Skip to content

feat(opencode): send x-opencode-session header; fix binary-breaking circular import - #14

Open
devilarch wants to merge 2 commits into
s0ld13rr:mainfrom
devilarch:opencode-session-header
Open

feat(opencode): send x-opencode-session header; fix binary-breaking circular import#14
devilarch wants to merge 2 commits into
s0ld13rr:mainfrom
devilarch:opencode-session-header

Conversation

@devilarch

Copy link
Copy Markdown

Summary

Two changes, both required for the compiled binary to talk to the OpenCode gateway:

1. x-opencode-session header (main change)

OpenCode Go requires the literal x-opencode-session header since 2026-09-06 for session affinity and prompt caching; requests missing it can fail with 400 Model is unavailable and lose sticky routing to the same backend.

The opencode-gateway header block in session/llm/request.ts only sent the rebranded x-pentestcode-session name, which the gateway does not recognize. This adds x-opencode-session (same stable sessionID value) alongside the existing headers. The single prepare() choke point covers all transports (chat-completions / responses / anthropic-messages) and both runtimes (AI SDK + native).

2. Circular import fix (core/filesystem)

filesystem.ts and filesystem/search.ts imported each other. Dev ESM resolves the cycle, but the compiled binary evaluates one side first, leaving FileSystemSearch.node undefined when filesystem.ts built its deps array — crashing the layer-graph walk (TypeError: undefined is not an object, evaluating 'a.name' at layer-node.ts) before any LLM request, so every session failed with "Unexpected server error".

search.ts now imports Entry/FindInput/Match directly from @pentestcode/schema/filesystem and takes GlobInput/GrepInput as a type-only import, removing the runtime back-edge with no behavior change.

Verification

  • bun run typecheck passes in packages/core and packages/opencode
  • Built single linux-x64 binary; smoke test passes
  • pentestcode run -m opencode-go/omen-alpha replies end-to-end through the gateway (was "Unexpected server error" before)
  • Same failure on every pre-fix binary run; no failures after

…led binary

filesystem.ts and filesystem/search.ts imported each other. ESM dev mode
resolves the cycle, but the compiled binary evaluates one side first and
FileSystemSearch.node was undefined when filesystem.ts built its deps
array, crashing the layer graph walk (TypeError: undefined is not an
object, evaluating 'a.name' at layer-node.ts) before any LLM request.

Import the schema structs (Entry/FindInput/Match) directly from
@pentestcode/schema/filesystem and take GlobInput/GrepInput as a
type-only import so search.ts no longer needs the runtime back-edge.
…finity

OpenCode Go started requiring the literal x-opencode-session header on
2026-09-06 for session affinity and prompt caching; requests missing it
can fail with 400 Model is unavailable. The opencode-gateway header
block here only sent the rebranded x-pentestcode-session name, which
the gateway does not recognize. Add x-opencode-session alongside the
existing headers; the value stays the stable per-session sessionID and
flows to all transports through the single prepare() choke point.
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.

1 participant