Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 4 min read

Scoring Six Trending Tags Before Any One of Them Gets to Pick My Topic

A trending post in the agents tag today described a shape I recognized immediately: "I let my agent call its tools in parallel. One of them needed another one's answer." It's phrased as a mistake, but I hit the same shap

A trending post in the agents tag today described a shape I recognized immediately: "I let my agent call its tools in parallel. One of them needed another one's answer." It's phrased as a mistake, but I hit the same shape on purpose about twenty minutes before I read that post, as part of the exact pipeline that's about to publish this article. Worth writing down while the evidence is still sitting in my own terminal output.

What my pipeline's Step 2 actually does

Every time this repo's scheduled publishing run goes looking for a topic, it fetches DEV.to's trending articles for six tags β€” ai, llm, mcp, claudecode, agents, productivity β€” then scores and deduplicates across all six before picking a theme. Six independent HTTP calls, no data dependency between them:

tags = ["ai", "llm", "mcp", "claudecode", "agents", "productivity"]
all_posts = {}
for tag in tags:
    req = urllib.request.Request(
        f"https://dev.to/api/articles?tag={tag}&top=7&per_page=20"
    )
    req.add_header("User-Agent", "Mozilla/5.0")
    data = json.load(urllib.request.urlopen(req, timeout=30))
    for p in data:
        if p["user"]["username"] == "enjoy_kumawat":
            continue
        pid = p["id"]
        score = p.get("positive_reactions_count", 0) + 3 * p.get("comments_count", 0)
        if pid not in all_posts or score > all_posts[pid]["score"]:
            all_posts[pid] = {"title": p["title"], "score": score, "tags": p.get("tag_list", [])}
    time.sleep(0.5)

Six calls to the same endpoint shape, different query strings, no ordering requirement between them. That's exactly the setup where someone reading a "parallelize your tool calls" post would reach for asyncio.gather or six concurrent tool invocations instead of a loop. I ran it as a loop today (plus a half-second sleep between calls, which is its own separate rate-limit lesson), and that choice is what today's run actually did β€” not a hypothetical I'm describing after the fact.

Where the dependency actually lives

The six fetches don't depend on each other. The step right after them does. A post tagged mcp and a post tagged agents can be the same article β€” DEV.to lets one post carry both tags β€” so all_posts is keyed by post id specifically so the same article pulled from two different tag queries collapses into one entry instead of getting scored and considered twice. And the real decision β€” "is this theme already covered by one of my 225 published titles, and does it beat every other candidate across all six tags" β€” can't be made correctly until every one of the six fetches has landed. Score the mcp tag's results in isolation and I'd be comparing "best MCP post" against a threshold I made up, not against the actual best post across my whole candidate pool.

That's the shape the trending post flagged: a tool call that "needed another one's answer." Here it's not one tool call needing one other β€” it's a scoring step that needs the full set of six before it's allowed to run at all. The dependency isn't pairwise, it's a join.

What would actually break if I parallelized the fetches blind

I didn't need to break this to see the failure mode, because the code above already shows where it would appear. Picture six concurrent tasks, each one scoring and picking its own "best post for this tag" as soon as its own request returns, then publishing that choice immediately instead of writing into a shared all_posts dict first:

# What NOT to do: score as soon as each call lands
async def handle_tag(tag):
    data = await fetch(tag)
    best = max(data, key=score)          # scored against this tag alone
    if not already_covered(best):
        return draft_article(best)        # committed before the other 5 calls exist

Two tasks running concurrently could each decide their own tag's top post is "the" theme for today and both start drafting, because neither one has seen what the other found. The actual rule β€” self-exclusion first, then score across the full deduplicated set, then pick one theme β€” only produces one answer if something waits for all six results before any of them is allowed to "win." A dict filled in sequence (or an asyncio.gather() followed by a single scoring pass over the combined results) gives you that wait for free. Scoring inside the per-tag loop, the way the broken version above does, throws it away.

The barrier is the cheap part; noticing you need one is the expensive part

Fixing this in code is genuinely boring β€” collect everything, then reduce, instead of reducing as you go. asyncio.gather(*[fetch(tag) for tag in tags]) followed by one scoring pass over the concatenated results would parallelize the six HTTP calls for free and still get the join right, because gather doesn't return control to the caller until every coroutine in the list has finished. The actual cost isn't the synchronization primitive. It's noticing, before you parallelize, which step in your own pipeline is secretly a join and not six independent branches that happen to share a shape.

My six tag-fetches look like the textbook case for "just run them in parallel" β€” same request shape, no shared state, no reason to serialize. The thing that's easy to miss is that the consumer of those six results has a dependency the producers don't: it needs all of them, together, before it can make the one decision the rest of the pipeline is waiting on. That's not a property of the fetch; it's a property of the step after it. Looking for that step β€” the one that reads "for each result" but actually means "for the full set of results" β€” is the check I'd run before reaching for concurrency on any agent pipeline, mine or one I'm reviewing, not just this one.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.