Skip to content

fix(agent-status): surface tool-failure errors across Cursor/Copilot/Grok - #8483

Merged
AmethystLiang merged 2 commits into
mainfrom
surface-agent-tool-failures
Jul 13, 2026
Merged

AmethystLiang merged 2 commits into
mainfrom
surface-agent-tool-failures

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

What & why

When an agent's tool call fails, the compact sidebar was showing the stale tool name/input instead of the failure error, hiding the error from the user. The sidebar prioritizes active-tool metadata over the failure message, so a just-failed tool that still looks "in-flight" masks the error text.

This extracts a shared clearActiveToolFieldsUpdate() helper in src/shared/agent-hook-listener.ts that clears toolName / toolInput / interactivePrompt on tool-failure events, so the failure message surfaces instead. It's applied uniformly across the agents that emit tool-failure hooks:

  • Claude — PostToolUseFailure
  • Cursor — postToolUseFailure
  • Copilot — PostToolUseFailure and ErrorOccurred
  • Grok — post_tool_use_failure

The failure error text is still surfaced as lastAssistantMessage for every agent (that logic runs after the clear and is unchanged). The clear composes with resolveToolState's existing clearsUnidentifiedTool / clearsUnpreviewableInput paths so the fields drop rather than inheriting stale values, and a subsequent PreToolUse restores normal tool display.

Testing

  • Added normalization tests for Claude, Cursor, Copilot, and Grok asserting the failure clears toolName/toolInput while surfacing the error, plus a Claude retry case confirming the next PreToolUse restores tool fields.
  • pnpm typecheck passes.

Made with Orca 🐋

Extract a shared clearActiveToolFieldsUpdate() helper and apply it to
Cursor's postToolUseFailure, Copilot's PostToolUseFailure/ErrorOccurred,
and Grok's post_tool_use_failure events, matching the existing Claude
behavior so the failure message surfaces instead of the last tool name.
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Agent hook normalization now clears cached tool name, input, and interactive prompt fields when Claude, Cursor, Copilot, or Grok tool failures occur. Failure text continues to populate lastAssistantMessage. Tests cover all four integrations, including Claude repopulating tool metadata on a subsequent PreToolUse event.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change and testing, but it omits required template sections like Screenshots, AI Review Report, Security Audit, and Notes. Add the missing template sections and fill them in: Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the core change: surfacing tool-failure errors in agent status across multiple agents.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/shared/agent-hook-listener.ts (1)

1773-1777: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a test for Copilot ErrorOccurred clearing behavior.

ErrorOccurred is now routed through clearActiveToolFieldsUpdate() alongside PostToolUseFailure, but only PostToolUseFailure has test coverage in server.test.ts. A dedicated test would guard against accidental removal of ErrorOccurred from the condition.

🧪 Suggested test for ErrorOccurred
   it('PostToolUseFailure surfaces the error and clears stale tool fields', () => {
     // ... existing test ...
   })
+
+  it('ErrorOccurred surfaces the error and clears stale tool fields', () => {
+    _internals.normalizeHookPayload(
+      'copilot',
+      buildBody({
+        hook_event_name: 'PreToolUse',
+        toolName: 'bash',
+        toolInput: { command: 'pnpm test' }
+      }),
+      'production'
+    )
+    const failed = _internals.normalizeHookPayload(
+      'copilot',
+      buildBody({
+        hook_event_name: 'ErrorOccurred',
+        toolName: 'bash',
+        toolInput: { command: 'pnpm test' },
+        error_message: 'agent crashed'
+      }),
+      'production'
+    )
+    expect(failed?.payload).toMatchObject({
+      state: 'working',
+      lastAssistantMessage: 'agent crashed'
+    })
+    expect(failed?.payload.toolName).toBeUndefined()
+    expect(failed?.payload.toolInput).toBeUndefined()
+  })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1cee47b9-a324-414c-84c4-5c172f7869cb

📥 Commits

Reviewing files that changed from the base of the PR and between 81ed573 and 46acc60.

📒 Files selected for processing (3)
  • src/main/agent-hooks/server.test.ts
  • src/shared/agent-hook-listener.test.ts
  • src/shared/agent-hook-listener.ts

@AmethystLiang
AmethystLiang merged commit 5856a9f into main Jul 13, 2026
2 checks passed
@AmethystLiang
AmethystLiang deleted the surface-agent-tool-failures branch July 13, 2026 05:21
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…Grok (stablyai#8483)

* fix(agent-status): surface Claude tool failures

* Fix compact sidebar hiding tool-failure errors behind stale tool name

Extract a shared clearActiveToolFieldsUpdate() helper and apply it to
Cursor's postToolUseFailure, Copilot's PostToolUseFailure/ErrorOccurred,
and Grok's post_tool_use_failure events, matching the existing Claude
behavior so the failure message surfaces instead of the last tool name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant