ADLC
Toolkit

flail-detector

Analyzes a build-session log for flail signatures and fails the gate when an agent is spinning.

flail-detector

ADLC phase: P4 Build · Gate: a build session that shows flail signatures is killed, not retried indefinitely.

The ADLC lifecycle, with P4 highlighted. Read the theory for P4

What it defends against

A build agent that has lost the thread will loop: hitting the same error over and over, wandering outside its declared scope, or churning the same file. Left alone it burns context and produces noise. flail-detector encodes the mechanical two-strike rule. It reads a session log and fails closed when it finds any of four signatures: a normalized error signature repeating past --max-repeat, a written path outside every --scope glob, one file edited three or more times, or a log exceeding --max-bytes. It is fully deterministic and makes no LLM calls.

Usage

adlc flail-detector <log-file> [--scope <glob>...] [--max-repeat <n>] [--max-bytes <n>] [--json]
FlagDescription
<log-file>Path to the session log to analyze (required positional). Treated as JSONL when more than half its non-empty lines parse as JSON objects, otherwise plain text.
--scope <glob>Declared-scope glob, repeatable. When given, written paths outside all globs are scope violations.
--max-repeat <n>Trigger the repeated-error signal at n identical normalized signatures (default 2).
--max-bytes <n>Trigger the size signal when the log exceeds n bytes (default: no limit).
--recordOn a clean verdict, append a flail-check entry to .adlc/manifest.jsonl (ADLC P4 evidence — see @adlc/runner). Never writes on a flail verdict or a could-not-analyze outcome.
--ticket <id>Ticket to scope the recorded manifest entry to (recorded as null when omitted).
--files <a,b,c>With --record: hash these changed files (path → sha256) into the flail-check entry, so adlc run p4 can tell the check still describes the current tree. Without it the entry binds no files and adlc run p4 rejects it. An unreadable path exits 1 and records nothing. Use the same list you pass to gate-manifest record p4-build --files.
--jsonMachine-readable JSON output for orchestrators.
--helpPrint help and exit 0.

Path-bearing verbs (Writing, Editing, Created) must open the line, optionally after indentation and log prefixes: timestamps (12:03:01 Writing <path>), bracketed fields ([INFO] Editing <path>), or upper-case level names (WARN Created <path>). A verb anywhere else is prose and yields no path, so a tool result such as File created successfully at: <path> is not read as a write to successfully.

Exit codes

0: clean. No flail signals detected, the session may continue.1: operational error (log file not found, bad argument), or could-not-analyze: the log had nothing to analyze (no non-empty lines). Never a pass, and never recorded as P4 evidence (issue #622). A log with lines but no extractable file path is analyzed normally — a well-behaved session may write nothing.2: flail. One or more signals triggered; kill the session and append the dead-ends to the ticket.

Example

$ adlc flail-detector session.log --scope 'src/**' --scope 'test/**'
flail-detector: FLAIL
  signals:
    repeated-error (1 signature(s)):
      [2x] error: cannot resolve module at line in
    scope-violation (1 path(s) outside scope):
      /etc/hosts
  recommendation:
    Kill the session. Append these dead-ends to the ticket.
exit 2

On a second trigger, escalate to P2: the ticket is wrong, not the agent.

Go deeper

packages/flail-detector

On this page