xonecas.io
60255
Zn

Zoea-Nova / commit 2782e97

fix: improve provider error handling and logging

- Add request size logging (message count, body bytes) to Ollama provider
- Fix retry logic to not spin on context timeout/cancellation
- Add error body logging for non-retryable Ollama errors
- Document game data compaction problem statement

This addresses timeout investigation without implementing crude truncation.
Providers now properly detect and return context deadline errors instead of
wasting retry attempts on already-expired contexts.

xonecas2026-02-08 2782e97089b33a5ddcd9df681b91a06b0f73a32a parent 4236b2e

3 files changed

documentation/architecture/GAME_DATA_COMPACTION.md+29−0
@@ -0,0 +1,29 @@
1+# Game Data Compaction
2+
3+## Problem Statement
4+
5+SpaceMolt game tools return large JSON payloads that can exceed LLM context windows.
6+
7+**Evidence (2026-02-05):**
8+- Ollama logs: `prompt=41611 tokens`, `limit=32768 tokens`
9+- Result: `context deadline exceeded` errors
10+- Cause: Tool results (notifications, ship logs, market data) accumulating in memory
11+
12+**Critical Constraint:**
13+Myses MUST see current game state to function. Blind truncation breaks gameplay.
14+
15+**Large Tool Results:**
16+1. `get_notifications` - Battle reports, trade offers, discoveries
17+2. `get_ship_logs` - Complete action history
18+3. `get_market_data` - Full market listings for all systems
19+4. `get_system` - Detailed system scan results
20+5. `captains_log_list` - All stored notes
21+
22+## Current Compression (v0.5.0)
23+
24+From `CONTEXT_COMPRESSION.md`:
25+- Turn-aware composition (historical vs current turn)
26+- Snapshot compaction (removes redundant `get_*` tool results)
27+- Orphaned tool call removal
28+
29+These strategies reduce message count but don't address individual message size.
internal/provider/ollama.go+19−0
@@ -197,6 +197,13 @@ func (p *OllamaProvider) createChatCompletion(ctx context.Context, req ollamaCha
197197
198198 url := p.baseURL + "/chat/completions"
199199
200+ log.Debug().
201+ Str("provider", "ollama").
202+ Str("model", p.model).
203+ Int("messages", len(req.Messages)).
204+ Int("body_bytes", len(body)).
205+ Msg("Sending request to Ollama")
206+
200207 maxRetries := len(ollamaRetryDelays)
201208 var lastErr error
202209 for attempt := 0; attempt <= maxRetries; attempt++ {
@@ -229,6 +236,11 @@ func (p *OllamaProvider) createChatCompletion(ctx context.Context, req ollamaCha
229236
230237 resp, err := p.httpClient.Do(httpReq)
231238 if err != nil {
239+ // Do not retry on context cancellation or timeout
240+ if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
241+ return nil, err
242+ }
243+
232244 lastErr = err
233245 continue
234246 }
@@ -251,6 +263,13 @@ func (p *OllamaProvider) createChatCompletion(ctx context.Context, req ollamaCha
251263 if resp.StatusCode < 200 || resp.StatusCode >= 300 {
252264 payload, _ := io.ReadAll(resp.Body)
253265 resp.Body.Close()
266+
267+ log.Error().
268+ Str("provider", "ollama").
269+ Int("status", resp.StatusCode).
270+ Str("body", string(payload)).
271+ Msg("Ollama non-retryable error")
272+
254273 return nil, fmt.Errorf("chat completion status %d: %s", resp.StatusCode, strings.TrimSpace(string(payload)))
255274 }
256275
internal/provider/opencode.go+4−0
@@ -226,6 +226,10 @@ func (p *OpenCodeProvider) createChatCompletion(ctx context.Context, req openai.
226226
227227 resp, err := p.httpClient.Do(httpReq)
228228 if err != nil {
229+ // Do not retry on context cancellation or timeout
230+ if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
231+ return nil, err
232+ }
229233 lastErr = err
230234 continue // Network error - retry
231235 }