Principle:AISecurityLab Hackagent Concurrency Control
| 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.