Skip to content

fix(ai): flatten xAI compaction requests like every step - #65726

Merged
rekram1-node merged 1 commit into
devfrom
xai-compact-flatten
Nov 23, 2026
Merged

rekram1-node merged 1 commit into
devfrom
xai-compact-flatten

Conversation

@rekram1-node

Copy link
Copy Markdown
Member

Issue for this PR

No linked issue. Found in a prompt-cache audit of the changes since v2.3.2.

Type of change

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

What does this PR do?

Since #65621, Protocol.make runs flattenRequest on every step's request for protocols without native namespaces, so past calls to a namespaced tool go to xAI under the flat name (crm_lookup). xAI's /compact call doesn't go through Protocol.make: ResponsesCompaction.make flattens only the tool list and lowers the history as it is, so the same past call goes out as lookup.

 step:      tools [crm_lookup]   history function_call crm_lookup
-/compact:  tools [crm_lookup]   history function_call lookup
+/compact:  tools [crm_lookup]   history function_call crm_lookup

The history then differs from the prefix the steps cached, so /compact misses the cache whenever the session has called a namespaced tool. XAIResponses.compact now flattens the whole request first, as Protocol.make does. OpenAI's compaction is unaffected: its protocol keeps native namespaces on both paths.

How did you verify your code works?

  • New test in packages/ai/test/provider/compaction.test.ts: for a request with a namespaced tool and a past call to it, the /compact body's tool and call names match the compiled step's (crm_lookup). It fails without the fix (lookup).
  • compaction.test.ts and effort-updates.test.ts in packages/ai pass; bun typecheck and bun run check pass.

Screenshots / recordings

N/A

Checklist

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

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks correct. I copied the new test into the base checkout and it fails there: the /compact history calls the tool lookup, while the compiled step calls it crm_lookup. With this PR both use crm_lookup, and compaction.test.ts and effort-updates.test.ts pass (70/70). tsc --noEmit passes for packages/ai. Running flattenRequest before ResponsesCompaction.make matches what Protocol.make does for every step. Folding tool updates after flattening is safe, and OpenAI compaction is untouched.

Public API: unchanged (XAIResponses.compact keeps its CompactOperation type).

No blocking concerns.

@rekram1-node
rekram1-node merged commit d3abc67 into dev Nov 23, 2026
11 checks passed
@rekram1-node
rekram1-node deleted the xai-compact-flatten branch November 23, 2026 06:44
@amrkmn amrkmn mentioned this pull request Nov 23, 2026
1 task
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.

1 participant