Repository navigation
feat(issues): clean a description once in the use-cases and store its text and policy - #305
Merged
Merged
Conversation
… text and policy A work item keeps ONE form of its description, the cleaned HTML, and what is derived from it (issue #48, D-020; the work items' half): `description_stripped`, the text, which is Django's `strip_tags` of the HTML, and `description_schema`, the version of the policy the HTML was cleaned under (ADR-0012's "record a schema version"). There is no `description_json` or `description_binary` column at P0; a second stored form would be a second source of truth, one of them not cleaned. - thrust_html::describe is the one place a description is cleaned and its text taken, and the use-cases call it (create_issue, and update_issue before anything reads the asks, so the history compares and quotes the cleaned form). The compat plane and /api/v1 hand it the text as sent and keep only the size check, in the pin's words, with their other fields' problems; a new IssueError::InvalidDescription is the use-case's own answer to an oversize one that came anyway. - WorkItemAttrs and WorkItemUpdate carry the two fields; an update that names no description leaves the row's own. - Migration 0019 adds the two columns, nullable, no default (an expand file). A row written before it has NULL in both and HTML cleaned by Plane's plain allow-list; nothing backfills or reads them yet. - Postgres and memory adapters read and write them. The ledger tests' made-up files were numbered 0019 and sort before the real 0019 now, so they are numbered 9000 and up, after every real file. strip_tags had no test: 77 of the sanitiser crate's mutants survived, all of them in it. It now has a `parity_` test against 507 answers of Django's function recorded by tools/strip-tags/record.py (Python 3.12.13; the default sanitiser's output for the XSS and editor corpora, and 75 hand-written cases). The port matches on all but three hand-written inputs that no sanitiser output can be (an attribute quote never closed, the text of a <script>, a malformed character reference with text after it); the test names them and asserts that exactly those differ. Mutation testing of the crate is now 124 mutants, 112 caught, 11 timeouts, 1 unviable, 0 missed; one equivalent mutant is excluded, with the proof. Shown failing: a creation that stores no text (the six creation cases), an update that drops the row's own text or skips the cleaning (the update model), and a description_json column in the migration (the Postgres test). Postgres adapter tests 83 of 83 against a real Postgres, the contract suite's main pass 73 of 73 on native-memory and native-pg, oracle-v1 PASS. Refs: #48 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev
temporarily deployed
to
preview-control-plane
November 18, 2026 06:26 — with
GitHub Actions
Inactive
Merged
This was referenced Nov 18, 2026
aRustyDev
added a commit
that referenced
this pull request
Nov 18, 2026
…309) A `style` value was judged after its comments were cut out and its backslashes dropped, so a CSS hex escape was never read: `j\61vascript:`, `\6a avascript:` and `\65xpression(` passed the value filter. PR #305's report named the first. The comment cut came before any escape was read as well, so `\/* javascript: */` lost its tail to a "comment" that a stylesheet never opens. `css_text` reads both in one pass, in the order a stylesheet does (CSS Syntax 3, 4.3.2 and 4.3.7): a comment runs to the first `*/` or the end of the value (`/*/` does not close itself), a backslash and one to six hex digits is the code point they name, taken greedily, and a backslash and any other character is that character and never an opener. A code point that is no `char` is dropped and a control character is removed, as `url_ok` already does: both can only make a token easier to see. A left-over backslash is still dropped. SCHEMA_VERSION goes from 1 to 2, because the policy changed (ADR-0012): a description cleaned under 1 may hold a `style` that 2 drops. Nothing re-cleans those rows, as with the rows from before migration 0019. The update model of thrust-core now starts its rows at policy 1 and expects 2 after a description is named, which it could not tell apart from "kept" while both were 1. Tests, in thrust-html/tests/policy.rs: a generated test that writes each character of a dangerous token plain, with a backslash, as a short hex escape closed by any whitespace or by nothing, or as six digits, in either case (the encoder is written from the spec, apart from the decoder); the pinned family of the gap; what the greedy reading makes something else, kept; a token inside a comment, kept; an escaped slash that opens no comment; and escaped harmless values, kept, as the control. Before the change the three tests that cover the gap failed and the controls passed. Refs: #48 Co-authored-by: Claude Sonnet 5.5 <[email protected]>
This was referenced Nov 18, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 3 of 3 for #48, the work items' half. It follows #300 (the sanitiser moved into
crates/core/html) and #302 (the hardened default), both merged. A work item now keeps one form of its description, and what is derived from it. #48 itself stays open: the pages half waits for M3, and no page exists in this repository yet.What changes
thrust_html::describeis the one place a description is cleaned and its text taken, and the use-cases call it:create_issue, andupdate_issuebefore anything reads the asks, so the history compares and quotes the cleaned form. The compat plane and/api/v1hand it the text as sent and keep only the size check, in the pin's words and with their other fields' problems. A newIssueError::InvalidDescriptionis the use-case's own answer to an oversize one that came anyway.description_stripped(the text: Django'sstrip_tagsof the cleaned HTML) anddescription_schema(the version of the policy it was cleaned under,thrust_html::SCHEMA_VERSION; ADR-0012's "record a schema version") are carried byWorkItemAttrsandWorkItemUpdate. An update that names no description leaves the row's own.description_jsonordescription_binarycolumn: a second stored form would be a second source of truth, one of them not cleaned (FR-14), andthrust-editor-docderives them from the HTML at P1.strip_tagsport is tested for the first time. Mutation testing had found 77 of the crate's mutants surviving, all in it. It now has aparity_test against 507 answers of Django's function, recorded bytools/strip-tags/record.py(the default sanitiser's output for the XSS corpus and the editor corpus, and 75 hand-written cases).0019_…, "the next file"; they sort before the real 0019 now, so they are numbered9000_…and up, after every real file however many there are.For you to decide or know
'', and NULL only ever means "written before 0019". That is my rule. The pin's own is not in this repository (itsIssue.saveis not here), so I did not copy it. No route serves the column, so nothing can tell today.strip_tagsdiffers from Python's parser on three hand-written inputs: an attribute quote never closed, the text of a<script>, and a malformed character reference followed by more text (Python then stops looking for tags). No sanitiser output can be any of the three (it removes a<script>with its text, quotes every attribute and escapes every stray&), so no description reachesstrip_tagsin those forms. The test names them and asserts that exactly those three differ, so a fix or a regression of any is seen. The oracle is the standard library's parser on Python 3.12.13, which Plane's image runs; its behaviour may change between patch releases, and I do not know which patch Plane runs.tools/strip-tags/record.pyregenerates it; the steps are in its docstring.validate_binary_dataand decoded withyrs, and a truncated or non-Yjs binary getting a 400).validate_binary_datais inthrust-htmland tested to the byte; nothing calls it yet.Checked
thrust-coretests<script>in it and expects the text and the policy to follow a description a request names, and to stay as they were when it names nonepg_adaptertests against a real Postgres (Docker)a_work_item_has_the_one_stored_form_of_a_description_and_no_other(acceptance box 1), the columns, the model comparison with the reference model, the round trip of the text and the policy, and the tests that apply every migration file again over a schema that has themdescription_jsoncolumn added to the migrationnative-memoryandnative-pgoracle-v1.sh native-memory controlsVERDICT: PASS, gate, corpus, self-test and controls all 0strip_tagsagainst Djangostrip_tags(nothing stripped, no;on entities, a counter and no parser), each seencrates/core/html/src/lib.rs(cargo-mutants 27.1.0).cargo/mutants.tomlwith the proof; one redundantn > 0is removed instead of excluded--in-diff)cargo nextest run --workspace, on the tree rebased ontomainoracle_tests that the profile excludes)cargo clippy -D warnings --locked: workspace,thrust-workerandthrust-edgeon wasm32,thrust-api-v1withopenapi;cargo fmt --check;cargo deny; doctestscheck-deps,check-layout(+ self-test),check-cargo-lock(+ self-test),check-release-plz --first-release required,check-plane-500,check-contract-counts(+ self-test),check-migration-lint,check-openapimain(#303)Not shown
worker-cfcells of the contract suite and the browser journeys are CI's. The book check was not run here (mdbook-mermaidis not installed); the docs change is table text, no page and no link.oracle_v1_write_with_sanitiser_matches_python_plus_js(pinned toplane_builder(), because nh3 is its oracle) was not re-run: it needs the generated spike-0006 output.description_strippedyet: no search, no preview, and no body that is served carries it. So no behaviour a user can see depends on it today.Refs #48
🤖 Generated with Claude Code