Skip to content

fix(session): fire system.transform before messages.transform#19961

Open
ualtinok wants to merge 1 commit intoanomalyco:devfrom
ualtinok:fix/plugin-hook-ordering
Open

fix(session): fire system.transform before messages.transform#19961
ualtinok wants to merge 1 commit intoanomalyco:devfrom
ualtinok:fix/plugin-hook-ordering

Conversation

@ualtinok
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

@ualtinok ualtinok force-pushed the fix/plugin-hook-ordering branch 2 times, most recently from 8bbea02 to 2490768 Compare April 1, 2026 17:22
@ualtinok ualtinok force-pushed the fix/plugin-hook-ordering branch from 21ca0d6 to 9e0a1f2 Compare April 3, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant