GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(session): fire system.transform before messages.transform by ualtinok · Pull Request #19961 · anomalyco/opencode

Conversation

@ualtinok

@ualtinok ualtinok commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #19960

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Reorders the plugin hook execution so experimental.chat.system.transform fires before experimental.chat.messages.transform. Previously, messages.transform ran first in prompt.ts while system.transform ran later inside llm.ts — plugins couldn't inspect the final system prompt when mutating messages.

The system prompt assembly (agent prompt + env + skills + instructions + user.system) and the system.transform hook + header caching logic were extracted from llm.ts into shared helpers (LLM.buildSystem, LLM.transformSystem). These are now called in prompt.ts before messages.transform, and llm.ts receives the already-finalized system prompt.

Also adds sessionID and model to the messages.transform input (previously empty {}), so plugins can correlate transformations across hooks.

agent.ts's independent system.transform call (for agent generation) is unchanged — different code path.

How did you verify your code works?

  • Typecheck passes clean
  • Full test suite: 1625 pass, 0 fail, 8 skip (identical to dev baseline)
  • Verified LLM.buildSystem produces the same system prompt shape as the old inline assembly in llm.ts
  • Verified LLM.transformSystem preserves the header caching rejoin behavior

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BrianAguilarWasco, chrisolszewski, codelonesomest, and elmagow reacted with heart emoji
All reactions
  • ❤️ 4 reactions
@github-actions github-actions Bot added the contributor label Mar 29, 2026
@github-actions github-actions Bot mentioned this pull request Mar 30, 2026
fix(opencode): keep dynamic user.system separate for prompt caching #20109
Closed
3 of 6 tasks
@ualtinok
ualtinok force-pushed the fix/plugin-hook-ordering branch 3 times, most recently from 21ca0d6 to 9e0a1f2 Compare April 3, 2026 22:10
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
@ualtinok
ualtinok force-pushed the fix/plugin-hook-ordering branch from 9e0a1f2 to f99f9a6 Compare April 17, 2026 12:51
@rekram1-node

rekram1-node commented May 15, 2026

Copy link
Copy Markdown
Member

/review

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

github-actions[bot]
github-actions Bot reviewed May 15, 2026
View reviewed changes
Comment thread packages/opencode/src/session/prompt.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

github-actions[bot]
github-actions Bot reviewed May 15, 2026
View reviewed changes
Comment thread packages/opencode/src/session/llm.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@rekram1-node

rekram1-node commented May 16, 2026

Copy link
Copy Markdown
Member

/review

slepkaviba reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rekram1-node

rekram1-node commented May 16, 2026

Copy link
Copy Markdown
Member

This looks like a lot more changes than simply changing the orders just at a glance

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

github-actions[bot]
github-actions Bot reviewed May 16, 2026
View reviewed changes
Comment thread packages/opencode/src/session/compaction.ts
})
const finalizeFailedSummary = (error: unknown) =>
Effect.gen(function* () {
msg.error = MessageV2.fromError(error, { providerID: model.providerID })

@github-actions github-actions Bot May 16, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion for the human to consider: this summary failure path persists msg.error, but it does not set msg.finish. Since failed compaction summaries are later returned as the last assistant message, a subsequent loop can see an errored summary with no finish and attempt the compaction path again instead of treating the turn as complete. Consider setting msg.finish = "error" before updateMessage, matching the existing compact-result error path below.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
github-actions[bot]
github-actions Bot reviewed May 16, 2026
View reviewed changes
Comment thread packages/opencode/src/session/prompt.ts
@@ -1755,13 +1760,39 @@ NOTE: At any point in time through this workflow you should feel free to ask the
yield* sessions.updateMessage(msg)
})

