Repository navigation
refactor(core): share session model requests - #42680
Merged
Merged
Conversation
# ------------------------ >8 ------------------------ # Do not modify or remove the line above. # Everything below it will be ignored. # # Conflicts: # packages/core/src/session/generate-node.ts # packages/core/src/session/model-request.ts # packages/core/src/session/runner/llm.ts # packages/core/test/session-generate.test.ts
kitlangton
enabled auto-merge (squash)
August 20, 2026 02:30
This was referenced Aug 20, 2026
jinhuang712
pushed a commit
to jinhuang712/opencode
that referenced
this pull request
Sep 26, 2026
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.
What
Route durable Session steps and transient
session.generatecalls through oneSessionModelRequest.prepareboundary for provider-visible request shaping.Transient generation now receives the same context-hook tool reconciliation, unsupported-media handling, image bounds, Session headers, prompt-cache identity, and HTTP request/response hooks as normal Session execution.
Before / After
Before: the runner used
SessionModelRequest.prepare, while transient generation independently rebuilt a similarLLMRequest. The generation path omitted media compatibility, image bounding, HTTP hooks, identity-aware renamed-tool reconciliation, and shared transport policy.After: callers select their own transcript, then pass
{ scope, transcript, toolChoice, webSocket }into the shared preparation stage. Both paths produce requests through the same provider-visible transformations. Durable runner calls explicitly opt into the stateful per-Session WebSocket channel; transient generation remains HTTP-only and cannot mutate or contend for runner transport checkpoints.How
packages/core/src/session/model-request.tsnow accepts a selected Session/model/tool scope plus a caller-built transcript and owns all shared request transformations.packages/core/src/session/runner/llm.tsowns step-limit prompts, tool-call rejection, continuation policy, and prompt-cache sequence diagnostics before/after preparation.packages/core/src/session/generate-node.tsowns preview-history selection and the private user prompt, then callsllm.generatewith the shared prepared request and options.v2: the shared preparation stage now also carries themodel.requestplugin hook (fix(core): prefer websocket with request hooks #43234) and fork-aware prompt cache keys (both previously duplicated per path), so transient generation inherits those too.LLMClient.generate.@opencode-ai/corebehavior change.Scope
packages/opencodeis unchanged.HttpApi, or generated-client changes.Testing
cd packages/core && bun typecheckcd packages/core && bun run buildcd packages/core && bun run test test/session-model-request.test.ts test/session-generate.test.ts test/session-runner.test.ts(157 passed, 534 assertions)bun turbo typecheck --concurrency=3(33 packages passed)Flow
sequenceDiagram participant Caller as Runner / Generate participant Prepare as SessionModelRequest.prepare participant Hooks as Plugin hooks participant LLM as LLMClient Caller->>Caller: Select transcript and execution policy Caller->>Prepare: scope + transcript + toolChoice + WebSocket policy Prepare->>Hooks: session.context Hooks-->>Prepare: transformed system, messages, tools Prepare->>Prepare: reconcile tools and normalize media Prepare-->>Caller: canonical request + HTTP/transport options Caller->>LLM: stream or generate