Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Claw-Code-Parity: Coarse-Grained Executor Wrappers

Claw-Code-Parity is a Rust port of an AI agent harness, organized as a workspace of 8 crates. Unlike ZeroClaw’s per-tool Tool trait, it uses a coarser-grained ToolExecutor trait where a single executor dispatches all tool calls through a central execute() method.

Architecture Difference

This architectural difference is precisely why we chose it as a second case study:

AspectZeroClawClaw-Code-Parity
Tool abstractionTool trait per toolToolExecutor trait per executor
DispatchEach tool has its own execute()Central execute_tool() with match statement
Wrapping granularityPer-tool: RateLimitedTool<FileReadTool>Per-executor: RateLimitedExecutor<StaticToolExecutor>
MiddlewareNone (inline guards)None (inline guards)

Composable ToolExecutor Wrappers

We implemented three wrappers in rust/crates/runtime/src/wrappers.rs:

RateLimitedExecutor

Sliding-window rate limiting with per-tool independent counters:

#![allow(unused)]
fn main() {
pub struct RateLimitedExecutor<T> {
    inner: T,
    max_calls: usize,
    window: Duration,
    history: BTreeMap<String, Vec<Instant>>,
}

impl<T: ToolExecutor> ToolExecutor for RateLimitedExecutor<T> {
    fn execute(&mut self, tool_name: &str, input: &str) -> Result<String, ToolError> {
        self.prune_expired(tool_name);
        if self.count(tool_name) >= self.max_calls {
            return Err(ToolError::rate_limited(tool_name));
        }
        self.record(tool_name);
        self.inner.execute(tool_name, input)
    }
}
}

PermissionGuardedExecutor

Gates tool access based on permission modes:

#![allow(unused)]
fn main() {
pub struct PermissionGuardedExecutor<T> {
    inner: T,
    active_mode: PermissionMode,
    tool_requirements: BTreeMap<String, PermissionMode>,
}
}

Tools can be assigned minimum permission levels. If the active mode is insufficient, the executor returns a permission error without forwarding to the inner executor.

AuditLoggingExecutor

Records all tool invocations for compliance and debugging:

#![allow(unused)]
fn main() {
pub struct AuditLoggingExecutor<T> {
    inner: T,
    log: Arc<Mutex<Vec<AuditEntry>>>,
}

pub struct AuditEntry {
    pub tool_name: String,
    pub timestamp: Instant,
    pub success: bool,
    pub error_message: Option<String>,
}
}

Composition

The three wrappers compose as nested types (Russian-doll pattern):

#![allow(unused)]
fn main() {
let executor = AuditLoggingExecutor::new(
    RateLimitedExecutor::new(
        PermissionGuardedExecutor::new(
            StaticToolExecutor::new(),
            PermissionMode::Default,
            tool_requirements,
        ),
        10,                          // max 10 calls
        Duration::from_secs(60),     // per 60-second window
    ),
    audit_log.clone(),
);
}

CI: Nightly Build Acceleration

We also contributed a CI workflow for accelerated release builds. The investigation process is instructive.

Hypothesis: cargo-slicer

cargo-slicer stubs unreachable library functions at the MIR level, skipping LLVM codegen for code the final binary never calls. On ZeroClaw (~100 crates), it saves approximately 27% of build time.

Benchmark Results

On this smaller workspace (8 crates), the results were different:

ConfigurationTimevs Stable
Stable baseline50.2s
Nightly (no slicer)41.4s-17.5%
cargo-slicer syn pre-analysis52.5s+4.6% (slower)
cargo-slicer MIR-precise49.3s-1.7%

Analysis

The RUSTC_WRAPPER dispatch overhead of cargo-slicer exceeds the LLVM codegen savings on small workspaces. The nightly Rust compiler alone provides the meaningful speedup, likely from improved optimization passes and codegen improvements.

Outcome

The CI workflow was simplified to cargo +nightly build --release with the benchmark data documented in the PR description as the decision rationale. The honest reporting of “we tried X, it didn’t help here, here’s what works instead” was well-received.

Crosscutting Concern Analysis

Applying the RE2026 methodology (8 traditional + 6 agent-specific patterns), we found:

ConcernScattering Degreeaspect-rs Applicable
Rate limitingHigh (tool dispatch)Yes
Permission checkingHigh (tool dispatch)Yes
Audit loggingMedium (scattered prints)Yes
Error recoveryMedium (retry patterns)Yes
Token budget trackingMedium (usage tracking)Yes
Sandbox enforcementLow (centralized)Yes
Prompt injection defenseAbsentGap

11 out of 12 patterns applicable (92%) – matching ZeroClaw’s coverage exactly.

Results

Both PRs have been merged to the fork’s main branch:

  • PR #1: Composable ToolExecutor wrappers with 10 unit tests
  • PR #2: Nightly CI build workflow with benchmark data

The upstream repository (ultraworkers/claw-code-parity) has PRs disabled, so contributions are demonstrated on the fork (yijunyu/claw-code-parity).