claude-task-master icon indicating copy to clipboard operation
claude-task-master copied to clipboard

bug: unable to extract JSON content when expanding task

Open conradob opened this issue 7 months ago • 8 comments

Description

When running the task-master expand command, it seems to be breaking when getting some special characters.

Is there a way to debug this to understand what is the expand response?

Steps to Reproduce

  1. For this task:
    {
      "taskId": 3,
      "taskTitle": "Create HTTP Client with Authentication",
      "complexityScore": 8,
      "recommendedSubtasks": 4,
      "expansionPrompt": "Break down the HTTP client implementation into subtasks covering: 1) Core fetch wrapper with authentication, 2) Advanced features including timeout, retries, and error handling, 3) Caching implementation, and 4) Comprehensive testing strategy. For each subtask, include detailed implementation code, TypeScript interfaces, and test scenarios.",
      "reasoning": "This task involves complex asynchronous operations, error handling, retry logic, and caching. It requires deep understanding of JavaScript promises, fetch API, and HTTP protocols. The implementation needs to be robust and handle various edge cases while maintaining type safety."
    },
  1. Run command:
task-master expand --id=3 --num=4 --prompt="Break down the HTTP client implementation into subtasks covering: 1) Core fetch wrapper with authentication, 2) Advanced features including timeout, retries, and error handling, 3) Caching implementation, and 4) Comprehensive testing strategy. For each subtask, include detailed implementation code, TypeScript interfaces, and test scenarios."
  1. Output:
