Repository navigation
Conversation
…uests
The V2 plugin registered its bootstrap injector only on
ctx.session.hook('context'). OpenCode 2 prepares each model request kind
through its own hook: normal agent turns through `context`, the
compaction (summary) request through `compaction`, and session-scoped
one-shot generation through `generate`
(packages/core/src/session/model-request.ts). Every built-in V2 plugin
registers its handler on all three, and the upstream V1 migration guide
says to do the same when a transform must apply to every request kind.
So the compaction request's first user message lacked the bootstrap
that every prior turn carried, and the prompt diverged right after
system + tools. On a provider with prefix caching that is a cold
re-prefill of the whole session on its largest request (#2391).
Reproduced on real OpenCode 2.1.2 and 2.1.3 with a scripted stub model
that pushes the session over the compaction ceiling: before, the
compaction request shares 26.5k of 30.8k serialized chars with the
previous agent request and differs at the first user message; after,
the previous request is a full prefix of the compaction request.
The handler body is unchanged (child-session skip, idempotence guard,
checkpoint-only append), lifted into a named function and registered on
all three hooks, each in its own try/catch. Based on PR #2409.
Fixes #2391
Co-authored-by: Aashish <145881415+aashish254@users.noreply.github.com>
Claude-Session: https://claude.ai/code/session_01SHANcr4A71nzuU9et4Fnba
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.
Who is submitting this PR? (required)
claude-opus-5-5)What your human partner asked you to do, in their words:
The orchestrating Claude Code session turned that into a brief for a subagent working in its own git worktree, using real OpenCode V1/V2 binaries and a local stub provider. The subagent reproduced, fixed and drafted this description. An independent code-review subagent then reviewed the branch before it was opened.
Human-authored summary (required, under 200 words)
Pending: Jesse (@obra) will write this section before the PR is reviewed.
What problem are you trying to solve?
#2391 (@tpischke): on OpenCode 2, the compaction request's first user message lacks the bootstrap that every normal turn carries. The prompt diverges right after system + tools, so prefix caching misses on the largest request of the session (the reporter measured 8,192 of 199,112 tokens cached and a 510 s prefill). I reproduced it on real OpenCode 2.1.2 and 2.1.3 by driving a session into automatic compaction with a scripted stub model. Before the fix, the compaction request shares 26.5k of 30.8k serialized chars with the previous agent request and differs at the first user message.
What does this PR change?
Registers the V2 bootstrap injector on the
compactionandgeneratesession hooks as well ascontext, with the handler body unchanged. Adds a hook-registration test and updates the two docs that named onlycontext.Is this change appropriate for the core library?
Yes. It's a cost and latency bug in the OpenCode V2 integration core ships, and it hits every V2 user whose session compacts.
What alternatives did you consider?
compactiononly (the reporter's patch): this leavesgenerate, which is built from the same session transcript (session/generate.ts), with the same prefix break. Upstream's built-ins and migration guide register all three.title: title requests build their own prompt and shouldn't carry the bootstrap.Does this PR contain multiple unrelated changes?
No.
Existing PRs
main), whose diff this PR is built on, with co-author credit to @aashish254. opencode: re-inject bootstrap after compaction #2283 (open) addresses a different V1 compaction problem.Environments tested
@opencode/cli)New harness support (required if this PR adds a new harness)
Not applicable. This PR adds no harness.
Evaluation
Probe the project files, with a stub model that reports 95k prompt tokens on a declared 100k window, so the host compacts automatically.Rigor
superpowers:writing-skillsand completed adversarial pressure testing (not a skills change)Human review
Merge note: conflicts with #2600
#2600 (#2197) and this PR both touch the V2 bootstrap guard. Whichever lands second hits one conflict hunk inside the V2 hook body. Resolve it by taking this PR's hunk and replacing
p.text.includes('EXTREMELY_IMPORTANT')with #2600'sp.text.startsWith(BOOTSTRAP_MARKER). The V1 guard and the constant merge cleanly. A trial merge resolved this way passestests/opencode/run-tests.sh(5/5). Landing both matters: once compaction carries the bootstrap, a summary that quotesEXTREMELY_IMPORTANTwould trip the old substring guard.https://claude.ai/code/session_01SHANcr4A71nzuU9et4Fnba