Skip to content

Implement modeled waiters - #991

Merged
arandito merged 3 commits into
developfrom
waiters
Nov 27, 2026
Merged

arandito merged 3 commits into
developfrom
waiters

Conversation

@arandito

Copy link
Copy Markdown
Contributor

Description

Adds wait_until_<waiter> methods to generated synchronous and asynchronous clients, implementing the design in #983. Each method polls its operation until an acceptor of the modeled waiter reports success or failure. It raises WaiterTimeoutError once max_wait_time passes.

Both code generators keep the @waitable trait in each operation's schema. The shared runtime, smithy_core.waiters.wait and smithy_core.aio.waiters.wait_async, builds the operation's waiter definitions from that trait on first use and caches them on the schema. Each attempt runs through the normal client pipeline.

This is stacked on add-error-code-to-response-metadata. errorType acceptors use its response_metadata.error_code to match errors the model doesn't define, such as EC2's.

Example

output = await client.wait_until_table_exists(table_name="orders", max_wait_time=300)

# Delays default to the waiter's, and callers can override either bound.
client.wait_until_table_exists(
    table_name="orders", max_wait_time=600, min_delay=5, max_delay=30
)

Methods return the output that matched a success acceptor. They return None when the waiter succeeds on an error. Other outcomes raise WaiterFailureError or WaiterTimeoutError.

Notes

  • max_wait_time, min_delay, and max_delay are reserved on every operation input, like stop_on_same_token. Adding a waiter to a model doesn't rename input members.
  • smithy_core._jmespath now supports comparisons, filters, &&, ||, !, literals, indexes, pipes, length(), and contains(). Every waiter path in the AWS models compiles.
  • The handwritten Java fixture gains GetItem with ItemReady and ItemDeleted waiters. The Python features fixture gains GetNote with NoteSaved and NoteDeleted waiters.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@arandito
arandito added this pull request to stack #992 November 25, 2026 11:54
@arandito arandito changed the title Implement modeled waiters Add generated waiters Nov 25, 2026
@arandito arandito changed the title Add generated waiters Implement modeled waiters Nov 25, 2026
@arandito
arandito marked this pull request as ready for review November 25, 2026 13:23
@arandito
arandito requested a review from a team as a code owner November 25, 2026 13:23
stobrien89
stobrien89 previously approved these changes Nov 25, 2026
Comment on lines +62 to +64
except Exception as error:
delay = state.accept(None, error)
output = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this also catches non-service errors, might be worth documenting that so callers will check last_error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documented this in the "Raises" section of the docstring.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heads up: these use :param:. #981 switches the generated clients to Google style, so whichever merges second should switch these too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated paginators and waiters to use Google style. Thanks for calling this out!

Comment on lines +121 to +132
for acceptor in self._definition.acceptors:
if acceptor.matcher.matches(self._request, output, error, self._operation):
break
else:
acceptor = None
state = (
acceptor.state
if acceptor is not None
else "failure"
if error is not None
else "retry"
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accept() checks acceptors before _retry_delay() checks the deadline. This means a slow successful request can return after max_wait_time elapses. Is this intentional?

@arandito arandito Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is intentional. The spec sets the last delay to remainingTime, so the final attempt starts at the limit and always finishes after it. Checking the deadline first would discard that response. smithy-java, smithy-rs, and smithy-ruby use the same order. This is made explicit in design/waiters.md under "Wait times and delays".

Comment on lines 286 to 291
def field(value: Any) -> Any:
if isinstance(value, dict):
return value.get(name) # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
if value is None or isinstance(value, str | int | float | list | tuple):
return None
return getattr(value, attribute, None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The waiter spec requires converting model values into JMESPath types. This returns Python values as bytes, datetime, and Decimal. Those values can miss on comparisons like is_number that accepts only int and float and stringEquals that accepts only str. Should a conversion happen before evaluating the path?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Reading model objects directly is intentional, so evaluating an expression doesn't need to convert the whole output before matching (this is important for endpoint resolution performance as well). But it means blob, timestamp, and bigDecimal values don't match the spec's data model. I checked all 1,086 output and inputOutput acceptors in the current AWS models and none of their paths reach one of these types, so no AWS waiter is affected today. A future model or a non-AWS model could still hit it.

I added a small fix that converts these values when a path reads them. Blobs become base64 strings, timestamps become epoch seconds, and bigDecimal becomes a float.

lukasdchang
lukasdchang previously approved these changes Nov 25, 2026
Base automatically changed from add-error-code-to-response-metadata to develop November 25, 2026 21:29
@arandito
arandito dismissed stale reviews from lukasdchang and stobrien89 via 870eef7 November 25, 2026 21:32
@arandito
arandito force-pushed the waiters branch 2 times, most recently from 870eef7 to 1b3141a Compare November 25, 2026 21:55
stobrien89
stobrien89 previously approved these changes Nov 25, 2026
@arandito
arandito merged commit ed27cd4 into develop Nov 27, 2026
26 of 27 checks passed
@arandito
arandito deleted the waiters branch November 30, 2026 16:05
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.

3 participants