From ad7821526c6cb98e43e5432eb73f94994880715b Mon Sep 17 00:00:00 2001 From: belarusian <10478328+belarusian@users.noreply.github.com> Date: Thu, 18 Jun 2026 01:05:46 -0400 Subject: [PATCH] fix(harness): complete onRound for all exit paths + normalize state --- src/agent.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/agent.ts b/src/agent.ts index 06f99d5..5b70a87 100644 --- a/src/agent.ts +++ b/src/agent.ts @@ -378,7 +378,7 @@ function runAgentStream(input: AgentLoopInput): Stream.Stream { if (!hasToolCalls) { const finalState: AgentLoopState = { round: round + 1, - messageCount: history.length + 2, + messageCount: history.length, toolCallCount, lastFinishReason: finishReason, hasToolCalls: false, @@ -406,7 +406,7 @@ function runAgentStream(input: AgentLoopInput): Stream.Stream { // Model returned tool-calls finish reason but no valid tool calls — fire callback with stuck state const stuckState: AgentLoopState = { round: round + 1, - messageCount: history.length + 2, + messageCount: history.length, toolCallCount, lastFinishReason: finishReason, hasToolCalls: false, @@ -815,7 +815,16 @@ export const makeAgentLoop = Layer.effect( } } - // Max steps reached + // Max steps reached + const stateMax: AgentLoopState = { + round, + messageCount: history.length, + toolCallCount, + lastFinishReason, + hasToolCalls: false, + lastText, + } + if (input.onRound) { try { input.onRound(stateMax); } catch {} } const response = buildResponse(lastEvents, accumulatedUsage) return { response,