Skip to content
kazma.
Search Kazma Documentation & Site
ع

Chaos testing (fault injection)

Kazma can inject failures into itself: slow or failing model calls, failing tool calls, failing database writes. It exists to prove that the retry, failover and error paths work, on a test server, before a real outage tests them. The code is kazma_core/chaos/__init__.py; the HTTP routes are kazma_ui/routes_chaos.py.

KAZMA_CHAOS_ENABLED=true (or 1, yes, on) turns the feature on. Without it the /api/chaos routes are not mounted, and every injection point is inert even if something registers an injection, so a stray call can never cause a real failure. The routes are admin-only. Do not enable it on a server people depend on.

An injection names a target. Three targets have an injection point in the product’s code; the others exist in the list but nothing checks them, so an injection aimed at them changes nothing.

TargetWhere it lands
llm_providerEvery attempt inside resilient_chat: a model call. An injected 408, 429 or 5xx is marked transient, so the real retry and failover logic runs on it
tool_executorUnifiedToolExecutor.execute (kazma_core/mcp/manager.py)
databasereply_sink.upsert_reply: saving a chat reply
message_bus, swarm_engine, gateway_adapter, webhook_handler, cache, external_apiNo injection point: nothing happens

Failure types: latency, error, timeout, circuit_breaker_open, resource_exhaustion, network_partition, data_corruption, partial_degradation.

Each runs for its duration, then its injection expires.

ExperimentTargetFailureChance per callRuns for
llm_high_latencyllm_provider7.5 s latency30 %60 s
llm_intermittent_errorsllm_providererror 50010 %120 s
llm_timeoutllm_providertimeout5 %60 s
circuit_breaker_force_openllm_providerbreaker open50 %30 s
database_slowdatabase3 s latency20 %60 s
database_errorsdatabaseerror 5035 %120 s
resource_exhaustiondatabaseresource exhaustion10 %60 s
tool_executor_failurestool_executorerror 50010 %60 s
message_bus_partitionmessage_buspartition10 %30 s — no effect (no injection point)
swarm_engine_degradationswarm_enginepartial degradation20 %120 s — no effect
gateway_adapter_errorsgateway_adaptererror 5025 %60 s — no effect
RouteWhat it does
GET /api/chaos/experimentsThe ready-made experiments
POST /api/chaos/experiments/{name}/runStart one
GET /api/chaos/injectionsInjections now active
DELETE /api/chaos/injections/{injection_id}Stop one
DELETE /api/chaos/injectionsStop all
POST /api/chaos/injections/customStart your own

A custom injection takes failure_type, target, probability (0 to 1) and duration_seconds (above 0), plus optional params: latency_ms, error_code, error_message, severity, metadata. Anything else is refused with a 400.

chaos_experiment(...) is an async context manager that injects for the duration of a block, chaos_injection(target) is the decorator that makes a function an injection point, and get_injector() gives the process’s injector. run_predefined_experiment(name), list_predefined_experiments() and list_active_injections() are what the routes call.