Skip to content

refactor(agent): consolidate inner-retry-loop recovery flags into TurnRetryState (god-file Phase 1b)#41828

Merged
teknium1 merged 1 commit into
mainfrom
hermes/godfile-phase1b
Jun 8, 2026
Merged

refactor(agent): consolidate inner-retry-loop recovery flags into TurnRetryState (god-file Phase 1b)#41828
teknium1 merged 1 commit into
mainfrom
hermes/godfile-phase1b

Conversation

@teknium1

@teknium1 teknium1 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

run_conversation's inner retry loop no longer tracks recovery state in ~15 scattered bare booleans — they're now fields on a single TurnRetryState dataclass.

Phase 1b of the god-file decomposition plan. The inner while retry_count < max_retries loop (~2,400 LOC) guards each recovery branch (per-provider OAuth refresh, format recovery, compression/length-continuation restart) with a one-shot boolean. They were inline locals threaded through the whole loop body; consolidating them gives the recovery bookkeeping a named, testable home.

Changes

  • agent/turn_retry_state.py (new): TurnRetryState dataclass — 15 recovery guards + restart signals, all defaulting False. Dependency-free.
  • agent/conversation_loop.py: the 15-line inline flag-init block becomes _retry = TurnRetryState(); 42 references rewritten flag_retry.flag. Kwarg names preserved (e.g. has_retried_429=_retry.has_retried_429).
  • Loop-control vars (retry_count, max_retries, max_compression_attempts) intentionally stay as locals — they're while-mechanics, not recovery bookkeeping.
  • tests/agent/test_turn_retry_state.py (new): pins the field contract + default semantics.

Validation

Before After
recovery flags in run_conversation 15 scattered locals 1 TurnRetryState object
bare unconverted refs after rewrite 0 (verified)
live simple + tool-calling turns OK
tests/run_agent/ (per-file process isolation) green 1615 passed / 0 failed

Behavior-neutral: pure local→attribute rewrite, no control-flow change. The recovery-branch tests (test_multimodal_tool_content_recovery, test_jsondecodeerror_retryable, test_31273_402_not_retried, etc.) all pass, exercising the flags via _retry.<flag>.

Note on scope

The deeper extraction of each recovery branch into a standalone handler was evaluated and deliberately not done here: those branches continue/break/return the loop and mutate agent + a dozen locals, so factoring them out cleanly needs a larger redesign of the live failover logic. This PR does the safe, valuable enabler (flag consolidation) without touching the error-recovery control flow.

Infographic

retry-state-consolidated

…nRetryState (god-file Phase 1b)

run_conversation's inner retry loop tracked recovery state in ~15 scattered
bare booleans (per-provider OAuth refresh guards, format-recovery guards,
restart signals). They are now fields on a single TurnRetryState dataclass the
loop mutates in place (_retry.<flag>), giving the recovery bookkeeping a named,
testable home.

Loop-control vars (retry_count, max_retries, max_compression_attempts) stay as
plain locals — they're while-mechanics, not recovery bookkeeping.

Behavior-neutral: pure local→attribute rewrite of 42 references; kwarg NAMES
preserved (e.g. has_retried_429=_retry.has_retried_429). Live simple + tool
turns OK.

Validation: tests/run_agent/ 1615 passed / 0 failed under per-file process
isolation; new test_turn_retry_state.py pins the field contract.
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/godfile-phase1b vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 10101 on HEAD, 10101 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5231 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

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