Repository navigation
feat(api): count the database statements of a request and hold lists to five - #108
Merged
Merged
Conversation
RoundTrips is an atomic count that Pg ticks before each statement it sends. Pg now has private fields and is made only by ClientHandle::pg(), and CountingConnector wraps another Connector so that every checkout hands out a counted handle. The counter sits on the connector and not on conn() because ten call sites take a connection straight from the connector (begin, the second connection of allocate, and the multi-statement writes), which a wrapper around conn() would have missed. COMMIT and ROLLBACK go through Pg now. ClientHandle::client() has two call sites left: pg() and Counted::client. Counted forwards discard, whose default would put a connection that is still inside an abandoned transaction back in the pool. Nothing is wired into a server here: without a CountingConnector no handle keeps a counter and behaviour is unchanged. The unit is a statement, which is one wire round trip because nothing puts two statements in flight on one client. It excludes connection handshakes and background work that runs after the answer. Tests (pg_adapter, needs Docker): a generated test checks, step by step, the statements sent by random sequences of begin, allocate, insert, commit, rollback, abandon, page and list against a small model of what the adapter sends, and a control requires the generator to reach every step class. Three properties a sequence cannot show are pinned: discard reaches the inner handle, a refused statement still counts, and two connectors over one pool count separately. Controls, each of which makes the tests fail: mutant_count_nothing fails four of five; COMMIT put back on the raw client fails only the generated test, shrunk to Insert then Commit; Counted::discard not forwarded fails the pinned test (abandoned rows became visible) and the generated one. The full pg_adapter suite passes, 60 of 60. scripts/mutants.sh gets the count-nothing run and kill_check_msg, because without Docker every pg_adapter test panics in its setup and kill_check reads that as a kill. Refs: #39 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…d hold lists to five With test routes on, a Postgres target puts x-thrust-db-round-trips on every response: the statements the request had sent through the adapter when the router answered. The Worker already builds its connector per request, so build_app wraps it in a CountingConnector and returns the counter from the arm that wired it, and a memory set returns none. The native server shares one PgDatabase across requests, so a layer inside Extension(app) swaps in a clone of the App whose database counts over a connector of the request own, on the shared pool. Both are installed only when test routes are on. list_endpoints_stay_within_five_db_round_trips (tests/budget) holds seven lists to 3 to 5 statements on a Postgres target: the slice work items, Plane projects (S17) and issues (S47), and /api/v1 projects, states, labels and work items, each seeded with six or more rows so that a statement per row would show. It measures the second request of each list, after the API key first-use stamp has landed in the background, and asserts at least 3 so a counter that counts nothing cannot pass. On a memory target it asserts the header is absent. That departs from the issue, which says to exclude the test there and adjust the count: asserting absence keeps the test from passing without looking and needs no --skip substring or per-target count. Measured on native-pg and worker-cf, identical on both: 3 for the slice work items, compat projects and compat issues; 4 for the four /api/v1 lists. EXPECT_MAIN goes from 56 to 57 and the main pass gives passed=57 expected=57 on native-memory, native-pg, worker-memory and worker-cf. The budget pass runs the test alone, for scripts/mutants.sh, and is not in contract-all. /api/v1 work items with expand=assignees send two statements per distinct assignee and are not covered; that is a known gap, to be recorded in status.md. The test has only been shown to pass so far. Its failure controls, the mutants, are the next commit. Refs: #39 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…on a counter that counts nothing Two mutants of the round-trip counter, built into thrust-server through pass-through features and run against native-pg with the budget pass, which is the budget test alone. mutant_extra_stmt_per_row sends one more statement for every row a work item page returns, the shape of Django N+1: the compat issues list goes from 3 to 9 statements and the /api/v1 work items list from 4 to 10, and the test fails with over budget. mutant_count_nothing makes every count 0 and the test fails with below floor. scripts/mutants.sh runs both in a loop that uses kill_check_msg, which the counter commit added: it also requires the log to contain the failure the mutant is for. kill_check counts any exit 101 with a FAILED line as a kill, and a run that never reached the test fails the same way: with Docker missing every pg_adapter test panics in its setup, and a wiring bug that leaves the header off fails the budget test. Controls for the guard itself: with the header blanked in the native server both mutants fail the test but neither is counted as killed and the script exits 1; and the function was run on a failing log with the message removed, a passing log, and a log with the message but exit 0, and refused all three. Refs: #39 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ses found over it The status page said the budget test did not exist until #39 landed, listed the counting connector as not covered, called S47 at most five statements by construction, and counted the budget among the unowned performance classes. It exists now, so G-4, G-13, G-21, G-22 and the defect matrix row X19 say so, and a new G-24 records what is held, what controls it, and what is not. Two cases are over the budget and are not fixed here. A limited guest on the compat issues list (S47) costs 6 statements, with rows and on an empty page, measured by hand on native-pg: the claim of at most five left out the session lookup, and the guest path adds a workspace access and a project lookup. The budget test asks as an admin, so it does not see this. And /api/v1 work items with expand=assignees send two statements per distinct assignee. The test header, the contract suite page and the app flow page say both. Not measured, and listed as such in G-24: the other lists as a limited guest, a stale session (one more statement, once an hour), and /api/v1 with expand=state,labels. The planning documents (SPEC section 6.4, ADR-0040 S3) already describe the budget as enforced by a counting connector, which is true now, so they are not touched. Refs: #39 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev
added a commit
that referenced
this pull request
Nov 10, 2026
One conflict, docs/src/testing/status.md: main's #108 took G-24 for the round-trip budget, so the v1 oracle's gate row is G-25 (G-23 points to it), and its list of what is not done no longer names the #39 budget. The Postgres adapter, where #108 rewrote the queries, merged without a conflict, and the branch's member sort_order column is in the rewritten ones. Refs: #58 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This was referenced Nov 10, 2026
feat(api-v1): the scoped oracle gate and corpus comparison, passing on the pin and four targets
#107
Merged
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.
Refs #39
The second half of #39 (FR-08 item 2): the placement half was #105. List endpoints are held to at most 5 database statements per request, by a counter in the Postgres adapter and a contract test that reads it.
What it does
RoundTripsis an atomic count thatPgticks before each statement it sends.Pghas private fields and is made only byClientHandle::pg(), andCountingConnectorwraps anotherConnectorso every checkout hands out a counted handle. It sits on the connector, not onconn(), because ten call sites take a connection straight from the connector (begin, the second connection ofallocate, and the multi-statement writes). COMMIT and ROLLBACK go throughPgnow, so they count.ClientHandle::client()has two call sites left,pg()andCounted::client.x-thrust-db-round-trips: non every response. The Worker already builds its connector per request, sobuild_appwraps it and returns the counter from the arm that wired it (memoryreturns none). The native server shares onePgDatabase, so a layer insideExtension(app)swaps in a clone of theAppwhose database counts over a connector of the request's own, on the shared pool.list_endpoints_stay_within_five_db_round_tripsholds seven lists to 3 to 5 statements: the slice's work items, Plane's projects (S17) and issues (S47), and/api/v1projects, states, labels and work items. Each is seeded with six or more rows, so a statement per row would show (the issue's "two rows" would not: 3 + 2 is still 5). It measures the second request of each list, after the API key's background first-use stamp has landed. The floor of 3 is what stops a counter that counts nothing from passing.EXPECT_MAINgoes from 56 to 57, and an opt-inbudgetpass runs the test alone, formutants.sh. It is not incontract-all.A count is the statements sent through
Pgbefore the response head. It leaves out connection handshakes and background work that runs after the answer.Measured
On
native-pgandworker-cf, identical on both: 3 for the slice's work items, S17 and S47; 4 for the four/api/v1lists.It can fail
mutant_extra_stmt_per_row(a statement per returned row): S47 goes to 9 and/api/v1work items to 10; the test fails with "over budget".mutant_count_nothing: every count is 0; the test fails with "below floor".scripts/mutants.shonnative-pgthrough a newkill_check_msg, which also requires the log to name the failure. Plainkill_checkscores any exit 101 as a kill, and a run that never reached the test fails the same way (no Docker: everypg_adaptertest panics in setup). Control for the guard: with the header blanked in the server, both mutants fail the test and neither counts as killed.pg_adapter(random sequences of begin, allocate, insert, commit, rollback, abandon, page and list against a model of what the adapter sends, with a control that the generator reaches every step class), plus three pinned properties. Controls that make it fail: the count-nothing mutant (4 of 5 tests), COMMIT put back on the raw client (the generated test only, shrunk to insert then commit), andCounted::discardnot forwarded (abandoned rows became visible).A departure from the issue
The issue says to exclude the test on memory targets and adjust the pass count. The test instead asserts the header is absent there, which keeps it from passing without looking, and needs no
--skipsubstring or per-target count.Over the budget, and not changed here
native-pg). The test asks as an admin, so it does not see this, and a guest request added to it would fail until the guest path is cheaper.status.mdsaid S47 was at most five "by construction"; that left out the session lookup./api/v1work items with?expand=assigneessend two statements per distinct assignee.Both are in
status.mdG-24, the test header, and the contract-suite page. Not measured: the other lists as a limited guest, a stale session (one more statement, once an hour),/api/v1with?expand=state,labels.Verified, and not
Run on the tree rebased over #105 and #106:
cargo fmt --check, clippy (native workspace, and the Worker on wasm32), the main pass on all four targets (passed=57 expected=57), the fullpg_adaptersuite (60 of 60), and the mutants above.scripts/mutants.shend to end locally, only its new parts and a syntax check, so themutantsjob here is the first full run. If it exits 4, that is the known flake (fix(ci): contract cells and the mutants job fail intermittently with exit 4 (the server under test never comes up) #93).placement.region = aws:us-east-1; add the 5-round-trip budget counter to the contract suite #39.scripts/stage2-contract.shhas stale hard-coded counts and needs them recomputed first.🤖 Generated with Claude Code