Skip to content

chore(worker): set placement.region = aws:us-east-1; add the 5-round-trip budget counter to the contract suite #39

Open

Description

@aRustyDev

Context

Neither crates/thrust-worker/wrangler.toml nor wrangler.stage2.toml has a [placement] section. The database is in us-east-1: ADR-0094:39, and the thrust-pg instances run on us-east-1a and us-east-1b nodes (research/0010:316). The Stage 2 numbers were taken from one laptop in the US east: list p95 86 ms, create p95 296 ms at c=1 and 559 ms at c=8, and 595 to 615 ms for the first database request on a fresh isolate (research/0004:383-387). Every statement goes through the Pg wrapper as one round trip (crates/thrust-adapters-postgres/src/lib.rs:106-127); today a list costs two (membership at lines 187-191, the list at lines 229-230). The contract suite is a black-box HTTP suite (docs/src/architecture/app.md:68), and bench takes iterations and concurrency (crates/thrust-contract-tests/src/bin/bench.rs:2).

Problem

The p95 < 500 ms target (SPEC.md:78) is set by three things the plan does not budget: placement, query count and the cold path.

  • Placement: Cloudflare puts each sequential query at 20 to 30 ms from a distant region and 1 to 3 ms when the Worker is placed nearby (hyperdrive/concepts/how-hyperdrive-works), and placement hints accept placement.region = "aws:us-east-1" (workers/configuration/placement).
  • Query count: Plane's project page fires 13 reads and its workspace wrapper fires 9 (research/0003:47-48). Without a budget, the compat layer will reproduce Django's N+1 query shapes.
  • Measurement: where p95 is measured is still open (Q-G5.2, QUESTIONS.md:299; SPEC.md:83).

Proposal

