Skip to content

fix(#1229): a published filter selects what the page is cut from - #1250

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1229-scheduler-state-filter
Sep 20, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1229-scheduler-state-filter

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

listSchedules read its three filters in three different places relative to the cut. ScheduleGroup
chose which name index to load and NamePrefix filtered that index — both ahead of the cut — but
State was applied inside the render loop, on the records the page had already selected. So a
state-filtered request was answered MaxResults schedules minus however many of that page failed the
filter, while the NextToken alongside had been computed from the unfiltered listing.

Found while converting this operation's token for #1086 and deliberately left out of PR #1228, which is
why scheduler_pagination.go carried it as "not fixed here". That bullet is now the fix's own
cross-reference rather than a standing divergence.

Why it is a divergence

API_ListSchedules publishes State in the same URI-parameter list as the other two filters and in
the same words:

State — If specified, only lists the schedules whose current state matches the given filter.
NamePrefix — Schedule name prefix to return the filtered list of resources.

So it is a filter on the listing, and the listing is what a page is cut from. The response member is
the ordinary cursor — "Indicates whether there are additional results to retrieve. If the value is
null, there are no more results."
— and nothing on the page says a page may be shorter than the
MaxResults it was asked for.

Two observations changed, the second worse:

  • ?State=ENABLED&MaxResults=20 over a group of 40 half of which are DISABLED answered fewer than 20
    enabled schedules with a cursor set, where AWS answers 20.
  • When every schedule on a page failed the filter it answered {"Schedules":[],"NextToken":"…"} with
    matches still to come. A caller that stops at an empty list — several SDK paginator idioms do — reads
    that as "the filter matched nothing". AWS can produce the shape too, but from server-side scan limits,
    never from applying a filter it publishes.

The reading taken, and the one refused

Filtering ahead of the cut means loading every record in the group per call rather than one page's
worth, because State lives in the record and not in the name index. That is the deliberate choice —
issue reading 1. The alternative, carrying State in the name index so the filter stays index-only,
would duplicate a field of the record into an index and leave UpdateSchedule with two places to write
it, which is the class #756 exists for. A state.Get per schedule in a group is not a cost worth that
in an in-process emulator.

What is unchanged, and said so

  • The offset now counts matching schedules, so a token issued with a State filter and replayed
    without one indexes into a different listing. Already true of NamePrefix, and already recorded in
    scheduler_pagination.go as a property of every offset paginator in the tree: the token carries an
    offset and nothing else. Not widened, not narrowed.
  • A name the index holds with no record behind it, and a record that will not decode, are still
    skipped
    (acceptance criterion 4). They are store inconsistencies rather than published filters —
    no request a caller can send produces either, and the page publishes no code for substrate's own
    index and records disagreeing, so a refusal would be inventing one. What changed is that skipping one
    can no longer shorten a page: it shortens the listing being cut from, exactly as a filter does.
  • MaxResults above the published maximum of 100 still clamps rather than being refused, with zero
    or below ignored in favor of substrate's own default of 20. Still recorded as not fixed here.

Verification

  • emulator/scheduler_list_filters_test.go builds its group through real CreateSchedule calls
    (cfn: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped #765) and asserts over the wire: twelve schedules alternating ENABLED/DISABLED, so every prefix
    of the unfiltered listing contains both. A full first page, a resumption that reaches all six matches
    in two pages, a MaxResults=1 walk asserting no page carries a cursor without a match, the
    unfiltered listing unchanged, State composing with NamePrefix, and a second test keeping
    ScheduleGroup scoping honest.
  • Non-vacuity: restoring the pre-fix order fails three of the subtests — the full page (2 of 4
    schedules), the resumption (wrong names, three pages), and the empty-page-with-cursor rule.
  • make lint → 0 issues. make test (race) → green. make docs-reference-check docs-versions version-check discarded-unmarshal-check wire-bookkeeping-check → green, 330 fields.
  • No wall clock, no network: the filters read record state, and the page-size readings are unchanged.

docs/services.md gains a section for the fix, the ListSchedules row records the filter order, and
PR #1228's "left as they were" paragraph now says which half was fixed.

Closes #1229.

listSchedules read its three filters in three places relative to the cut:
ScheduleGroup chose which name index to load and NamePrefix filtered that index,
both ahead of it, but State ran inside the render loop — on the records the page
had already selected. So a state-filtered request was answered MaxResults
schedules minus however many of that page failed the filter, while the NextToken
alongside had been computed from the unfiltered listing.

API_ListSchedules publishes State in the same URI-parameter list as the other two
and in the same words ("If specified, only lists the schedules whose current
state matches the given filter."), and the cursor is the ordinary "Indicates
whether there are additional results to retrieve". Nothing on the page says a
page may be short. ?State=ENABLED&MaxResults=20 over a group of 40 half of which
are DISABLED answered fewer than 20 with a cursor set, where AWS answers 20; and
a page all of whose schedules failed the filter answered an empty Schedules array
alongside a NextToken, which a caller that stops at an empty list reads as
"nothing matches".

All three filters now run before the cut, so a page carries min(MaxResults,
remaining matches). The cost is a state.Get per schedule in the group per call,
because State lives in the record and not in the name index — taken deliberately
over copying State into the index and leaving UpdateSchedule two places to write
it, which is the class #756 is about.

A name the index holds with no record behind it, and a record that will not
decode, are still skipped: those are store inconsistencies rather than published
filters, and no request a caller can send produces either. What changed is that
skipping one can no longer shorten a page.
@scttfrdmn scttfrdmn added this to the v0.121.0 milestone Sep 20, 2026
@codecov

codecov Bot commented Sep 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit a247d7f into main Sep 20, 2026
18 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1229-scheduler-state-filter branch September 20, 2026 08:11
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.

scheduler: ListSchedules applies its State filter after the page is cut, so a filtered page is short and its NextToken is misleading

1 participant