Skip to content

fix(#1528, #1543, #1566, #1568): shared cursor pagination primitive, with ELB, RAM, CodePipeline, CloudFront and IAM on it - #1679

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/v0133-pagination
Nov 24, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/v0133-pagination

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Fixes #1528
Fixes #1543
Fixes #1566
Fixes #1568
Part of #1612: this is the shared cursor pagination primitive. #1612's generated validation layer is the W-V workstream and is not in this PR.

The primitive

emulator/pagination.go:

  • page[T](items []T, key func(T) cursorKey, req pageRequest) (pageResult[T], error). cursorKey is {Sort, Tie}. The helper sorts a copy by key (ascending, or descending with req.Descending) and resumes strictly after the decoded cursor, so a deleted cursor record resumes where it was. Truncated is set only when a further item exists.
  • pageAfter[T] is the same cut for raw-ID cursors, with no token. CloudFront and IAM use it.
  • pageRequest.validate() decodes the token without reading any items. Each caller runs it before reading state.
  • Token format: base64 (standard, padded) of {"o":op,"h":fnv64a(filter),"s":sort,"t":tie}. h is 16 hex digits over the canonical filter members: names sorted, values sorted as a set, empty values dropped, every string length-prefixed. A token is accepted only if its base64 and its JSON both round-trip byte for byte (no unknown, missing or reordered members) and its o and h match the request. Every refusal wraps the sentinel errPageToken, and each service maps it to its own code.
  • pageSizeRange.check(v, refuse) applies the published bounds and renders the refusal through the service's error constructor.
  • Adapters in pagination_adapters.go:
    • jsonNextToken(jsonPaging, filter, nextToken, maxResults) for RAM and CodePipeline;
    • elbMarker(req, op, filter);
    • iamMarker(req, maxItems, marker), which keeps IAM's existing base64-of-last-key cursor;
    • restXMLMarker(req, def, invalid) for CloudFront's raw-ID Marker.
  • The Secrets Manager and Step Functions cursors are not generalised. Their token shapes and refusal rules differ, so moving them would change behaviour. queryMarkerPage is unchanged.

Per issue

  • ELB (elb: the six paginated describes page by offset, so a listing that changes mid-walk skips or repeats records #1528): ELBv2 DescribeLoadBalancers, DescribeTargetGroups, DescribeListeners and DescribeRules use a value cursor in ARN order. Classic DescribeLoadBalancers uses one in name order, and lists a name requested twice once. The two DescribeLoadBalancers bind ops that carry the API version (DescribeLoadBalancers@2015-12-01 and @2012-06-01), so neither accepts the other's marker.
    • The filter members hashed into the marker are Names, *Arns, LoadBalancerArn, ListenerArn and LoadBalancerNames.
    • PageSize is 1–400 through the existing elbPageSize. A bad, foreign or filter-mismatched marker is ValidationError/400, the Query Common Errors code that each operation links as its own.
    • DescribeAccountLimits stays on its offset; its MQ== pins are untouched.
  • RAM (ram: ListPrincipals and ListResources page on an offset, so a mid-walk delete or disassociation skips an item #1566): ListPrincipals and ListResources key the cursor and the dedupe on the entity alone (principal ID or resource ARN) and render in that order. A principal or resource in several shares is listed once and carries the first share in ARN order as its resourceShareArn. API_Principal and API_Resource describe that member as "a resource share" the item is associated with, so any one of its shares is valid.
    • maxResults is 1–500, InvalidParameterException, unchanged.
    • A bad, foreign or filter-mismatched token is InvalidNextTokenException/400, using the pages' own wording, and is refused before any state is read. GetResourceShares' op:ARN token is not JSON, so both list operations refuse it, and GetResourceShares refuses theirs.
  • CodePipeline (codepipeline: ListPipelines reads no maxResults or nextToken and skips an unreadable pipeline #1543): ListPipelines reads maxResults and nextToken, using a name cursor. Both codes are published on API_ListPipelines:
    • maxResults outside 1–1000 is ValidationException/400;
    • a bad token is InvalidNextTokenException/400, with the page's gloss as the message.
    • An absent maxResults is 1000, which is substrate's reading because the page publishes no default.
    • Every record is loaded before the page is cut. A record that cannot be read fails the call, and an index entry whose record is gone is passed over, so a token always names a pipeline that follows.
  • CloudFront (CloudFront ListDistributions renders no Marker or MaxItems and pages nothing #1568): ListDistributions and ListOriginAccessControls read the Marker and MaxItems query parameters and list in ID order.
    • Every response renders Marker, MaxItems, IsTruncated and Quantity, plus NextMarker (the page's last ID) when truncated.
    • MaxItems defaults to 100, substrate's reading, because neither page publishes a default. A value that is not a positive integer is InvalidArgument/400, the one code both pages publish.
    • Any Marker is accepted. An unknown or deleted ID resumes after where it sorts.
    • Both listings read every record before cutting the page. A store Get failure fails the call; a dangling or undecodable record is passed over. Only the distributions on the page spend a status-countdown observation.
    • Other CloudFront list operations: substrate routes only one more, ListInvalidations. Its page publishes a most-recent-first order with an ID marker, which needs a decision about ordering, so it is listed in pagination: migrate the remaining 80 mutable offset paginators to the cursor primitive, in protocol batches #1677. ListCachePolicies and the other list operations are not routed.
  • IAM: paginateIAMKeys (10 sites) and iamTagListingResponse (4 sites) now go through iamMarker.
    • A Marker that is not canonical base64 of a non-empty key is ValidationError/400 (IAM CommonErrors: "The input doesn't meet the required format or constraints."), not page one.
    • A deleted marker key resumes in place; before this it also restarted at page one.
    • The tag listings' marker changes from the next page's raw key to base64 of the page's last key, the same form every other IAM listing uses.
    • decodeSimulationMarker now delegates to decodeOffsetPaginationToken. A bad marker on SimulatePrincipalPolicy or SimulateCustomPolicy is InvalidInput/400, published by both operations ("The request was rejected because an invalid or out-of-range value was supplied for an input parameter.").

The refusal messages are substrate's own. No page publishes wording for them, except RAM's InvalidNextTokenException and CodePipeline's, which use the pages' text.

Tests

  • pagination_test.go: table tests covering
    • order, ties and descending order;
    • an empty listing and the size bounds;
    • truncation exactly at a multiple of the page size;
    • mutation mid-walk: delete or insert before, at and after the cursor, ascending and descending;
    • token round-trip and canonical form;
    • a foreign op, a reused filter, forged hashes, and unknown, missing or reordered members.
  • Wire tests:
    • elb_page_cursor_test.go: a mid-walk create and delete on v2 LBs, v2 TGs and classic, plus op and filter binding;
    • ram_pagination_test.go: the order, a mid-walk disassociate, associate and share delete, and filter binding;
    • codepipeline_list_pipelines_test.go;
    • cloudfront_list_pagination_test.go;
    • iam_marker_test.go: 12 listings refuse forged markers, and a ListUsers walk survives a mid-walk delete.
  • Updated tests that forged offsets or raw markers:
    • elb_page_cursor_test.go: the past-the-end case is now DescribeAccountLimits only;
    • ram_pagination_test.go: the offset-clamp test is replaced by composite-cursor tests;
    • iam_tagging_test.go:402: the marker is now base64 of owner;
    • iam_simulate_test.go: the tolerant-marker cases are now refusals.
  • pagination_token_refusal_test.go and the other offset tests cover operations this PR does not migrate, and are unchanged.

Routed-operation catalog unchanged (no operations added).

Gates run locally

  • make lint test e2e
  • The Service Reference Drift set: operation-catalog-check docs-reference-check docs-headings-check operation-docs-check authz-reference-check cfn-schema-check doc-links-check
  • The Wire Bookkeeping Drift set: wire-bookkeeping-check discarded-unmarshal-check discarded-marshal-check discarded-state-check nondeterminism-check comment-history-check
  • docs-versions, docs-counts-check
  • SUBSTRATE_IAC=1 make iac-e2e (Terraform journey and CDK journey, both pass)
  • VitePress build

Patch functions are at 89–100% statement coverage. The uncovered lines are the page error returns behind a token that was already validated.

Review fixes (second commit)

  • RAM's cursor is on the entity alone, and wire tests cover the cursor's entity associated to an earlier share, the cursor's entity disassociated, a disassociate after the cursor with adds on both sides, and a share delete.
  • The ELB generations are op-distinct, with a cross-generation refusal test.
  • CodePipeline and CloudFront load and filter before cutting the page, with dangling-entry and store-failure tests.
  • Filter values are compacted, so ["x","x"] hashes the same as ["x"] (tested).
  • The zero key is a valid position: tokens carry s and t always, and it round-trips (tested). IAM keys are names, paths or ARNs with a published minimum length of 1, so none is empty.
  • The simulate-index stability comment and docs/reference/iam.md are corrected: positions are fixed by the request, but SimulatePrincipalPolicy's decisions are not.
  • OAC Quantity now precedes Items.
  • The CHANGELOG marks substrate's own messages.
  • The package-level paging vars are now funcs.
  • Filed elb: DescribeTargetGroups ignores its LoadBalancerArn filter, because target groups record no attachments #1684 (v0.137.0) for DescribeTargetGroups ignoring LoadBalancerArn, which predates this PR and is too large to fix here.

Follow-up

…with ELB, RAM, CodePipeline, CloudFront and IAM on it
@scttfrdmn scttfrdmn added this to the v0.133.0 milestone Nov 24, 2026
@scttfrdmn scttfrdmn added type: bug Something is not working correctly fidelity labels Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

RAM lists and pages on the entity alone; the two DescribeLoadBalancers
generations bind distinct ops; CodePipeline and CloudFront load and filter
before cutting the page, and a CloudFront store failure fails the list;
filter values are a set; the zero key is a position; the simulate index
comment is corrected; paging vars become funcs.
@scttfrdmn
scttfrdmn merged commit 1f27a3a into main Nov 24, 2026
20 checks passed
@scttfrdmn
scttfrdmn deleted the fix/v0133-pagination branch November 24, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment