summaryrefslogtreecommitdiff
path: root/tests/opencode/test-hook-registration.mjs
AgeCommit message (Collapse)Author
2026-10-22fix(opencode): inject the V2 bootstrap on compaction and generate requestsJesse Vincent
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