Skip to content
SohamDutta02Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

faultline

A fault-injection harness for tool-using LLM agents. It puts a proxy between an agent and its tools, breaks the tool traffic in controlled ways (rate limits, timeouts, corrupted JSON, stale or wrong data, writes that commit but report failure), and measures which agent architectures still get the job done.

Agents are graded on the state of the world they leave behind, not on what they say. Every trial resets a seeded warehouse, snapshots it, lets the agent work, snapshots it again, and runs task-specific checks against both snapshots.

                 reset + snapshot (direct, never faulted)
   runner ────────────────────────────────────────────────┐
     │                                                     ▼
     │ task     ┌────────────┐  tool calls  ┌──────────┐  ┌─────────────┐
     └────────▶ │   agent    │ ───────────▶ │  proxy   │─▶│ toolserver  │
                │ (an arch.) │ ◀─────────── │ (faults) │◀─│ (the world) │
                └────────────┘              └──────────┘  └─────────────┘
                      │ answer                                   │
                      ▼                                          ▼
                   verifier ◀──────── before / after snapshots ──┘

Playground: a retrying client riding out timeouts on reads, then losing the write

Web app

python -m api serves everything on http://127.0.0.1:8000: the toolserver and fault proxy run in-process, next to the API and the UI.

  • Playground: pick a task, a harness (a preset, or built slot by slot) and a fault config, run one trial and watch it stream. Every tool call shows its status, latency, the fault the proxy injected, any client retries and which channel made it; the trace also shows the harness state the model was shown, the first answer's grade and each feedback round. The verdict panel shows why a failure happened, whether the answer's report matches the world, what feedback changed, the checks, the final answer, the cost and a diff of the world.
  • Sweeps: launch (optionally with an ablation), follow and stop sweeps, then read them as a pass-rate heatmap by fault config and architecture, plus harness spread, controlled comparisons and interactions, failure attribution, feedback outcomes and reports. Select a cell to list its trials, and open any trial to replay its trace.
  • Compare: two sweeps cell by cell, with what changed in each harness.
  • Catalog: the trial pipeline, fault configs, tasks, the harness subsystems and presets, and a live harness audit.

The scripted architectures work without an API key, so the whole app is usable offline; the model-driven ones unlock once a model provider is configured (see Models). The Playground and the sweep form take a model id per run. The app runs one job at a time (a trial or a sweep), because the warehouse and the fault config are shared by everything in the process.

Sweep results Trial replay, dark theme
# build the UI once (Node 20+), then serve
cd web && npm ci && npm run build && cd ..
python -m api                        # --port, --host, --db

# or work on the UI with hot reload: API on :8000, vite on :5173
python -m api
cd web && npm run dev

# or run it all in a container
docker build -t faultline .
docker run -p 8000:8000 -v faultline-data:/data -e ANTHROPIC_API_KEY=... faultline   # or GEMINI_API_KEY, OPENAI_*

To put it online behind HTTPS and a password, see docs/deploy.md (compose.yaml runs the app behind Caddy).

Quick start

python -m venv .venv
source .venv/bin/activate            # Windows: .venv\Scripts\activate
pip install -r requirements.txt -r requirements-dev.txt

python -m pytest                     # offline test suite, no API key needed

# control sweep: the scripted architectures, no model involved
python -m sweep.run --label control --archs oracle oracle_retry --serve
python -m sweep.report --label control --by-task

To run the LLM architectures, copy .env.example to .env and set a key for one provider (see Models), then:

python -m sweep.run --label gemini-001 --model gemini-2.0-flash --serve
python -m sweep.report --label gemini-001 --by-task --markdown results/gemini-001.md
python -m sweep.trials --label gemini-001 --outcome fail_wrong_answer   # find failures
python -m sweep.trials --trial 1a2b3c4d                                  # replay one

Models

The model id picks the provider; --provider (or FAULTLINE_PROVIDER) overrides the guess.

model id provider needs
gemini-* Google Gemini GEMINI_API_KEY
claude-* (default claude-haiku-5-5) Anthropic Messages API ANTHROPIC_API_KEY
gpt-*, o1/o3/o4* OpenAI chat completions OPENAI_API_KEY
anything else (Qwen/Qwen3-8B, llama3.1, ...) any OpenAI-compatible server: vLLM, SGLang, Ollama, llama.cpp, OpenRouter OPENAI_BASE_URL; a key only if the server wants one

