Skip to content

fix(client): writes whose retries run out after an uncertain attempt are unknown - #67

Merged
kalaspuff merged 9 commits into
mainfrom
fixes-stack/06-outcome-after-retries
Oct 30, 2026
Merged

kalaspuff merged 9 commits into
mainfrom
fixes-stack/06-outcome-after-retries

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Retries ran out. When the later attempts were throttled (or got conflicts, 5xx, TransactionInProgressException) until max_attempts, the call raised the last attempt's error, a ThrottlingError or InternalServerError with .retryable == True. The repository's write ids, which settle unknown outcomes, only run on WriteOutcomeUnknownError, so they never ran. Effects:
    • create() raised ThrottlingError for an item it had stored, and the application's retry then raised ItemAlreadyExistsError for its own item.
    • A transaction that was applied raised TransactionInProgressError. Repeating it, which comes with a new token, applied it twice (an ADD balance :d took the amount twice).
    • The last attempt's own uncertainty was ignored: a 5xx on attempt 1 of an increment raised WriteOutcomeUnknownError, but on the last attempt (or with RetryPolicy.none()) a retryable InternalServerError.
  • 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 raised ShutdownError while its item was stored. The core's close() 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: the create() above succeeds. Reads and batch writes, which have no outcome to lose, raise the last error as before. Calls in progress finish their retries after close(); 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 (a TransportError, not retryable) where it raised ThrottlingError, InternalServerError, ServiceError or a retryable TransportError. Code that caught those for writes should catch WriteOutcomeUnknownError (or TransportError), read the item, and repeat only writes that apply once. With RetryPolicy(retry_timeouts=False), a timeout still raises TransportError, as documented.

Checklist

  • Tests cover the change (Rust client tests, Python integration tests with injected faults)
  • Docs updated (errors guide and reference, AGENT_GUIDE.md, architecture, docstrings, changelog)
  • make check passes locally (lint, types, clippy, consistency, Rust and Python tests)
  • Breaking change? Explained above (the title has no !: it fixes documented behaviour)

Worth confirming

  • Decision: calls in progress finish their retries after close(), as the core's docstring said, rather than stopping and raising WriteOutcomeUnknownError for writes that may have been applied. A call can then outlive close() by up to its remaining attempts.
  • Decision: a write whose only or last attempt timed out or got a 5xx is an unknown outcome too, also with 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.
  • Decision: batch writes (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 raise WriteOutcomeUnknownError, which model writes settle by their write id, while reads still raise the last error. Transactions and PartiQL transactions now use the same path, and close() 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 ThrottlingError or InternalServerError from a write that ran out of attempts now gets WriteOutcomeUnknownError, which is not .retryable.

fctl review's first look at 851d0f5 · 10 files, +227 −35 · Review agent settings

fctl-sh Bot and others added 6 commits October 30, 2026 22:17
…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]>
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]>
…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]>
Base automatically changed from fixes-stack/05-non-ascii-expressions to main October 30, 2026 21:28
@fctl-review

This comment has been minimized.

Comment thread docs/guides/errors-and-retries.md Resolved
@kalaspuff
kalaspuff added this pull request to stack #71 October 30, 2026 21:37
@fctl-sh

fctl-sh Bot commented Oct 30, 2026

Copy link
Copy Markdown
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":

  1. fix(client): writes whose retries run out after an uncertain attempt are unknown #67 fix(client): writes whose retries run out after an uncertain attempt are unknown ← this pull request
  2. fix(repository): items stored before the model had a version can be saved #68 fix(repository): items stored before the model had a version can be saved
  3. fix(models): members of mixin enums are the plain values of str and int fields #69 fix(models): members of mixin enums are the plain values of str and int fields
  4. fix(query): requests of growing reads ask for at most a page's worth of items #70 fix(query): requests of growing reads ask for at most a page's worth of items
  5. fix(errors): errors pickle, so they cross process boundaries #72 fix(errors): errors pickle, so they cross process boundaries

The findings that are not fixed here are filed as issues (see the next comment on #72).

@kalaspuff
kalaspuff merged commit 74554c8 into main Oct 30, 2026
22 checks passed
@kalaspuff
kalaspuff deleted the fixes-stack/06-outcome-after-retries branch October 30, 2026 21:40
This was referenced Oct 30, 2026
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.

1 participant