Skip to content

fix(client): add system text to compaction and generate requests - #54

Merged
Codestz merged 1 commit into
mainfrom
fix/system-text-every-request
Oct 31, 2026
Merged

Codestz merged 1 commit into
mainfrom
fix/system-text-every-request

Conversation

@Codestz

@Codestz Codestz commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Fixes #53.

On OpenCode 2, Cockpit's agent halves (Review, Shell, Trail) added their system text only through the session context hook. OpenCode builds compaction and generate (warming) requests through separate compaction and generate hooks, so those requests had a different system block and missed the provider's prompt cache. OpenCode fixed the same problem in its own plugins in anomalyco/opencode#48749.

Change

  • dualServer registers the same handler on context, compaction and generate.
  • V2ServerContext.session.hook now accepts all three names.

The hook split landed before OpenCode 2.0.0, so every 2.x release has it. OpenCode 1 is unchanged.

Verified

  • Unit: the v2 setup test now checks that all three hooks are registered and that each one adds the text.
  • End to end on OpenCode 2.0.18, with a scratch plugin logging each request's system block after every hook ran. Steps: send a prompt, then call session.compact.
primary compaction
main 9 parts 4 parts, different hash
this branch 9 parts 9 parts, same hash

bun run check: 2,554 pass, 0 fail.

OpenCode 2 builds compaction and generate (warming) requests through
their own session hooks, not context. Registering only on context left
those requests with a shorter system block, so they missed the
provider's prompt cache and prefilled the conversation again.

Fixes #53
@Codestz
Codestz merged commit ef97013 into main Oct 31, 2026
2 checks passed
@Codestz
Codestz deleted the fix/system-text-every-request branch October 31, 2026 17:01
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.

Review's system text is missing from compaction and warming requests, which breaks prompt caching

1 participant