--model on sweep.run and runner.trial picks the model for that run; with none, FAULTLINE_MODEL applies, else the default model of the first provider that has a key. Every trial records the model that drove it.

# your own model, served with tool calling on
vllm serve Qwen/Qwen3-8B --enable-auto-tool-choice --tool-call-parser hermes
OPENAI_BASE_URL=http://localhost:8000/v1 python -m sweep.run --label qwen3-8b --model Qwen/Qwen3-8B --pace 0 --serve

The harness fingerprint leaves the model out, so the same harness can be compared across models: run the same matrix with two --models, then python -m sweep.compare --base gemini-001 --head qwen3-8b. The report notes that the model changed.

Sampling differs by provider: Gemini and local OpenAI-compatible servers run at temperature 0; Claude models and OpenAI's own API run at their default sampling (OpenAI's reasoning models reject a temperature). Repeats and paired cells absorb the noise, but expect more of it there. Rate limits, overloads and server errors are retried with backoff; a quota, credit or spend limit pauses the sweep instead of failing every remaining cell.

--serve runs the toolserver and proxy inside the sweep process on free ports. To keep them running between commands instead, start python -m runner.stack (toolserver on 8100, proxy on 8200) and drop --serve. The sweep refuses to start if it cannot reach a proxy, so agent traffic can't silently bypass fault injection.

Sweep size and resuming

The default sweep is 6 tasks x 3 LLM architectures x 7 fault configs x 3 repeats = 378 trials, with --pace 15 seconds between LLM trials for free-tier rate limits. Narrow it with --tasks, --archs, --configs, --repeats.

--ablate HARNESS adds a controlled-variable set around a harness (see Ablations and attribution); --ablate full is 12 harnesses, so narrow the rest of the matrix to keep it affordable.

Sweeps are resumable: rerun with the same --label and only missing cells run. Cells run repeat-major, so a sweep stopped halfway has every cell at the same depth. Model API failures (quota, network) are recorded as fail_harness, excluded from pass rates, and re-run on resume; the sweep stops on a daily quota error or after three API failures in a row.

Faults

config targets layer phase what the agent sees
none clean responses
rate_limit all tools, 30% transport request 429 with retry-after; the call never ran
timeout all tools, 25% transport request 504 after 2s; the call never ran
malformed_json read tools, 30% schema response 200 with a truncated JSON body
stale_data search_inventory semantic response stock inflated to qty * 1.5 + 20
plausible_wrong get_pricing semantic response unit price 40% too low
partial_write first place_order semantic response 500 write may not have completed, but the order was committed

Phase matters for writes. Request-phase faults answer before forwarding, so the toolserver never sees the call and a retry is safe. Response-phase faults rewrite a reply the toolserver already produced, so a write behind one has happened.

Configs live in proxy/configs/*.yaml:

faults:
  - type: rate_limit           # a key of proxy.faults.REGISTRY
    rate: 0.3                  # chance per matching call
    target: [get_pricing, "list_*"]   # name, prefix*, list, or "*"
    max_fires: 1               # optional cap per trial
    params: {retry_after: 1}   # fault-specific

Fault firing is seeded per (task, config, repeat) cell. Every architecture in a cell gets the same seed, so they face the same fault schedule and their results can be compared pairwise. A config can also be posted inline as the JSON body of POST /_proxy/config.

Tasks

task category the job what the faults probe
t1_stock_lookup read only report stock of A-22 stale reads can't be detected by re-reading
t2_simple_order single write order 5 x A-22 for CUST-100 a retried partial write duplicates the order
t3_budget_order read then write order as many D-40 as CUST-102's credit allows credit, not stock, binds; a wrong price makes the order bounce or overshoot
t4_cancel_order corrective write cancel CUST-101's mistaken C-02 order, leave the rest must find the right order among distractors
t5_tier_quote read only quote 10 x D-40 at CUST-101's tier multi-hop read; wrong prices are internally consistent
t6_stock_fallback read then write order 20 x C-09, or whatever is in stock stale stock causes a rejection whose message reveals the truth

Harnesses

An architecture is a harness: everything around the model that decides how much of its capability gets realized. faultline splits a harness into five subsystems, each a slot with named options, so each one can be changed and measured on its own.

subsystem what it covers options (baseline first)
instructions the system prompt base; fault_aware: how the tools fail and what to trust
tools the tool interface and the client that calls it plain; retrying: retries reads on 429/5xx/timeouts/unparseable bodies, writes only on 429
environment the world the tools act on, and its guarantees bare; idempotent: writes carry an idempotency key, so a repeat returns the first result instead of acting twice
state what the harness tracks between steps transcript: the conversation only; ledger: a harness-kept record of write outcomes and contradictory reads, shown to the model every turn
feedback how work is checked before it counts as done none; critic: a read-only LLM reviewer that can send the work back, up to two revisions; checks: deterministic verification with no model; critic_independent, checks_independent: the same, reading ground truth (an upper bound)

Presets name common harnesses:

id harness
single the baseline: one tool-calling loop, no safety nets
retry single+tools=retrying
critic single+feedback=critic
checks single+feedback=checks
full every subsystem at its strongest deployable option: fault_aware, retrying, idempotent, ledger, checks
oracle no model: a scripted per-task policy with no retries; the control column, and lets the pipeline run without a key
oracle_retry the oracle on the retrying client: what client retries alone buy, with no model involved

Any harness can be written as a preset plus edits: +slot=option sets a slot and -slot resets it to the baseline. critic+instructions=fault_aware is a valid architecture id anywhere one is accepted (CLI, API, UI), and retry-tools is single. The scripted controls only take edits to tools and environment.

Every harness has a fingerprint: a hash of its prompts, tool schemas, client policy and option versions, but not the model. Two ids for the same harness share a fingerprint.

Environment

The fault configs are what the experiment does to the environment; the environment slot is what the harness designer chooses about it. Under idempotent the client sends a request_id with every write (a hash of the trial, the tool and its arguments), the toolserver performs each keyed write at most once, the tool descriptions say so, and the retrying client can retry writes like reads. The trade-off: two identical writes in one trial collapse into one.

State

The ledger is rebuilt from the agent's own calls and responses (never from the proxy's fault headers). It records each write as done, rejected, not executed (429), or unknown (5xx, timeout, unreadable body) until a list_orders read settles whether it went through. It warns when a write went through more than once, when two reads disagree with no write in between that explains it, and when a read came back unreadable. It is appended to the system prompt before each model call, and logged as a state event whenever it changes.

Feedback

checks is the harness's verification command: no model, a handful of reads, and the same revise loop as the critic. From the agent's own calls it finds writes that returned an error but went through (or didn't), orders placed more than once, and facts that a fresh read contradicts once the agent's own orders are accounted for. A wrong fact is reported once (the agent can't un-read it, only stop relying on it); problems with orders are reported until they're fixed. The checks are calibrated in the test suite: zero false alarms on the oracle's correct runs of every task, through either channel.

Feedback reads through a channel. critic and checks read through the same fault proxy as the agent, so a fault that fools the agent can fool the check: a stale stock level re-reads stale. The _independent variants read the toolserver directly. Real agents don't always have an independent source of truth, so treat those as an upper bound on what feedback can buy, and the gap between the two as the value of independence. Trace events carry the channel (agent, review, truth).

Every harness with feedback grades the world at the moment the agent first says it's done, before any review (a checkpoint event), so each trial records what feedback actually changed: whether it fixed a failing answer, broke a passing one, raised a false alarm or missed a failure, and what the review cost.

Outcomes

outcome meaning
pass every check passed
fail_wrong_answer at least one check failed (wrong number, wrong or duplicate order, world mutated...)
fail_misreport every check passed, but the answer says the work failed
fail_no_answer the agent finished without a final message
fail_loop step budget (--max-steps, default 12 per turn) exhausted
fail_crash the architecture raised an exception
fail_harness the model API failed; not counted, re-run on resume

Reports

The checks grade the world; the report grades what the agent said about it. An agent that placed the order and then answers "the order failed" leaves the world right and its user wrong: a user who believes it places the order again. Every answered trial gets one of:

report the answer... and the checks
accurate says the work was done (or gives the value asked for) pass
says it failed or gave up fail
false_success says the work was done fail
false_failure says it failed or gave up pass: the outcome is fail_misreport
hedged says it doesn't know whether the work went through either; not penalized
unclear can't be read with confidence either; not penalized

Only false_failure changes an outcome; a false_success trial was already fail_wrong_answer, and the report says it also claimed success. The claim is read from the plain-text answer by fixed rules in tasks/report.py, with no model involved. They ignore quoted tool output ({...}), so a pasted error body that says "may not have completed" isn't read as the agent hedging, and they lean towards unclear rather than a wrong reading. tests/test_report.py holds the labelled answers they are checked against, and python -m harness.audit --calibrate checks that the oracle's correct answers all read as accurate.

Sweeps recorded before reports were graded show a warning in the report; python -m sweep.regrade --label X regrades them from the stored answers, without re-running anything.

Reading the report

python -m sweep.report --label X prints:

  • pass rate per fault config and architecture, with the trial count;
  • change vs no-fault baseline, in percentage points, per architecture;
  • trials where the fault fired, with a warning if a config never fired (the targeted tool was never called, or traffic bypassed the proxy);
  • outcomes and mean cost (tool calls, tool errors, client retries, LLM calls, tokens, seconds) per architecture;
  • reports: per architecture, how many answers were accurate, hedged, unclear, false successes and false failures, and the share of wrong-world answers that claimed the work was done;
  • feedback: first answer vs final for harnesses with feedback: first-pass and final pass rates, answers fixed and broken, flags, false alarms, misses, and the extra tool calls and tokens the review cost;
  • harness spread: the best and the worst model harness per fault config;
  • controlled comparisons: every pair of harnesses that differ in exactly one subsystem, with the pass-rate change, the cost change and pass-rate points per 1k extra tokens, by fault config, plus interaction warnings;
  • failure attribution: each failure's cause, and the share of failures each subsystem should have prevented;
  • with --by-task, a task x config grid per architecture.

python -m sweep.trials lists trials by config, arch, task or outcome, and --trial <id> replays one trial's event log: model turns, tool calls (with their channel when it isn't the agent's), injected faults (F), harness state updates, the first-pass checkpoint and feedback verdicts.

Ablations and attribution

If it isn't model weights, it's harness: at a fixed model, the harness spread section shows how far apart the best and worst harness land under each fault.

Every pair of harnesses in a sweep that differ in exactly one subsystem is an exclusion test for that subsystem. Because every harness in a cell faces the same fault schedule, the report pairs their trials cell by cell. --ablate HARNESS builds the pairs on purpose, in two contexts:

python -m sweep.run --label abl --ablate full --configs none timeout stale_data partial_write --serve
# single, single+<each subsystem full changes>        add-one: what it adds to the baseline
# full-<each subsystem>, full                         leave-one-out: what full loses without it

Names that spell the same harness are kept once, so --ablate on a harness that changes two subsystems needs only four harnesses.

When the same change (say tools: plain -> retrying) moves the pass rate by very different amounts in different contexts (10 points or more, overall or under one fault), the report flags an interaction: the subsystem's value depends on the rest of the harness, and neither ablation number is its value on its own. The scripted controls show one with no model involved (--ablate oracle_retry+environment=idempotent, 3 repeats):

change context pass, all faults under timeout under partial_write
environment: bare -> idempotent oracle (no retries) +0 +0 +0
environment: bare -> idempotent oracle_retry +9 +11 +50
tools: plain -> retrying bare environment +15 +28 +0
tools: plain -> retrying idempotent environment +24 +39 +50

Idempotent writes are worth nothing to a client that never retries, and the retrying client is worth more in an environment where writes are safe to repeat. Under partial writes each is worth nothing alone and 50 points together: only a client that can resend safely finds out the write went through. An add-one ablation from the baseline would call the environment useless.

Ablation says how much; it doesn't say where the remaining failures come from. Each failed trial gets an attribution from its trace, world diff and feedback checkpoint: a cause, the subsystem whose job it was to prevent it, and the evidence.

cause subsystem what happened
crash the harness raised: a bug
feedback_broke_it feedback the first answer passed; after review it didn't
loop state step budget exhausted
misreported state the work was done, but the answer says it failed after a write error (instructions if no write errored)
duplicate_write state a write errored but went through, then was repeated (instructions if there was no error)
lost_write tools a write errored and never went through
trusted_bad_data feedback a read was altered and nothing caught it
gave_up_on_errors tools transport or schema errors that were never recovered
misread_write state a write reported failure but went through, and the agent acted on the failure
reasoning_error instructions wrong with no unrecovered fault (or the model's limit)

Attributions are stored with each trial; python -m sweep.attribution --label X recomputes them for a sweep (for one recorded before this existed, or after the rules change).

Harness rot

A harness rots like code: prompts get edited, retry policies tuned, checks extended, while the results that describe it stay in the database. Every trial records the fingerprint of the harness that produced it (and the harness itself, once, in a harness table), so drift shows up instead of silently mixing into the numbers.

  • Resuming a sweep whose cells came from an older version of their harness is refused, naming the parts that changed. --rerun-stale redoes those cells under the current harness, --allow-mixed keeps them. The report warns when an architecture's results come from an older harness or mix versions.
  • python -m sweep.compare --base before --head after is the regression report for a harness change: pass rates on cells paired across the two sweeps (same fault seeds), which parts of each harness changed, and the cells that moved by 10 points or more (--threshold).
  • python -m harness.audit checks for drift: the tool specs the model sees against the toolserver's real routes, prompts that name tools that don't exist, presets that don't resolve. Against the results database (--db, or faultline.db if it exists) it also finds options whose code changed without a version bump, so their old results still look current, and presets whose latest results come from an older harness. --calibrate verifies the verifier: the checks must raise no false alarms on the oracle's correct runs of every task and catch four seeded failures. CI runs python -m harness.audit --calibrate; --strict fails on warnings too.

Control results

The control sweep (--archs oracle oracle_retry oracle_retry+environment=idempotent, 3 repeats, 18 trials per cell) is deterministic. It shows what each fault does to a client that knows exactly what to do, with and without client retries, and with retries in an environment whose writes are idempotent:

config oracle oracle_retry oracle_retry, idempotent env
none 100% 100% 100%
rate_limit 50% 94% 94%
timeout 44% 72% 83%
malformed_json 67% 100% 100%
stale_data 67% 67% 67%
plausible_wrong 67% 67% 67%
partial_write 50% 50% 100%

Retries recover rate limits and corrupted bodies almost entirely. They recover timeouts only on reads: a write that timed out might have committed, so the retrying client hands it back instead of risking a duplicate, and those trials still fail. Semantic faults are untouched, since a stale or wrong value re-reads the same way, and the client reports the wrong value as the answer: those are the sweep's false_success reports.

A partial write never leaves a wrong world behind a client that doesn't retry blindly, but it does leave a wrong report: the write commits, the client sees a 500, gives up and says the order failed. Every partial-write trial on the three ordering tasks is a fail_misreport, with or without client retries, since the retrying client won't resend a write that may have gone through.

Making writes idempotent is an environment change, not a client change, and it fixes both. The retrying client can resend a timed-out or failed write safely: it recovers most of the timed-out writes (what's left are calls that timed out on all three attempts), and a partial write's resend comes back as a success, so the client reports what actually happened.

Extending

  • Fault: subclass proxy.faults.Fault, set id, layer and phase, implement apply, add it to REGISTRY, and add a config YAML.
  • Task: write @check functions over (before, after, answer) in tasks/catalog.py, add a Task (with setup orders if it needs existing state), and add an oracle solver in agents/oracle.py. The test suite runs the oracle against every catalog task.
  • Harness option: add an Option to the slot's module in harness/ (instructions.py, tools.py, environment.py, state.py, feedback.py). Put what defines it (prompt text, policy parameters) in content so it is fingerprinted, and bump version when you change its behaviour in code. It is usable as single+slot=option right away; add a preset in harness/spec.py if it deserves a name.
  • Model provider: implement the agents.llm.Backend protocol (one complete(messages, tools, system) -> Reply method, translating the provider-neutral conversation; see agents/anthropic_backend.py), and route model ids to it in agents/backends.py.

Layout

toolserver/   seeded warehouse world and six tool endpoints (FastAPI)
proxy/        fault-injecting reverse proxy, fault classes, configs
tasks/        task catalog, checks, verifier, report grading (what the answer claims vs the world)
agents/       model backends (Gemini, Anthropic, OpenAI-compatible), toolbox clients, agent loop, oracle, architecture registry
harness/      the five harness subsystems, presets, harness names, fingerprints, deterministic checks, audit
runner/       single-trial runner, in-process server stack
sweep/        sweep runner, SQLite store, report, controlled comparisons, failure attribution, harness
              versions, sweep comparison, trial inspector, regrading
api/          FastAPI app: catalog, live trial streams (SSE), sweep control
web/          React + TypeScript UI (Vite)
tests/        offline pytest suite
settings.py   URLs, model, API key (from .env)

Limitations

  • Reports are read from plain text by fixed rules. An answer they can't read confidently is unclear and isn't penalized, so a misreport phrased in a way the rules don't cover gets through as a pass. They read whether the work was done, not the details: "ordered 12" when 7 were ordered isn't caught unless the world is wrong too.
  • One small seeded world. Results say how architectures compare under these faults, not how a given agent would do in production.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages