You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Partial OpenAI SSE responses with text bypass infinite retry and end the turn #4997
An OpenAI-compatible streaming response that ends after visible text but before a provider finish event is treated as a successful response. The agent ends its turn without running the tools it planned to call, even when KIMI_CODE_INFINITE_RETRY=1.
I observed this in three independent runs. Each response stopped immediately after the model said it would write a report. The report-writing tool was never called, and the request was not retried.
Observed response
The recorded SSE response ends like this, followed by EOF:
data: {"choices":[{"delta":{"content":"Let me write the report."},"finish_reason":null}]}
: keep-alive
There is no subsequent finish_reason, usage chunk, or data: [DONE].
Cause
The OpenAI stream reaches EOF without throwing an exception.
settleLlmRequest only checks whether the response is empty or contains only thinking content in packages/agent-core-v2/src/human/llm/policy/settle.ts:295-300.
Because the response already contains visible text such as Let me write the report., emptyResponseError returns null. settleLlmRequest therefore returns type: 'done' even though it never received a finish event.
pushDone in packages/agent-core-v2/src/llm-adapter/model/generate.ts:215-222 unconditionally emits a finish event, even when outcome.finish is undefined.
The guard in packages/agent-core-v2/src/agent/loop/requester.ts:525-531 only checks that a finish event exists, so it does not throw LLM request stream ended without a finish event. Execution never reaches the infinite retry path in requester.ts:588-615.
Expected behavior
A stream that ends before the provider's finish event should be treated as a failed request. With KIMI_CODE_INFINITE_RETRY=1, the request should be retried instead of ending the agent turn.
Actual behavior
The request is recorded with null finish reasons and empty output usage, and the agent turn ends as done. Any tool calls the model was about to make are lost.
A regression test could stream a non-empty text delta and then close without a finish event, and assert that the requester retries rather than returning a successful response.
Activity