Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:AISecurityLab Hackagent Concurrency Control

From Leeroopedia
Knowledge Sources
Domains Security_Testing, Concurrency
Last Updated 2026-10-29 00:00 GMT

Overview

A concurrency limiting pattern that uses shared semaphores to cap how many goals are attacked, how many requests reach the target, and how many samples are judged at once, across all attacks in a campaign.

Description

A campaign runs multiple attacks, each processing multiple goals, each sending requests to the target and judges. Without shared limits, a parallel campaign can overwhelm a provider with rate limits or exhaust local resources.

HackAgent uses three shared semaphores, configured by ConcurrencySpec:

  • attack: How many goals may be generating requests at the same time.
  • target: How many requests may be waiting on the target at the same time.
  • judge: How many replies may be judged at the same time.

These are shared across all attacks in a campaign, so the limits are global, not per-attack. The semaphores are held for the duration of the rate-limited operation: the target semaphore is held during the actual model call (latency is measured from when the slot is acquired), not during request generation.

Usage

Use this principle when a pipeline has multiple levels of concurrent work that must each respect a different rate limit. Shared semaphores ensure the limits are global; per-operation semaphores would let each attack exceed the limit independently.

Theoretical Basis

# Abstract algorithm (NOT real implementation)
class _Limits:
    attack: asyncio.Semaphore
    target: asyncio.Semaphore
    judge: asyncio.Semaphore

async def _complete(self, messages):
    async with self.limits.target:  # hold the slot during the call
        started = monotonic()
        response = await self.resolved.target.acomplete(messages)
        elapsed = monotonic() - started
    return replace(response, latency_ms=round(elapsed * 1000))

The clock starts once the slot is held, so the latency is the target's and not the time spent queueing.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment