Repository navigation
fix(client): writes whose retries run out after an uncertain attempt are unknown - #67
Merged
Merged
Conversation
…e process
The conversions between Python values and DynamoDB values, the
expression parser and the PartiQL parser recursed without a bound. A
value with thousands of nested lists or maps, one that contains itself
(`item["self"] = item`), a crafted pagination cursor, or an expression
or statement with a few thousand nested parentheses exhausted the stack
and killed the interpreter with SIGSEGV. The parsers run for AWS
clients too: update expressions and PartiQL statements are parsed on a
runtime thread (2 MiB of stack) to decide whether a retry is safe, so a
3 KB UPDATE statement crashed the process before any request was sent.
- The binding stops at DynamoDB's limit of 32 nested levels and raises
ValidationError with DynamoDB's message ("Nesting Levels have exceeded
supported limits"), before any request. That also catches cycles.
- Both parsers refuse parentheses, NOT, functions and value brackets
nested more than 100 levels deep with a ValidationException. DynamoDB
refuses redundant parentheses and allows 300 operators, so only
contrived expressions nest that deep. Parentheses are now handled
next to NOT, which keeps the large frame of the comparison parser off
the recursion: 400 levels fit in a debug build's 2 MiB stack, where
200 did before, so the limit leaves a wide margin.
Co-authored-by: Carl Oscar Aaro <[email protected]>
Co-authored-by: Carl Oscar Aaro <[email protected]>
The expression lexer reported an unexpected character with a span of one byte, so a character outside ASCII (`größe > :v`, or a non-breaking space pasted into `a = :v`) made the error message slice into the middle of it and panic. In-memory calls raised an internal error, and `_core._apply_update()` and `_core._check_expressions()` raised a PanicException, which `except Exception` does not catch. AWS clients failed the same way before sending UpdateItem, whose expression the core parses to decide whether a retry is safe. The span now covers the whole character: such expressions are syntax errors (ValidationException), and AWS clients send them to DynamoDB. Co-authored-by: Carl Oscar Aaro <[email protected]>
…ynamoDB does Review fixes for the nesting limits: - PartiQL statements longer than DynamoDB's 8,192 characters are refused (ValidationException). `a AND a AND ...` builds a nested condition tree without nesting, and dropping a 20,000-term chain overflowed the stack of a runtime thread, also for AWS clients, whose statements are parsed before sending. - The elements of a set are no level of their own, as in DynamoDB: a set inside 31 lists is valid again. Only a set in a set is converted one level deeper, so nested frozensets stay bounded. - decode_cursor() turns a RecursionError of the JSON parser (cursors nested about 20,000 levels deep, on Python 3.12 and 3.13) into "invalid cursor". Co-authored-by: Carl Oscar Aaro <[email protected]>
…cii-expressions # Conflicts: # CHANGELOG.md
…are unknown After an attempt that may have been applied (a timeout, a lost connection, a 5xx), a write whose later attempts were throttled until the attempts ran out raised the last attempt's error, a ThrottlingError or InternalServerError that says it is retryable. The repository's write ids, which settle unknown outcomes, never ran: `create()` raised ThrottlingError for an item it had stored, and the application's retry raised ItemAlreadyExistsError. A transaction that was applied raised TransactionInProgressError, and repeating it (with a new token) applied it twice. The last attempt's own uncertainty was ignored too: a 5xx on attempt 1 of an `ADD` raised WriteOutcomeUnknownError, on the last one a retryable InternalServerError. The retry loop now records every attempt that may have been applied, the last one included, and a write whose call ends without an answer that settles the outcome (a retryable error, no response) raises WriteOutcomeUnknownError. Transactions get the same rule; their later answers are settled by the token. Reads are unchanged. close() also refused the retries of calls in progress, so a write whose first attempt may have been applied raised ShutdownError. Calls in progress now finish their retries, as the core's close() documented; new calls are refused. Co-authored-by: Carl Oscar Aaro <[email protected]>
…ack/06-outcome-after-retries
…ack/06-outcome-after-retries
This comment has been minimized.
This comment has been minimized.
…escription Co-authored-by: Carl Oscar Aaro <[email protected]>
Contributor
Author
|
Stack of 5 open pull requests (from a pass over the library for bugs; #61 to #65 are merged already), merged in this order with "Squash and merge":
The findings that are not fixed here are filed as issues (see the next comment on #72). |
This was referenced Oct 30, 2026
This was referenced Oct 30, 2026
Closed
Closed
This was referenced Oct 30, 2026
Closed
Table updates: provisioned billing without index throughput, and calls while a table is changing
#87
Closed
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
The errors guide promises that after an attempt that may have been applied (a timeout, a lost connection, a 5xx), dynamoxy never reports a failure the write may have caused, and never applies a write twice. Two paths in the core's retry loop broke that promise, because they reported an error that says nothing was applied:
TransactionInProgressException) untilmax_attempts, the call raised the last attempt's error, aThrottlingErrororInternalServerErrorwith.retryable == True. The repository's write ids, which settle unknown outcomes, only run onWriteOutcomeUnknownError, so they never ran. Effects:create()raisedThrottlingErrorfor an item it had stored, and the application's retry then raisedItemAlreadyExistsErrorfor its own item.TransactionInProgressError. Repeating it, which comes with a new token, applied it twice (anADD balance :dtook the amount twice).WriteOutcomeUnknownError, but on the last attempt (or withRetryPolicy.none()) a retryableInternalServerError.close()during a retry. The loop refused every further attempt once the client was closed, so a write whose first attempt may have been applied raisedShutdownErrorwhile its item was stored. The core'sclose()documents "calls in progress finish".The loop now records every attempt that may have been applied, the last one included. A write whose call ends without an answer that settles the outcome now raises
WriteOutcomeUnknownError(not retryable): a retryable error, no response, or credentials or a request that failed before sending. That covers item writes, PartiQL writes and transactions; a transaction's later answers are otherwise settled by its token. Model writes then settle it by their write id: thecreate()above succeeds. Reads and batch writes, which have no outcome to lose, raise the last error as before. Calls in progress finish their retries afterclose(); new calls are still refused.Verified with new Rust tests on paused time and new Python integration tests with injected faults: a lost response followed by throttling, for puts (model and dict-level), transactions and increments; a 5xx on the last and only attempt; reads; and
close()during a retry. The tests fail without the change. Also with the whole Rust and Python suites, clippy, ruff, pyrefly and the consistency checks.Breaking change
A write that fails after an attempt that may have been applied raises
WriteOutcomeUnknownError(aTransportError, not retryable) where it raisedThrottlingError,InternalServerError,ServiceErroror a retryableTransportError. Code that caught those for writes should catchWriteOutcomeUnknownError(orTransportError), read the item, and repeat only writes that apply once. WithRetryPolicy(retry_timeouts=False), a timeout still raisesTransportError, as documented.Checklist
AGENT_GUIDE.md, architecture, docstrings, changelog)make checkpasses locally (lint, types, clippy, consistency, Rust and Python tests)!: it fixes documented behaviour)Worth confirming
close(), as the core's docstring said, rather than stopping and raisingWriteOutcomeUnknownErrorfor writes that may have been applied. A call can then outliveclose()by up to its remaining attempts.RetryPolicy.none()(one attempt), so model writes settle it by their write id with a consistent read. Before, it raised the attempt's own retryable error.BatchWriteItem) keep raising the last error: they have no conditions and return nothing of their items, so a repeat is safe.fctl session
Note
Medium risk. It changes the retry loop that every call to DynamoDB goes through, and the error a failed write raises, which application code may handle, though only when retries run out or
close()is called during a call.What it does. A write whose retries ran out after an attempt that may have been applied (a timeout, a lost connection or a 5xx) used to raise the last attempt's retryable error, such as
ThrottlingError, so the write ids could not settle it and a repeat could apply the write twice. Such writes now raiseWriteOutcomeUnknownError, which model writes settle by their write id, while reads still raise the last error. Transactions and PartiQL transactions now use the same path, andclose()no longer cuts short the retries of calls already in progress. Docs, changelog and tests cover the new behavior; the latest commit only rewraps a paragraph of the errors guide.Changed error type. Code that caught
ThrottlingErrororInternalServerErrorfrom a write that ran out of attempts now getsWriteOutcomeUnknownError, which is not.retryable.fctl review's first look at
851d0f5· 10 files, +227 −35 · Review agent settings