Retry model streams only before the first delta #11

Merged
weichen merged 1 commits from feature/llm-robustness into main 2026-10-03 15:56:15 +00:00
Owner

Summary

  • Recognize context overflow from a pattern table (413, context_length_exceeded, prompt-too-long, Chinese, MiniMax/Z.AI wording).
  • Honor Retry-After (seconds or HTTP date, capped) and otherwise back off with jitter. Retry 408, 429, 5xx, 529, and in-stream capacity errors.
  • Forward stream events immediately. Retry only when no delta has been forwarded.
  • Do not execute a tool call cut off by length or an unclean end. Reject a call whose name or arguments JSON is incomplete and write a paired error.
  • Split usage into the last request (context) and the cumulative sum (billing).

Test plan

  • GOWORK=off go test -race -count=1 ./runtime/llm/ ./runtime/
## Summary - Recognize context overflow from a pattern table (413, context_length_exceeded, prompt-too-long, Chinese, MiniMax/Z.AI wording). - Honor Retry-After (seconds or HTTP date, capped) and otherwise back off with jitter. Retry 408, 429, 5xx, 529, and in-stream capacity errors. - Forward stream events immediately. Retry only when no delta has been forwarded. - Do not execute a tool call cut off by length or an unclean end. Reject a call whose name or arguments JSON is incomplete and write a paired error. - Split usage into the last request (context) and the cumulative sum (billing). ## Test plan - [x] GOWORK=off go test -race -count=1 ./runtime/llm/ ./runtime/
weichen added 1 commit 2026-10-03 15:55:58 +00:00
Retry model streams only before the first delta
ci / vet-and-test (pull_request) Successful in 47s
ci / docker-checkout-hostgateway (pull_request) Successful in 1s
9f5751c205
Why: Buffering a whole attempt hid live output, overflow detection missed common provider errors, and a cut-off tool call could still run.
Evidence: GOWORK=off go test -race -count=1 ./runtime/llm/ ./runtime/ passed.
Impact: WithRetry forwards events immediately and retries only when nothing has been forwarded. Length or an unclean end drops unfinished tool calls. Loop usage keeps a billing sum and the last request separately.
Refs: feature/llm-robustness
Co-authored-by: Cursor <cursoragent@cursor.com>
weichen merged commit 9335fd40e6 into main 2026-10-03 15:56:15 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weichen/Agent-Native#11