Skip to content

Render isolated configuration for PR previews - #304

Merged
aRustyDev merged 1 commit into
mainfrom
codex/isolated-preview-config
Nov 18, 2026
Merged

aRustyDev merged 1 commit into
mainfrom
codex/isolated-preview-config

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

Add an isolated Preview profile that takes explicitly supplied PR resources, keeps the Preview room local, and disables email. Refuse production data and rate-limit identifiers and unexpected binding shapes. Record the remaining migration and deployment work and the Marketplace action assessment in the preview plan.

The renderer does not provision resources, prove Hyperdrive origin or Cloudflare-applied binding identities, or deploy a Preview; those remain required before wiring this profile to CI.

Validation: generated Preview configuration tests (1,440 passed), including a control that permits the production Hyperdrive ID and is rejected by the test suite.

@aRustyDev
aRustyDev temporarily deployed to preview-control-plane November 18, 2026 06:18 — with GitHub Actions Inactive
@aRustyDev
aRustyDev merged commit 00a99bb into main Nov 18, 2026
17 checks passed
@aRustyDev
aRustyDev deleted the codex/isolated-preview-config branch November 18, 2026 06:50
aRustyDev added a commit that referenced this pull request Nov 18, 2026
…etters table on every target (#310)

* feat(ports): tell a permanent consumer error from a transient one, and say what each means for the message

`EventConsumer::handle` returned `Result<(), String>`, so every failure looked alike: a queue adapter could not know that an event
with no `project_id` can never succeed (Stage 2 delivered one four times before the queue gave up) while a database that was down
might. It now returns `ConsumerError`, `Permanent` or `Transient`.

The policy that follows from the kind is one pair of functions in `thrust-ports`, for every queue adapter to call: `disposition`
(ack, deliver again after a delay, or dead-letter) and `retry_delay` (5 s doubled for every delivery, never more than 60 s).
`MAX_DELIVERIES` is 4, the first delivery and the three retries the Worker's `max_retries = 3` allows.

Core classifies in `consumer_error`: an error about the message (`Invalid`, `NotFound`, the authorization ones, `TooLarge`) is
permanent, one about something the consumer needed (`Internal`, which every port error arrives as, `Upstream`, `RateLimited`,
`Conflict`) is transient. Its `match` names every variant with no wildcard arm. One known misclassification is documented on it: a
history row for a work item the adapter does not have comes back as a backend error, so it is retried and then dead-lettered.

`DeadLetter` joins `Envelope` in `thrust-contracts`; nothing writes or reads one yet. Nothing yet acts on the kinds either: the
queue adapters still ignore or retry as before, which the commits after this one change.

Tested: the disposition of every answer on every delivery count 1..=6 against a table the test owns, and properties over the whole
range of `u32` for the delay and the limit; every `CoreError` variant against its kind, a property that the kind never depends on the
error's text, and the two events the issue names (no `project_id`; a backend error of the memory adapter) through the real consumer.
Controls, each killed (exit 100): a permanent answer retried, an off-by-one at the limit, the limit raised to five, no cap on the
delay, a finished message dead-lettered; permanent and transient swapped in either direction, the reason dropped, `Invalid`
transient.

Refs: #53
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* feat(queue): a dead_letters table, written through the consumer and read on `GET /internal/dead-letters`

A message the consumer sets aside now has somewhere to go. `dead_letters` (migration 0020) holds one row per message: the queue's own
id when it has one (so a message delivered again lands on the row it made), when it was set aside, the topic, the event's id when the
body decoded, the body as it arrived, why, and how many times it was delivered (NULL for a message Cloudflare's own dead-letter queue
moved, because that queue starts the count again). It has no tenant: a body that does not decode names none.

Ports: `Database::insert_dead_letter` (idempotent on `id`, the first write stands) and `dead_letters` (newest first, ties broken by
`id` in byte order, which Postgres is asked for with `COLLATE "C"`), both untenanted like the outbox's. `EventConsumer::dead_letter`
is the one way a queue adapter writes one, because an adapter holds no `SystemScope` and `scripts/check-deps.sh` keeps it that way.

Core: `record_dead_letter` stamps the time and, when the queue has no id, mints one. It also replaces a NUL in any text with U+FFFD:
Postgres cannot store a NUL in `text`, a body is whatever a producer sent, and a message whose dead-letter write fails is delivered
again, fails again and is lost, which is what a dead letter exists to prevent. The change is made there, once, so both adapters
answer alike.

`GET /internal/dead-letters` (the admin token, test routes on) lists them, so one contract test can read every target.

The number is 0020 because 0019 is `0019_description_stripped.sql` (issue #48, #305), which landed on main while this was being
built; the issue's own 0002 was taken long before. The Postgres ledger test plants made-up migrations, and since #305 it numbers them
from 9000, so a real 0020 does not collide with them and that test needs no change here (an earlier version of this work moved its
numbers up by one, as was done when 0018 was added; that is no longer needed and was dropped in the rebase).

Nothing sets a message aside yet: the queue adapters still ignore or retry as before, which the next commits change.

Tested: the memory adapter against a reference model over sequences (ties in time, ids that differ in case, a limit, a reset); the
generated parity model of the Postgres adapter gets the same two operations and five new step classes, and its hermetic check that the
generator reaches every class fails when it cannot make a tie, a redelivery or a listing; a round trip of arbitrary text through the
core write, NULs included. Controls, each killed: a second write that replaces the first, a repeated id answering true, oldest first,
ties in ascending id order, no limit, one row too many; a NUL kept in the body, the error or the topic, the queue's id ignored, the
time or the attempts or the event id dropped. These were run before the rebase onto #305; the same tests are re-run on the rebased
tree before the pull request is opened (see its body).

Refs: #53
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* feat(queue): the in-process queue retries a transient error with backoff and sets the rest aside

`MemoryQueue` ran the consumer and threw its answer away (`let _ = c.handle(&env).await`), so on native-memory, native-pg and
worker-memory a message that failed was neither retried nor recorded. It now follows the policy of `thrust_ports::disposition` after
every answer: a done message is finished; a transient error is delivered again after `retry_delay` (5, 10, 20 s), up to four deliveries;
a permanent error, or the fourth transient one, is set aside through `EventConsumer::dead_letter` with the message's envelope as its
body, the topic it was sent to, the event's id, why, and how many times it was delivered.

The write of a dead letter gets the same policy: a transient failure is tried again after the same waits, and a write that fails four
times is given up on and counted (`MemoryQueue::lost_count`), because an in-process queue has nowhere else to put the message.

The adapter has no timer, so the wait is brought by the composition root: `MemoryQueue::with_sleep`. The native server passes
`tokio::time::sleep`. Without one a retry follows at once, which is what the hermetic tests and the Worker's in-memory target need (a
task that waits seconds does not outlive the request there), so no existing caller changes.

Tested by a model of the queue against a reference written out in the test (four deliveries, waits of 5, 10 and 20 s, the same for the
write of the letter) over generated answers, with failing writes and with and without a sleep. Controls, each killed: every answer taken
as done, the delivery count skipping one, no wait, a dead letter with an id of its own, without its topic, its event id or its reason,
holding the payload only, with one delivery too many, a lost message not counted, a failed write not tried again, a write that gives
up taken as done.

Refs: #53
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* feat(worker): the queue consumer sets a message aside through the dead-letter queue instead of dropping or retrying it blind

The Worker retried every failure after a flat 5 s, whatever it was, and acknowledged and dropped a body that was not an event, so a
message that could never succeed was delivered four times before Cloudflare's own limit moved it, and one that was not an event was
lost with a log line. It now follows the same policy as the in-process queue, and the Worker is a thin shell around the decisions.

Decisions, in `thrust-ports` and tested natively: `settle` decodes the body, asks the consumer, and applies `disposition`: a body that
is not an event is set aside at once, exactly as it came, with no event id, and the consumer is never asked about it; an event the
consumer accepts is done; a permanent error is set aside; a transient one is delivered again after 5, 10 and 20 s and set aside on the
fourth delivery. `settle_dead_letter` is the other queue's side: a message the Worker set aside becomes the row it describes, and a
message Cloudflare moved there itself becomes a row under its own id with no count of deliveries (that queue starts the count again).

The Worker consumes both queues, told apart by `THRUST_EVENTS_DLQ`. It reads each message on its own (`raw_iter`, so one body that is
not a string no longer fails the batch), counts deliveries with `MessageExt::attempts()` (workers-rs 0.9), and acts on the answer:
acknowledge, deliver again after the delay, or send a `DeadLetterMessage` to the dead-letter queue and acknowledge. If that send fails
the message is not acknowledged, so it is delivered again, and the queue's own `max_retries` moves the original there if that keeps
failing, which the consumer of that queue turns into a row all the same. A Worker that does not know the dead-letter queue's name sets
nothing aside, so a misconfiguration cannot make a message go round.

`DeadLetterMessage` is the wire type on that queue, in `thrust-contracts`. It parses text that any producer's message can be, so it has
a fuzz harness, committed seeds and `fuzz_replay_` tests with their must-fail controls (rust-test-fuzz), and properties that run on every
`cargo nextest run`. A cargo-fuzz campaign has not been run: it needs nightly and cargo-fuzz.

Configuration: all four Worker configs get the `EVENTS_DLQ` producer, a consumer on the dead-letter queue (`max_retries = 10`, and no
dead-letter queue of its own, which miniflare refuses), and `THRUST_EVENTS_DLQ`; the local config also gets the `dead_letter_queue` on
the events consumer that only the deploy template had. The deploy parity test now checks the topology in both files (the dead-letter
queue is produced to and consumed, its consumer has none, the var names it) and that the events consumer's `max_retries` allows
`MAX_DELIVERIES`, read from the ports source; 8 new controls, all run under GNU sed as well as BSD sed.

The `queue-raw` probe puts raw text on the events queue binding: `/internal/inject-event` takes only a valid envelope, so it is the one
way to reach the branch for a body that does not decode.

Not run here: the Worker against a real queue (the contract tests of the next commit do that), and
`.github/scripts/tests/test-deploy-target.sh`, which fails on this machine on a clean `main` too.

Refs: #53
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* test(queue): the contract suite shows a permanent error set aside at once on every target, and an undecodable message set aside on the Worker

Two tests, one for each way a message used to be lost or retried blind.

- permanent_consumer_error_is_dead_lettered_without_retry (all four targets): an event with no `project_id`, which FR-21 and S2-9 name
  as the example, is set aside after ONE delivery with its error naming the field, and the body in the row decodes to the envelope.
  A second poison event is injected after it and the first still appears once, so a redelivered message cannot make a second row.
  `/internal/dead-letters` is added to the admin gate test (no token, wrong token: 401), because a dead letter carries an event body.
- worker_bindings_undecodable_message_is_dead_lettered (worker-cf `bindings` pass): the `queue-raw` probe sends text that is not an
  envelope straight to the events queue, and the row for it must appear with a null `event_id` and `attempts == 1`. Named
  `worker_bindings_*` because that prefix is what the `bindings` pass selects; the issue's `worker_undecodable_*` would run in no pass.

Counts move by one test each: contract.sh EXPECT_MAIN 73 -> 74 and EXPECT_BINDINGS 5 -> 6 (the admin-gate lines go into an existing
test, so they add none); stage2-contract.sh main 67 -> 68 and bindings 3 -> 4, and its header says why the bindings pass now needs the
dead-letter queue that wrangler.stage2.toml got in the previous commit. scripts/check-contract-counts.sh reads the numbers back.

The planted defect is `mutant_invalid_is_transient` (an invalid message is treated as transient), forwarded by thrust-server and
listed in scripts/mutants.sh. Under it the message is delivered again after 5 s, 10 s and 20 s and set aside at its fourth delivery,
so the 15 s wait in the new test fails: the row is killed.

Verified on this Mac (wrangler 4.151.2, worker-build 0.9.0):
- native-memory, native-pg, worker-memory and worker-cf `main`: 74 of 74. worker-cf `bindings`: 6 of 6.
- the mutant, native-memory and worker-cf: each fails exactly the one test meant for it.
- ack-and-drop put back in the Worker handler, by hand: it fails exactly the tests meant for it. The Worker is not in mutants.sh,
  which builds native-memory only, so both Worker controls were run by hand (the same precedent as G-39).

Not run: stage 2 against a deployed Worker (it needs the staging account).

Refs: #53
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* docs(queue): record the consumer failure policy, the dead_letters table and what was not shown

The policy is now one thing on every target, so the pages that described the old behaviour (a flat 5 s retry, an undecodable body
acknowledged and dropped, a dead-letter queue nothing read) say what it is now.

- ADR-0070: an FR-21 paragraph in the round-29 section, and an "Update - issue #53" with the policy table and what it settled: the
  kind is chosen in core by an exhaustive match on CoreError, with one known misclassification (a history row for a work item the
  adapter does not have is a foreign-key error, so it is transient: delivered four times and set aside with its reason, not lost);
  MAX_DELIVERIES is 4 and the deploy parity test holds both wrangler configs to it; the policy lives in thrust-ports; a dead letter
  is a row whose id is the queue's own id, with `attempts` nullable because Cloudflare's DLQ restarts the count; the Worker sends a
  DeadLetterMessage and consumes the dead-letter queue itself so one writer makes every row; a dead letter whose own write fails four
  times is lost; a queue has one active consumer.
- QUESTIONS.md Q-0006.5 was already answered, so it gets "Implemented (issue #53)" and not a second answer; PLAN.md marks the row.
- architecture/infra.md (the queue-consumer paragraph is rewritten), architecture/app.md (the ports table), flows/app.md (the
  `/internal/dead-letters` route and the Failures paragraph) and architecture/deploy.md (the Worker now consumes the dead-letter
  queue, so check that nothing else is attached before the first deploy). patterns.md says an adapter writes a dead letter through
  `EventConsumer::dead_letter` because it holds no SystemScope.
- features.md, evidence-and-controls.md, techniques/mutation.md and defect-matrix.md (X5) list `mutant_invalid_is_transient` and
  the two new contract tests.
- testing/status.md G-47 records what is covered and six things NOT shown: no cargo-fuzz campaign on DeadLetterMessage::parse (needs
  nightly and cargo-fuzz, the owner's to install; the committed seeds are replayed by `fuzz_replay_` on every run); the Worker's
  path ran on local workerd, not on Cloudflare, and stage 2 has not been run against it; a message near Cloudflare's 128 KB limit
  cannot be wrapped and reaches the table by the queue's own backstop with no count and no reason; the transient path is not
  tested over HTTP (its 5, 10 and 20 s are held by the in-process queue's model with a recording sleep, and by `settle`'s table); a
  dead letter whose own write fails four times is lost and nothing reads the count; and test-deploy-target.sh fails on the
  development Mac on an untouched main, so CI is its first verdict.

Verified: the book builds (mdbook with mdbook-mermaid) and its own check scripts, self-test included, pass.

Refs: #53
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* fix(ci): the isolated Preview profile knows the dead-letter producer and variable, and still gives a Preview the events producer alone

#304 added the `isolated` profile of scripts/preview-config.py, which accepts production's queue shape only as written: exactly one
producer, EVENTS, and exactly four variables. This branch adds a second producer (EVENTS_DLQ) and a variable (THRUST_EVENTS_DLQ) to the
production template, so on the rebased tree `test_preview_config.py` failed 40 of its isolated runs ("isolated N: succeeds: got 1,
wanted 0"): every isolated Preview would have been refused.

The decision, which the profile exists to force: a Preview consumes nothing (production consumes), so it sets nothing aside, so it has
no use for the dead-letter producer or the variable that names the dead-letter queue. The profile now requires the template to have
exactly the EVENTS and EVENTS_DLQ producers and the five variables, and still writes the events producer alone, under the PR's own queue
name, with the variables it already wrote. A third producer, a missing dead-letter producer and a missing THRUST_EVENTS_DLQ are refused
and named, as an unknown binding always was. The check that a Preview's queue is not production's now covers every production queue.

Tests (test_preview_config.py, 1483 passed, 0 failed; was 40 failed before the change to the script): each of the 40 generated isolated
runs now also holds the producer list to the events producer alone; three refusals are new. Control: the same test run against a copy of
the script with the producer-shape check removed fails exactly the two producer refusals (the variable refusal still passes, as it
should), so those checks can fail.

Not run: a real Preview deploy of an isolated target (it needs the PR's provisioned resources and the account).

Refs: #53
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>

This branch was previously deployed

1 inactive deployment
preview-control-plane — c9ede1d9 Deployed Nov 18, 2026 by aRustyDev via reconcile #91
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