Skip to content

About

Experimental cancellation fault injection and explicit invariant checks for trusted local asyncio scenarios.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

CancelProof

Cancellation fault injection and explicit invariant checks for trusted local Python async scenarios.

CancelProof calls real asyncio.Task.cancel() at checkpoints you name, observes application state before harness cleanup, and writes portable JSON, HTML and Markdown reports. Each run uses a fresh subprocess with a parent deadline. Python 3.12+; standard asyncio; Windows and Linux.

Source experimental edition. It controls named checkpoints, not arbitrary awaits or bytecode. It does not prove race freedom, infer business correctness, or sandbox malicious Python code. Imports and scenarios execute with your permissions. Run only trusted local targets. Reports can contain values you explicitly share.

Source repository: KaiserIIII/cancelproof. Hosted Windows/Linux × Python 3.12/3.13 checks execute the full suite and the constructed acceptance cases; see Actions. These bounded tests do not replace broad workload or historical-version validation.

Install

Download or clone this repository, open its source directory, then create a virtual environment and use its Python:

py -3.13 -m venv .venv
.venv\Scripts\python -m pip install --require-hashes -r requirements-dev.lock
.venv\Scripts\python -m pip install --no-build-isolation --no-deps .
.venv\Scripts\python -m pytest -q
.venv\Scripts\Activate.ps1
python3.12 -m venv .venv
.venv/bin/python -m pip install --require-hashes -r requirements-dev.lock
.venv/bin/python -m pip install --no-build-isolation --no-deps .
.venv/bin/python -m pytest -q
. .venv/bin/activate

The engine has no runtime third-party dependencies. The pinned development environment includes pytest, the build backend, and HTTPX for the ASGI example. No hosted API, cloud service, telemetry, database, or network listener is required.

The remaining examples use the activated environment's python. If PowerShell execution policy prevents activation, use .venv\Scripts\python instead of python in each example; on Linux use .venv/bin/python. No system policy change is necessary.

Run a real cancellation

python -m cancelproof run cancelproof.examples:lock_broken --plan examples/plans/lock.json --output output/broken
python -m cancelproof run cancelproof.examples:lock_fixed --plan examples/plans/lock.json --output output/fixed
python -m cancelproof explore cancelproof.examples:lock_fixed --max-runs 8 --seed 7 --output output/explore
python -m cancelproof replay output/fixed/replay.json --output output/replayed

Output directories must be new. The broken lock example leaves its lock acquired and returns FAIL (exit 2); the fixed example releases it in an async context manager and returns PASS (exit 0). Open output/fixed/report.html locally. HTML contains no scripts or remote assets.

CLI exit codes: 0 PASS, 2 FAIL, 3 INCONCLUSIVE/NOT_RUN, 1 input/import/output error. Argparse syntax errors use 2. stdout is machine-readable JSON; Unicode is losslessly escaped for legacy Windows terminals.

Write your own scenario

# my_scenarios.py, importable from the current directory
import asyncio

async def transaction(probe):
    lock = asyncio.Lock()
    probe.watch_lock("released", lock)
    probe.expect_cancelled("scenario")  # only enforced when a planned cancel is accepted
    async with lock:
        await probe.checkpoint("after_lock")
from cancelproof import run_scenario

report = run_scenario("my_scenarios:transaction", {
    "actions": [{"checkpoint": "after_lock"}]
})
assert report["verdict"] == "PASS"

In an async test, use await arun_scenario(...). The pytest plugin exposes cancelproof and cancelproof_async fixtures; neither changes the caller's loop policy. The target runs in another process: use an importable module, not a closure or a live object. Explicitly pass business evidence through events or invariant actual callbacks; parent memory is not shared.

See API and input contract, architecture, Chinese guide, security, and third-party notes. Final measured results and remaining acceptance gaps are recorded in FINAL_REPORT.md.

Honest scope

  • Normal cancellation is not automatically a bug. FAIL requires a false invariant, declared lifecycle/propagation contract violation, or observed runtime error.
  • Pending application tasks without a declared finish contract are INCONCLUSIVE candidates. Explicit legitimate background exclusions are supported and still cleaned before worker exit.
  • Plans, source digest and checkpoint sequence support controlled replay. A seed changes selected checkpoint order, not the OS or stock event-loop scheduler. Repeated runs can differ.
  • Source digest covers the scenario module, not imported dependencies. A mismatch prevents the target callable from running; importing its trusted module still occurs.
  • Hard timeouts are INCONCLUSIVE: no reliable final state is invented. Processes are reaped, but descendants, native resources and memory are not sandboxed.
  • Task creation accounting covers Probe/loop-factory paths. Direct asyncio.Task(...) construction or replacing the factory bypasses accounting and completed-task retention; these target behaviors are unsupported.
  • LoomCheck already offers checkpoint schedules, replay and shrinking; pyleak already diagnoses pending tasks; direct Task.cancel() plus assertions can express these tests. Our increment is a cancellation-oriented request/report contract with separate-process deadline handling, not a new scheduler or scientific innovation.

Local ASGI integration

python -m cancelproof run cancelproof.examples:asgi_fixed --plan examples/plans/asgi.json --output output/asgi

This executes HTTPX ASGITransport against the included request handler, sends a real in-process HTTP test request, cancels the request task and checks request resources, background tasks and absence of a cancelled commit. It is not a production server/socket/load test, and HTTPX ASGITransport does not drive ASGI lifespan.

MIT license. Only the experimental source is published; no PyPI package, formal Release, or public service is provided.

About

Experimental cancellation fault injection and explicit invariant checks for trusted local asyncio scenarios.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages