Files
twenty/packages
sonarly-bot 4ffe8127ae fix(ai-chat): support OpenAI ZDR stateless tool execution
https://sonarly.com/issue/40356?type=bug

AI chat fails for OpenAI Zero Data Retention orgs because Twenty sends conversation/tool history that depends on provider-persisted item IDs. OpenAI rejects those references in ZDR mode, causing chat turns to fail.

Fix: Implemented a backend-layer compatibility fix for OpenAI ZDR stateless behavior in the same execution path that was failing:

- In `ChatExecutionService.streamChat`, before `convertToModelMessages(...)`, I now branch on provider SDK package and sanitize replayed history for OpenAI.
- For OpenAI (`@ai-sdk/openai`), the service removes persisted `tool-*` parts from replayed UI messages before conversion.
- This prevents replaying cross-turn tool-call references that depend on provider-side item persistence, which is exactly what OpenAI ZDR rejects.
- The change is intentionally narrow: only OpenAI is affected; other providers keep current behavior.

This addresses the user-impacting failure mode where tool-using turns in existing threads broke under OpenAI ZDR.

Authored by Sonarly by autonomous analysis (run 46013).
2026-05-24 15:42:11 +00:00
..