Function read_from_composes_with_limit
pub async fn read_from_composes_with_limit<F: Fixture>(
open: impl AsyncFn() -> F,
) -> RuleOutcomeExpand description
Reading forwards from a cursor with a budget spends the budget.
CF-12’s SHOULD, ES-14 and VT-28 all name this one composition as the
consumer that motivates them — a paging loop that resumes carries from,
and ReadOptions’ own documentation writes the idiom out as
.limit(budget - fetched) — and until this rule the suite issued it
nowhere. from was composed with to, with backwards, and with
backwards and limit; forwards from with limit appeared at no
call site among the eighty-nine rules that preceded this one.
It rejects ForwardPagingBudgetStore: limit applied only where from
is absent, because the resume branch was written after the paging query
and nobody threaded the budget into it. That is the order every SQL
adapter in this workspace will be written in, and the backwards branch is
left correct in it — so read_backwards_from_with_limit passes and this
is the only rule that sees it. The caller it protects is a projection
runner asking for five hundred events from its checkpoint and being handed
the whole stream, with no error anywhere.
§Why the query has two items, and why there is no to here
Two items because CF-12’s finding is about the generated SQL, where the
cursor and the disjunction are built by different hands:
UnparenthesisedPredicateStore binds the bound to the last item alone and
fails here for that reason, and LimitPerItemStore writes the budget onto
one statement per item and fails here for its own. A single-item query
would see neither.
No to here, and the reason given for that was half right and was
acted on as though it were whole. from cuts the front of the read
while to and limit both cut the back, so in read order the two
commute exactly — that much is true, and it is why the wrong
implementation an adversarial review proposed for the pair (the budget
applied before the bound) is not a defect at all and is not registered.
What it does not follow is that no rule was owed. Commuting is an
argument about the order two options are applied in;
WindowedPagingBudgetStore does not reorder them, it drops the budget
because a bound is present, and no amount of commutation reaches that. It
passed all ninety-two rules that preceded read_to_composes_with_limit,
which is the rule that owns the pair now.
The two items’ matches are contiguous blocks rather than interleaved, for
limit_applies_across_items_not_per_item’s reason: interleaving makes
item order and position order disagree, and ItemOrderedUnionStore and
SortByEventTypeStore would then fail this rule for reasons
query_item_order_does_not_change_the_result_set and
read_defaults_to_ascending_order already own. The window the assertion
names straddles the boundary between the blocks, which is what makes
it a statement about the merged result rather than about either item: a
store that pages each item separately cannot produce it.
The assertion names three positions the store itself assigned, so a store that returns nothing fails it and so does one that returns everything. That is the non-vacuity anchor, and it is why there is no separate one.