Skip to content

fix(tagging): five tag-read operations emit tags sorted by key (#946) - #955

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/tag-read-order
Sep 16, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/tag-read-order

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Five tag reads flattened a resource's map[string]string of tags into an ordered list by ranging it, so the order on the wire came from the map's hash seed. Two identical reads of unchanged state could report one resource's tags in a different order — the one thing an emulator whose whole claim is byte-identical replay must not do.

The five: ACM ListTagsForCertificate, CloudFront ListTagsForResource, Kinesis ListTagsForStream, S3 GetBucketTagging and GetObjectTagging.

Why neither earlier fix reached them

This defect class has been fixed twice already, and both fixes are structurally unable to touch these sites:

A map rendered as a JSON object was never affected either, because encoding/json sorts map keys itself. The defect is specific to a map flattened into an ordered array or into a repeated XML element, where nothing sorted.

The fix

All five call sortTagsByKey — the generic helper #862 introduced, which already carries the written rationale — so no sixth ordering rule enters the tree. That satisfies this issue's AC 3 by reuse rather than by adding a helper; the DynamoDB precedent the issue cites predates the helper and is left alone.

Provenance, per operation rather than blanket

This is the correction already posted on #946 before this diff: the issue's "Nothing, for any of the five" holds for four, not five.

Operation Provenance
ACM ListTagsForCertificate Substrate's reading. No cursor, no ordering statement — its page has exactly one request parameter
CloudFront ListTagsForResource Substrate's reading. No cursor, no ordering statement
S3 GetBucketTagging / GetObjectTagging Substrate's reading. Neither page states an order
Kinesis ListTagsForStream Implied by AWS's own cursor. ExclusiveStartTagKey is "the key to use as the starting point for the list of tags. If this parameter is set, ListTagsForStream gets all tags that occur after ExclusiveStartTagKey", and Tags is "a list of tags associated with StreamName, starting with the first tag after ExclusiveStartTagKey and up to the specified Limit". A tag cannot occur after a key unless the tags are walked in some order over keys — the same reasoning that made ListObjectVersions' order cursor-implied in #865

Which order is substrate's reading in all five cases; AWS's own Kinesis sample response is not sorted. Substrate implements neither ExclusiveStartTagKey nor Limit and answers HasMoreTags: false unconditionally, so that cursor cannot be exercised yet — #954, filed for it, for which this sort is the prerequisite: a cursor paged over an unstable order skips and repeats tags. The two were kept apart deliberately, because this PR changes a success body's order and #954 changes which tags a caller receives.

Tests

emulator/tag_read_order_test.go, five cases, every tag written through the owning service's own tag call and every read over the wire (#765's standing rule). Two assertions per operation, and neither substitutes for the other: three successive reads are byte-identical on the raw body, and the keys come back sorted. The six keys are written in reverse-sorted order.

The tests were proved load-bearing rather than assumed so, and the method is recorded in the file: removing the five sorts fails four of the five immediately, and the fifth under -count=10 — a six-key map can iterate sorted by chance, which is why the three-read helper exists. With the sorts in place both assertions hold on every run, so nothing here can flake; what is probabilistic is only how reliably these tests would have caught the old handler.

Documentation

docs/services.md gains one shared subsection, A tag set read back out of a map, placed in the existing ordering reference beside the three provenance tiers #865 and #887 established, plus a row for each of the five operations. Kinesis's operations table was also missing all three of its tag operations, which are added — the table still omits five other implemented operations, which is a separate finding.

Compatibility

A consumer asserting on a tag's position in any of those five responses may now see a different order than before — a stable one. An assertion that happened to pass on Go's map order can fail, and that is the defect surfacing rather than a new one.

Closes #946.

The five operations get a table row each and one shared subsection in the
ordering reference, with the provenance stated per operation: substrate's
reading for ACM, CloudFront and both S3 reads; implied by AWS's own
ExclusiveStartTagKey cursor for Kinesis, whose cursor is #954.

Kinesis's operations table was also missing all three of its tag operations.
@codecov

codecov Bot commented Sep 16, 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 09ec1dd into main Sep 16, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/tag-read-order branch September 16, 2026 23:58
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.

Five tag-read operations emit tags in Go map order, so two identical calls can differ

1 participant