Skip to content

fix(refresh): stop refresh hanging on slow / reasoning models - #89

Merged
study8677 merged 2 commits into
mainfrom
fix/refresh-timeout-hang
Jun 4, 2026
Merged

fix(refresh): stop refresh hanging on slow / reasoning models#89
study8677 merged 2 commits into
mainfrom
fix/refresh-timeout-hang

Conversation

@study8677

Copy link
Copy Markdown
Owner

Problem

ag-refresh appeared to hang for many minutes with a slow reasoning model (MiniMax-M3) β€” sometimes >1h β€” while ag-ask worked fine.

Root cause (diagnosed, not a deadlock)

asyncio.wait_for does fire; refresh always completes. The "hang" was:

  1. A bare asyncio.TimeoutError (our own per-attempt deadline) was classified retryable β†’ _run_with_retry ran 4 attempts Γ— full timeout per step (AG_REFRESH_RETRY_COUNT default 3). Retrying a slow model the same way just multiplied wall-clock for the same outcome.
  2. The per-attempt timeout defaults were tuned for fast models and far too low for a reasoning model β€” module agents at 45s, and conventions (a 3-hop handoff swarm, 3 sequential calls under one timeout) at 90s.

Fix

  1. _is_retryable_error: a bare wait-for timeout is non-retryable β†’ fall back immediately instead of 4Γ—. Messaged provider timeouts (504/gateway time-out) stay retryable.
  2. Raise refresh timeout defaults: conventions 90β†’300, module 45β†’240, map 90β†’240, registry 60β†’120. A bare timeout no longer retries, so a higher ceiling only costs time if a call genuinely runs that long; fast models finish well under it.
  3. Document the timeouts in engine/.env.example (+ reasoning-model note).

Verified

  • Measured: with adequate timeout, a full multi-module refresh completes with real (non-fallback) docs on MiniMax-M3 (conventions + 3 module docs + map, status success).
  • engine/tests/test_refresh_retry.py added (bare timeout β†’ not retried; messaged/transient β†’ retried). Full engine suite: 223 passed.

πŸ€– Generated with Claude Code

study8677 and others added 2 commits June 4, 2026 19:51
Two changes so `ag-refresh` works out-of-the-box with slow reasoning models
(e.g. MiniMax-M3) instead of appearing to hang for many minutes:

1. A bare asyncio.wait_for timeout is no longer treated as retryable
   (_is_retryable_error). Our own per-attempt deadline elapsing means the model
   is slow/stalling, not transiently failing β€” retrying the same full-length
   attempt just multiplied wall-clock by (AG_REFRESH_RETRY_COUNT + 1) (default
   4x) for the same outcome. It now falls back immediately. Messaged provider
   timeouts ("504" / "gateway time-out") stay retryable.

2. Raise the refresh per-attempt timeout defaults, which were tuned for fast
   models and too low for reasoning models (one call may emit a long reasoning
   block; conventions is a 3-hop handoff swarm):
   - AG_REFRESH_AGENT_TIMEOUT_SECONDS 90 -> 300  (conventions swarm)
   - AG_MODULE_AGENT_TIMEOUT_SECONDS  45 -> 240  (per-module doc)
   - AG_MAP_AGENT_TIMEOUT_SECONDS     90 -> 240  (map.md)
   - AG_REGISTRY_TIMEOUT_SECONDS      60 -> 120
   A bare timeout no longer retries, so a higher ceiling only costs time if a
   call genuinely runs that long; fast models finish well under these.

Verified end-to-end: a full multi-module refresh completes with real
(non-fallback) docs on MiniMax-M3. Adds test_refresh_retry.py and documents
the timeouts in engine/.env.example.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
OOTB verification showed per-module knowledge-doc calls still timing out at
240s with MiniMax-M3 (3 modules concurrent) and falling back; the proven
value is 300s (same as the conventions swarm). Raise
AG_MODULE_AGENT_TIMEOUT_SECONDS and AG_MAP_AGENT_TIMEOUT_SECONDS defaults
240 -> 300 so refresh produces real (non-fallback) docs out of the box.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@study8677
study8677 merged commit 1575775 into main Jun 4, 2026
8 checks passed
@study8677
study8677 deleted the fix/refresh-timeout-hang branch June 4, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant