Back to KB
Difficulty
Intermediate
Read Time
4 min

Rust: Tag Your Agent Tools With Side-Effect Metadata Before Dispatching Them in Parallel

By Codcompass Team··4 min read

The bug was quiet until it wasn't.

A parallel tool dispatcher sent two database WRITE operations to the same record at the same time. No lock. No guard. Both completed. The record ended up in a state that neither operation intended. It took a while to find because the individual tool functions were correct in isolation. The problem was the dispatcher had no information about whether two tools could safely run together.

The fix was straightforward: attach side-effect metadata to each tool before dispatch, then check it. That is what tool-side-effects-tag-rs does.

The shape of the fix

use tool_side_effects_tag::{SideEffects, Tag, SideEffect};

fn fetch_user(id: u64) -> String {
    format!("user:{}", id)
}

fn update_balance(id: u64, delta: i64) -> bool {
    // writes to DB
    true
}

fn main() {
    let tagged_fetch = Tag::new(
        fetch_user,
        SideEffects::from([SideEffect::Read, SideEffect::Idempotent]),
    );

    let tagged_update = Tag::new(
        update_balance,
        SideEffects::from([SideEffect::Write]),
    );

    // safe to run tagged_fetch concurrently with itself
    println!("fetch parallel safe: {}", tagged_fetch.side_effects().is_parallel_safe());
    // false for tagged_update
    println!("update parallel safe: {}", tagged_update.side_effects().is_parallel_safe());

    // is_retry_safe checks for Idempotent or Read, not Write or Destructive
    println!("fetch retry safe: {}", tagged_fetch.side_effects().is_retry_safe());
    println!("update retry safe: {}", tagged_update.side_effects().is_retry_safe());
}

Enter fullscreen mode Exit fullscreen mode

With those predicates, th

🎉 Mid-Year Sale — Unlock Full Article

Base plan from just $4.99/mo or $49/yr

Sign in to read the full article and unlock all 635+ tutorials.

Sign In / Register — Start Free Trial

7-day free trial · Cancel anytime · 30-day money-back