claude-code - 💡(How to fix) Fix TaskList tool returns rows in non-monotonic order (appears to sort by last-updated, not task ID) [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52011Fetched 2026-04-23 07:38:56
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
labeled ×4closed ×1

Calling `TaskList` after updating several tasks returns rows in an order that does not match their numeric IDs. In the observed case, IDs 6, 7, 8, 9, 10 all reached `completed` status but `TaskList` returned them in the order 6, 7, 10, 8, 9. The ordering appears to be a secondary sort on something like `updated_at`, not on task ID.

Models emit `TaskList` output to users verbatim, so a non-monotonic order reads as a mistake the assistant made. In this session, the user asked "why did you number this sequence 1, 2, 5, 3?" before I realized the model was not choosing the order — the tool was.

Root Cause

Calling `TaskList` after updating several tasks returns rows in an order that does not match their numeric IDs. In the observed case, IDs 6, 7, 8, 9, 10 all reached `completed` status but `TaskList` returned them in the order 6, 7, 10, 8, 9. The ordering appears to be a secondary sort on something like `updated_at`, not on task ID.

Models emit `TaskList` output to users verbatim, so a non-monotonic order reads as a mistake the assistant made. In this session, the user asked "why did you number this sequence 1, 2, 5, 3?" before I realized the model was not choosing the order — the tool was.

RAW_BUFFERClick to expand / collapse

Summary

Calling `TaskList` after updating several tasks returns rows in an order that does not match their numeric IDs. In the observed case, IDs 6, 7, 8, 9, 10 all reached `completed` status but `TaskList` returned them in the order 6, 7, 10, 8, 9. The ordering appears to be a secondary sort on something like `updated_at`, not on task ID.

Models emit `TaskList` output to users verbatim, so a non-monotonic order reads as a mistake the assistant made. In this session, the user asked "why did you number this sequence 1, 2, 5, 3?" before I realized the model was not choosing the order — the tool was.

Reproduction

  1. Create tasks 6, 7, 8, 9, 10 (in ID order) via `TaskCreate`.
  2. Mark them `completed` in the following update sequence:
    • Set #6 → in_progress → completed
    • Set #7 → in_progress → completed
    • Set #8 → in_progress → completed
    • Set #9 → in_progress → completed
    • Set #10 → in_progress → completed
  3. Call `TaskList`.
  4. Observe that the returned rows appear as 6, 7, 10, 8, 9, not 6, 7, 8, 9, 10.

Actual output (literal, from session on 2026-04-22)

``` #6 [completed] Survey existing launchd jobs for pattern #7 [completed] Pick schedule slot after vault sync #10 [completed] Create gbrain-embed page in GBrain + update memory #8 [completed] Write com.pai.gbrain-embed.plist #9 [completed] Load, test-run, verify ```

Expected

Either:

  • Sort by numeric task ID ascending by default (most intuitive for small, human-authored lists), or
  • Document the sort order explicitly so model/tool callers can re-sort before presenting to users.

Why it matters

Users interpret `TaskList` output as the model's own ordering decision. Non-monotonic IDs read as sloppy. A stable, ID-ascending default would eliminate the confusion entirely; alternatively, an explicit `sort` parameter (`id` / `updated_at` / `status`) documents intent.

Environment

  • darwin 25.4.0, zsh
  • Claude Code CLI
  • Model: Opus 4.7 (1M context)
  • Observed 2026-04-22

extent analysis

TL;DR

The issue can be resolved by implementing a default sort order by numeric task ID ascending in the TaskList function or by adding an explicit sort parameter to allow callers to specify the sort order.

Guidance

  • Verify that the TaskList function is currently sorting tasks based on the updated_at field instead of the numeric task ID.
  • Consider adding an explicit sort parameter to the TaskList function to allow callers to specify the sort order, such as id, updated_at, or status.
  • If a default sort order is preferred, update the TaskList function to sort tasks by numeric task ID ascending by default.
  • Document the sort order used by the TaskList function to ensure that callers are aware of the ordering and can adjust accordingly.

Example

# Example of adding an explicit sort parameter to the TaskList function
def TaskList(sort_order='id'):
    # Retrieve tasks from database or other data source
    tasks = retrieve_tasks()
    
    # Sort tasks based on the specified sort order
    if sort_order == 'id':
        tasks.sort(key=lambda x: x.id)
    elif sort_order == 'updated_at':
        tasks.sort(key=lambda x: x.updated_at)
    # Add additional sort orders as needed
    
    return tasks

Notes

The issue may be specific to the Opus 4.7 model and the Claude Code CLI, and the solution may need to be adapted for other models or environments.

Recommendation

Apply a workaround by adding an explicit sort parameter to the TaskList function, allowing callers to specify the sort order and ensuring that the output is consistent and predictable. This approach provides flexibility and documentation of the sort order, addressing the user's concerns about the perceived ordering decision made by the model.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix TaskList tool returns rows in non-monotonic order (appears to sort by last-updated, not task ID) [1 participants]