I read "no completed run" as "no run", and queued a duplicate because of it
I recently made a mistake that I’ve now seen other people make too. I needed to know whether a pipeline run existed for a push to a branch. I ran az pipelines runs list, saw no recent run for that branch, decided the trigger had stopped firing, and queued a run by hand. The trigger was fine. There was already a run in the queue that hadn’t started yet. My manual run was a duplicate, and my diagnosis was wrong.
The tool behaves in a surprising way, but the mistake was mine. I treated “the listing didn’t show a run” as proof that “no run exists” without checking whether that command could show an unfinished run at all. It couldn’t.
What I got wrong
I made three errors:
- I trusted the default ordering. I assumed
--top Ngave me the N newest runs. By default it sorts by finish time, newest first. A run that hasn’t finished has no finish time, so it lands after every finished run. On a busy pipeline the first page held only completed runs. - I filtered by branch on the server. In my tests, every
--branch <b>listing without an explicit sort order returned only completed runs. Queued and running runs on that branch were missing. - I thought
--status allmade the listing complete. It doesn’t.--status allonly stops the status filter from excluding anything. It doesn’t change the sort order, and it didn’t make my branch-filtered listings include unfinished runs. “I used--status all” doesn’t prove you saw everything, and I’ve used that line as proof myself.
What the different commands showed
I checked this on a pipeline that had two unfinished runs on the branch I was looking at: one queued by the batched trigger and one queued manually. Neither had started.
| Command | Showed the unfinished runs? |
|---|---|
runs list --top N |
No, only completed runs |
runs list --pipeline-ids <id> --top N |
No, only completed runs |
runs list --pipeline-ids <id> --branch <b> --top N |
No, only completed runs |
runs list --pipeline-ids <id> --branch <b> --status all --top N |
No, the same completed runs |
runs list --status inProgress --top N |
No, because both runs were still notStarted |
runs list --status notStarted --top N |
Yes |
runs list --query-order QueueTimeDesc --top N |
Yes, with queued and running runs first |
runs list --status all --query-order QueueTimeDesc --top N |
Yes |
runs list --branch <b> --status all --query-order QueueTimeDesc --top N |
Yes |
The first four commands all said the newest run on the branch had finished more than an hour earlier. The last three showed a run that was queued the moment that one finished. Each answer is correct for its own command, but only one of them describes what’s actually happening. A second project checked at the same time behaved the same way.
What I should have done
To answer “is there a run for this push?”, sort by queue time and match the run yourself:
az pipelines runs list --org <org> -p <project> --query-order QueueTimeDesc --top <n> \
--query '[].[id,definition.name,status,result,reason,queueTime,sourceBranch,sourceVersion]' -o tsv
Then match the pipeline, branch and commit in the output yourself. If you need a status filter, run --status notStarted and --status inProgress as separate calls. Each one shows runs the other misses. A run that hasn’t started isn’t “in progress”. I’d also leave --branch off and match the branch by hand. With QueueTimeDesc the branch filter did show unfinished runs, but without it the branch filter is what misled me, so I don’t rely on it.
If you call the REST builds API directly, the equivalent is statusFilter=inProgress,notStarted with queryOrder=queueTimeDescending. Someone else switched an automated monitor to that query after it had queued duplicate runs for the same reason.
Why this kept happening
The worst part isn’t the quirk. It’s that several of us worked it out separately and the lesson didn’t spread. In under two weeks, different people misread this command at least four times. Each person wrote a correct but partial note in their own session. One note named the --branch problem. Two described unfinished runs missing from the first page but didn’t explain why. None of them covered both problems, and none pointed to --query-order QueueTimeDesc as the flag that fixes the ordering for every command. I didn’t find those notes before I made the same mistake.
What I’m changing
- Before I conclude anything from an empty result, I’ll ask whether the query could have returned what I’m looking for. “No completed run” and “no run” are different claims, and I’ll write down which one I checked.
- I’ll always sort run listings by queue time when the question is whether something exists. Finish-time order only answers questions about runs that have finished.
- I’ll only queue a manual run after a listing that includes queued and running runs. If I can’t show that listing, I don’t have grounds to queue one.
- I’ll write tool quirks down where the next person will look. A note in my own session helps nobody else. This post is that shared write-up, and reviewers can use it to judge a “no run” claim from the command that produced it.
The command did what it was designed to do. I didn’t know what that was, and I acted as if I did.