fix(engine): render local-history reruns as Responses-API input items (analysis-smoke EngineAgentExhaustedError) - #83
Open
inf-quantavius wants to merge 1 commit into
Conversation
Rerunning from AgentContext (mid-stream recovery, refusal retries, the final_answer reprompt) sent chat-completions-shaped messages — assistant tool_calls arrays and role=tool results — inside a Responses-API input array. The API rejects the content-less assistant item with 400 'Missing required parameter: input[N].content'; since non-terminal 400s are deliberately retriable, the same invalid history was resent until the circuit breaker tripped and the run died with EngineAgentExhaustedError. Convert at the render boundary: tool turns become function_call / function_call_output items, text messages stay message items, and None content degrades to an empty string.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The nightly [Inference] LLM Ops Analysis Smoke (dev) failed on 2026-07-28 (run 30326543437): both fixed-analysis runs (
iar_55bgjz7omQ8Oq5BHy4toetask scope,iar_v2ydWpePBNlNqHerYtFXPagent scope) endedstatus=error stage=halowith:Root cause
Dev ClickHouse (
default.inferences, 03:40–04:00 UTC window) shows the underlying LLM failures: 29 gpt-5.5 requests tov1/responsesrejected withDissecting a failing request:
input[2]is{"role":"assistant","tool_calls":[...]}with nocontentandinput[3]is{"role":"tool","content":...}— chat-completions shapes inside a Responses-APIinputarray.Mechanism:
OpenAiAgentRunner.runrebuilds every attempt's input from local history:[m.model_dump(exclude_none=True) for m in agent_context.to_messages_array()]— chat-completions-shapedAgentMessages.OpenAIProviderdefaultuse_responses=True; all requests land onv1/responses). A healthy first attempt sends only[system, user](valid), and mid-run turns use the SDK's own Responses items (function_call_output— visible in the 88 successful multi-turn requests in the same window).final_answerreprompt — re-renders the stored chat shape. Once history contains a tool turn, the assistanttool_callsmessage has nocontent→ deterministic 400.is_retriable_llm_errordeliberately retries non-terminal 400s ("a clean rerun from local history fixes stale server-side state") — but here the local history itself renders invalid, so the rerun can never succeed. 10 identical failures →EngineAgentExhaustedError.In the failing window all 29 failed requests carried chat-style
tool_calls(and nofunction_call_output); all 88 multi-turn successes carriedfunction_call_output(and notool_calls). The failure is deterministic once any resend path triggers after a tool turn — which is probabilistic per run, hence the smoke passing 07-26/07-27 and failing 07-28.Not a monorepo regression — none of the 110 monorepo commits since the last green run touch this path. Prod is affected too: the same error signature appears in prod
default.inferencesdaily since at least 2026-07-17 (11–61 requests/day), i.e. real HALO/analysis runs intermittently dying the same way.Fix
Add a render boundary,
engine/agents/responses_input.py::to_responses_input, used byOpenAiAgentRunner.runin place of the rawmodel_dump:{"role", "content"}message items (Nonecontent →"", since message items requirecontent)tool_calls→ optional text message item + one{"type": "function_call", "call_id", "name", "arguments"}item per callrole="tool"results →{"type": "function_call_output", "call_id", "output"}itemsOrder is preserved, so the existing context invariant from
trim_incomplete_tool_turn(every call answered by its result) carries over to call/output pairing.Tests
tests/unit/agents/test_responses_input.py: tool-turn pair conversion, text+tool_calls assistant,None-content edges, compacted-summary passthrough.test_runner_retries_refusal_after_tool_result_without_replaying_tool_outputto the Responses shapes.ruff check/ruff formatclean.Provenance
U0B5KMSTCKX)95a7ee0d