Kyle Carberry
|
2bdacae5f5
|
feat(chatd): add LLM stream retry with exponential backoff (#22418)
## Summary
Adds automatic retry with exponential backoff for transient LLM errors
during chat streaming and title generation. Inspired by
[coder/mux](https://github.com/coder/mux)'s retry mechanism.
## Key Behaviors
- **Infinite retries** with exponential backoff: 1s → 2s → 4s → ... →
60s cap
- **Deterministic delays** (no jitter)
- **Error classification**: retryable (429, 5xx, overloaded, rate limit,
network errors) vs non-retryable (auth, quota, context exceeded, model
not found, canceled)
- **Retry status published to SSE stream** so frontend can show
"Retrying in Xs..." UI
- **Title generation** retries silently (best-effort, nil onRetry
callback)
## New Package: `coderd/chatd/chatretry/`
| File | Purpose |
|------|---------|
| `classify.go` | `IsRetryable(err)` and `StatusCodeRetryable(code)` |
| `backoff.go` | `Delay(attempt)` — exponential doubling with 60s cap |
| `retry.go` | `Retry(ctx, fn, onRetry)` — infinite loop with
context-aware timer |
## Test Helpers: `coderd/chatd/chattest/errors.go`
Anthropic and OpenAI error response builders for use in chattest
providers:
- `AnthropicErrorResponse()`, `AnthropicOverloadedResponse()`,
`AnthropicRateLimitResponse()`
- `OpenAIErrorResponse()`, `OpenAIRateLimitResponse()`,
`OpenAIServerErrorResponse()`
## SDK Changes: `codersdk/chats.go`
- New `ChatStreamEventType: "retry"`
- New `ChatStreamRetry` struct with `Attempt`, `DelayMs`, `Error`,
`RetryingAt` fields
- TypeScript types auto-generated
## Changed Files
- `coderd/chatd/chatloop/chatloop.go` — wraps `agent.Stream()` in
`chatretry.Retry()`
- `coderd/chatd/chatd.go` — publishes retry events to SSE stream with
logging
- `coderd/chatd/title.go` — wraps `model.Generate()` in silent retry
- `coderd/chatd/chattest/anthropic.go` / `openai.go` — error injection
support
## Tests
42 tests covering classification (33), backoff (9), and retry scenarios
(8).
|
2026-02-27 18:34:33 -05:00 |
|
Kyle Carberry
|
edee917d88
|
feat: add experimental agents support (#22290)
feat: add AI chat system with agent tools and chat UI
Introduce the chatd subsystem and Agents UI for AI-powered chat
within Coder workspaces.
- Add chatd package with chat loop, message compaction, prompt
management, and LLM provider integration (OpenAI, Anthropic)
- Add agent tools: create workspace, list/read templates, read/write/
edit files, execute commands
- Add chat API endpoints with streaming, message editing, and
durable reconnection
- Add database schema and migrations for chats, chat messages, chat
providers, and chat model configs
- Add RBAC policies and dbauthz enforcement for chat resources
- Add Agents UI pages with conversation timeline, queued messages
list, diff viewer, and model configuration panel
- Add comprehensive test coverage including coderd integration tests,
chatd unit tests, and Storybook stories
- Gate feature behind experiments flag
---------
Co-authored-by: Cian Johnston <cian@coder.com>
Co-authored-by: Danielle Maywood <danielle@themaywoods.com>
Co-authored-by: Jeremy Ruppel <jeremy@coder.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
|
2026-02-27 16:50:56 +00:00 |
|