Skip to content

sns: GetTopicAttributes reports an invented SubscriptionsCount hardcoded to 0, and none of the three subscription counts AWS publishes #993

Closed

Description

@scttfrdmn

GetTopicAttributes reports a SubscriptionsCount attribute that API_GetTopicAttributes does not publish, hardcoded to "0", and reports none of the three subscription counts AWS does.

emulator/sns_plugin.go:356-359, in getTopicAttributes:

attrs := map[string]string{
    "TopicArn":           t.ARN,
    "SubscriptionsCount": "0",
}
for k, v := range t.Attributes {
    attrs[k] = v
}

SubscriptionsCount appears nowhere on API_GetTopicAttributes. The page's Attributes list publishes three subscription counts and substrate reports none of them:

  • SubscriptionsConfirmed – "The number of confirmed subscriptions for the topic."
  • SubscriptionsDeleted – "The number of deleted subscriptions for the topic."
  • SubscriptionsPending – "The number of subscriptions pending confirmation for the topic."

So a caller reading the attribute AWS documents gets nothing back, and a caller reading the one substrate invents gets 0 — a value nothing writes, for a member no SDK models. It is the #914 class (a member name AWS's shape does not have) crossed with the #847 class (a count read from a field no writer touches).

The value is also not merely mis-named: the per-topic subscription index is already in state at snsSubTopicIDsStateKey and listSubscriptionsByTopic reads it, so a real count is a load away.

Two more members AWS's own sample carries and substrate omits

API_GetTopicAttributes' sample response has exactly three entries — Owner, Policy and TopicArn. Substrate reports TopicArn and neither of the other two unless something stored them:

What confirmed-versus-pending means here

Substrate has no ConfirmSubscription, so every subscription it mints is effectively confirmed the moment Subscribe returns — Subscribe hands back a real subscription ARN rather than the string "pending confirmation" that API_Subscribe documents for an unconfirmed one. That makes the split decidable rather than guesswork: SubscriptionsConfirmed is the length of the per-topic index, SubscriptionsPending is 0, and SubscriptionsDeleted has no state behind it at all because Unsubscribe removes the record rather than tombstoning it.

Whether to report SubscriptionsDeleted as 0 or omit it is a real decision. Reporting 0 claims a fact nothing tracks; omitting it is the honest-empty behaviour #827 established. Recommend omitting, and stating why.

Acceptance criteria

  • SubscriptionsCount is removed. No response member carries a name AWS's page does not publish.
  • SubscriptionsConfirmed reports the actual length of the per-topic subscription index, not a constant — asserted over the wire after two Subscribe calls and again after one Unsubscribe.
  • SubscriptionsPending reports 0, with a doc comment recording that substrate mints no unconfirmed subscription because it implements no ConfirmSubscription.
  • SubscriptionsDeleted is either omitted with the honest-empty reasoning stated, or backed by state that actually counts deletions — not reported as a constant.
  • Owner reports the account segment of the topic's ARN, matching AWS's sample.
  • Policy is either implemented or recorded as unmodelled in docs/services.md, with the kms: CreateKey drops Policy, and GetKeyPolicy answers an empty-statement document instead of AWS's default key policy #983 parallel named.
  • Assertions are on raw XML and check the attribute key set, not a decoded map — a decoded map cannot distinguish an absent member from one reporting the zero value, which is how a hardcoded "0" survived this long.
  • docs/services.md records the attribute set substrate reports and the ones it does not.
  • CHANGELOG.md updated under ## [Unreleased].

Provenance

The three subscription-count attributes, Owner, Policy and the three-entry sample response are quoted from API_GetTopicAttributes. That SubscriptionsCount appears nowhere on the page was checked against the whole page, not just the Attributes list. Omitting SubscriptionsDeleted rather than reporting 0 is substrate's reading, resting on #827.

Surfaced while implementing #926, which touched this handler's not-found path only.

Activity

  1. added this to the v0.119.0 milestone on Sep 17, 2026
  2. added
    type: bug
    on Sep 17, 2026
  3. scttfrdmn commented on Sep 18, 2026

    @scttfrdmn
    OwnerAuthor

    Premise corrections before the PR opens, verified at 9da7791.

    The cited lines are stale. SubscriptionsCount is at emulator/sns_plugin.go:404, in a handler that now spans :396-431; :356-359 is deleteTopic's response struct. Everything the issue says about the literal is otherwise exact, and the page check reproduces: SubscriptionsCount appears nowhere on API_GetTopicAttributes — not in the Attributes list, not in the sample, not in the Errors section.

    SubscriptionsPending and SubscriptionsDeleted have no backing state at all, which is stronger than "not reported". There is no ConfirmSubscription anywhere in the tree (zero matches), SNSSubscription (sns_types.go:52-70) has no status field, and Unsubscribe (:608-667) deletes the record and filters both indexes rather than tombstoning. So Pending is structurally 0 and Deleted is unsourceable: any value substrate reported would be invented. Taking the issue's recommendation, Deleted is omitted under the honest-empty rule — and the reasoning is a little stronger than "nothing tracks it". A monotonic counter incremented in Unsubscribe would be easy, but AWS publishes only "The number of deleted subscriptions for the topic" and says nothing about how long a deleted subscription is counted, so a never-decaying counter would be substrate's invention rather than its reading of the page. Omission claims nothing.

    The cross-account index disagreement, and the decision. The topic record is keyed by the ARN's account and Region — requireTopic (:163-176) passes snsParseTopicARN's target to loadTopic and takes no *RequestContext, which #925 made structural. Every one of the seven per-topic subscription index sites is keyed by the caller's instead (:571, :576, :649, :659, :690, :834, :1023), and Subscribe's own comment records that deliberately: "The record and the two indexes below stay keyed by the caller … a cross-account subscription is not modeled, and moving them would leave Publish reading an index the subscriptions are not in."

    So the two keyings disagree for a cross-account ARN, and the issue does not say which one the count uses. Decision: the caller's, matching all seven existing sites — including listSubscriptionsByTopic:690. The property that decides it is assertable: SubscriptionsConfirmed and ListSubscriptionsByTopic read the same index under the same key, so they cannot disagree about the same topic. Keying the count by the ARN's target instead would have made them disagree by construction — GetTopicAttributes reporting 0 while ListSubscriptionsByTopic returned the subscriptions. Reversing the index keying is the larger, separate question Subscribe's comment already frames; this issue does not reopen it.

    A finding the issue misses, and it changes the order of two lines. setTopicAttributes (:435-450) writes any AttributeName into t.Attributes unchecked, and getTopicAttributes merges that stored map after its own literals (:407-409). So today a stored TopicArn shadows the real one, and after this fix a stored SubscriptionsConfirmed would shadow the derived count — a caller could make the emulator report a subscription count of its choosing. The derived members must therefore be written last, after the merge, and the doc comment says why. That SetTopicAttributes accepts an attribute name its own page does not publish is a separate defect and will be filed separately rather than folded in.

    Recording the published set while it is in front of us. API_GetTopicAttributes publishes sixteen attribute names: DeliveryPolicy, DisplayName, EffectiveDeliveryPolicy, Owner, Policy, SignatureVersion, SubscriptionsConfirmed, SubscriptionsDeleted, SubscriptionsPending, TopicArn, TracingConfig, KmsMasterKeyId, and four FIFO-only (ArchivePolicy, BeginningArchiveTime, ContentBasedDeduplication, FifoTopic). Substrate derives four and passes the rest through from whatever SetTopicAttributes or CreateTopic stored, which is the right shape for all of them except Policy — the page also carries an explicit absence rule for SignatureVersion ("If the API response does not include the SignatureVersion attribute, it means that the SignatureVersion for the topic has value 1"), so not inventing it is what the page asks for, and no change is needed there.

    Owner needs no ARN parsing: SNSTopic.AccountID is already persisted (sns_types.go:22-23) and is by construction the ARN's account segment, because requireTopic builds the state key from that segment.

    On the raw-XML acceptance criterion. The stated reason is not quite the reason. snsTopicAttributes (tagging_sns_test.go:206-230) decodes into a map[string]string, and a map can distinguish an absent key from one carrying "0" — that is not how the hardcoded "0" survived; it survived because no test read the attribute at all. What a map genuinely cannot see is a duplicated <entry>, which is exactly the failure mode the derive-after-merge ordering above could introduce if it were written as two appends instead of one map write. So the new sibling helper asserts the ordered key slice from the raw XML, and the existing map helper stays for value assertions.

  4. added a commit that references this issue on Sep 19, 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: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions