Skip to content

Audit the remaining ~60 List call sites for an AWS-documented order that differs from lexicographic #887

Closed

Description

@scttfrdmn

#865 made MemoryStateManager.List return keys in lexicographic order and put the guarantee in StateManager.List's doc comment, so all 124 non-test .List( sites are now deterministic. That fixed the run-to-run instability. It did not establish that lexicographic is the order AWS documents at each site, and only the sites reaching a response body under a cursor were audited individually.

This issue is the remaining audit: for each listing that still inherits lexicographic order by default, confirm against the operation's own API reference page whether AWS publishes a different order — and where it does, sort into it at the call site rather than relying on the default.

What #865 audited, and how

Three provenance tiers were established and recorded in docs/services.md:

  1. Documented by AWS — API_ListMultipartUploads publishes a "Sorting of multipart uploads in response" section (ascending object key, then ascending initiation time for uploads sharing a key). Substrate's previous order was a citable violation, and listMultipartUploads now sorts into it explicitly.
  2. Required by the operation's own cursor — API_ListObjectVersions (NextKeyMarker is "the first key not returned that satisfies the search criteria"), RGTA GetResources (PaginationToken), and the four ELBv2 Describes (Marker/PageSize). A cursor over an unstable order can skip or repeat, so these are correct now by construction.
  3. Undocumented — API_ListBuckets says nothing about bucket order and API_DescribeRules states none. Lexicographic there is substrate's reading, resting on the replay promise, and it is written up that way rather than as matching AWS.

The remaining sites fall in tier 3 by assumption, not by having been checked. That assumption is what needs testing.

The sites to audit

Roughly sixty, concentrated in these files (counts are non-test .List( sites, not distinct operations):

File Sites Notes
ec2_plugin.go 23 the largest set; several Describes publish no order, but DescribeSnapshots/DescribeImages and the paginated Describes need checking individually
iam_plugin.go, iam_list_policies.go, iam_account_authorization_details.go 12 already routed through paginateIAMKeys, which sorts — so these are believed fine and need confirming, not fixing
s3_plugin.go 9 three audited in #865; the rest not
rds_plugin.go 5
elasticache_plugin.go 4 :163 clusters, :383 replication groups, :563 subnet groups, :662 parameter groups — all four under Marker/MaxRecords cursors, so tier 2 at minimum
lambda_plugin.go 3 :517 and :838 over function:, :1281 over esm: — ListFunctions publishes a FunctionVersion/Marker pair worth checking
apigateway_plugin.go 2 :702, :1321 — both take a computed prefix, so the effective order depends on the key layout as much as the sort
cloudwatch_plugin.go 1 :481, computed prefix
ssm_plugin.go 1 :954 — lists EC2 instances from ec2Namespace, a cross-service read worth noting on its own
remainder ~12 ce_plugin.go, bedrock_runtime_ctrl.go, ec2_snapshot_control.go, timestream_ctrl.go, tagging_plugin.go's sixteen scanners (audited as one cursor in #865)

Not every site is a listing — some are internal scans whose order never reaches a caller, and those can be dismissed with a line each rather than researched. Separating those out is most of the work.

Acceptance criteria

  • Every non-test .List( site is classified: reaches a response body (needs an order decision) or internal scan (does not). The count of each is recorded on the issue.
  • For each site in the first class, the operation's AWS API reference page is consulted and the site assigned one of the three tiers above. A tier-1 finding — AWS publishes an order substrate does not produce — is a defect, and each one gets a fix plus a test.
  • Any site under a pagination cursor whose key order does not match the cursor's comparison basis is a defect even if AWS documents no order, for the same reason NextKeyMarker was: the cursor can skip or repeat. elasticache_plugin.go's four are the first candidates.
  • docs/services.md records the tier-1 findings by operation, and states for the tier-3 remainder that lexicographic is substrate's reading — as state: MemoryStateManager.List returns keys in Go map order, so 111 call sites answer differently run to run #865 did for ListBuckets.
  • Any test that was silently passing on the old order and had to be adjusted is recorded on the issue as a finding, not quietly relaxed.

The audit itself does not have to land in one PR; a per-service sweep with the classification table kept up to date on this issue is fine, and probably better.

Follow-up to #865.

Activity

  1. added
    type: chore
    on Sep 15, 2026
  2. added this to the v0.117.0 milestone on Sep 15, 2026
  3. scttfrdmn commented on Sep 16, 2026

    @scttfrdmn
    OwnerAuthor

    Audit complete — the inventory, the tier assignments, and two corrections to this issue's own body

    PR #914 carries the one defect the audit found. This comment is the record AC 1 asks for.

    Inventory

    128 non-test .List( call sites across 46 files — not the ~60 this issue estimated. Classified by whether the order is observable:

    Class Sites Meaning
    A 50 The keys reach an AWS-shaped response body, so a caller can observe the order.
    B 21 The keys reach one of substrate's own control endpoints.
    C 57 Internal scan — a single-key lookup, a mutation that stops at the first match, or a set re-sorted before it is rendered.

    By subsystem:

    Subsystem Sites A / C / B
    EC2 family 32 18 / 11 / 3
    tagging_plugin.go 20 0 / 20 / 0
    ELB family 17 5 / 11 / 1
    IAM 15 9 / 5 / 1
    S3 family 10 4 / 5 / 1
    RDS 5 5 / 0 / 0
    ElastiCache 4 4 / 0 / 0
    Lambda 4 2 / 1 / 1
    API Gateway 2 1 / 1 / 0
    SSM 2 1 / 0 / 1
    CloudWatch 1 1 / 0 / 0
    remainder (ce_plugin.go, replay.go, control endpoints) 16 —

    The tagging_plugin.go block is the largest class C by far: twenty scanners feed getResources, whose ARN sort (tagging_plugin.go:111-113) discards their order entirely.

    Tier assignments — no new tier-1 operation exists

    Eleven further AWS pages were read this pass: RDS DescribeDBInstances and DescribeDBClusters; ElastiCache DescribeCacheClusters, DescribeReplicationGroups and DescribeCacheSubnetGroups; API Gateway GetRestApis; CloudWatch DescribeAlarms and ListMetrics; SSM DescribeParameters and GetParametersByPath; and EC2's Query request page. None publishes an ordering statement. ListMultipartUploads (fixed in #865) remains the only documented order in the codebase.

    EC2 is settled by a blanket disclaimer rather than per operation, on Query-Requests.html:

    The order of the elements in the response, including those within nested structures, might vary. Applications should not assume that the elements appear in a particular order.

    All 30 EC2-family sites are therefore tier 3, and substrate's lexicographic order is a stronger guarantee than AWS gives — which is the right direction, but must not be read as matching AWS.

    Tier 2 needed care to draw correctly. A cursor alone does not make an operation tier 2; the cursor has to have positional semantics:

    • Tier 2 — RDS/ElastiCache Marker. Documented positionally: "the response includes only records beyond the marker, up to the value specified by MaxRecords". A record cannot be beyond another without an order. An offset cursor therefore diverges from a published contract. This is the defect, at exactly three sites.
    • Tier 3 — API Gateway position, CloudWatch NextToken, SSM NextToken. Documented as opaque, with no positional semantics stated. Substrate's base64-offset implementations there are substrate's reading, not defects — though see the finding below about what they do with a token they did not issue.

    Two corrections to this issue's body

    1. "all four [ElastiCache describes] under Marker/MaxRecords cursors" is wrong. Only describeCacheClusters implements pagination. describeReplicationGroups (elasticache_plugin.go:383), describeCacheSubnetGroups (:563) and describeCacheParameterGroups (:662) implement none at all — they return the whole listing and no Marker, and ignore MaxRecords. Filed separately.
    2. "~60 sites" is 128. The estimate was low by more than half.

    Adjusted test, recorded here rather than quietly relaxed (AC 5)

    TestElastiCachePlugin_CacheClusterPagination (emulator/elasticache_plugin_test.go) failed against the fix, and it deserved to. It created five clusters, asserted page one contained a <Marker>, then requested page two with a hand-written "Marker": "2" — the offset the old cursor happened to emit — and ended with _ = body. It never asserted anything about page two's contents. That is exactly why it passed while the cursor was capable of dropping a record: the only thing it checked was that a marker existed. It now walks the marker page one actually returned and asserts page two's records and that they do not repeat page one's.

    No other test in the tree paged either family, so this was the only adjustment.

    Verified correct, recorded so the claim is not overstated

    • s3_plugin.go:2180 loadUploadParts already sorts numerically, with the reason written down: "State keys sort lexicographically, which puts part 10 before part 2."
    • ec2_describetags.go already sorts, validates MaxResults against its own min/max, and refuses a NextToken it did not issue — its :300 comment already states the argument this issue is about: "an offset-based NextToken over an unordered list could…".
    • A repo-wide grep found exactly one state.Put with a numeric key component (fmt.Sprintf("part:%s/%d", …)), so no other listing can hit the 1/10/11/2 trap.
    • listObjectVersions' newest-first ordering is safe: both saveVersionIDs call sites (s3_plugin.go:928, :1200) prepend, so the stored list is newest-first by construction. It rests on two call sites agreeing rather than on anything stated, which is worth a doc comment but is not a defect.

    Out of scope, filed rather than folded in

    • RDS and ElastiCache honour a MaxRecords outside the documented 20-100 range and silently rewrite an unusable one #913 — MaxRecords outside the documented 20–100 range is honoured, and an unusable one is silently rewritten to 100.
    • Six RDS/ElastiCache listings implement no pagination at all.
    • An undecodable pagination token is treated as page one at CloudWatch DescribeAlarms, both SSM listings and listObjectsV2, where AWS publishes InvalidNextToken/400. Same class as defect 2 here, different services.
    • EC2's describes implement no MaxResults/NextToken at all.
    • lambda_plugin.go:1281 ListEventSourceMappings and apigateway_plugin.go:1321 GetBasePathMappings are unpaginated.
  4. scttfrdmn commented on Sep 16, 2026

    @scttfrdmn
    OwnerAuthor

    The out-of-scope findings above are now filed: #913 (MaxRecords outside the documented 20–100 range), #915 (a pagination token substrate never issued is answered with page one — CloudWatch DescribeAlarms, both SSM listings, S3 ListObjectsV2; InvalidNextToken/400 is published for the first three), #916 (six RDS/ElastiCache describes publish Marker/MaxRecords and implement neither), #917 (EC2's describes implement no MaxResults/NextToken, plus Lambda ListEventSourceMappings and API Gateway GetBasePathMappings). All four are on milestone v0.118.0.

  5. added 6 commits that reference this issue on Sep 17, 2026
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

    type: chore

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions