Skip to content

SQS: seedable eventual-consistency delay on GetQueueUrl after CreateQueue #413

Closed

Description

@scttfrdmn

Summary

Substrate models eventual consistency as a first-class, seedable concept (emulator/consistency.go). The SQS plugin, however, makes a just-created queue immediately resolvable by GetQueueUrl. On real AWS there's a brief window where CreateQueue has returned but GetQueueUrl still 400s with NonExistentQueue (create→lookup propagation). A consumer's create-then-open-then-retry loop can't be exercised against Substrate today because the race never happens.

This fits the charter exactly: scope.md calls out "seedable outcomes that let a consumer's poll/retry/wait loop be tested" as in scope. This is that, for the CreateQueue→GetQueueUrl consistency window.

Why this matters (concrete)

In spore-host/spawn#70, a freshly-booted pool worker resolves its run queue via GetQueueUrl right after the submitter's CreateQueue. On real AWS it occasionally hit NonExistentQueue and (originally) exited with no retry. We added a bounded retry in OpenQueue, but couldn't test that retry offline — against Substrate the queue is always instantly visible, so the retry path is never taken in CI. A seedable delay would let the retry logic be regression-tested without a real instance.

Proposed

A seed that makes GetQueueUrl (and optionally GetQueueAttributes) for a given queue name return NonExistentQueue for the first N calls (or until a simulated-clock offset) after its CreateQueue, then resolve normally — mirroring the pattern already used for other seedable outcomes:

  • e.g. POST /v1/sqs/consistency {queue_name, get_url_misses: 3} (or a clock-duration form), and it decrements/expires like the existing consistency model.
  • Default (unseeded) behavior stays instant-resolve, so existing tests are unaffected.

Acceptance

  • With a seeded delay, GetQueueUrl on a just-created queue returns NonExistentQueue for the seeded window, then resolves — so a consumer's retry loop can be tested to succeed within budget and to fail loudly past it.
  • Unseeded behavior unchanged (instant resolve).

Scope note

Seedable observation of an existing API's eventual-consistency behavior — the same shape as Substrate's existing seedable outcomes. No workload execution.

Reported from spore-host/spawn#70 pooled-execution validation (companion to the OpenQueue retry, spawn#464).

Activity

  1. added
    type: feature
    area: consistency
    priority: medium
    on Aug 1, 2026
  2. added this to the v0.81.0 milestone on Aug 1, 2026
  3. scttfrdmn commented on Aug 1, 2026

    @scttfrdmn
    OwnerAuthor

    Implemented in two PRs — #426 (merged) and #427 (open) — both landing in v0.81.0.
    Three decisions here differ from what the issue proposed, so the reasoning is below.

    The error code is QueueDoesNotExist, not AWS.SimpleQueueService.NonExistentQueue

    The issue body uses the dotted string, and substrate did emit it — at 14 sites. That
    had to be corrected before the seed, or the seed would have reproduced the exact
    defect you filed, one layer down: the retry loop still couldn't be written idiomatically,
    because the error it needs to catch wasn't catchable.

    AWS's GetQueueUrl reference documents the error as QueueDoesNotExist (HTTP 400); the
    dotted string appears nowhere in the current API reference. SQS is an
    awsQueryCompatible JSON protocol service, and the dotted form is the
    query-compatibility alias, which AWS sends in an x-amzn-query-error header — not
    in __type.

    Verified against both SDKs rather than from memory:

    __type substrate sends botocore resolves to your except clause
    AWS.SimpleQueueService.NonExistentQueue (before) same string bare ClientError — except sqs.exceptions.QueueDoesNotExist never matched
    QueueDoesNotExist (now) QueueDoesNotExist the modeled class, matches

    aws-sdk-go-v2/service/sqs agrees: its deserializer dispatches on
    strings.EqualFold("QueueDoesNotExist", errorCode), and the dotted string appears
    nowhere in the module — so errors.As(err, &types.QueueDoesNotExist{}) never
    matched either.

    I deliberately did not add the x-amzn-query-error compat header. Because
    writeError already derives x-amzn-ErrorType from the code, correcting the code
    fixes both SDKs with no new plumbing; adding the header would need a cross-cutting
    change to the shared error type for one service's legacy alias and would still leave
    Error["Code"] reading the legacy string. If you have anything matching on the old
    string, that's the one behavior change to know about.

    Counts, not durations

    You offered "or a clock-duration form" — the seed is counted in misses instead,
    and this isn't a shortcut. Substrate's TimeController.Now() advances with wall
    time
    from its baseline; it's not a frozen, manually-stepped clock. A duration seed
    would therefore self-expire partway through a test, making "still missing" assertions
    wall-clock dependent, which substrate's own testing rules forbid outright. A miss
    counter is exactly reproducible: seed 2, and calls 1–2 fail and call 3 succeeds, on
    every machine, forever.

    POST   /v1/sqs/consistency   {"queueName":"run-q","getUrlMisses":2}
    DELETE /v1/sqs/consistency?queueName=run-q     # or no query to clear all
    

    Keyed by queue name or the "*" wildcard. GetQueueUrl and GetQueueAttributes get
    independent counters — your full suggestion; AWS documents QueueDoesNotExist on
    both — so you can exercise one retry loop without perturbing the other. Both default
    to 0, so unseeded behavior is unchanged.

    Two ordering rules that matter for how you'll write the harness:

    • A miss is consumed only when the queue actually exists. Seeding before
      CreateQueue is safe and is the natural order; lookups against the still-absent
      queue fail but don't spend the budget. Otherwise a pre-create seed would be
      silently burned and your retry assertion would mean nothing.
    • A seed counts down the next N misses; it does not re-arm on CreateQueue.
      createQueue is idempotent here, so "after its CreateQueue" is ambiguous when
      create runs twice, and re-arming would make the data path write control-plane state.

    Seeds live in the state store, so POST /v1/state/reset clears them between cases.
    Full docs in docs/services.md under "Seeding the create-then-lookup consistency
    window".

    One thing this does not fix

    SQS errors are emitted as JSON regardless of request protocol. Substrate resolves
    the error protocol per service and SQS is JSON-RPC, so a query-protocol request gets
    a JSON error document rather than the XML <Error> shape real SQS would return. It
    doesn't affect either SDK — both send JSON — but if you have anything hand-parsing
    query-protocol error responses, it will surprise you. Out of scope here; now documented
    in docs/services.md. Say the word if it's blocking and I'll file it.

    Also noticed while in here

    CreateQueue documents QueueDeletedRecently (the 60-second wait after a delete) and
    QueueNameExists (same name, different attributes). createQueue is unconditionally
    idempotent and returns the existing URL regardless of attribute differences, so both
    of those consumer error branches are unreachable too — the same shape of problem as
    this issue. Filed separately; it can reuse this seed namespace.

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

    area: consistencyarea: sqspriority: mediumtype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions