fix(decomposer): guard against empty content array and malformed JSON#727
Open
vishkrish200 wants to merge 2 commits intoComposioHQ:mainfrom
Open
fix(decomposer): guard against empty content array and malformed JSON#727vishkrish200 wants to merge 2 commits intoComposioHQ:mainfrom
vishkrish200 wants to merge 2 commits intoComposioHQ:mainfrom
Conversation
- Use optional chaining on res.content[0] in classifyTask and decomposeTask so an empty content array doesn't crash with TypeError - Change decomposeTask fallback from "[]" to "" so empty content hits the "no JSON array" error with a clear message - Wrap JSON.parse in try-catch to surface malformed JSON with context - Add decomposer.test.ts: 18 tests covering all pure functions and LLM error paths via a mocked Anthropic client Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
Three unsafe patterns in
classifyTask()anddecomposeTask()inpackages/core/src/decomposer.ts:res.content[0]accessed without a length check — the Anthropic API can return an emptycontentarray on certain error conditions, which would throw an unhandledTypeErrorwith no context. Fixed with optional chaining onblock?.type."[]"for a non-text block would pass the regex check, parse to an empty array, then throw a misleading "produced 0 subtasks" error. Changed to""so it correctly hits the "no JSON array in response" error path.JSON.parsewith no try-catch — malformed JSON from the API threw a rawSyntaxErrorwith no indication of what was being parsed. Wrapped in a try-catch that includes the offending string in the message.How to test it
pnpm --filter @composio/ao-core testNew test file
packages/core/src/__tests__/decomposer.test.tscovers:formatLineage,formatSiblings,getLeaves,getSiblings,formatPlanTree,propagateStatus)classifyTaskwith empty content → defaults to"atomic"decomposeTaskwith empty content → throws "no JSON array in response"decomposeTaskwith malformed JSON → throws "invalid JSON in response: ..."