Covers FR-08 items (1) to (3). The plan side is the ADR-0040 (S3, S5) and ADR-0094 round-29 notes and the SPEC §6.4 text.

  • Add to both wrangler files:
    [placement]
    region = "aws:us-east-1"
  • Budget list endpoints at no more than 5 database round trips per request. The Postgres adapter counts every statement issued through Pg during one request (the review's "counting Connector") and reports the count only when THRUST_TEST_ROUTES is on, for example in an x-thrust-db-round-trips response header. A contract test asserts the count on the Postgres targets.
  • Re-run bench at c=1 and c=8 against the deployed Worker with placement set, from the same vantage point as research/0004 §10.3. The Stage 2 resources were deleted (wrangler.stage2.toml:3), so run this together with the spike 0002 runs in spike(db): run spike 0002 with a worker-pg cell and an instance-level worker-do SQLite cell #37, which recreate them and also add the distant-region bench.
  • Context for Q-G5.2, which the plan edits answer: "p95 of a synthetic probe from the origin's region on the warm path, 5-minute cadence, cold starts reported separately; availability over a rolling 30 days on the same probe". FR-08 (4), the allocation order, is measured in spike(db): run spike 0002 with a worker-pg cell and an instance-level worker-do SQLite cell #37.

Acceptance criteria

  • grep -n 'region = "aws:us-east-1"' crates/thrust-worker/wrangler*.toml matches both files, and wrangler deploy --dry-run accepts the config.
  • The Workers API reports the deployed Worker's placement (workers/configuration/placement, "Check placement status").
  • Contract test list_endpoints_stay_within_five_db_round_trips passes on native-pg and worker-cf, and it fails against a mutant that issues one extra statement per returned row. Add the mutant to scripts/mutants.sh, where it must be reported KILLED.
  • On the memory targets, which count nothing, the test is excluded explicitly and the expected pass count is adjusted, so it cannot pass vacuously.
  • The c=1 and c=8 results with placement on are recorded next to the research/0004 §10.3 table.

References

  • Review: .agents/plans/contrail/reviews/2026-10-19-fable-architecture-review.md (FR-08)
  • crates/thrust-worker/wrangler.toml; crates/thrust-worker/wrangler.stage2.toml; crates/thrust-adapters-postgres/src/lib.rs:106-127,187-191,229-230; crates/thrust-contract-tests/src/bin/bench.rs
  • SPEC §6.4 (SPEC.md:78,83); Q-G5.2 (QUESTIONS.md:299); ADR-0040 S3 and S5 (adrs/data/base/0040-system-of-record-database.md:82,84); ADR-0043; ADR-0094:39
  • research/0004 §10.3 (research/0004-rust-on-workers-binding-matrix.md:383-387); research/0003-compat-plane-inventory.md:47-48; spike 0002 step 7
  • Cloudflare docs: workers/configuration/placement; hyperdrive/concepts/how-hyperdrive-works

Finding: FR-08

Activity

  1. added
    area:infra
    review:fable-2026-10-19
    on Oct 20, 2026
  2. aRustyDev commented on Nov 11, 2026

    @aRustyDev
    OwnerAuthor

    Where #39 stands against its acceptance criteria

    State as of main after #121 (the live-run record) merged, 7d6d27a. Four of five are met as written and one is met in intent.

    # Criterion State Evidence
    1 grep matches both wrangler files; wrangler deploy --dry-run accepts the config Met #105. [placement] region = "aws:us-east-1" is in wrangler.toml and wrangler.stage2.toml only; scripts/check-placement.sh runs in CI and fails if either file lacks the table or holds anything else in it (region excludes mode, host and hostname), or if the spike's wrangler.pg.stage.toml gets a literal one.
    2 The Workers API reports the deployed Worker's placement Met (live run, 2026-11-11, #121) The API returned placement: {mode: "targeted", region: "aws:us-east-1"} for the deployed spike Worker. The cf-placement header agrees: a request that entered at EWR answered remote-IAD, and 18 of 18 probes from the laptop (edge IAD) answered local-IAD. The stack was torn down afterwards and the teardown checked by listing.
    3 list_endpoints_stay_within_five_db_round_trips passes on native-pg and worker-cf and fails against the per-row mutant, which scripts/mutants.sh reports KILLED Met #108, and #112 for the guest path. 3 statements for the slice's work items, S17 and S47; 4 for /api/v1 projects, states, labels and work items; 3 and 4 for a limited guest; each list seeded with six or more rows. mutant_extra_stmt_per_row and mutant_count_nothing are both killed, each with the message that names it. It also passed on the deployed Worker in the live run (stage2-contract.sh budget, the same nine counts).
    4 On the memory targets the test is excluded explicitly and the expected pass count adjusted Met in intent, not as written The test is not excluded: it runs on the memory targets and asserts the header is absent, so it cannot pass there without looking, and EXPECT_MAIN is 57 on all four targets (no --skip, no per-adapter count). Recorded in #108's description. If the literal reading is wanted, the fallback is a per-adapter --skip in contract.sh.
    5 The c=1 and c=8 results with placement on are recorded next to the research/0004 §10.3 table Met (#121) research/0004 §10.3a, directly after §10.3: three runs each of bench 200 1 and bench 200 8 with placement on, from the same vantage (a laptop in Virginia). Create p95 138-174 ms at c=1 and 307-432 ms at c=8; list p95 85-106 ms at c=1. Caveats are in the section: one vantage, three runs, a different build from §10.3, no placement-off arm, so the lower create latency is not attributed to placement (research/0011 §6.8 found no difference between on and off from this vantage).

    Found on the way

    • A limited guest was over the budget. Plane's issues list (S47) cost 5 statements with rows and 6 on an empty page, for a guest who sees only what they made, because the project's guest_view_all_features flag was read apart from the page. The page's SQL reads it now (guest: 3 with rows, 4 empty, the same as an admin), and the budget test asks as a guest, with items and without. Fixed in fix(api): read a limited guest's project flag in the page statement #112.
    • /api/v1 work items with ?expand=assignees send two statements per distinct assignee (unbounded), and ?expand=state,labels should be 6 by reading the code. Neither is measured or covered by the test. Follow-up issue: perf(api-v1): ?expand=assignees sends two statements per distinct assignee #123; recorded as a known gap in G-24.
    • scripts/stage2-contract.sh main expected 31 tests; the suite has 51 (counted with --list). Fixed in docs(testing): record the live run of #39 (placement, budget counts, bench) #121. Run live, 50 of the 51 passed and the 51st, create_is_rate_limited_per_user, did not finish: it sends up to 2 x limit + 1 creates, and the Worker's limit was 1,000,000 (raised for the bench). It was stopped after about 90 minutes. The script now refuses a limit above 1000 before it sends anything. So main has not been run to the end against a deployed Worker in this run.

    What was not done

    A placement-off arm in the same run, a second vantage (research note 0011 §6.9 has us-west-2, from the spike), and main to the end (above). The stack is gone, so a repeat needs a new run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:infraprio:p0review:fable-2026-10-19

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions