fix: persist tool error status in conversation history reload

When reloading a conversation, failed tool calls incorrectly showed checkmark instead of X because the is_error field was lost in the history rendering pipeline. Propagate is_error from DB extraction through to the frontend rendering to match the live SSE behavior.
This commit is contained in:
a1094174619
2026-05-19 23:50:29 +08:00
parent a0dfdb79df
commit 4e42f2a017
2 changed files with 16 additions and 7 deletions

View File

@@ -116,9 +116,10 @@ def _extract_tool_calls(content: Any) -> List[Dict[str, Any]]:
] ]
def _extract_tool_results(content: Any) -> Dict[str, str]: def _extract_tool_results(content: Any) -> Dict[str, dict]:
""" """
Extract tool_result blocks from a user message, keyed by tool_use_id. Extract tool_result blocks from a user message, keyed by tool_use_id.
Values are {"result": str, "is_error": bool}.
""" """
if not isinstance(content, list): if not isinstance(content, list):
return {} return {}
@@ -133,7 +134,7 @@ def _extract_tool_results(content: Any) -> Dict[str, str]:
rb.get("text", "") for rb in result_content rb.get("text", "") for rb in result_content
if isinstance(rb, dict) and rb.get("type") == "text" if isinstance(rb, dict) and rb.get("type") == "text"
) )
results[tool_id] = str(result_content) results[tool_id] = {"result": str(result_content), "is_error": bool(b.get("is_error", False))}
return results return results
@@ -242,7 +243,11 @@ def _group_into_display_turns(
# Attach tool results to tool steps # Attach tool results to tool steps
for step in steps: for step in steps:
if step["type"] == "tool": if step["type"] == "tool":
step["result"] = tool_results.get(step.get("id", ""), "") tr = tool_results.get(step.get("id", ""), {})
if not isinstance(tr, dict):
tr = {"result": tr}
step["result"] = tr.get("result", "")
step["is_error"] = tr.get("is_error", False)
if steps or final_text: if steps or final_text:
turn = { turn = {

View File

@@ -1728,10 +1728,14 @@ function renderStepsHtml(steps) {
} else if (step.type === 'tool') { } else if (step.type === 'tool') {
const argsStr = formatToolArgs(step.arguments || {}); const argsStr = formatToolArgs(step.arguments || {});
const resultStr = step.result ? escapeHtml(String(step.result)) : ''; const resultStr = step.result ? escapeHtml(String(step.result)) : '';
const isErr = step.is_error === true;
const iconClass = isErr
? 'fas fa-times text-red-400 flex-shrink-0 tool-icon'
: 'fas fa-check text-primary-400 flex-shrink-0 tool-icon';
html += ` html += `
<div class="agent-step agent-tool-step"> <div class="agent-step agent-tool-step${isErr ? ' tool-failed' : ''}">
<div class="tool-header" onclick="this.parentElement.classList.toggle('expanded')"> <div class="tool-header" onclick="this.parentElement.classList.toggle('expanded')">
<i class="fas fa-check text-primary-400 flex-shrink-0 tool-icon"></i> <i class="${iconClass}"></i>
<span class="tool-name">${escapeHtml(step.name || '')}</span> <span class="tool-name">${escapeHtml(step.name || '')}</span>
<i class="fas fa-chevron-right tool-chevron"></i> <i class="fas fa-chevron-right tool-chevron"></i>
</div> </div>
@@ -1742,8 +1746,8 @@ function renderStepsHtml(steps) {
</div> </div>
${resultStr ? ` ${resultStr ? `
<div class="tool-detail-section tool-output-section"> <div class="tool-detail-section tool-output-section">
<div class="tool-detail-label">Output</div> <div class="tool-detail-label">${isErr ? 'Error' : 'Output'}</div>
<pre class="tool-detail-content">${resultStr}</pre> <pre class="tool-detail-content${isErr ? ' tool-error-text' : ''}">${resultStr}</pre>
</div>` : ''} </div>` : ''}
</div> </div>
</div>`; </div>`;