Skip to content

agent run never completes — engine hangs after model finishes with finish_reason=stop #5

Description

@RangerVzla

When running anda agent run --prompt "...", the command polls the daemon for completion but never returns, even though the LLM successfully responds to all requests and the last model response has finish_reason: "stop".

The conversation remains in a non-terminal state indefinitely, causing agent run to hit its --wait-timeout-secs limit and fail with:

Error: "agent did not complete conversation N within 300s"

To Reproduce

  1. Start the daemon with a custom OpenAI-compatible endpoint (tested with llama.cpp serving gemma-4-26B)
  2. Run: anda agent run --prompt "Di hola" --wait-timeout-secs 300
  3. Observe via proxy that the LLM responds correctly to all requests (~21 seconds)
  4. After the last model response, the engine does nothing for 4+ minutes until timeout

Evidence (proxy logs)

All requests to the LLM complete successfully with stop reasons:

13:53:46 REQ 1 → CHAT: "Di hola"
13:53:47 RES 1 → prompt=6742 comp=5 content="¡Hola!" finish_reason=stop ✅

13:53:47 REQ 2 → MEMORY FORMATION (KIP Brain)
13:53:59 RES 2 → prompt=18835 comp=477 tool_calls=[execute_kip] ✅

13:53:59 REQ 3 → MEMORY FORMATION with tool results
13:54:05 RES 3 → prompt=19397 comp=479 tool_calls=[execute_kip] ✅

13:54:05 REQ 4 → MEMORY FORMATION final
13:54:06 RES 4 → prompt=19925 comp=24 content=101 finish_reason=stop ✅

─────── ZERO requests to LLM for 4+ minutes ───────
13:58:46 → TIMEOUT: "agent did not complete conversation within 300s"

The LLM completed all 4 turns in ~21 seconds. The remaining 279 seconds were spent polling internally with no further LLM calls.

Expected behavior

After the final model response with finish_reason: "stop", the engine should mark the conversation as complete and agent run should return the response.

Environment

  • anda_bot version: 0.11.3
  • anda_engine version: 0.13.14 (from logs)
  • OS: Debian 13 (Linux x86_64)
  • LLM backend: llama.cpp (OpenAI-compatible API), model gemma-4-26B-A4B-it-UD-Q4_K_XL.gguf
  • Config: stream: false, family: openai, no channels configured
  • Running as: systemd daemon, headless server (no D-Bus/keyring)

Additional context

  • The daemon itself stays active (running) — it's the conversation state machine that never reaches terminal state
  • This happens with both stream: true and stream: false
  • The proxy confirms all HTTP responses from the LLM are valid JSON with proper finish_reason
  • No errors appear in daemon logs beyond the keyring warning
  • Hermes Agent and direct curl tests against the same llama.cpp endpoint work perfectly
  • The issue is reproducible on every agent run invocation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions