feat(opencode): send x-opencode-session header; fix binary-breaking circular import - #14
Open
devilarch wants to merge 2 commits into
Open
feat(opencode): send x-opencode-session header; fix binary-breaking circular import#14devilarch wants to merge 2 commits into
devilarch wants to merge 2 commits into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two changes, both required for the compiled binary to talk to the OpenCode gateway:
1.
x-opencode-sessionheader (main change)OpenCode Go requires the literal
x-opencode-sessionheader since 2026-09-06 for session affinity and prompt caching; requests missing it can fail with400 Model is unavailableand lose sticky routing to the same backend.The opencode-gateway header block in
session/llm/request.tsonly sent the rebrandedx-pentestcode-sessionname, which the gateway does not recognize. This addsx-opencode-session(same stablesessionIDvalue) alongside the existing headers. The singleprepare()choke point covers all transports (chat-completions / responses / anthropic-messages) and both runtimes (AI SDK + native).2. Circular import fix (
core/filesystem)filesystem.tsandfilesystem/search.tsimported each other. Dev ESM resolves the cycle, but the compiled binary evaluates one side first, leavingFileSystemSearch.nodeundefinedwhenfilesystem.tsbuilt its deps array — crashing the layer-graph walk (TypeError: undefined is not an object, evaluating 'a.name'atlayer-node.ts) before any LLM request, so every session failed with "Unexpected server error".search.tsnow importsEntry/FindInput/Matchdirectly from@pentestcode/schema/filesystemand takesGlobInput/GrepInputas a type-only import, removing the runtime back-edge with no behavior change.Verification
bun run typecheckpasses inpackages/coreandpackages/opencodepentestcode run -m opencode-go/omen-alphareplies end-to-end through the gateway (was "Unexpected server error" before)