xonecas.io
60255
Zn

Zoea-Nova / commit 7799e98

fix: graceful recovery from max tool iterations

Problem: When a mysis hit MaxToolIterations (10 tool calls in a turn),
it would error out, transition to Errored state, and require manual restart.
This broke autonomous operation and lost progress.

Solution: Treat max iterations as a turn boundary, not a fatal error.
- Log warning instead of returning error
- Increment encouragement counter (if autonomous turn)
- Return nil (success) to continue autonomous loop
- All 10 tool calls already executed and stored

Behavior:
- Turn with user message hits limit → counter stays 0, continues
- Autonomous turn hits limit → counter increments, continues
- Third autonomous turn hits limit → counter reaches 3, goes idle
- Broadcast after limit → resets counter, continues

Truth table compliance: Verified by zoea-analyser agents
- Maintains all state transitions from MESSAGE_FORMAT_GUARANTEES.md
- Preserves autonomous operation
- Graceful degradation instead of hard failure

This completes the autonomous turn loop implementation:
- Myses take up to 3 autonomous turns before idle
- Complex multi-step workflows (10+ tool calls) handled gracefully
- Progress preserved across turn boundaries
- Natural idle transition after 3 encouragements

Files changed:
- internal/core/mysis.go (lines 718-749): Max iterations handling

Related: fix/autonomous-loop-correct branch (commit 788254c)
Verified: Two zoea-analyser agents confirmed safety and compliance

xonecas2026-02-08 7799e98ee58a20895bbcee7acab3bf517cd6fe28 parent 788254c

1 file changed

internal/core/mysis.go+30−2
@@ -715,10 +715,38 @@ func (m *Mysis) SendMessageFrom(content string, source store.MemorySource, sende
715715 return nil
716716 }
717717
718- // Signal network idle on max iterations
718+ // Max tool iterations reached - end this turn gracefully and continue to next turn
719+ // This is NOT an error - the mysis made progress and should continue autonomous operation
720+ log.Warn().
721+ Str("mysis", a.name).
722+ Int("max_iterations", constants.MaxToolIterations).
723+ Msg("Max tool iterations reached - ending turn, will continue next turn")
724+
725+ // Signal network idle
719726 a.bus.Publish(Event{Type: EventNetworkIdle, MysisID: a.id, Timestamp: time.Now()})
720727
721- return fmt.Errorf("max tool iterations (%d) exceeded", constants.MaxToolIterations)
728+ // Increment encouragement counter if this was an autonomous turn
729+ // Same logic as successful turn completion (lines 697-713)
730+ if addedSyntheticEncouragement {
731+ a.mu.Lock()
732+ a.encouragementCount++
733+ count := a.encouragementCount
734+ a.mu.Unlock()
735+
736+ log.Debug().
737+ Str("mysis", a.name).
738+ Int("count", count).
739+ Msg("Autonomous turn completed (max iterations) - incremented encouragement counter")
740+
741+ // If we've hit the limit, transition to idle immediately
742+ if count >= 3 {
743+ a.setIdle("No user messages after 3 encouragements")
744+ return nil
745+ }
746+ }
747+
748+ // Return success - turn completed, continue to next turn
749+ return nil
722750 }
723751
724752 // SendMessage sends a message to the mysis for processing.