Files
mtusi2026lab5/evidence/pipeline-faults-2026-10-02.md
T

39 lines
4.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Versioned pipeline fault injection — 2026-10-02
## Hypothesis and method
A process death before or after an S3 side effect, a duplicate delivery, an expired lease, and a reordered older-version delivery should leave one logical variant set per `(attachment_id, pipeline_version, name)`. A failed current job should replay only by an explicit audited operator action. RabbitMQ remains at-least-once: duplicate messages are expected; the durable PostgreSQL state and deterministic S3 keys make their effects idempotent.
`student-tests/test_pipeline_faults.py` creates synthetic 320×200 PNG uploads in the same PostgreSQL/MinIO stand as the application. It runs the real `src.worker.process_message` in child processes with `LAB5_FAULT_POINT` and `LAB5_FAULT_JOB_ID`; `os._exit(72)` terminates the child at the selected durable boundary. The parent checks database state, expires a simulated dead worker lease, runs recovery, redelivers the same logical job with the next managed attempt, and compares variant rows/checksums. The normal worker and publisher are stopped while injecting faults so their consumers cannot race the test. The test also forces a bounded temporary failure, verifies terminal `failed`, then uses the audited replay operation. No broker message is fabricated by the test; separate handoff/outbox tests exercise publication and confirm.
Fault points in worker code: `after_claim_before_s3`, `after_s3_before_result_commit`, `after_result_commit_before_ack`. Each is disabled unless both environment variables name a point and exact synthetic job ID. The test runs once on the existing educational volumes and once on a fresh, isolated Compose project. The isolated project had zero `attachment_jobs` and zero `attachment_job_replays` before the run; its volumes were removed afterward. Main lab5 volumes were preserved.
## Reproduce
```sh
# Existing local stand, with worker and publisher stopped:
docker compose --env-file .env stop worker publisher
docker compose --env-file .env run --rm --build --no-deps -T worker python - < student-tests/test_pipeline_faults.py
# Fresh, isolated PostgreSQL and S3 volumes; no API port and no normal consumer:
docker compose -p mtusi2026lab5fresh --env-file .env up -d --build postgres migrate s3-bootstrap
docker compose -p mtusi2026lab5fresh --env-file .env run --rm --build --no-deps -T worker python - < student-tests/test_pipeline_faults.py
docker compose -p mtusi2026lab5fresh --env-file .env down -v
```
On this host Docker builds used the ignored `compose.local.yaml` DNS override via `COMPOSE_FILE=compose.yaml:compose.local.yaml`; it does not alter application behavior. The first attempt to use `up --wait` on the isolated project exited 1 because Docker Compose treated the completed one-shot `migrate` service as not running; inspection showed `migrate` exited 0, PostgreSQL/S3 were healthy, and both relevant tables contained zero rows before the fault test.
## Observed result
Both runs returned the same anonymized raw summary (one JSON line per run):
```json
{"after_result_commit_before_ack_duplicate":"pass","after_s3_before_result_commit":"pass","before_side_effect_lease_recovery":"pass","bounded_transient_retry_then_replay":"pass","duplicate_reorder_new_version":"pass","failed_registry_operator_replay":"pass"}
```
For each ready version, the test found exactly the four expected variant names (`original`, `thumbnail`, `crop`, `optimized`), a matching original SHA-256, and the expected current `pipeline_version`. Replaying an already ready job returned `duplicate_or_stale`. After a second version became ready, an older delivery left its checksums and current version unchanged; version 1 rows remained available as history. The failed-job replay wrote one audit row and used a new attempt without deleting prior outbox history. The transient retry test exhausted a two-attempt budget, recorded `failed`, then succeeded only after replay reset that budget.
`student-tests/test_publish_confirm_gap.py` separately stopped the normal publisher and worker, accepted a queued upload, published a persistent broker copy with confirm, intentionally left its outbox row unconfirmed, expired that claim, and ran normal `publish_batch` again. Before starting worker, RabbitMQ reported two queued copies and PostgreSQL reported confirmed outbox. After worker resumed, the attachment reached ready with one public three-variant set. This demonstrates the expected duplicate from publish-before-confirm and safe handling of it. `student-tests/test_upload_handoff.py` also passed with broker and worker down at upload time, then API/broker restart and the original accepted job reaching ready.
The controlled process death checks durable boundaries, not the probability of such a crash under load. The local stand has one MinIO and one PostgreSQL instance, so this result does not prove service availability during their outage or exactly-once delivery.