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
- Call
list_tasks with the following parameters:
{
"sortBy": "createdTime",
"sortOrder": "desc",
"limit": 5
}
-
Decode the ObjectID timestamps of the returned tasks
-
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
Description
When using
list_taskswithsortBy: "createdTime"andsortOrder: "desc", tasks are not sorted by creation time correctly. The oldest tasks appear first instead of the newest.Steps to Reproduce
list_taskswith the following parameters:{ "sortBy": "createdTime", "sortOrder": "desc", "limit": 5 }Decode the ObjectID timestamps of the returned tasks
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
sortOrderparameter.Root Cause Analysis
The
sortTasksfunction usessortOrderfield as a proxy for creation time:The
sortOrdervalues 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