Repository navigation
fix(streams): DescribeStream refuses a Limit below 1 or above 100 - #633
LeeroyHannigan wants to merge 8 commits into
Conversation
The handler validates Limit before storage is reached. The backends index
the shard list at Limit minus one, so a Limit of 0 was an integer underflow
in the request task.
The range, 1 to 100, is the one the DescribeStream API Reference gives, and
the constant cites it. The two refusals carry the messages the service sent
on 2026-10-22 in us-east-1, for DescribeStream on an existing stream with
the SDK's parameter validation off so the requests reached the service:
Limit 0 and Limit -1:
400 {"__type":"com.amazon.coral.validate#ValidationException","message":"1 validation error detected: Value at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1"}
Limit 101 and Limit 1000:
400 {"__type":"com.amazon.coral.validate#ValidationException","message":"One or more parameter values were invalid: Limit cannot be greater than the maximum: 100"}
The test module quotes both responses. The handler refuses the Limit before
it looks the stream up. The service's order for a bad Limit on a missing
stream is unmeasured, because the measurement ran on an existing stream
only, and the test comment says so.
The stream handler tests run over a storage double that counts
describe_stream calls: Limit 0, -3, 101 and 1000 are refused with these
messages and never reach storage, while Limit 1 and Limit 100 reach it.
crates/engine/src/streams.rs keeps the unit tests in streams_tests.rs from main and the test_storage and describe_limit_tests modules from this branch.
…ite test context The tests ran on a storage double in crates/engine/src/streams/test_storage.rs that implemented every storage trait. Main changed those traits after this branch was cut, so the double no longer compiled. The crate already builds an OperationContext on an in-memory SQLite engine for its unit tests, in crates/engine/src/partiql/test_context.rs. The tests now use that context, and this commit deletes the double. partiql::test_context and its context function become pub(crate) so the streams tests can reach them. The context's database holds no stream. A refused Limit still carries its measured message, which shows the check ran before storage. For Limit 1 and Limit 100 the test asserts that neither Limit message comes back, in place of counting the storage calls. No helper in the crate opens a migrated in-memory engine, so there is no stream to describe, and the module doc says so.
…aint()
Main added the constraint() helper to crates/engine/src/streams.rs. ListStreams and GetRecords use it for the same Limit sentence that this branch wrote out in full for DescribeStream.
handle_describe_stream now calls constraint("limit", "have value greater than or equal to 1"). The message text does not change, and the DescribeStream Limit tests still assert the measured sentence.
demohan
left a comment
There was a problem hiding this comment.
On an existing stream both refusals match the service byte for byte, com.amazon.coral.validate#ValidationException and the lowercase message key included, for Limit 0, -1, -3 and ±2^31, and for 101, 1000, 2^31-1, 2^31 and i64::MAX. Limit 1, 2 and 100, an absent Limit and a null Limit answer as the service does. Each of 71 shapes went twice to the Streams endpoint in us-east-1 and to SQLite and PostgreSQL builds of this head and main 3534c9e; the two backends answer alike, and all four go through this handler and stream_lineage::describe_stream. The PartiQL edits widen two test-only items under #[cfg(test)], and six PartiQL statements answer the same on head and main.
fmt, clippy and the 1.88 MSRV check are clean on the engine crate, 869 tests pass at head and 892 on head merged with main (which merges cleanly), and six negative controls fail as expected. CI is green on 58 checks, from a run on 2026-11-14 with main now 38 commits ahead.
I will approve once the upper bound is checked after the lookup and the two errors combine as below.
crates/engine/src/streams.rs:37
Limit 0 with a short ExclusiveStartShardId answers one combined message on the service: 2 validation errors detected: Value at 'exclusiveStartShardId' ... greater than or equal to 28; Value at 'limit' ... greater than or equal to 1. This head, like main, answers the shard id error alone. A 78-character shard id is refused on the service with less than or equal to 65, alone with Limit 101 and combined with Limit 0; this head has no upper length check, so it answers the Limit sentence for 101 and the limit error alone for 0. Main's validation_errors_detected and clause(), which GetShardIterator uses, would join them.
| "have value greater than or equal to 1", | ||
| ))); | ||
| } | ||
| if limit > DESCRIBE_STREAM_LIMIT_MAX { |
There was a problem hiding this comment.
The service checks the two bounds at different points: it refuses a Limit below 1 before it looks the stream up, and a Limit above 100 after. With Limit 101 and a well-formed ARN for a stream that does not exist, the service and main both answer 400 ResourceNotFoundException Requested resource not found: Stream: <arn> not found, main's body byte-equal to the service's. This head answers ValidationException ... Limit cannot be greater than the maximum: 100. The same holds for an existing table with a wrong stream label and with a valid ExclusiveStartShardId added, four samples per shape. Limit 0 on a missing stream answers ValidationException on the service and here, so the lower bound is in the right place. Moving this check below the describe_stream call would match; describe_limit_tests.rs:55 asserts the current order, and its module doc (:23) notes the order was not measured.
There was a problem hiding this comment.
Fixed in eaba19c. The handler checks the upper bound after describe_stream answers, so Limit 101 on a stream that does not exist gets ResourceNotFoundException, as on main. The lower bound stays before the lookup.
The test table has the rows: Limit 1, 101 and 1000 on the missing stream, and Limit 101 with a 36-character ExclusiveStartShardId. Each asserts the full ResourceNotFoundException message. On the previous handler the table fails at the Limit 101 row.
| use extenddb_core::error::DynamoDbError; | ||
|
|
||
| use super::handle_describe_stream; | ||
| use crate::partiql::test_context::context; |
There was a problem hiding this comment.
The new tests do not compile without the engine's partiql feature: cargo test -p extenddb-engine --no-default-features --lib --no-run fails with E0433 on this import, and exits 0 with the new module removed. CI does not build that configuration.
There was a problem hiding this comment.
Fixed in 0c97f41. streams.rs declares the module under cfg(all(test, feature = "partiql")). cargo test -p extenddb-engine --no-default-features --lib --no-run builds with the gate and fails with E0433 without it.
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn describe_stream_passes_limits_1_and_100() { |
There was a problem hiding this comment.
In this context a request that reaches storage answers InternalServerError, because the in-memory database is not migrated, so the test passes on a 500 and checks only that neither Limit sentence comes back. Asserting ResourceNotFoundException for the missing stream would check the answer.
There was a problem hiding this comment.
Fixed in eaba19c. The test runs on the engine's test context over SqliteEngine::new_in_memory, which migrates the database, with a table Orders that has a stream. The rows on the missing stream assert the full ResourceNotFoundException message. Limit 1 and Limit 100 on the existing stream assert the StreamArn in the description.
…am lookup
The service checks the two Limit bounds at different points. It refuses a
Limit below 1 before it looks the stream up, in one message with the other
member constraints. It refuses a Limit above 100 only after it has found the
stream. Measured 2026-11-25 in us-east-1, each request twice, on a stream of
a table that does not exist. Limit 1, 101 and 1000 got
ResourceNotFoundException "Requested resource not found: Stream: <arn> not
found", and so did Limit 101 with a 36-character ExclusiveStartShardId.
Limit 0 and -1 got the below-one ValidationException. Limit 0 with a
13-character ExclusiveStartShardId got both clauses in one message:
400 {"__type":"com.amazon.coral.validate#ValidationException","message":"2 validation errors detected: Value at 'exclusiveStartShardId' failed to satisfy constraint: Member must have length greater than or equal to 28; Value at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1"}
Limit 101 with that 13-character id got the ExclusiveStartShardId clause
alone.
handle_describe_stream now collects the ExclusiveStartShardId clause and the
below-one Limit clause in one list, through main's clause() and
validation_errors_detected(). When the list is not empty, it refuses before
the lookup. It checks the upper bound once describe_stream has answered.
Main's lookup answers ResourceNotFoundException for a missing stream, so
main's answer to Limit 101 on a missing stream stays.
The test module runs the handler on the engine's test context over
SqliteEngine::new_in_memory, which migrates the database, with a table
Orders that has a stream. One table of 14 rows asserts each answer by
equality. The refusals carry their full messages. The missing stream gets
the ResourceNotFoundException message. Limit 1 and Limit 100 on the
existing stream get the StreamArn echoed.
Two earlier messages on this branch no longer describe the code. The first
commit says the tests run over a storage double that counts describe_stream
calls, and that Limit 101 and 1000 never reach storage. e41b5c6 deleted the
double, and with this commit Limit 101 and 1000 reach storage and are
refused after the lookup.
…tiql feature The test module imports partiql::test_context::context, and crates/engine/src/lib.rs declares the partiql module under the partiql feature. With cargo test -p extenddb-engine --no-default-features --lib --no-run the module did not compile: E0433, cannot find partiql in crate. CI builds the engine's tests with default features only, so no job showed it. The module is now declared under cfg(all(test, feature = "partiql")), like the partiql module it reads from. The same command exits 0 with the gate.
|
Fixed in eaba19c. The handler collects the The 65-character maximum is not checked on main either. #1480 tracks it with the measured bodies. |
The WebAssembly parity corpus sends DescribeStream with Limit 4294967297 to a table's stream and expected all four shards. That was the answer before this branch. The branch refuses a Limit above 100 once it has found the stream, as the service does for 101 and 1000. The case now expects that refusal by its message. It still catches a build that reads the Limit as 32 bits: 4294967297 is 1 there, and Limit 1 is served. On 25 Nov the service answered ResourceNotFoundException for Limit 4294967297 and for 2147483648, two sends each. The stream was one of a table that does not exist. So the service reads both values as a Limit and looks the stream up first.
demohan
left a comment
There was a problem hiding this comment.
The items from the earlier review are resolved at 4af9d30, and the 65-character ExclusiveStartShardId bound is in #1480.
- Limit 101, 1000, 2^31, 4294967297 and i64::MAX on a stream that does not exist, or on a wrong stream label, answer
ResourceNotFoundExceptionbyte-equal to the service and to main, and on an existing stream they answer the Limit sentence. Limit 0 and -1 are still refused before the lookup, as on the service. - Limit 0 or -1 with a 13-character
ExclusiveStartShardIdanswers the service's two-clause message on an existing and on a missing stream, and Limit 101 or 1 with it answers the start clause alone. 93 shapes went twice each to the Streams endpoint in us-east-1 and to SQLite and PostgreSQL builds of this head, and the two backends answer alike on all 93. - Limits above 100 now reach storage; every backend passes the Limit to the shared page function, which caps the page, and i64::MAX answers without a 500.
- The test module builds without
partiql, and the missing-stream rows assert the fullResourceNotFoundExceptionmessage on a migrated engine. Moving the upper check back above the lookup, returning the start clause alone, dropping either bound, removing the gate, or reading Limit as 32 bits each fail a test. The wasm corpus case for 4294967297 matches the service. fmt, clippy with and without default features, the 1.91.1 check and 891 engine tests are clean. The one failing CI job,wasm, fails buildingcrates/core/src/metrics/segments.rs, which this branch does not carry; it comes from main since #398.
| //! | ||
| //! On 2026-11-25, each request twice, on a stream of a table that does not | ||
| //! exist: Limit 0 and -1 got the first body above; Limit 1, 101 and 1000, and | ||
| //! Limit 101 with a 36-character `ExclusiveStartShardId`, got 400 |
There was a problem hiding this comment.
Optional. VALID_ID is 37 characters, so this line and the PR body's table say 36 for a 37-character id. The answer is the same at either length.
There was a problem hiding this comment.
Thanks, you're right. The measured id was shardId-00000001700000000000-00000000, which is 37 characters, and the body's table now says 37. The test comment stays as it is, because the answer is the same at either length.
| //! | ||
| //! On 2026-11-25, each request twice, on a stream of a table that does not | ||
| //! exist: Limit 0 and -1 got the first body above; Limit 1, 101 and 1000, and | ||
| //! Limit 101 with a 36-character `ExclusiveStartShardId`, got 400 |
There was a problem hiding this comment.
The same note as the one above, answered there: the body's table now says 37, and the test comment stays as it is.
| //! | ||
| //! On 2026-11-25, each request twice, on a stream of a table that does not | ||
| //! exist: Limit 0 and -1 got the first body above; Limit 1, 101 and 1000, and | ||
| //! Limit 101 with a 36-character `ExclusiveStartShardId`, got 400 |
There was a problem hiding this comment.
The same note as the one above, answered there: the body's table now says 37, and the test comment stays as it is.
Changes since the last review
origin/maininto the branch.ExclusiveStartShardIdandLimitclauses in one message. It replaces the two tests with one 14-row table on a migrated in-memory engine.cfg(all(test, feature = "partiql")).Limit4294967297 incrates/wasm-adapter/parity/corpus.json. The case expected all four shards of the stream. It now expects the refusal of aLimitabove 100, by its message. A build that reads theLimitas 32 bits still fails the case, because 4294967297 is 1 there and Limit 1 is served.What
Amazon DynamoDB Streams refuses a DescribeStream
Limitbelow 1 or above 100 with a 400ValidationException. The DescribeStream API Reference documents a minimum value of 1 and says "The upper limit is 100". The service checks the two bounds at different points. It refuses aLimitbelow 1 before it looks the stream up, in one message with the other member constraints. It refuses aLimitabove 100 only after it finds the stream. On a stream that does not exist, that request getsResourceNotFoundException.On main,
handle_describe_streampasses the request'sLimitto storage unchanged, and no backend refuses a value. Since #515, main'scrates/storage/src/stream_lineage.rspages the shard list, and it reads aLimitbelow 1 as 1. So, from the code, Limit 0 and Limit -1 return one shard, and Limit 101 and Limit 1000 return shards. Before #515, Limit 0 panicked the request task with an integer underflow, and the client saw the connection close.This change collects the failed member constraints in
handle_describe_streambefore it calls storage. They are anExclusiveStartShardIdunder 28 characters, which main already refused alone, and aLimitbelow 1. When the list is not empty, the handler refuses with main'svalidation_errors_detected, so both clauses go in one message, as the service sends them. After storage answers, the handler refuses aLimitabove 100 with the second message.DESCRIBE_STREAM_LIMIT_MAXholds the 100 and cites the API Reference. Both refusals areValidationException, which ExtendDB already sends in thecom.amazon.coral.validate#namespace.The service also refuses an
ExclusiveStartShardIdover 65 characters, and main checks only the 28-character minimum. #1480 tracks that bound. It is not changed here.Why
Part of #621. ListStreams and GetRecords, the other two operations in #621, are not changed here.
Measurements
Measured in us-east-1 with SDK parameter validation turned off, so each value reached the service. On an existing stream, on 2026-10-22 and 2026-10-27 (#621 publishes the 2026-10-27 run):
{"__type":"com.amazon.coral.validate#ValidationException","message":"1 validation error detected: Value at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1"}{"__type":"com.amazon.coral.validate#ValidationException","message":"One or more parameter values were invalid: Limit cannot be greater than the maximum: 100"}LastEvaluatedShardIdOn 2026-11-25, each request twice, on a stream of a table that does not exist:
{"__type":"com.amazonaws.dynamodb.v20120810#ResourceNotFoundException","message":"Requested resource not found: Stream: <arn> not found"}{"__type":"com.amazon.coral.validate#ValidationException","message":"2 validation errors detected: Value at 'exclusiveStartShardId' failed to satisfy constraint: Member must have length greater than or equal to 28; Value at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1"}{"__type":"com.amazon.coral.validate#ValidationException","message":"1 validation error detected: Value at 'exclusiveStartShardId' failed to satisfy constraint: Member must have length greater than or equal to 28"}Not measured:
Limitwith anExclusiveStartShardIdunder 28 characters on an existing stream. Both checks run before the lookup, so the handler answers as it does for the missing stream.Testing done
The tests are in
crates/engine/src/streams/describe_limit_tests.rs. The module runs the handler on the engine's test context overSqliteEngine::new_in_memory, which migrates the in-memory database, and creates the tableOrderswith a stream. One table of 14 rows asserts each answer by equality. The refusals carry their full messages. The stream that does not exist gets theResourceNotFoundExceptionmessage. Limit 1 and Limit 100 on the existing stream get theStreamArnechoed.streams.rsdeclares the module undercfg(all(test, feature = "partiql")), because it importspartiql::test_context::context.cargo test -p extenddb-engine --lib: 891 passed.Limitabove 100 before the lookup, fails at the row Limit 101 on the missing stream. It getsValidationExceptionin place ofResourceNotFoundException.cargo test -p extenddb-engine --no-default-features --lib --no-runbuilds. With the plaincfg(test)gate it fails with E0433.cargo test --locked -p extenddb-wasm-adapter --test paritypasses at 4af9d30. Thewasmjob on 0c97f41 failed at the DescribeStream case withLimit4294967297, which expected four shards.cargo fmt --all -- --check,cargo clippy -p extenddb-engine --all-targets -- -D warningsandcargo +1.91.1 check -p extenddb-engine --all-targetsare clean.Limit, so none changed.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, or public CLI surface, an RFC has been accepted or is linked
below. Otherwise, an ADR captures the decision (link below).
ADR / RFC: n/a
Breaking changes
None.
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.