Bring the stdlib suite and image generator of the lab 5 preparation:
make suite-preflight checks services, readiness, schema columns, broker
topology and the faults override, and make level3 runs the grade 3
scenarios (smoke through the pipeline, worker down with API, relay and
broker restarts, duplicate delivery after ready, poison image, S3
outage with recovery, retries up to JOB_MAX_ATTEMPTS) and checks the
invariants into evidence/level3.json. make pipeline-evidence shows the
queued job on the broker while the worker is stopped, its properties
and contract payload, the 409 before ready and SIGTERM of the relay and
the worker; make topology dumps queues, consumers with prefetch,
permissions and users.
The lab 4 failover and S3 outage scenarios and the upload fault suite
now expect 202 and wait for ready, the stack evidence lists the broker
and its client packages, and the CI acceptance job runs the pipeline
scenarios and the SIGTERM check of the new processes.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Embed the checked lab 5 preparation: RabbitMQ 4.1.8 pinned by digest
with a fixed node hostname, a volume, a read-only root and 512 MiB,
whose topology (vhost messenger, exchange attachments, quorum queue
attachments.process with a dead letter exchange, delivery limit 10 and
reject-publish overflow) and users come from definitions imported on
every boot. The relay may only write to the exchange, the worker may
only read the queue, configure belongs to the operator, there is no
guest, and the management UI is published on 127.0.0.1 only. The relay
and the worker run from the application image with a heartbeat health
check, init, a read-only root and their own limits; the worker gets its
own S3 user that reads staging and writes originals and variants, and
s3-init creates it idempotently. The API has no broker credentials.
make secrets also creates the broker passwords, URLs, hashed users and
the worker S3 keys; the restart hook now stops the balancer, the API,
the relay and the worker and restarts PostgreSQL, Valkey, S3 and the
broker with their volumes; worker.sh and broker.sh stop, start and
inspect the processes for the failure demonstrations; the limits
policy covers the new services and the loopback UI port.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The messaging zone asks a new AttachmentStates port whether any listed
attachment of the chat has failed and answers 409 conflict before the
message is stored; queued and processing attachments can still be
sent right after the upload. The check runs only on the first execution
of a key, so a replay returns the original 201 even if the attachment
failed later. main.py wires the port to the attachments directory, so
neither zone reads the other's tables.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Upload now stages the checked original under staging/, and one
transaction moves the intent to queued, inserts the job (pipeline
version 1, attempt 1), its outbox row and an audit event; the 202 is
the in-memory snapshot, never a reread. Content answers 409 until the
attachment is ready, the thumbnail variant is served from the
published version and absent variants are 404.
The relay publishes outbox rows through FastStream with publisher
confirms, mandatory routing and persistent delivery, marks a row only
after the broker acked it, returns jobs whose lease expired and deletes
the staging object of ready attachments. The worker consumes the
quorum queue through a FastStream subscriber that declares nothing,
takes prefetch from WORKER_CONCURRENCY and acks manually after the
result commit, rejects messages off jobs.schema.json to the dead letter
exchange and requeues after an infrastructure error. A job is claimed
under a lease token; the original is copied to originals/ and a
256 px JPEG thumbnail is written under a content-addressed key; the
commit is fenced by the token, inserts variants with ON CONFLICT DO
NOTHING and publishes only a newer pipeline version. A transient error
reschedules the same job with an exponential delay and a new outbox
row, the last attempt fails with retry_exhausted, an undecodable image
fails at once with invalid_image, and a redelivered finished job is a
recorded no-op.
The worker and the relay are assembled in worker.py and relay.py with
the dishka FastStream integration and the platform providers of the
API; the shared core imports neither FastStream nor aio-pika. Tests
cover the thumbnail geometry and rendering, the job message against
the contract, the pipeline against PostgreSQL (duplicates, parallel
copies, retries, the attempt bound, leases and fencing) and the broker
adapters against a throwaway RabbitMQ with the stand's topology and
permissions.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Migration 0004 widens the attachment states to queued, processing and
failed, adds the staging and original keys, the published pipeline
version and the error code, and moves the lab 4 object key into them
while leaving the old column nullable until a contract step. New tables
hold the variants under the effect key (attachment, pipeline version,
name), the jobs with attempt, claims and lease, the outbox rows the
relay publishes and the audit of job transitions. Partial indexes serve
the relay scan of unpublished rows, the search for expired leases and
the staging cleanup.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Plan grade 3 of lab 5: upload answers 202 queued after the original is
in a private staging prefix and the attachment, its job and an outbox
row are committed in one transaction; a separate relay publishes the
outbox to a RabbitMQ quorum queue with publisher confirms and returns
jobs with an expired lease; a separate worker on FastStream claims a
job under a lease, publishes the original and a 256 px JPEG thumbnail,
commits the result fenced by the lease token and acks only after the
commit, retries transient errors up to JOB_MAX_ATTEMPTS and fails
undecodable images at once. Content answers 409 until ready and a
failed attachment cannot be sent.
The change adds the lab5-attachment-pipeline and lab5-job-delivery
capabilities and deltas to lab4-attachments, lab4-upload-resilience,
lab1-messenger-history and lab3-load-balancing.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Bring the Claude Code settings, the lint hook, the opsx commands and
skills, the architecture notes, the lab 1 to lab 4 specs and the
archived lab 1 to lab 4 changes into the lab 5 skeleton, so lab 5
continues the same spec history instead of starting from scratch. The
files come from the lab 4 solution commit d2744bc.
Rewrite AGENTS.md and the openspec context and rules for lab 5: upload
answers 202 queued after the original is in a private staging prefix
and the attachment, the job and the outbox row are committed in one
transaction, a separate relay publishes the outbox to RabbitMQ with
publisher confirms, a separate worker built from the same image
consumes the queue through FastStream with a manual ack after the
result commit, PostgreSQL stays the source of truth for job states,
Out of scope moves to labs 6-7, track 1 and broker HA, and the rules
add the failure windows between PostgreSQL and the broker, the effect
key and the lease to specs and designs.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>