Selecting the Latest Targeted Revision
Learn how to select the newest draft revision in a bounded workflow queue by sorting descending revisions before path tie-breaks.
Table of Contents5 sections

A source often has multiple review revisions, and if a targeted workflow scans only a bounded prefix, an older revision can displace the newest one.
Quick solution:
// Sort matching revision drafts by descending -rN before path tie-break
const selected = drafts
.filter(d => d.source === targetSource)
.sort((a, b) => parseRevision(b) - parseRevision(a) || a.path.localeCompare(b.path))[0];
Prerequisites include a list of draft objects containing explicit revision numbers. A caution to keep in mind is that untargeted batches still require stable default ordering to avoid regression.
Diagnosing Revision Queue Scan Failures
When a workflow inspects a limited batch of files, lexicographical sorting on paths can place an older revision at the front of the queue. For instance, revision 16 might appear before revision 24 due to naming conventions or directory structures. Because the inspection budget is bounded, the workflow processes the stale revision and exits before reaching the correct draft.
To understand this behavior in practice, you can review how modern API routing and queue boundaries operate in platform documentation such as Cloudflare Workflows or when managing object trees via the REST API endpoints for Git trees, and also consider Automating Android Ci Workflows With Github.
Implementing Newest-First Revision Sorting
To ensure the correct draft is chosen, modify your sorting logic to prioritize descending revision numbers before falling back to path comparisons. This approach guarantees that even if a scan window is bounded, the highest revision number is always evaluated first.
| Option | When to Use It | Trade-off or Failure Mechanism | Recommendation |
|---|---|---|---|
| Lexicographical Path Sort | Ordinary untargeted batch operations. | Fails to prioritize newer revision numbers when path names differ. | Use only for default untargeted runs. |
| Descending Revision Sort | Targeted source runs with multiple drafts. | Requires reliable parsing of revision tags like -rN. |
Use for all targeted workflow queues. |
Verification Checklist
- Filter drafts explicitly by the requested source target.
- Parse the revision identifier into a numeric value.
- Sort matching drafts in descending order by revision number.
- Apply path tie-breaking only after revision sorting.
- Confirm via test that the highest revision is selected.
Conclusion
By following the steps outlined above and implementing the newest-first revision sorting logic, you can ensure that your workflow always selects the latest targeted revision, even in cases where the scan window is bounded. This approach helps prevent older revisions from being processed incorrectly and ensures that your workflow operates efficiently and effectively.
Continue Exploring
You Might Also Like

Deferring Publication After a Budget-Safe Draft Revision
Learn how to preserve a serverless publishing workflow draft when request limits prevent same-run publication by deferring publication.

Secure Public Receipt Link with Access Token
Learn how to build a privacy-safe public receipt link using high-entropy bearer tokens, SHA-256 hashing at rest, constant-time verification, no-store caching, and an explicit allowlisted response DTO.

Build a Secure Iframe Widget for Other Websites
Learn how to build and securely embed an interactive iframe widget on third-party websites by enforcing least-privilege sandboxing, validating postMessage payloads, and configuring strict CSP policies.