Skip to content

Bug: sortBy createdTime does not work correctly #19

@Leoyishou

Description

@Leoyishou

Description

When using list_tasks with sortBy: "createdTime" and sortOrder: "desc", tasks are not sorted by creation time correctly. The oldest tasks appear first instead of the newest.

Steps to Reproduce

  1. Call list_tasks with the following parameters:
{
  "sortBy": "createdTime",
  "sortOrder": "desc",
  "limit": 5
}
  1. Decode the ObjectID timestamps of the returned tasks

  2. Observe that tasks are sorted oldest-first, not newest-first as expected

Expected Behavior

Tasks should be sorted by creation time in descending order (newest first).

Actual Behavior

Tasks are sorted in ascending order (oldest first), regardless of the sortOrder parameter.

Root Cause Analysis

The sortTasks function uses sortOrder field as a proxy for creation time:

case "createdTime": {
    const orderA = a.sortOrder ?? 0;
    const orderB = b.sortOrder ?? 0;
    comparison = orderA - orderB;
    break;
}

The sortOrder values are extremely large negative numbers (~8.9×10^18), exceeding JavaScript's safe integer range (2^53 ≈ 9×10^15). This causes precision loss during arithmetic operations.

Proposed Fix

See PR #18 - Extract timestamp from MongoDB ObjectID instead of using sortOrder field.

Environment

  • dida365-mcp-server version: latest (via npx)
  • Node.js version: v22.x
  • OS: macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions