Skip to content

fix(runtime): prevent infinite turn loop when model fails to emit finish #140

Description

@mdev34-lab

Problem

Some models can produce a valid final textual response while repeatedly failing to emit AlphaCode's finish tool call. The runtime currently allows this to become an unbounded continuation loop.

Reproduction

With Nex-N2.5-Pro, a trivial session was observed behaving like this:

  1. User sends Bom dia.
  2. Model responds Bom dia! Como posso ajudar?.
  3. The model's own reasoning repeatedly recognizes that it must call finish (We need call finish exactly once.), but emits only the same text response.
  4. AlphaCode starts another turn.
  5. The same thing happens again, repeatedly.
  6. The session never reaches terminal state.

The observed trace repeated the same response across 8+ turns.

Expected behavior

A model that fails to emit finish must not be able to keep the session alive indefinitely. The runtime should have a deterministic, model-independent termination invariant for this class of failure.

The fix should be implemented in the actual runner/control-flow, not as a prompt-only instruction or a provider-specific Nex workaround.

Requirements

  • Reproduce the failure with an integration/regression test against the actual runner/turn loop using a simulated model that returns final text but never calls finish.
  • Ensure the runner reaches a bounded terminal state instead of repeatedly invoking the model forever.
  • Preserve normal multi-turn agent behavior and legitimate tool-call continuation.
  • Do not special-case Nex-N2.5 or hardcode provider/model names.
  • Make the termination behavior explicit and observable in the runtime state/result.

Context

This is a runtime safety/liveness issue exposed by Nex-N2.5-Pro, not merely a model-quality issue. Nex-N2.5 documents function calling support, so AlphaCode should tolerate models that occasionally fail to materialize a required terminal tool call rather than turning that failure into an infinite loop.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions