Skip to content

Conversation

@ojh102
Copy link

@ojh102 ojh102 commented Feb 11, 2026

Summary

Fixes #1749

  • Add typeof output.output !== "string" guard in edit-error-recovery and delegate-task-retry hooks to prevent TypeError crash when MCP tools return non-string results

Problem

MCP tools (e.g., Linear MCP, Notion MCP) can return structured JSON objects instead of plain strings. When this happens, output.output is undefined in the afterToolResult callback, causing:

TypeError: undefined is not an object (evaluating 'output.output.toLowerCase')

Two hooks are affected:

  • src/hooks/edit-error-recovery/hook.ts — calls output.output.toLowerCase()
  • src/hooks/delegate-task-retry/hook.ts — passes output.output to detectDelegateTaskError()

Fix

Added the same guard pattern already used in tool-output-truncator.ts:

if (typeof output.output !== "string") return

This ensures both hooks gracefully skip when the tool output is not a string, consistent with existing conventions in the codebase.

Changes

File Change
src/hooks/edit-error-recovery/hook.ts Add string type guard before .toLowerCase()
src/hooks/delegate-task-retry/hook.ts Add string type guard before detectDelegateTaskError()

Summary by cubic

Prevented TypeError crashes in afterToolResult hooks when MCP tools return non-string outputs. Added a string check for output.output in edit-error-recovery and delegate-task-retry, skipping processing if it isn’t a string.

Written for commit bb6a011. Summary will update on new commits.

…ooks

MCP tools can return non-string results (e.g. structured JSON objects).
When this happens, output.output is undefined, causing TypeError crashes
in edit-error-recovery and delegate-task-retry hooks that call methods
like .toLowerCase() without checking the type first.

Add typeof string guard in both hooks, consistent with the existing
pattern used in tool-output-truncator.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 11, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Simple defensive type guards adding typeof checks for string output. No functional changes, prevents runtime errors. 2 lines, 2 files, clearly safe with no regression risk.

@ojh102
Copy link
Author

ojh102 commented Feb 11, 2026

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Feb 11, 2026
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.

TypeError crash in afterToolResult hooks when MCP tool returns non-string output

1 participant