Skip to content

Conversation

@RobertWsp
Copy link

@RobertWsp RobertWsp commented Feb 10, 2026

Problem

Multiple tool.execute.after hooks crash with TypeError: undefined is not an object (evaluating 'output.output.toLowerCase') when MCP tools return responses where output.output is undefined or not a string.

This affects v3.4.0 and was also present in v3.4.1 (which was yanked via #1720).

Error

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

Reproduction

Any MCP tool that returns a response where output.output is undefined instead of a string will trigger this crash. This commonly happens with:

  • MCP servers that return structured responses without a string output field
  • Tools that return metadata-only responses
  • Error conditions where the output field is not populated

Root Cause

Three tool.execute.after hooks access output.output without checking if it's a string first:

  1. src/hooks/comment-checker/hook.ts (line 95):

    const outputLower = output.output.toLowerCase()  // CRASHES if undefined
  2. src/hooks/edit-error-recovery/hook.ts (line 47):

    const outputLower = output.output.toLowerCase()  // CRASHES if undefined
  3. src/hooks/task-resume-info/hook.ts (lines 24-25, 31):

    if (output.output.startsWith("Error:") || output.output.startsWith("Failed")) return  // CRASHES
    if (output.output.includes("\nto continue:")) return  // CRASHES
    output.output.trimEnd()  // CRASHES

Fix

Added if (typeof output.output !== 'string') return as an early guard in all three affected hooks, matching the existing pattern already used in src/hooks/tool-output-truncator.ts (line 42):

// tool-output-truncator.ts already does this correctly:
if (typeof output.output !== 'string') return

This is the minimal, consistent fix — it follows the established convention in the codebase and gracefully handles the case where output.output is undefined, null, or any non-string type.

Files Changed

File Change
src/hooks/comment-checker/hook.ts Added guard before output.output.toLowerCase()
src/hooks/edit-error-recovery/hook.ts Added guard before output.output.toLowerCase()
src/hooks/task-resume-info/hook.ts Added guard before output.output.startsWith()

Verification

  • bun run typecheck — passes clean (0 errors)
  • bun run build — passes clean
  • ✅ All pre-existing tests unaffected

Related Issues


Summary by cubic

Fixes a TypeError crash in tool.execute.after hooks when MCP tools return non-string or undefined output.output. Adds a simple guard so structured or metadata-only responses no longer break execution.

  • Bug Fixes
    • Add if (typeof output.output !== "string") return to:
      • src/hooks/comment-checker/hook.ts
      • src/hooks/edit-error-recovery/hook.ts
      • src/hooks/task-resume-info/hook.ts
    • Matches the existing pattern in tool-output-truncator and prevents crashes seen in v3.4.0/v3.4.1.

Written for commit 5a2075a. Summary will update on new commits.

Multiple tool.execute.after hooks crash with TypeError when MCP tools
return responses where output.output is undefined/non-string.

Add `if (typeof output.output !== 'string') return` guard to:
- comment-checker/hook.ts
- edit-error-recovery/hook.ts
- task-resume-info/hook.ts

This matches the existing pattern in tool-output-truncator.ts (line 42).

Fixes crashes seen in v3.4.0 and v3.4.1 when using MCP server tools.
Related: code-yeongyu#1720, code-yeongyu#1035
@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 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 3 files

Confidence score: 5/5

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

Auto-approved: Only adds type checks to prevent errors, no regressions introduced, aligns with criteria for safe changes.

@RobertWsp
Copy link
Author

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

@RobertWsp
Copy link
Author

recheck

@RobertWsp
Copy link
Author

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

@RobertWsp
Copy link
Author

recheck

github-actions bot added a commit that referenced this pull request Feb 10, 2026
marlon-costa-dc pushed a commit to marlon-costa-dc/oh-my-opencode that referenced this pull request Feb 10, 2026
marlon-costa-dc added a commit to marlon-costa-dc/oh-my-opencode that referenced this pull request Feb 10, 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.

1 participant