Skip to content

refactor(core): share session model requests - #42680

Merged
kitlangton merged 3 commits into
v2from
share-model-request
Aug 20, 2026
Merged

kitlangton merged 3 commits into
v2from
share-model-request

Conversation

@kitlangton

@kitlangton kitlangton commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Route durable Session steps and transient session.generate calls through one SessionModelRequest.prepare boundary 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 similar LLMRequest. 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.ts now accepts a selected Session/model/tool scope plus a caller-built transcript and owns all shared request transformations.
  • packages/core/src/session/runner/llm.ts owns step-limit prompts, tool-call rejection, continuation policy, and prompt-cache sequence diagnostics before/after preparation.
  • packages/core/src/session/generate-node.ts owns preview-history selection and the private user prompt, then calls llm.generate with the shared prepared request and options.
  • Merged with current v2: the shared preparation stage now also carries the model.request plugin 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.
  • HTTP-hook coverage verifies transient generation forwards middleware through LLMClient.generate.
  • A patch changeset records the @opencode-ai/core behavior change.

Scope

  • V2 only; packages/opencode is unchanged.
  • No Protocol, Server HttpApi, or generated-client changes.
  • No changes to durable Session history or transient generation persistence semantics.
  • Stateful Session WebSocket transport remains exclusive to durable runner calls.

Testing

  • cd packages/core && bun typecheck
  • cd packages/core && bun run build
  • cd 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)
  • Full Core suite review run: 1,794 passed, 16 skipped
  • Push hook: 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
Loading

# ------------------------ >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
kitlangton enabled auto-merge (squash) August 20, 2026 02:30
@kitlangton
kitlangton merged commit ea7fa43 into v2 Aug 20, 2026
10 checks passed
@kitlangton
kitlangton deleted the share-model-request branch August 20, 2026 02:33
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant