Implement durable image processing pipeline with outbox and recovery

This commit is contained in:
Polusikkkk
2026-11-17 18:48:50 +03:00
parent 276dbdad8a
commit be223efc8b
84 changed files with 8982 additions and 18 deletions
+58
View File
@@ -0,0 +1,58 @@
{
"scenario": "worker crash after S3 writes, before result COMMIT",
"attachment_id": "5f4ea8f0-0efb-4fa2-bd7a-d4c07fa3a469",
"initial_job": {
"job_id": "48d3eef7-6769-4bbd-902e-55e52b89f67a",
"status": "queued",
"attempt": 1,
"outbox_count": 1,
"published": false
},
"after_crash": {
"job_id": "48d3eef7-6769-4bbd-902e-55e52b89f67a",
"status": "processing",
"attempt": 1,
"lease_remaining_seconds": 116.606905,
"fault_consumed": true,
"variant_rows": 0
},
"objects_before_recovery": [
"originals/5f4ea8f0-0efb-4fa2-bd7a-d4c07fa3a469",
"variants/5f4ea8f0-0efb-4fa2-bd7a-d4c07fa3a469/v1/crop",
"variants/5f4ea8f0-0efb-4fa2-bd7a-d4c07fa3a469/v1/optimized",
"variants/5f4ea8f0-0efb-4fa2-bd7a-d4c07fa3a469/v1/thumbnail"
],
"confirmed_intermediate_state": {
"job_id": "48d3eef7-6769-4bbd-902e-55e52b89f67a",
"status": "processing",
"attempt": 1,
"lease_remaining_seconds": 111.482557,
"fault_consumed": true,
"variant_rows": 0
},
"final_job": {
"job_id": "48d3eef7-6769-4bbd-902e-55e52b89f67a",
"status": "ready",
"attempt": 2,
"outbox_count": 2,
"published": true
},
"variant_rows": 3,
"objects_after_recovery": [
"originals/5f4ea8f0-0efb-4fa2-bd7a-d4c07fa3a469",
"variants/5f4ea8f0-0efb-4fa2-bd7a-d4c07fa3a469/v1/crop",
"variants/5f4ea8f0-0efb-4fa2-bd7a-d4c07fa3a469/v1/optimized",
"variants/5f4ea8f0-0efb-4fa2-bd7a-d4c07fa3a469/v1/thumbnail"
],
"worker_events": [
"worker-1 | 2026-11-17 14:49:11,362 INFO delivery job_id=48d3eef7-6769-4bbd-902e-55e52b89f67a redelivered=False",
"worker-1 | 2026-11-17 14:49:14,573 WARNING child_fault job_id=48d3eef7-6769-4bbd-902e-55e52b89f67a stage=after_objects exit_code=75",
"worker-1 | 2026-11-17 14:49:18,242 INFO delivery job_id=48d3eef7-6769-4bbd-902e-55e52b89f67a redelivered=True",
"worker-1 | 2026-11-17 14:49:18,244 INFO ack job_id=48d3eef7-6769-4bbd-902e-55e52b89f67a",
"worker-1 | 2026-11-17 14:51:14,782 INFO job transition job_id=48d3eef7-6769-4bbd-902e-55e52b89f67a status=queued reason=lease_expired",
"worker-1 | 2026-11-17 14:51:17,341 INFO delivery job_id=48d3eef7-6769-4bbd-902e-55e52b89f67a redelivered=False",
"worker-1 | 2026-11-17 14:51:20,984 INFO ack job_id=48d3eef7-6769-4bbd-902e-55e52b89f67a"
],
"elapsed_s": 135.979,
"result": "PASS"
}
+44
View File
@@ -0,0 +1,44 @@
{
"scenario": "worker crash after ready commit, before ack",
"attachment_id": "821b61c9-7251-491b-ad51-c29870dd43ab",
"job_id": "92915f04-938a-4253-823f-8c299eb87788",
"initial_job": {
"job_id": "92915f04-938a-4253-823f-8c299eb87788",
"status": "queued",
"attempt": 1,
"outbox_count": 1,
"published": false
},
"worker_before_fault": {
"started_at": "2026-11-17T14:39:01.016850053Z",
"restart_count": 0
},
"delivery_events": [
"worker-1 | 2026-11-17 14:39:02,540 INFO delivery job_id=92915f04-938a-4253-823f-8c299eb87788 redelivered=False",
"worker-1 | 2026-11-17 14:39:05,774 WARNING fault_injection job_id=92915f04-938a-4253-823f-8c299eb87788 stage=before_ack exit_code=75",
"worker-1 | 2026-11-17 14:39:08,149 INFO delivery job_id=92915f04-938a-4253-823f-8c299eb87788 redelivered=True",
"worker-1 | 2026-11-17 14:39:08,150 INFO ack job_id=92915f04-938a-4253-823f-8c299eb87788"
],
"worker_after_fault": {
"started_at": "2026-11-17T14:39:06.865588951Z",
"restart_count": 1
},
"final_job": {
"job_id": "92915f04-938a-4253-823f-8c299eb87788",
"status": "ready",
"attempt": 1,
"outbox_count": 1,
"published": true
},
"fault": {
"consumed": true
},
"variant_rows": 3,
"final_object_keys": [
"originals/821b61c9-7251-491b-ad51-c29870dd43ab",
"variants/821b61c9-7251-491b-ad51-c29870dd43ab/v1/crop",
"variants/821b61c9-7251-491b-ad51-c29870dd43ab/v1/optimized",
"variants/821b61c9-7251-491b-ad51-c29870dd43ab/v1/thumbnail"
],
"result": "PASS"
}
+13
View File
@@ -0,0 +1,13 @@
test_busy_upload_lock_prevents_deletion (__main__.CleanupStagingTests.test_busy_upload_lock_prevents_deletion) ... ok
test_expired_failed_dry_run_is_non_destructive (__main__.CleanupStagingTests.test_expired_failed_dry_run_is_non_destructive) ... ok
test_expired_failed_staging_is_deleted_and_reference_cleared (__main__.CleanupStagingTests.test_expired_failed_staging_is_deleted_and_reference_cleared) ... ok
test_old_orphan_is_deleted_without_attachment_update (__main__.CleanupStagingTests.test_old_orphan_is_deleted_without_attachment_update) ... ok
test_processing_is_preserved_even_when_old (__main__.CleanupStagingTests.test_processing_is_preserved_even_when_old) ... ok
test_queued_is_preserved_even_when_old (__main__.CleanupStagingTests.test_queued_is_preserved_even_when_old) ... ok
test_recent_failed_state_preserves_old_object (__main__.CleanupStagingTests.test_recent_failed_state_preserves_old_object) ... ok
test_recent_object_is_preserved (__main__.CleanupStagingTests.test_recent_object_is_preserved) ... ok
----------------------------------------------------------------------
Ran 8 tests in 0.054s
OK
+48
View File
@@ -0,0 +1,48 @@
{
"scenario": "failed staging integrity and audited replay",
"attachment_id": "9bcd1157-a974-444f-bba6-ec4fc558d287",
"job_id": "c48f14d0-586d-4c76-9b0e-a1b90e2e0cd8",
"failed_job": {
"job_id": "c48f14d0-586d-4c76-9b0e-a1b90e2e0cd8",
"status": "failed",
"attempt": 1,
"outbox_count": 1,
"published": true
},
"rejected_replay": {
"result": "error",
"error_type": "ValueError"
},
"dry_run": {
"result": "dry_run",
"job_id": "c48f14d0-586d-4c76-9b0e-a1b90e2e0cd8",
"previous_attempt": 1,
"new_attempt": 2,
"new_max_attempts": 6,
"previous_error_code": "invalid_image"
},
"applied_replay": {
"result": "replayed",
"job_id": "c48f14d0-586d-4c76-9b0e-a1b90e2e0cd8",
"previous_attempt": 1,
"new_attempt": 2,
"new_max_attempts": 6,
"previous_error_code": "invalid_image"
},
"final_job": {
"job_id": "c48f14d0-586d-4c76-9b0e-a1b90e2e0cd8",
"status": "ready",
"attempt": 2,
"outbox_count": 2,
"published": true
},
"ready_replay": {
"result": "noop",
"job_id": "c48f14d0-586d-4c76-9b0e-a1b90e2e0cd8",
"status": "ready",
"reason": "job_is_not_current_failed_work"
},
"audit_rows": 1,
"object_count": 4,
"result": "PASS"
}
+4
View File
@@ -0,0 +1,4 @@
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://127.0.0.1:18085"
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 130, "failed_attempts": 2, "first_recovery_seconds": 2.089}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+18
View File
@@ -0,0 +1,18 @@
[
{
"container_id": "bfa59f929e063a129517dd173a77bd12a619f6e5bac20f0215f9fdafb92c300b",
"status": "running",
"running": true,
"started_at": "2026-11-17T15:28:48.449382903Z",
"finished_at": "2026-11-17T15:28:43.450087124Z",
"exit_code": 0
},
{
"container_id": "ff57dc533c533c0f3121e8c3377c2aa697cbd8da304adbebf4dce43b0a0998b8",
"status": "exited",
"running": false,
"started_at": "2026-11-17T15:28:47.804844296Z",
"finished_at": "2026-11-17T15:30:39.004319199Z",
"exit_code": 0
}
]
+11
View File
@@ -0,0 +1,11 @@
test_contract_dimensions_and_original (test_image_pipeline.ImagePipelineTests.test_contract_dimensions_and_original) ... ok
test_exif_orientation (test_image_pipeline.ImagePipelineTests.test_exif_orientation) ... ok
test_invalid_input (test_image_pipeline.ImagePipelineTests.test_invalid_input) ... ok
test_rounding_down (test_image_pipeline.ImagePipelineTests.test_rounding_down) ... ok
test_small_image_not_upscaled_except_crop (test_image_pipeline.ImagePipelineTests.test_small_image_not_upscaled_except_crop) ... ok
test_transparency_becomes_white (test_image_pipeline.ImagePipelineTests.test_transparency_becomes_white) ... ok
----------------------------------------------------------------------
Ran 6 tests in 0.100s
OK
+34
View File
@@ -0,0 +1,34 @@
{
"scenario": "API crash after COMMIT while publisher is stopped",
"attachment_id": "b5d15121-0129-4bf5-a249-2000aa16e911",
"before_crash": {
"job_id": "0010fe3a-2555-4ddf-a8da-9ce29abd9dd5",
"status": "queued",
"attempt": 1,
"outbox_count": 1,
"published": false
},
"after_api_kill": {
"job_id": "0010fe3a-2555-4ddf-a8da-9ce29abd9dd5",
"status": "queued",
"attempt": 1,
"outbox_count": 1,
"published": false
},
"after_publisher_start": {
"job_id": "0010fe3a-2555-4ddf-a8da-9ce29abd9dd5",
"status": "queued",
"attempt": 1,
"outbox_count": 1,
"published": true
},
"final": {
"job_id": "0010fe3a-2555-4ddf-a8da-9ce29abd9dd5",
"status": "ready",
"attempt": 1,
"outbox_count": 1,
"published": true
},
"ready_after_worker_start_s": 4.038,
"result": "PASS"
}
+3
View File
@@ -0,0 +1,3 @@
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://127.0.0.1:18085"
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
+38
View File
@@ -0,0 +1,38 @@
{
"scenario": "queued upload survives API and broker restart",
"attachment_id": "6876fe3c-1544-4e70-8011-b82c8b446ac9",
"message_id": "244c0f7c-c17b-4c17-867c-47e5da0e799a",
"job_before_restart": {
"status": "queued",
"attempt": 1,
"published": true
},
"queue_before_restart": {
"name": "attachment.process.v1",
"durable": true,
"messages_ready": 1
},
"container_starts_before": {
"ea6e598f8967caf02b45629157b7156d60952001b4c73647212bb0124e0094f2": "2026-11-17T13:52:02.655967981Z",
"cd7a5131f262d163ca99084295bf4c291e971fb087af1dbd2020e13dd8e4d91f": "2026-11-17T13:52:02.172273085Z",
"d8f9d07940fea84f297d8562c8a4721cc5eac6b9bd684b0ea1edf9f51ffed1fd": "2026-11-17T13:56:52.523576495Z"
},
"container_starts_after": {
"ea6e598f8967caf02b45629157b7156d60952001b4c73647212bb0124e0094f2": "2026-11-17T13:57:33.504017667Z",
"cd7a5131f262d163ca99084295bf4c291e971fb087af1dbd2020e13dd8e4d91f": "2026-11-17T13:57:32.869870682Z",
"d8f9d07940fea84f297d8562c8a4721cc5eac6b9bd684b0ea1edf9f51ffed1fd": "2026-11-17T13:57:34.831360909Z"
},
"queue_after_restart": {
"name": "attachment.process.v1",
"durable": true,
"messages_ready": 1
},
"ready_after_worker_start_s": 5.857,
"original_sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75",
"variants": [
"crop",
"optimized",
"thumbnail"
],
"result": "PASS"
}
+163
View File
@@ -0,0 +1,163 @@
{
"before": [
{
"service": "api",
"container_id": "bfa59f929e063a129517dd173a77bd12a619f6e5bac20f0215f9fdafb92c300b",
"started_at": "2026-11-17T15:18:11.387840892Z",
"status": "running",
"volumes": []
},
{
"service": "api",
"container_id": "ff57dc533c533c0f3121e8c3377c2aa697cbd8da304adbebf4dce43b0a0998b8",
"started_at": "2026-11-17T15:18:10.988865407Z",
"status": "running",
"volumes": []
},
{
"service": "broker",
"container_id": "26183862d5be1a9677d3981cdd4aa7ab41583720ea6ff51664b4b6ca1a30df54",
"started_at": "2026-11-17T14:37:29.569999892Z",
"status": "running",
"volumes": [
"mtusi2026lab5_broker_data"
]
},
{
"service": "cleanup",
"container_id": "d29213849d9d711eb711621a965f2f6720c6c4351b10705f06a07969fb43bc2d",
"started_at": "2026-11-17T15:22:37.758977743Z",
"status": "running",
"volumes": []
},
{
"service": "lb",
"container_id": "c7d31b9c6c1fb456d4b79b50521f00c6690e9fdf016fc53c9245f009296b242c",
"started_at": "2026-11-17T13:52:03.2138386Z",
"status": "running",
"volumes": []
},
{
"service": "postgres",
"container_id": "ad1aa87a07ef37319bb04c6e1caa05c5d7e0455bab6a8156603cb93ae3ed1638",
"started_at": "2026-11-17T13:51:56.606984187Z",
"status": "running",
"volumes": [
"mtusi2026lab5_postgres_data"
]
},
{
"service": "publisher",
"container_id": "123cc8ab2c6227e49096b6b41e3d59fc2b69d8e091a63e44b65662d72d13857b",
"started_at": "2026-11-17T15:04:26.1288457Z",
"status": "running",
"volumes": []
},
{
"service": "redis",
"container_id": "bc013b9a224e5d3aae5a3afed9880af92db0921acee34e9187ea7467eb5cafd4",
"started_at": "2026-11-17T13:51:56.57427508Z",
"status": "running",
"volumes": [
"mtusi2026lab5_redis_data"
]
},
{
"service": "s3",
"container_id": "4731679b480bde3edf68aaac640f2108a864efd437541891986480a404aefbf6",
"started_at": "2026-11-17T13:51:56.614820161Z",
"status": "running",
"volumes": [
"mtusi2026lab5_s3_data"
]
},
{
"service": "worker",
"container_id": "168ec66f5667bb59a99acd51a13fb36fcabc8d726d935007b3d4a605a8f0e798",
"started_at": "2026-11-17T15:18:59.941835146Z",
"status": "running",
"volumes": []
}
],
"result": "HOOK_COMPLETED",
"after": [
{
"service": "api",
"container_id": "bfa59f929e063a129517dd173a77bd12a619f6e5bac20f0215f9fdafb92c300b",
"started_at": "2026-11-17T15:28:48.449382903Z",
"status": "running",
"volumes": []
},
{
"service": "api",
"container_id": "ff57dc533c533c0f3121e8c3377c2aa697cbd8da304adbebf4dce43b0a0998b8",
"started_at": "2026-11-17T15:28:47.804844296Z",
"status": "running",
"volumes": []
},
{
"service": "broker",
"container_id": "26183862d5be1a9677d3981cdd4aa7ab41583720ea6ff51664b4b6ca1a30df54",
"started_at": "2026-11-17T15:28:45.809717435Z",
"status": "running",
"volumes": [
"mtusi2026lab5_broker_data"
]
},
{
"service": "cleanup",
"container_id": "fe25b5c8dff54d1283675dcb8a31136f727b83e1bedef3a073df68c9084bd67c",
"started_at": "2026-11-17T15:28:49.052588548Z",
"status": "running",
"volumes": []
},
{
"service": "lb",
"container_id": "c7d31b9c6c1fb456d4b79b50521f00c6690e9fdf016fc53c9245f009296b242c",
"started_at": "2026-11-17T15:28:49.152009495Z",
"status": "running",
"volumes": []
},
{
"service": "postgres",
"container_id": "ad1aa87a07ef37319bb04c6e1caa05c5d7e0455bab6a8156603cb93ae3ed1638",
"started_at": "2026-11-17T15:28:44.877894569Z",
"status": "running",
"volumes": [
"mtusi2026lab5_postgres_data"
]
},
{
"service": "publisher",
"container_id": "8b583aba3eadce6ff307738c148164901325c1b763a7bfcd7a8cad1fbbc0df21",
"started_at": "2026-11-17T15:28:47.928076896Z",
"status": "running",
"volumes": []
},
{
"service": "redis",
"container_id": "bc013b9a224e5d3aae5a3afed9880af92db0921acee34e9187ea7467eb5cafd4",
"started_at": "2026-11-17T15:28:44.875553344Z",
"status": "running",
"volumes": [
"mtusi2026lab5_redis_data"
]
},
{
"service": "s3",
"container_id": "4731679b480bde3edf68aaac640f2108a864efd437541891986480a404aefbf6",
"started_at": "2026-11-17T15:28:46.590899487Z",
"status": "running",
"volumes": [
"mtusi2026lab5_s3_data"
]
},
{
"service": "worker",
"container_id": "168ec66f5667bb59a99acd51a13fb36fcabc8d726d935007b3d4a605a8f0e798",
"started_at": "2026-11-17T15:28:47.957685083Z",
"status": "running",
"volumes": []
}
]
}
+64
View File
@@ -0,0 +1,64 @@
{
"scenario": "temporary S3 read failure exhausts bounded retries",
"attachment_id": "aa0f40d2-b242-4f79-95d6-3dd758e5f094",
"initial_job": {
"job_id": "e01d1f5b-9e96-4d61-b7cc-84320920a6dc",
"status": "queued",
"attempt": 1,
"max_attempts": 5,
"error_code": null,
"lease_cleared": true,
"outbox": [
{
"attempt": 1,
"published": false,
"delay_seconds": 0.0
}
]
},
"observed_attempts": [
1,
2,
3,
4,
5
],
"final_job": {
"job_id": "e01d1f5b-9e96-4d61-b7cc-84320920a6dc",
"status": "failed",
"attempt": 5,
"max_attempts": 5,
"error_code": "retry_exhausted",
"lease_cleared": true,
"outbox": [
{
"attempt": 1,
"published": true,
"delay_seconds": 0.0
},
{
"attempt": 2,
"published": true,
"delay_seconds": 1.238091
},
{
"attempt": 3,
"published": true,
"delay_seconds": 0.55709
},
{
"attempt": 4,
"published": true,
"delay_seconds": 3.659677
},
{
"attempt": 5,
"published": true,
"delay_seconds": 4.988969
}
]
},
"terminal_observation_seconds": 5,
"elapsed_s": 26.369,
"result": "PASS"
}
+2
View File
@@ -0,0 +1,2 @@
python3 tests/smoke.py --base-url "http://127.0.0.1:18085"
PASS: lab5 public API scenario; infrastructure and grading evidence remain separate.
+62
View File
@@ -0,0 +1,62 @@
{
"scenario": "scoped staging cleanup safety",
"queued_dry_run": {
"mode": "dry-run",
"grace_seconds": 0,
"attachment_id": "b8f27860-a4b8-49e4-a2a7-34a151b9c5bb",
"scanned": 2,
"ignored": 0,
"fresh": 0,
"busy": 0,
"active": 1,
"gone": 0,
"candidates": 1,
"deleted": 0
},
"queued_apply": {
"mode": "apply",
"grace_seconds": 0,
"attachment_id": "b8f27860-a4b8-49e4-a2a7-34a151b9c5bb",
"scanned": 2,
"ignored": 0,
"fresh": 0,
"busy": 0,
"active": 1,
"gone": 0,
"candidates": 1,
"deleted": 1
},
"attachment_id": "b8f27860-a4b8-49e4-a2a7-34a151b9c5bb",
"ready_dry_run": {
"mode": "dry-run",
"grace_seconds": 0,
"attachment_id": "b8f27860-a4b8-49e4-a2a7-34a151b9c5bb",
"scanned": 1,
"ignored": 0,
"fresh": 0,
"busy": 0,
"active": 0,
"gone": 0,
"candidates": 1,
"deleted": 0
},
"ready_apply": {
"mode": "apply",
"grace_seconds": 0,
"attachment_id": "b8f27860-a4b8-49e4-a2a7-34a151b9c5bb",
"scanned": 1,
"ignored": 0,
"fresh": 0,
"busy": 0,
"active": 0,
"gone": 0,
"candidates": 1,
"deleted": 1
},
"final_storage_state": {
"keys": [],
"status": "ready",
"staging_reference": false
},
"result": "PASS"
}