fix(vercel-ai): strip retry suffix from UI `errorText` and preserve LLM cache
Closed
TI
3mo ago+37+37+01234567890123456789-31-31-01234567890123456789
Summary
RetryPromptPart.model_response() appends "\n\nFix the errors and try again." — an instruction meant for the LLM, not for end users. This suffix was leaking into Vercel AI errorText in both the streaming and dump paths, breaking frontend logic that checks errorText values (e.g. errorText === "Cancelled" to distinguish cancelled vs failed state).
Core change: Add RetryPromptPart.error_description() — returns the error text without the retry suffix. model_response() now delegates to it, so all existing callers are unaffected.
Vercel AI adapter:
- Dump path: Uses
error_description()for UI-facingerror_text; stores the fullmodel_response()incall_provider_metadata.pydantic_ai.model_responsefor round-trip cache fidelity - Load path: Prefers
provider_meta['model_response']forToolReturnPart.content, falls back toerror_text— LLM prompt cache is preserved after dump → load - Streaming path: Uses
error_description()directly
This ensures the LLM sees identical text before and after a dump/load round-trip (no cache break), while the UI gets clean error text without the retry instruction.
Test plan
- All 106
test_vercel_ai.pytests pass - Snapshot tests updated for new metadata field and round-trip content
-
ruff check/ruff format/pyrightclean on changed files - Verify errorText in Vercel AI frontend no longer contains suffix
- Verify dump → load → next LLM turn produces identical prompt (cache hit)