Expanding task 3...
[INFO] Reading tasks from <PROJECT_PATH>/tasks/tasks.json
[INFO] Expanding task 3: Create HTTP Client with Authentication
[INFO] Found complexity analysis for task 3: Score 8
[INFO] Using explicitly provided subtask count: 4
[INFO] Using expansion prompt from complexity report and simplified system prompt for task 3.
⠋ Generating 4 subtasks...[INFO] Using AI service with role: main
[INFO] generateTextService called {"role":"main","projectRoot":"<PROJECT_PATH>"}
[INFO] New AI service call with role: main
[INFO] Attempt 1/3 calling generateAnthropicText (Provider: anthropic, Model: claude-3-7-sonnet-20250219, Role: main)
⠴ Generating 4 subtasks...[INFO] generateAnthropicText succeeded for role main (Provider: anthropic) on attempt 1
[INFO] generateTextService succeeded using role: main
[INFO] Successfully received text response from AI service
[INFO] Attempting to parse subtasks object from text response...
[INFO] Extracted JSON content from Markdown code block.
[ERROR] Failed to parse JSON object: Unexpected token 'y', "typescript\"... is not valid JSON
[ERROR] Problematic JSON string (first 500 chars): typescript\n// Example implementation\nexport interface RequestOptions extends RequestInit {\n  baseUrl?: string;\n  headers?: Record<string, string>;\n  params?: Record<string, string>;\n  timeout?: number;\n  auth?: {\n    type: 'bearer' | 'basic' | 'apiKey';\n    token?: string;\n    username?: string;\n    password?: string;\n    headerName?: string;\n  };\n}\n\nexport class HttpClient {\n  private baseUrl: string;\n  private defaultOptions: RequestOptions;\n\n  constructor(baseUrl: string =
[ERROR] Original Raw Response (first 500 chars): {
  "subtasks": [
    {
      "id": 1,
      "title": "Implement Core HTTP Client with Authentication",
      "description": "Create a base HTTP client wrapper around fetch API with authentication support",
      "dependencies": [],
      "details": "1. Create TypeScript interfaces for request/response types\n2. Implement a base HttpClient class with methods for GET, POST, PUT, DELETE\n3. Add authentication handling (Bearer token, Basic auth, API key)\n4. Support request/response interceptors\n5
[ERROR] Error during AI call or parsing for task 3: Failed to parse JSON response object: Unexpected token 'y', "typescript\"... is not valid JSON
[ERROR] Error expanding task 3: Failed to parse JSON response object: Unexpected token 'y', "typescript\"... is not valid JSON
Error expanding task 3: Failed to parse JSON response object: Unexpected token 'y', "typescript\"... is not valid JSON

Expected Behavior

Should expand the task

Actual Behavior

It's currently erroring

Screenshots or Logs

See above

Environment

  • Task Master version: 0.13.2
  • Node.js version: v22.14.0
  • Operating system: MacOS
  • IDE (if applicable): CLI

Additional Context

Running CLI command

conradob avatar May 05 '25 19:05 conradob

Which AI are you using ?

Crunchyman-ralph avatar May 06 '25 13:05 Crunchyman-ralph

I get this too when using Gemini Flash 2.5 Thinking

alicoding avatar May 06 '25 15:05 alicoding

I meant what does your mcp.json config look like and .taskmasterconfig ?

Crunchyman-ralph avatar May 07 '25 15:05 Crunchyman-ralph

I meant what does your mcp.json config look like and .taskmasterconfig ?

I was having the same error as OP, but based on your reply I changed the maxTokens, since it was in 120k, to 1kk and now its working, in my case (gemini-2.5-pro-exp-03-25)

diaraujo13 avatar May 07 '25 17:05 diaraujo13

I'm having the same issue, using gemini-2.5-pro-exp-03-25:

Error: Failed to parse JSON response object: Unexpected end of JSON input

And even claude-3-7-sonnet-20250219:

Failed to parse JSON response object: Unexpected token p in JSON at position 0

victorsmoliveira avatar May 07 '25 19:05 victorsmoliveira

TBH, when using with the MCP through Cursor, I'm not facing this issue. This occurred when I was using the task-master as stated in step 2.

conradob avatar May 09 '25 15:05 conradob

im facing the same issue with gemini-2.5-flash-preview-04.

[ERROR] Error during AI call or parsing for task 9: Failed to parse JSON response object: Unexpected token i in JSON at position 394 [ERROR] Error expanding task 9: Failed to parse JSON response object: Unexpected token i in JSON at position 394 Error expanding task 9: Failed to parse JSON response object: Unexpected token i in JSON at position 394

Doohwancho avatar May 12 '25 08:05 Doohwancho

i get this too using gemini-2.5-pro-preview. is there a way around it?

daver1958 avatar May 26 '25 01:05 daver1958

Feels like a lot of this has been fixed in past releases, definitely improved in 0.18.0. If the issue persists, please create a new issue

Crunchyman-ralph avatar Jun 21 '25 19:06 Crunchyman-ralph

I'm facing the exact same issue, does anyone find any solutions?

mode: gemini-2.5-flash-preview-04-17

craftgear avatar Jun 23 '25 13:06 craftgear

@craftgear could you give us your error ?

Crunchyman-ralph avatar Jun 23 '25 13:06 Crunchyman-ralph

@craftgear I would ask you to create a separate issue since I feel like this was resolved, and you're probably running into a different type of issue

Crunchyman-ralph avatar Jun 23 '25 13:06 Crunchyman-ralph

@Crunchyman-ralph Hey, thanks for chiming in. Got it, I'm gonna open an new issue.

FYI, Here is what I get anyway.

[ERROR] Advanced extraction: Failed to parse JSON object: Unexpected token '`', "```json
{
"... is not valid JSON
[ERROR] Advanced extraction: Problematic JSON string for parse (first 500 chars): ```json
{
  "subtasks": [
    {
      "id": 1,
      "title": "Install Markdown Parser Library",
      "description": "Add the chosen Markdown parser library (e.g., `marked.js`) to the project dependencies.",
      "dependencies": [],
      "details": "Use npm or yarn to install the library: `npm install marked` or `yarn add marked`. Ensure it's added to the project's `package.json`.",
[ERROR] Error during AI call or parsing for task 3: Failed to parse JSON response object after both simple and advanced attempts: Unexpected token '`', "```json
{
"... is not valid JSON
[ERROR] Error expanding task 3: Failed to parse JSON response object after both simple and advanced attempts: Unexpected token '`', "```json
{
"... is not valid JSON
[ERROR] Failed to expand task 3: Failed to parse JSON response object after both simple and advanced attempts: Unexpected token '`', "```json
{
"... is not valid JSON

craftgear avatar Jun 24 '25 13:06 craftgear