const finalizeFailedAssistant = (error: unknown) =>
Effect.gen(function* () {
msg.error = MessageV2.fromError(error, { providerID: model.providerID })

@github-actions github-actions Bot May 16, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion for the human to consider: this new pre-stream failure path records msg.error, but it leaves msg.finish unset. The prompt loop only exits early when the latest assistant has a non-tool finish, so a later loop() call on the same session can treat this errored assistant as unfinished and retry the same user turn. This probably should mark the assistant as finished, consistent with other error paths that use finish = "error".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ualtinok

ualtinok commented May 16, 2026

Copy link
Copy Markdown
Contributor Author

This looks like a lot more changes than simply changing the orders just at a glance

I will explain the reasoning when I get back home.

slepkaviba reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ualtinok
ualtinok marked this pull request as draft May 16, 2026 12:54
@github-actions github-actions Bot mentioned this pull request May 18, 2026
feat(plugin): add experimental.message.store.before hook #28224
Closed
3 of 6 tasks
@ualtinok
ualtinok marked this pull request as ready for review May 19, 2026 05:24
@ualtinok

ualtinok commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

Hey @rekram1-node, I made some changes after your first review. Let me first explain why it looks more changes than needed:

The original plan was just reordering the 2 hooks but as LLM.stream contract has direct callers, we needed to preserve backwards compatibility to make the least changes. That was wrong call, we now removed the backward compatibility and all callers including compaction route uses the same contract.

I've been testing this PR on my local since the implementation and there's no problems observed. If you need longer explanation of the surface, I can give more detailed answer. I believe this PR is ready to ship.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@elmagow

elmagow commented May 26, 2026

Copy link
Copy Markdown

Can we have this reviewed? thanks

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ualtinok
ualtinok force-pushed the fix/plugin-hook-ordering branch 5 times, most recently from 8c371a9 to 1cb9c3e Compare June 6, 2026 09:45
@ualtinok
ualtinok force-pushed the fix/plugin-hook-ordering branch 3 times, most recently from c97494d to 01faef0 Compare June 14, 2026 05:03
@github-actions github-actions Bot mentioned this pull request Jul 6, 2026
📊 AI CLI 工具社区动态日报 2026-07-06 loxehate/loxehate.github.io#8
Closed
@ualtinok
ualtinok force-pushed the fix/plugin-hook-ordering branch from db13429 to 43afdf2 Compare July 7, 2026 08:56
ualtinok added 2 commits July 15, 2026 09:08
@ualtinok
fix(session): fire system transform before messages transform
5d80969
@ualtinok
fix(session): import v2 event helpers
5207442
@ualtinok
ualtinok force-pushed the fix/plugin-hook-ordering branch from 43afdf2 to 5207442 Compare July 15, 2026 07:18
randomvariable added a commit to randomvariable/opencode that referenced this pull request Aug 3, 2026
@randomvariable @claude
feat: improve deepseek prompt cache reuse
787a213
Keep the volatile current date out of the cached system prefix for DeepSeek
models (both the V2 runner and V1 path) and instead append it to the
trailing user turn, add SystemContext.omit, and rework DeepSeek reasoning
handling so reasoning_content is only replayed across assistant tool turns
(and caching hints are skipped) — maximizing DeepSeek prompt-prefix cache
reuse.

Ported from anomalyco#31867 (adapted for the Effect layer; the prepare() date test
passes an explicit system prompt since anomalyco#19961 moved system assembly to
callers).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
randomvariable added a commit to randomvariable/opencode that referenced this pull request Aug 3, 2026
@randomvariable @claude
feat(opencode): interrupt a running subagent — steer / cancel / abort
cd4f0a2
Add an experimental subagent-interrupt capability (behind
OPENCODE_EXPERIMENTAL_SUBAGENT_INTERRUPT): an Interrupt service with
pending/terminal state, task_steer/task_cancel/task_abort tools (gated by a
new `interrupt` permission), a POST /session/:id/interrupt endpoint, and a
turn-boundary consume in the prompt loop that injects an escaped steer/cancel
frame plus a visible transcript marker. Cancel records a terminal reason and
force-breaks after a grace window; abort writes a marker, records the
terminal, and cancels the BackgroundJob immediately. The TUI gains an
esc-with-reason flow, footer button, and distinct interrupt markers.

Ported from anomalyco#32425 (adapted for the Effect layer; merged with the prior
task.ts/registry.ts/prompt.ts changes from anomalyco#29447/anomalyco#32122/anomalyco#12520/anomalyco#32192/anomalyco#19961).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions github-actions Bot mentioned this pull request Aug 15, 2026
fix(opencode): coalesce system messages for OpenAI-compatible providers #42801
Closed
3 tasks done
Qiiks added a commit to Qiiks/opencode that referenced this pull request Aug 23, 2026
@Qiiks
fix(session): restore experimental.chat.system.transform firing in re…
429a9ec
…quest prep

The Aug-15 upstream merge dropped both firings of this hook: ualtinok's
prompt.ts-side trigger from fcb023e (port of anomalyco#19961) conflicted away,
and upstream's request.ts-side block never landed in the resolution.
Every plugin registering the hook (magic-context guidance injection +
prompt-hash cache-flush coordination, aft-opencode hints) has been
silently inert since.

Restore upstream v1.18.18 semantics: fire after system assembly with
{sessionID, model}, then rejoin a mutated multi-part system into
header+rest so prompt-prefix caching stays stable. Regression test
proves prepare() now delivers plugin mutations into prepared.system.
@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thdxr thdxr closed this Oct 10, 2026
This was referenced Oct 12, 2026
Evaluate moving the harness and SDK to OpenCode V2 fro-bot/agent#1805
Closed
build(harness): rebase the harness onto OpenCode 1.19.0 fro-bot/agent#1806
Merged
@marcusrbrown marcusrbrown mentioned this pull request Oct 27, 2026
build(harness): rebase the harness onto OpenCode 1.19.4 fro-bot/agent#1959
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@github-actions github-actions[bot] github-actions[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

system.transform fires after messages.transform — plugins can't coordinate system+message mutations

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@ualtinok @rekram1-node @elmagow @thdxr
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.