Principle:AISecurityLab Hackagent Trace Tree Recording
| Knowledge Sources | |
|---|---|
| Domains | Security_Testing, Observability, Tracing |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
A trace recording pattern that captures what an attack did as a tree of nodes — not a flat log — so the structure of a search (branches, iterations, decisions) is preserved and readable.
Description
A search is not a list of calls. It is a tree: BoN fans a step out into candidates, PAIR runs independent streams, TAP expands each surviving node into children and prunes the rest. Recording that as a flat log loses the structure, and loses it badly under concurrency — asyncio finishes tasks in whatever order it likes, so arrival order is not position.
Every TraceNode carries its own path: a tuple like (2, 0) meaning the first child of the third node. Position is recorded, never inferred. There are four kinds of node:
- phase: A step of the algorithm (an iteration, a stream, a branch).
- call: One model call — target, role, or panel — in a uniform shape so cost can be read without knowing which attack produced it.
- decision: Why the search went the way it did — stopped, pruned, backtracked, skipped.
- artifact: Something the attack wrote down that is not a call (e.g., RAG's poisoned documents).
The recording uses ContextVar-based state so concurrent branches of one search each get their own position. The campaign runner opens a recording() per goal and records every call itself; attacks mark only their own structure.
Usage
Use this principle when an algorithm's search structure is itself informative — when the reader needs to understand why an attack succeeded (which branch, which decision) rather than just that it did. Flat logs are insufficient for tree-shaped or concurrent search algorithms.
Theoretical Basis
# Abstract algorithm (NOT real implementation)
# Each node carries its own position, recorded via ContextVar
_trace = ContextVar("trace", default=None)
_path = ContextVar("path", default=())
@contextmanager
def phase(label):
node = _trace.get().add("phase", label=label, path=_path.get())
token = _path.set(node.path) # children nest under this path
yield node.path
_path.reset(token)
# A Finding carries the path of its phase, so its attempt
# can be matched to the work that produced it.
The trace is split between attempts via _slices: a node belongs to the finding whose path contains it. Nodes under no finding's phase go to the first attempt, so every node is kept and none is stored twice.