Skip to content

Add deterministic chaos experiment runner#279

Merged
JE-Chen merged 2 commits into
devfrom
feat/chaos
Jun 21, 2026
Merged

Add deterministic chaos experiment runner#279
JE-Chen merged 2 commits into
devfrom
feat/chaos

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jun 21, 2026

Copy link
Copy Markdown
Member

Summary

resilience recovers from failures (retry, circuit breaker); this is the inverse — it causes controlled failures and checks a steady-state hypothesis still holds. Modelled on the Chaos Toolkit lifecycle: verify steady state before, run the method (fault activities), verify after, then always run rollbacks (LIFO). Returns a journal.

  • ChaosExperiment(title, probes, method, rollbacks), Probe(name, call, tolerance), Fault(name, apply).
  • run_experiment(experiment, *, clock=) — journal {status, deviated, run, rollbacks, steady_states}; failed-before-method if the hypothesis fails up front.
  • latency_fault / exception_fault — fault factories with injectable RNG (rate) + sleep.

tolerance is a literal, a [low, high] range, or a predicate. Probes/faults/rollbacks are caller callables; clock/RNG/sleep injectable → deterministic tests (no real failures or sleeping). Probe/fault errors are caught and recorded. Pure stdlib (random+time).

Five-layer wiring

  • Headless core: je_auto_control/utils/chaos/
  • Facade: re-exported from __init__.py + __all__
  • Executor: AC_run_chaos — action-list spec {title, probes:[{name, action}], method:[{name, action}], rollbacks:[[...]]}
  • MCP: ac_run_chaos
  • Script Builder: "Run Chaos Experiment" under Flow

Tests & docs

  • test/unit_test/headless/test_chaos_batch.py (10 tests: no-deviation, failed-before-method, deviation, tolerance range/predicate, exception fault, LIFO rollbacks, injectable clock, executor)
  • v71 feature docs (EN + Zh) + toctree
  • What's-new in all three READMEs

Lint clean: ruff / pylint / bandit (B311 nosec, repo convention) / radon.

resilience recovers from failures; this causes controlled ones and checks
a steady-state hypothesis still holds (Chaos Toolkit lifecycle: verify
before, inject faults, verify after, roll back LIFO). Probes/faults/
rollbacks are callables and the clock/RNG/sleep are injectable, so
experiments run deterministically in tests. Wired through the facade,
AC_run_chaos executor command (action-list spec), MCP tool and the Script
Builder.
@codacy-production

codacy-production Bot commented Jun 21, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 43 complexity · 0 duplication

Metric Results
Complexity 43
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@JE-Chen JE-Chen merged commit fd0c7e0 into dev Jun 21, 2026
16 checks passed
@JE-Chen JE-Chen deleted the feat/chaos branch June 21, 2026 01:59
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant