Skip to content

fix(session): bound /btw side-question snapshot to recent messages - #2051

Open
YOMXXX wants to merge 2 commits into
XiaomiMiMo:mainfrom
YOMXXX:fix/btw-side-question-context
Open

fix(session): bound /btw side-question snapshot to recent messages#2051
YOMXXX wants to merge 2 commits into
XiaomiMiMo:mainfrom
YOMXXX:fix/btw-side-question-context

Conversation

@YOMXXX

@YOMXXX YOMXXX commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1855. /btw <question> is marketed as a "side question without context cost", but forkQuery (packages/opencode/src/tool/session.ts) passed the entire session history to buildPrefix, so the fork's prompt was the full session (observed 1M+ input tokens on ~300k-token sessions → empty answer / hang).

Fix: bound the side-question snapshot to the most recent MAX_FORK_QUERY_MESSAGES (12) messages, while guaranteeing the last user message stays in the window (buildLLMRequestPrefix dies without a user message — an uncatchable defect).

  • sliceSideQuestionContext(msgs, max, mustInclude?) — new helper: normally the last max messages; extends to include the last matching element (the last user message) if it would otherwise be cut off.
  • forkQuery passes (m) => m.info.role === "user" as the predicate.
  • watermark (session boundary) and agent identity stay computed from the full session — only the snapshot content is bounded.
  • Covers all side-ask paths (session.ask route + session ask tool op both call forkQuery).

The fork's prompt is [...forkCtx.inheritedMessages, ...ownNewModelMsgs] and does not re-pull history, so bounding inheritedMessages bounds the fork.

Test Plan

  • New unit tests: sliceSideQuestionContext bounds to last max; keeps all under cap; preserves order; extends window to include the last user message when the tail has none; stays bounded when the tail already contains a user message.
  • bun test test/tool/session-side-question.test.ts — 5 pass.
  • bun typecheck — clean.

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.

/btw (session.ask) can send multi-million-token prompts on ~300k sessions; empty answer, not "without context cost"

1 participant