-
-
Notifications
You must be signed in to change notification settings - Fork 40.8k
Description
Upstream Bug in @mariozechner/pi-agent-core
This is the root cause of the "missing tool result" bug (#8643, #13351). Filing here because badlogic/pi-mono has issues disabled.
Problem
In @mariozechner/pi-coding-agent's agent-session.js, _resolveRetry() fires on the message_end event handler — before tool execution completes in the retried agent loop.
// Current code (fires too early):
if (assistantMsg.stopReason !== "error" && this._retryAttempt > 0) {
this._emit({ type: "auto_retry_end", success: true, attempt: this._retryAttempt });
this._retryAttempt = 0;
this._resolveRetry(); // resolves BEFORE tools execute
}When the retry's assistant response includes tool calls (stopReason: "toolUse"), waitForRetry() resolves while tools are still pending. This causes OpenClaw's attempt finally block to flush pending tool results as synthetic errors before tools ever run.
Suggested Upstream Fix
Move _resolveRetry() to the agent_end handler so it resolves after the full loop completes:
if (event.type === "agent_end" && this._retryAttempt > 0) {
this._emit({ type: "auto_retry_end", success: true, attempt: this._retryAttempt });
this._retryAttempt = 0;
this._resolveRetry();
}Current Workaround
#13746 adds agent.waitForIdle() before the flush to ensure the retry loop fully completes. This works but is a workaround — the proper fix belongs upstream.