Skip to content

fix(eval): don't wrap sync answer_question with asyncio.run#4471

Merged
rysweet merged 1 commit intomainfrom
fix/agent-subprocess-asyncio-misuse
Apr 25, 2026
Merged

fix(eval): don't wrap sync answer_question with asyncio.run#4471
rysweet merged 1 commit intomainfrom
fix/agent-subprocess-asyncio-misuse

Conversation

@rysweet
Copy link
Copy Markdown
Owner

@rysweet rysweet commented Apr 25, 2026

Symptom

Observed in Simard daemon journal during gym benchmark runs (every L1-L12 testing phase failing):

File '/home/.../eval/agent_subprocess.py', line 167, in testing_phase
  result = asyncio.run(
      agent.answer_question(question, question_level=level, return_trace=True)
  )
File '/usr/lib/python3.13/asyncio/runners.py', line 89, in run
  raise ValueError('a coroutine was expected, got {!r}'.format(coro))
ValueError: a coroutine was expected, got ('', ReasoningTrace(...))

The bench logs surfaced this as Testing phase failed: WARNING: amplihack_memory.graph not available, which obscured the real cause.

Root cause

agent.answer_question is a sync method (AnswerSynthesizerMixin.answer_question in src/amplihack/agents/goal_seeking/answer_synthesizer.py:52) that internally uses _run_async_or_return to dispatch to the async implementation and return the value directly. Wrapping it with asyncio.run() then handed asyncio the already-resolved tuple ('', ReasoningTrace) instead of a coroutine.

Fix

Call agent.answer_question(...) directly. learn_from_content (line 120) is genuinely async and remains wrapped.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

agent.answer_question is a sync method that internally uses
_run_async_or_return to dispatch to the async implementation. Wrapping
its return value with asyncio.run() raised:

  ValueError: a coroutine was expected, got ('', ReasoningTrace(...))

because asyncio.run was being handed the already-resolved tuple.

Symptom (observed in Simard daemon journal during gym benchmark runs):
  File '/home/.../eval/agent_subprocess.py', line 167, in testing_phase
    result = asyncio.run(
        agent.answer_question(question, question_level=level, return_trace=True)
    )
  File '/usr/lib/python3.13/asyncio/runners.py', line 89, in run
    raise ValueError('a coroutine was expected, got {!r}'.format(coro))
  ValueError: a coroutine was expected, got ('', ReasoningTrace(...))

This caused L1-L12 benchmark testing phases to fail with
'Testing phase failed: WARNING: amplihack_memory.graph not available'
masking the actual asyncio misuse.

learn_from_content (line 120) is genuinely async and remains wrapped.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Repo Guardian - Passed

All 1 changed file(s) reviewed — no ephemeral content or temporary scripts detected.

File Status
src/amplihack/eval/agent_subprocess.py ✅ Durable source code — bug fix removing incorrect asyncio.run() wrapper

Generated by Repo Guardian for issue #4471 ·

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