Skip to content

feat(workspace-events): add agent tool error event - #6689

Open
BillLeoutsakosvl346 wants to merge 2 commits into
stagingfrom
feat/agent-tool-error-trigger
Open

feat(workspace-events): add agent tool error event#6689
BillLeoutsakosvl346 wants to merge 2 commits into
stagingfrom
feat/agent-tool-error-trigger

Conversation

@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor

Summary

  • add an agent_tool_error Sim Workspace Event with bounded, safe tool failure metadata
  • represent recovered Agent tool failures as handled error spans while keeping the Agent and workflow successful
  • expose Agent Tool Error in the workspace-event trigger editor

Validation

  • confirmed the localhost trace and persisted execution record show Workflow: success, Agent: success, and always_fail: handled error
  • bun run --cwd apps/sim test -- lib/workspace-events/*.test.ts lib/logs/execution/trace-spans/trace-spans.test.ts triggers/sim/workspace-event.test.ts
  • bunx tsc --noEmit -p apps/sim/tsconfig.json
  • bun run check:api-validation
  • bun run check:trigger-block-cycle
  • bun run check:utils
  • bun run check:source-text

@vercel

vercel Bot commented Aug 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 14, 2026 1:08am

Request Review

@cursor

cursor Bot commented Aug 14, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes execution trace semantics and workspace event emission on the hot completion path; misclassified tool failures could affect alerts and trace error highlighting, though tests cover common envelope shapes.

Overview
Introduces an agent_tool_error Sim workspace event (trigger dropdown, bounded toolError payload, emission at run completion when agent tool spans fail) that can fire alongside execution_success when the agent recovers.

Trace span building now derives tool errors from multiple provider shapes via getToolCallErrorMessage, marks failed tool children on successful agents as errorHandled, and hasErrorInTree respects unhandled errors in child tool spans so the workflow can stay green while tool rows show failure.

The log trace detail panel labels spans with Handled error when a direct error span is errorHandled.

Reviewed by Cursor Bugbot for commit 1bd73bd. Bugbot is set up for automated code reviews on this repo. Configure here.

@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor Author

File breakdown

Tool-error detection and trace construction

These files determine whether an Agent tool failed and how that failure is represented:

  • apps/sim/executor/types.ts

    • Allows normalized tool calls to carry provider success and status signals.
  • apps/sim/lib/logs/execution/trace-spans/span-factory.ts

    • Recognizes the supported tool-failure formats.
    • Marks recovered failures as errorHandled.
    • Keeps the Agent and workflow successful.
  • apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts

    • Tests the real nested error shape returned by always_fail.
    • Confirms Workflow: success, Agent: success, Tool: handled error.

Logs display

These files control how handled failures appear in the trace interface:

  • apps/sim/app/workspace/[workspaceId]/logs/components/log-details/utils.ts

    • Prevents a handled tool error from making its successful Agent ancestor appear errored.
  • apps/sim/app/workspace/[workspaceId]/logs/components/log-details/components/trace-view/trace-view.tsx

    • Labels the failed tool as Handled error.

Workspace-event behavior and payload

These files define and deliver the new event:

  • apps/sim/lib/workspace-events/constants.ts

    • Registers agent_tool_error and declares its available outputs.
  • apps/sim/lib/workspace-events/types.ts

    • Defines the typed, safe tool-error metadata.
  • apps/sim/lib/workspace-events/payload.ts

    • Builds the event payload without exposing tool arguments or complete results.
  • apps/sim/lib/workspace-events/emitter.ts

    • Finds failed Agent tool spans after run completion.
    • Dispatches one event per failed tool invocation.
  • apps/sim/lib/workspace-events/emitter.test.ts

    • Verifies recovered failures emit agent_tool_error.
    • Confirms execution_success can still fire for the same run.
    • Confirms successful tools do not emit the new event.

Trigger editor

These files expose the event when configuring a Sim Workspace Events trigger:

  • apps/sim/triggers/sim/workspace-event.ts

    • Adds “Agent Tool Error” to the event dropdown.
  • apps/sim/triggers/sim/workspace-event.test.ts

    • Verifies the new event exposes runId, toolError, and the standard event fields.

No database migration, API route, provider implementation, or new infrastructure was added.

@greptile-apps

greptile-apps Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds workspace events for Agent tool failures while preserving successful Agent and workflow status for recovered failures.

  • Classifies supported tool-failure result shapes as handled error spans with bounded messages.
  • Emits one agent_tool_error payload per failed Agent tool invocation.
  • Exposes the event and its tool metadata in the workspace-event trigger editor.
  • Updates trace presentation and tests for recovered tool failures.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/lib/logs/execution/trace-spans/span-factory.ts Recognizes explicit and nested tool-failure shapes, creates handled error spans, and bounds recorded error messages.
apps/sim/lib/workspace-events/emitter.ts Collects failed tool spans directly beneath Agent spans and dispatches scoped agent_tool_error events.
apps/sim/lib/workspace-events/payload.ts Adds the bounded agent_tool_error wire payload while preserving the common event schema.
apps/sim/lib/workspace-events/constants.ts Registers the new event type and conditionally exposes its run and tool-error fields.
apps/sim/triggers/sim/workspace-event.ts Makes Agent Tool Error selectable in the workspace-event trigger editor.
apps/sim/app/workspace/[workspaceId]/logs/components/log-details/utils.ts Prevents handled descendant failures from incorrectly marking successful parent traces as errored.

Sequence Diagram

sequenceDiagram
  participant Tool as Agent Tool
  participant Agent as Agent Execution
  participant Trace as Trace Span Builder
  participant Emitter as Workspace Event Emitter
  participant Subscriber as Subscriber Workflow

  Tool-->>Agent: Failure result
  Agent-->>Trace: Successful Agent log with failed tool call
  Trace->>Trace: Create error tool span
  Trace->>Trace: Mark errorHandled when Agent succeeded
  Trace-->>Emitter: Persisted trace spans
  Emitter->>Emitter: Collect Agent tool errors
  Emitter-->>Subscriber: agent_tool_error payload
Loading

Reviews (2): Last reviewed commit: "fix(logs): recognize nested tool failure..." | Re-trigger Greptile

Comment thread apps/sim/lib/logs/execution/trace-spans/span-factory.ts
@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor Author

@greptileai

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