Skip to content

refactor(rate-limits): delete the slice's create limit, its binding and its settings - #166

Merged
aRustyDev merged 4 commits into
mainfrom
refactor/delete-create-rate-limit
Nov 14, 2026
Merged

aRustyDev merged 4 commits into
mainfrom
refactor/delete-create-rate-limit

Conversation

@aRustyDev

@aRustyDev aRustyDev commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Step 5c-3c of moving off /api/_slice, the last piece of step 5c-3 (the owner's order was the core #161, the adapters #164, then this). The per-user create limit was applied by the slice's create_work_item, which #161 deleted. Nothing reads it now, and /api/v1 has its own per-key allowance.

What goes

  • CoreConfig.create_rate_limit and THRUST_CREATE_RATE_LIMIT, in the native server and the Worker.
  • CoreConfig.rate_window_secs and THRUST_RATE_WINDOW_SECS, and the Worker's startup check of that window. Only the create limit's use-case read them (no other reader in the workspace); /api/v1's window is the period in THRUST_V1_RATE_LIMIT and sign-in's is a constant.
  • The RL_CREATE binding and its [[ratelimits]] block in wrangler.toml, wrangler.stage2.toml and wrangler.pg.stage.toml, and the Worker's env.rate_limiter("RL_CREATE").
  • In thrust-adapters-cloudflare, KeyClass::Create and CfRateLimiter.create. A key that starts with create: is a key of no class now: an error, never a free pass. The tests list it as three refused keys.
  • Target::create_limit (no caller) and THRUST_EXPECT_CREATE_LIMIT; THRUST_WORKER_CREATE_LIMIT and the create handling in scripts/worker-dev.sh; RATE_LIMIT in scripts/contract.sh; the create refusal in scripts/stage2-contract.sh.

The deploy pipeline (#165) declared the binding too

#165 landed while this PR was open. It merged cleanly as text, but its template wrangler.deploy.toml, its renderer scripts/render-wrangler.sh (the __RL_CREATE_ID__ marker, the variable, the rule that the ids differ), deploy.yml and the deploy-worker action (an rl-create-id input) all declare or pass the binding this PR deletes, and test-deploy-template.sh holds the template to the same bindings as wrangler.toml. Left alone it would fail CI. They are changed in the last commit:

  • The RL_CREATE block and marker go from the template; the renderer's id list, fixtures and distinctness rule are about two ids; the action loses rl-create-id and deploy.yml the variable.
  • The renderer's self-test loses the four cases about THRUST_RL_CREATE_ID (unset, empty, and the two equalities) and gains two, as the control for the removal: a template that still has the retired marker is refused, with or without THRUST_RL_CREATE_ID in the environment. 45 ok on main, 43 ok here.
  • Control: main's template against this wrangler.toml fails deploy_parity.py (exit 1, naming RL_CREATE); the fixed template agrees.
  • The THRUST_RL_CREATE_ID variable of the GitHub environments is unused now. It is harmless, and deleting it is yours.

One option is retargeted, not deleted

scripts/spike-0002-pg.sh deploy --create-limit N is now --v1-limit N and rewrites the RL_V1 limit (marker __V1_LIMIT__ on that line, default 60). The engine pass goes through /api/v1, so RL_V1 is the binding it needs raised on a deployed Worker; --create-limit raised one that the pass no longer touched. A dry run of its sed on the template changes only that line. Nothing is deployed from here, so the option itself has not been run against Cloudflare.

Operations: deploy the Worker and its config together

The code no longer asks for RL_CREATE and the config no longer declares it, so the two are a pair. The previous Worker with this config would fail to start (it asks for a binding that is not there; see the control below). A deploy of this commit is consistent.

Docs

G-26 records the deploy part too. docs/src/architecture/infra.md (the diagram, the bindings table, the rate-limit notes, the stage-2 description, the namespace ids and the environment table), contract-suite.md, defect-matrix.md and G-26 in docs/src/testing/status.md, whose "Not done" clause is now only the slice routes with no Plane counterpart and then SLICE_PREFIX. ADR 0033 and the plans keep the old names: they are history.

Verification

On the merged tree (main gained #163, so EXPECT_MAIN is 73, and then #165; this PR adds and removes no contract test):

  • native-memory: main 73 of 73, sweeper 3 of 3, csrfoff 6 of 6. Before the merge, also engine 4 of 4 and worker-memory main.
  • worker-cf main 73 of 73, started from a throwaway config with RL_SIGNIN and RL_V1 only (its log names no RL_CREATE). Before the merge, also worker-cf bindings 5 of 5.
  • cargo nextest run 3860 of 3860 (6 fewer than before: the Cloudflare class tests have 2 classes where they had 3, and the 3 refused keys are added); the doctests; cargo clippy --workspace --all-targets -- -D warnings and cargo fmt --all --check clean.
  • The ci-scripts job's tests and the deploy guards (the renderer's --self-test, the workflow lint of deploy.yml and the action) under dash in an Ubuntu 24.04 container, with python3, jq and nc, on this tree and on main as a baseline: all pass on both. scripts/check-placement.sh passes.
  • sh -n of the four changed scripts under dash (an Ubuntu container, where /bin/sh is dash, as in CI), with a deliberately broken script that must fail the check, and does.

Controls (temporary, reverted):

  • create mapped to a class again in KeyClass::of: the 3 refused-key cases fail, 127 others pass.
  • A Worker that asks for a binding its config lacks never comes up (wrangler: "Binding ... is undefined", exit 4), so the worker-cf cell catches a binding mismatch and its pass without RL_CREATE is evidence. (That message is not the exit=4 flake's.)
  • stage2-contract.sh refuses THRUST_EXPECT_V1_LIMIT=1000000 (exit 2) and passes the guard at the default.

One test, parity_slugify_of_drawn_names_is_the_pins in thrust-api-v1, was reported "leaky" once in the full parallel run and passed clean in three solo runs; it is in a crate this PR does not touch.

Not run locally: native-pg (CI runs it) and any deploy.

Part of #58; this PR does not close it.

🤖 Generated with Claude Code

aRustyDev and others added 4 commits November 14, 2026 02:56
…nd its settings

Step 5c-3c of moving off /api/_slice, the last piece of step 5c-3 (the owner's order was the core, then the adapters, then this, one PR each). The per-user create limit was applied by the slice's `create_work_item`, which #161 deleted. Nothing reads it now, and /api/v1 has its own per-key allowance.

Deleted:
- `CoreConfig.create_rate_limit` and `THRUST_CREATE_RATE_LIMIT`, in the native server and the Worker.
- `CoreConfig.rate_window_secs` and `THRUST_RATE_WINDOW_SECS`, and the Worker's startup check of that window. Only the create limit's use-case read them (checked: no other reader in the workspace); /api/v1's window is the period in `THRUST_V1_RATE_LIMIT` and sign-in's is a constant of the core's config.
- The `RL_CREATE` binding and its `[[ratelimits]]` block in wrangler.toml, wrangler.stage2.toml and wrangler.pg.stage.toml, and the Worker's `env.rate_limiter("RL_CREATE")`.
- In thrust-adapters-cloudflare, `KeyClass::Create` and `CfRateLimiter.create`. A key that starts with `create:` is a key of no class now: an error, never a free pass. The tests list it, as three refused keys.
- `Target::create_limit` (no caller) and `THRUST_EXPECT_CREATE_LIMIT`; `THRUST_WORKER_CREATE_LIMIT` and the create handling in scripts/worker-dev.sh; `RATE_LIMIT` in scripts/contract.sh; the create refusal in scripts/stage2-contract.sh.

One option is retargeted, not deleted: `scripts/spike-0002-pg.sh deploy --create-limit N` is `--v1-limit N` and rewrites the `RL_V1` limit (marker `__V1_LIMIT__` on that line, default 60). The engine pass goes through /api/v1, so RL_V1 is the binding it needs raised on a deployed Worker; `--create-limit` raised one that the pass no longer touched. The infra, contract-suite and defect-matrix pages and G-26 say so.

Operations: the Worker built from this commit and this commit's config are a pair. The code no longer asks for `RL_CREATE` and the config no longer declares it, so the previous Worker with this config would fail to start (it asks for a binding that is not there). Deploy them together.

The two assertions that changed in thrust-adapters-cloudflare/tests/rate_limiter.rs are the class list (two classes, not three) and the setting name the period tests pass to `check_binding_period`, which was `THRUST_RATE_WINDOW_SECS` and is the name the Worker still passes (`the period of THRUST_V1_RATE_LIMIT`).

Checked: native-memory main 70 of 70, sweeper 3 of 3, csrfoff 6 of 6, engine 4 of 4; worker-memory main 70 of 70; worker-cf main 70 of 70 and bindings 5 of 5, from a config with RL_SIGNIN and RL_V1 only; `cargo nextest run` 3860 of 3860 (6 fewer than before: the class tests have 2 classes where they had 3, and the 3 refused keys are added); doctests; clippy and rustfmt; `sh -n` of the four changed scripts under dash (an Ubuntu container). One test, thrust-api-v1's `parity_slugify_of_drawn_names_is_the_pins`, was reported "leaky" once in the full parallel run and passed clean in three solo runs; it is in a crate this change does not touch.

Controls, temporary and reverted:
- `create` mapped to a class again in `KeyClass::of`: the 3 refused-key cases fail, 127 others pass.
- a Worker that asks for a binding its config lacks never comes up (wrangler: "Binding ... is undefined", exit 4), so the worker-cf cell catches a binding mismatch and its pass without RL_CREATE is evidence.
- stage2-contract.sh refuses `THRUST_EXPECT_V1_LIMIT=1000000` (exit 2) and passes the guard at the default.
- the spike script's `sed` on the staging template changes only the RL_V1 line (a dry run; nothing is deployed from here).
- the dash check of the scripts fails a deliberately broken script.

Not run: native-pg (CI runs it) and any deploy.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Main gained #163 (the stock app's OIDC routes, dark until a provider is configured): EXPECT_MAIN 70 became 73, and it changed scripts/contract.sh, docs/src/architecture/infra.md and docs/src/testing/status.md, which this branch edits too. The merge was clean, with no conflicts: #163's block in contract.sh (the e2e pass starts with no OIDC provider) is in a different place from the lines this branch removes, and its infra.md and status.md additions are separate paragraphs and a separate row. This branch adds and removes no contract test, so main's 73 is the count. Main reintroduced none of the names this branch deletes (searched the tree).

Checked on the merged tree: native-memory main 73 of 73, sweeper 3 of 3, csrfoff 6 of 6; worker-cf main 73 of 73, started from a config with RL_SIGNIN and RL_V1 only; clippy clean on the workspace; `sh -n` of the four changed scripts under dash, with a broken-script control that fails.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…r deletion

Main gained #165, the deploy pipeline, while this branch's PR was open. The merge is clean as text, with no conflicts, and it adds no contract test (EXPECT_MAIN stays 73). It is not clean in meaning: the pipeline's template, renderer, workflow and action declare the `RL_CREATE` binding this branch deletes, and `test-deploy-template.sh` holds the template to the same bindings as wrangler.toml, so the template has to follow. That is the next commit.

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

The deploy pipeline (#165) declared the binding that this PR's earlier commit deletes from the Worker and the other configs: the template crates/thrust-worker/wrangler.deploy.toml had an `RL_CREATE` block with a `__RL_CREATE_ID__` marker, scripts/render-wrangler.sh filled it from `THRUST_RL_CREATE_ID`, and deploy.yml and the deploy-worker action passed that variable through. Left alone it fails CI: `test-deploy-template.sh` requires the template and wrangler.toml to bind the same things (`deploy_parity.py`), and the template would still have a binding wrangler.toml no longer has. My first push did not have #165 in it; the failure was found when main moved, by searching its tree for the names this PR deletes.

Changed:
- wrangler.deploy.toml: the `RL_CREATE` block and its marker go; the comment says the environment has two namespace ids, not three, and that there was a third.
- render-wrangler.sh: the marker, the variable, the id list in the header and the self-test fixtures go, and the rule that the ids differ is about two ids now (its message says "the two"; the self-test's fragment "must differ from one another" still matches). The cases for `THRUST_RL_CREATE_ID` unset and empty and for the two equalities that involved it go with it (four cases). Two cases are added, as the control for the removal: a template that still has the retired `__RL_CREATE_ID__` marker is refused ("which this script does not know"), with or without `THRUST_RL_CREATE_ID` still in the environment, so a stale template cannot be rendered into a config that declares a binding the Worker does not use.
- The deploy-worker action loses its `rl-create-id` input and its `THRUST_RL_CREATE_ID` env; deploy.yml loses the variable from its list of an environment's variables, from the dry run's environment and from both `rl-create-id:` inputs; test-deploy-worker.sh drops it from its good environment.
- G-26 records this.

Checked, under dash in an Ubuntu 24.04 container (CI's shell) on this tree and, as a baseline, on origin/main, with python3, jq and nc installed: every test of the `ci-scripts` job and both deploy guards (the renderer's `--self-test` and the workflow lint of deploy.yml and the action) pass on both. The renderer's self-test is 43 ok on this tree and 45 on main: four cases removed, two added. `scripts/check-placement.sh` passes. clippy and rustfmt are clean on the merged tree.

Control: main's template against this wrangler.toml fails the parity check (exit 1: the template has `RL_CREATE`, wrangler.toml does not); the fixed template agrees.

The `THRUST_RL_CREATE_ID` variable of the GitHub environments is unused now. It is harmless and deleting it is the owner's. A deploy of this commit renders a config with two rate-limit bindings and a Worker that asks for those two.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev merged commit f7b9287 into main Nov 14, 2026
70 of 73 checks passed
@aRustyDev
aRustyDev deleted the refactor/delete-create-rate-limit branch November 14, 2026 18:57
aRustyDev added a commit that referenced this pull request Nov 15, 2026
…t the slugify test's defect (#182)

#166's message reports `parity_slugify_of_drawn_names_is_the_pins` as "leaky" once in a full run. The test is pure: an `include_str!` fixture parsed per test, no thread, no process, no static, no shared path, so nothing in it can leak. nextest's `LEAK` (0.9.140, `leak-timeout` 200 ms by default since 0.9.108) is a pass whose stdout or stderr pipe is still open that long after the process exited, and a leak passes unless the profile asks for `result = "fail"`.

Reproduced on 2026-11-15 on the Mac that saw it: 1 of 30 full `--profile ci --workspace` runs (20 plain, 10 with 18 busy loops on 18 cores) flagged one test, and it was `thrust-core::change_password ...::sign_ins_first_1_true` at 0.211 s, not a slugify test; 20 runs of `-p thrust-api-v1` alone under the same load flagged none (128,560 test runs, 1 leak). That test has one thread and spawns nothing, so another process held its pipe. CI's `hermetic` logs (Linux) hold no LEAK in 49 runs, which does not tell the platforms apart (about 1.4 expected at the Mac's rate; none has a probability near 1 in 4).

The mechanism reproduces without any test of ours (`tools/fd-race`, std only): 16 threads spawn children with piped stdout, one in eight living 400 ms; on macOS 5 of 62,976 short children (3 runs) had their stdout held 100 ms or more after exiting, 406 to 408 ms at worst, the holder's lifetime; on Linux 0 of 41,984 (2 runs). On macOS std makes a pipe with `pipe()` then `fcntl(FD_CLOEXEC)`, and a child another thread spawns between the two keeps the write end across `exec`; Linux has `pipe2(O_CLOEXEC)`. What is not shown: that nextest's own spawn is what does it in a run (no `lsof` while a leak happened).

As the owner chose for the case where the slugify leak is not found: no change to a test and none to `.config/nextest.toml` (a leak is a pass; `result = "fail"` would turn about 1 test run in 128,000 of an OS race into a red build; a longer `leak-timeout` is rule 3's timeout raised to get green). D-19 records it, so a LEAK on a Mac is read as noise about the run and one in CI as a finding.

Refs: #58

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
aRustyDev added a commit that referenced this pull request Nov 15, 2026
…ent, so there is nothing to delete (#180)

G-26 ended with "the `THRUST_RL_CREATE_ID` variable of the GitHub environments is unused now, and deleting it is the owner's". It is not in any: read through the API (`gh api repos/aRustyDev/thrust/environments/<env>/variables` and `/secrets`) for `production`, `staging`, `production-do-lifecycle` and `staging-do-lifecycle`, and for the repository (`/actions/variables`, `/actions/secrets`), every list is empty, with admin permission on the repository. The infra repo has no `THRUST_RL` and declares no `github_actions_environment_variable`. In this repository only G-26 and `render-wrangler.sh`'s self-test (which exports it to show that it is ignored) name it; #166 removed the last reader.

So the entry no longer leaves a chore to the owner, and says there is nothing to set when the environments are filled in. No GitHub setting was changed.

Refs: #58

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
This was referenced Nov 15, 2026
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