Repository navigation
fix(opts): validate sampler configs (--data-size-list, --key-stddev, --key-pattern=G:G) (Refs #426 phase 3) - #430
Conversation
…--key-pattern=G:G)
Reject sampler configurations that can never produce a value at parse /
construction time instead of hanging the worker loop or tripping the
Gaussian assert:
- --data-size-list entries with weight 0: the size sampler would skip
them and (if every bucket is zero-weight) spin forever picking
nothing. Issue redis#426 item 10.
- --key-stddev must be finite and > 0: NaN compared false against the
previous "<= 0" guard, and +/-inf produced a Gaussian rejection
sampler that never satisfied its range constraint. Issue redis#426
item 15.
- --key-pattern=G requires key-maximum - key-minimum >= 2: the
Gaussian distribution asserts median > min && median < max, which
is impossible on a 1-key range. SIGABRT before the fix. Issue redis#426
item 16.
All three paths now emit a readable error and exit with code 2 (the
parser-error convention used elsewhere in memtier_benchmark.cpp).
Regression coverage in tests/test_cli_validation_sampler.py exercises
each rejection plus a healthy G:G config to guard against false
positives.
Refs redis#426
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Review: docs & commit message (haiku 4.5)
Verdict: Commits clean; DEVELOPMENT.md needs sampler validation documentation. |
|
Review: performance (haiku 4.5) verdict: parse-time sampler config validation, prevents runtime hangs ✓ • data-size-list weight validation: Iterates once at parse time over weight entries; rejects zero-weight buckets that would break the size sampler. The check is a simple equality test (it->weight == 0) per entry. Zero request-loop overhead. ✓ • key-stddev finitude check: Uses std::isfinite() at parse time to reject inf/nan inputs. The Gaussian rejection sampler would loop forever on non-finite stddev; early rejection prevents worst-case hang. Single parse-time call, zero per-request cost. ✓ • key-pattern=G range validation: Checks degenerate 1-key ranges (key_maximum - key_minimum < 2) at startup before the sampler runs. Prevents assert() in the Gaussian median calculation. One range comparison per startup. ✓ • No sampler loop changes: The rejection-sampler runs during the benchmark; by gating pathological configs at parse time, we prevent infinite loops/asserts without touching the hot-path sampler code. ✓ Summary: Pre-benchmark validation for distribution samplers. The checks (finitude, non-zero weights, range size) are single evaluations that prevent infinite loops or asserts during the benchmark run. Zero steady-state per-request overhead; actually improves latency by rejecting hang-prone configs early. |
|
Review: design & API (sonnet 4.6) Verdict: The three fixes are correct and the test coverage is solid; the placement of the G-range check (in
|
fcostaoliveira
left a comment
There was a problem hiding this comment.
Review: security (opus 4.7)
- LOAD-BEARING: the
--key-stddevfix is correct — the new!std::isfinite(cfg->key_stddev) || cfg->key_stddev <= 0chain handles NaN (which compared false to everything and slipped through the old<= 0guard),+inf, and-inf. Note:<cmath>is already included at memtier_benchmark.cpp:75, sostd::isfiniteresolves cleanly. The same NaN-slips-through-comparison anti-pattern exists for otherstrtodusers —--miss-rate-thresholdat line 1415 already has the correct guard, but a quickgrep strtodaudit (e.g.--key-stddevwas the only buggy one) confirms scope is closed. --data-size-listweight=0 reject correctly bounds the sampler-loop-forever DoS. Combined with PR #428's size=0 check, the size sampler's input domain is now fully constrained.--key-pattern=Grange check (max - min >= 2) at memtier_benchmark.cpp:3075 correctly defends the Gaussian sampler assert. The subtraction is done onunsigned long long(key_minimum/key_maximum); thecfg.key_maximum < cfg.key_minimumcheck before the subtract correctly prevents unsigned underflow. Good.- Defaults interaction:
config_init_defaultssetskey_maximum = 10000000if unset (memtier_benchmark.cpp:580), andkey_minimumdefaults to 0, so the common case stays unaffected. The validator runs after defaults are applied — verified at the call site. exit(2)here is consistent with the rest of the parser-error convention but slightly inconsistent with the-1 -> usage() -> exit(2)flow used elsewhere in argv parsing. Cosmetic.- No format-string / credential exposure. The
%llumatchesunsigned long longcleanly. No new attacker-controlled input is logged.
Verdict: LGTM. Phase-3 sampler-safety scope is correctly delivered; the NaN/inf handling for key_stddev is the kind of subtle floating-point bug that's easy to miss and this catches it cleanly.
fcostaoliveira
left a comment
There was a problem hiding this comment.
Review: correctness & latent bugs (opus 4.7)
memtier_benchmark.cpp:3068-3079G-range check is overly strict: rejects--key-minimum=1 --key-maximum=2(range 1, max-min=1, fewer than 2) as well as--key-minimum=1 --key-maximum=3(range 2, max-min=2 — accepted). For min=1/max=2 the Gaussian median 1.5 satisfiesmedian>min && median<max, so this would have worked. The current cutoff is more conservative than the actual sampler invariant. Either relax to< 1(i.e. reject only true degenerate ranges) and let the sampler invariant catch the edge cases, or keep the conservative bound and reword the error from "3 keys" to something the sampler actually demands.memtier_benchmark.cpp:3073cfg.key_maximum < cfg.key_minimumis checked first (good — avoids unsigned underflow in the subtraction) but the resulting error message conflates two cases ("max<min" and "range too small"). Two messages would be friendlier.memtier_benchmark.cpp:3070the check guards oncfg.key_pattern[set] == 'G' || cfg.key_pattern[get] == 'G'. If only the get pattern is G but--ratiois1:0(set-only), the run will never invoke the Gaussian sampler and a degenerate range would otherwise be fine. False positive in a real benchmark config. Probably acceptable trade-off for safety, but worth a note in the message ("required because ANY of set/get uses G").memtier_benchmark.cpp:1162-1174overlaps with PR #428 — both add afor (... item_list)loop in the samecase 'a':arm. Whichever lands first will leave the other PR with a non-trivial conflict; consider pre-merging the loops into a single validation pass (size==0,weight==0, plus 512MiB cap) in one of the PRs.memtier_benchmark.cpp:1225key_stddevcheck ordering:!endptr || *endptr != '\0' || !std::isfinite(...) || <= 0— ifendptr == NULLis taken, the later checks never run, so safe.strtod("nan")sets*endptr='\0', then!isfiniterejects.strtod("")setsendptr=optarg, so*endptris'\0'. That accepts empty string with stddev=0 — wait,cfg->key_stddev <= 0catches it. OK, defensible, but the empty-input case relies on the<= 0arm and not theendptr == optargarm; an explicitendptr == optargcheck would be more readable.memtier_benchmark.cpp:3078usesexit(2)directly while every other parse error in this filereturn -1s throughusage() -> exit(2). Same exit code so user-observable behavior matches, but the inconsistency means this path skipsusage()-driven cleanup if any is ever added.
Verdict: Comment
fcostaoliveira
left a comment
There was a problem hiding this comment.
Review: edge cases & failure modes (opus 4.7)
Verdict: LGTM with one scope gap on arbitrary-command per-command key patterns.
- Invocation paths: only the long-option case for
--key-stddevand--data-size-list; the G-range check runs afterconfig_init_defaults()so defaults (key_max=10_000_000) apply.parse_uridoesn't touch any of these. All paths covered. - Per-command G pattern is not checked.
cfg.arbitrary_commands->at(i).key_pattern == 'G'(e.g.--command "GET __key__" --command-key-pattern G) reaches the Gaussian sampler over the globalkey_minimum/key_maximumrange too, and would re-trigger the same SIGABRT this PR closes. The new validation only inspects the top-levelcfg.key_pattern[set]/[get]. Worth either widening the check or filing as a follow-up. - Cap boundary:
(key_maximum - key_minimum) < 2admits diff=2 (e.g. min=1, max=3 → 3 distinct keys), rejects diff=1 and diff=0. Edge:key_minimum=0(struct default, no--key-minimumgiven) +key_maximum=2→ diff=2 → admitted, which is the smallest legal range. Edge:key_minimum > key_maximumis caught explicitly. Good — but tests cover only diff=0; consider diff=1 (cap-1) and diff=2 (cap) for completeness. std::isfinitecorrectly rejects NaN, +inf, -inf since NaN compares false to everything (the old<= 0check explicitly fails on NaN).strtod("inf", ...)returns HUGE_VAL with no errno,strtod("nan", ...)returns NaN — both rejected. Good.strtodERANGE not consulted:--key-stddev=1e9999overflows to HUGE_VAL (which IS finite on glibc — it's INFINITY for typical doubles, soisfinitecatches it). Underflow1e-9999returns 0 with errno=ERANGE → caught by the<= 0check. So effectively fine, but checking errno would be tidier and consistent with #429.- G-range check uses
exit(2)directly rather thanreturn -1like the rest ofconfig_parse_args. The PR comment says "matches usage() → exit(2)" — but the rest ofconfig_parse_argsreturns -1 and the caller doesusage(); exit(2);. Here the check is inmain()(post-init_defaults), where directexit(2)is more consistent with the other post-defaults validations (e.g.--clients-start,--thread-conn-start-min-jitter-microsuseexit(1)). Mixing 1 and 2 in the same block is the smaller inconsistency — consider unifying.
fcostaoliveira
left a comment
There was a problem hiding this comment.
Review: style & readability (sonnet 4.6)
Verdict: one structural inconsistency worth addressing.
-
Gaussian key-range check is in
main()afterconfig_init_defaults()rather than inconfig_parse_args()(memtier_benchmark.cpp): every other CLI validation returns -1 fromconfig_parse_args, which then callsusage()and exits with code 2. The Gaussian check is a post-parse validation that callsexit(2)directly. The code comment says it must run afterconfig_init_defaults(because defaults fill in the key range), which is the correct reason — but this should be called out explicitly, otherwise it looks like an oversight rather than a deliberate placement. A brief "// must follow config_init_defaults(): key_minimum/maximum defaults are applied there" would make it self-documenting. -
Error message phrasing inconsistency with PR #428: the new
data-size-listweight-zero message says "weight greater than zero" (words); the size-zero message in PR #428 says "size > 0" (symbol). These two messages will appear adjacent in the samecase o_data_size_list:block after both PRs land; aligning them to the same form avoids a jarring inconsistency. -
std::isfinitecheck moves before<= 0check (memtier_benchmark.cpp,o_key_stddevcase): the reordering is correct becauseNaN <= 0is always false. The existing comment says "Reject non-finite stddev" which is what, not why. The why — that NaN's unordered comparison with<= 0yields false so the old guard didn't catch it — is the key insight worth preserving. -
Python test: all five cases use
env.skipOnCluster()(test_cli_validation_sampler.py): the skip is harmless but unnecessary for tests that reject before any network activity. A comment noting that the skip is conservative (the parser fires before connect, so cluster/standalone doesn't matter) would clarify intent. -
Commit message headline truncated (
fix(opts): validate sampler configs (--data-size-list, --key-stddev, …): suggest "fix(opts): validate sampler configs for zero-weight, non-finite stddev, G-range (#426)".
Review fix on redis#430 (correctness reviewer): the original `(max - min) < 2` cutoff rejected the perfectly valid 2-key Gaussian case (min=1, max=2). The sampler computes a default median of `(max - min)/2.0 + min + 0.5` which for that case is 1.5 -- strictly inside (1, 2), passes the `assert(median > min && median < max)`. The actual SIGABRT path was a user passing a `--key-median` that lands outside (min, max). Fix: * Reject only `max <= min` for --key-pattern=G (the truly-degenerate single-key case). * Additionally validate that any user-supplied `--key-median` lands strictly inside `(min, max)`. Default median=0 means "auto-compute" and is always safe. Refs redis#426 phase 3.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit d5b882c. Configure here.
…et flake ASAN TLS cells under CI load dropped the first connection mid- handshake on the happy-path test (3 cells failed identically with 'Connection reset by peer / Maximum reconnection attempts (0) exceeded'). Make the workload a deterministic 10-request smoke and add --reconnect-on-error so the rc==0 assertion measures the parser path that the test exists to verify, not TLS flake. Refs redis#426 phase 3.
The previous hotfix (--reconnect-on-error + --max-reconnect-attempts=5)
still relied on a successful TCP/TLS connection, but the test harness
does not inject --tls/--cert flags here, so on TLS-only CI cells
(ASAN/TSAN/UBSan TCP TLS, OSS TCP TLS v1.2/v1.3) the workload cannot
connect at all and the rc==0 assertion always tripped.
Restructure the assertion to match the test's documented purpose:
verify only that the *parser* accepts the valid G:G config. The
workload's runtime outcome is intentionally ignored.
- Assert rc != 2 (parser did not reject).
- Assert none of the Items 10/15/16 rejection diagnostics appear in
stderr.
- Bound the run with --connection-timeout=1 and
--max-reconnect-attempts=1 so a TLS-only environment can't keep the
subprocess alive past _run_memtier's 10s timeout.
Refs redis#426 phase 3.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The d5b882c relaxation of the G-range cutoff from `(max - min) < 2` to `key_maximum <= key_minimum` was based on a wrong arithmetic claim in the accompanying comment: for (min=1, max=2) the auto-computed median in gaussian_distribution_range is median = (max - min) / 2.0 + min + 0.5 = 1/2.0 + 1 + 0.5 = 2.0 so the subsequent `assert(median > min && median < max)` fires (2.0 < 2 is false) and the process SIGABRTs -- exactly the regression Item 16 was supposed to prevent. Confirmed locally: with min=1, max=2 the previous build hit the crash-handler bug-report dump. Restore the original `(max - min) < 2` cutoff (and keep the unsigned- wrap-safe explicit `key_maximum < key_minimum` clause that d5b882c added), and rewrite the comment with the correct arithmetic so the choice of cutoff is auditable. The smallest accepted range is now (max - min) == 2 (e.g. min=1, max=3 -> auto-median = 2.5). This re-tightens the parser-reject path picked up by cursor[bot] on the previous commit; the negative test `test_key_pattern_g_one_key_range_rejected` continues to pass because the new diagnostic still contains the substring `key-pattern=G`. Refs redis#426 phase 3. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Resolves the case 'o_data_size_list' overlap with PR redis#428: combine both validations into one pass over data_size_list.item_list: * size == 0 -> error: zero-size trips protocol.cpp:309 assert (item 9 from redis#426) * size > 512 MiB -> error: exceeds proto-max-bulk-len cap (PR redis#428) * weight == 0 -> error: zero-weight makes the sampler loop forever picking nothing (item 10 from redis#426, phase 3)
The prior run hit the pre-existing master flakes
`Test OSS-CLUSTER API: TCP {Plaintext,TLS}` (15-min step timeout) and
the older workflow can't be partial-reran. Empty commit to force a
fresh run.
PR redis#402 added PARALLELISM=2 to the sanitizer (ASAN/UBSan/TSAN) cluster cells because cluster bootstrap + serial RLTest pass routinely hit the workflow's 15-minute step ceiling. The regular Test workflow's OSS-CLUSTER cells were not updated at the time and have been a known master flake ever since (~3/8 master runs fail at the same 15-minute mark; deep-CI investigators on PRs redis#425 / redis#427 / redis#430 / redis#431 all confirmed the pattern). Add PARALLELISM=2 to the two affected cells: - OSS-CLUSTER API: TCP Plaintext - OSS-CLUSTER API: TCP TLS The 49/99-shard mega-cluster cells already use a single targeted test (TEST=test_rate_limited_completion_no_hang), so they're under budget without parallelism. Bundled with PR redis#430 because that PR was being blocked by exactly this flake on its final CI run.
…445) The fuzzer excluded flags/inputs (--cluster-mode against standalone, --authenticate empty, --wait-ratio, G:G degenerate, --data-size-list zero-weight/zero-size, negative count flags) because they used to crash or hang. The phase-1-3 parser fixes (#427/#428/#429/#430) plus the connection-stage-timeout supervisor (#431) now bound all of those. Removed the exclusions and wired the fuzzer into CI so it runs nightly. Also fix .githooks/pre-commit to work from linked worktrees: locate the Makefile via git-common-dir and export GIT_INDEX_FILE so that `git diff --cached` inside the Makefile rule sees the worktree-local index rather than the main worktree's index. Refs: 2.4 review #20 (Review 8 + Review 17). Co-authored-by: Claude Sonnet 4.6 <[email protected]>

Summary
Phase 3 of #426: reject sampler configurations that can never produce a
value, at parse / construction time, instead of letting them hang the
worker loop or trip the Gaussian assert (SIGABRT) at runtime.
Closes the following items from #426:
--data-size-list 8:0: a zero-weight bucket made thesize sampler skip every entry, so it spun forever picking nothing.
Now rejected with
error: data-size-list entries must have weight greater than zero.--key-pattern G:G --key-stddev inf(ornan): theGaussian rejection sampler can never satisfy
val < min || val > max + 1on a non-finite stddev. NaN also slipped through the old
<= 0guardbecause NaN compares false to everything. Now rejected with
error: key-stddev must be a finite number greater than zero.--key-pattern G:Gover a 1-key range: the Gaussianpath asserts
median > min && median < max, which is impossible whenthe range has fewer than 2 buckets (SIGABRT on master). Now rejected
with
error: key-pattern=G requires a key range spanning at least 3 keys.All three paths exit with code 2 (the parser-error convention used
elsewhere in
memtier_benchmark.cpp).Test plan
Regression coverage in
tests/test_cli_validation_sampler.py:--data-size-list=8:0-> exit 2 with weight diagnostic--key-pattern G:G --key-stddev inf-> exit 2 with finite diagnostic--key-pattern G:G --key-stddev nan-> exit 2 with finite diagnostic--key-pattern G:G --key-minimum=1 --key-maximum=1-> exit 2 with G-range diagnostic--key-pattern G:G --key-minimum=1 --key-maximum=1000 --key-stddev=100(valid) -> exit 0Manual repros from #426 confirmed fixed:
memtier_benchmark --data-size-list 8:0 --test-time=1-> no hang, exit 2memtier_benchmark --key-pattern G:G --key-stddev inf --test-time=1-> no hang, exit 2memtier_benchmark --key-pattern G:G --key-maximum 1 --test-time=1-> no SIGABRT, exit 2make format-checkclean.tests/test_mget_validation.pystill green(no regression on the adjacent validation suite).
Refs #426
Note
Low Risk
Changes are input validation and parser-only tests; no runtime benchmark logic or security-sensitive paths beyond clearer early failures.
Overview
Phase 3 of #426 hardens CLI validation so impossible sampler settings fail at parse time with exit code 2 instead of hanging workers or SIGABRT in the Gaussian path.
--data-size-listnow rejects zero-weight entries (e.g.8:0), alongside existing checks for zero size and oversize values.--key-stddevmust be a finite number > 0 (inf/nanare rejected). After defaults apply,--key-patternwithGrequires at least a 3-key span (key-maximum - key-minimum >= 2), handles inverted min/max, and enforces a user--key-medianstrictly inside(min, max).New RLTest coverage lives in
tests/test_cli_validation_sampler.py. CI setsPARALLELISM: "2"on the two OSS-cluster API matrix jobs.Reviewed by Cursor Bugbot for commit dd97270. Bugbot is set up for automated code reviews on this repo. Configure here.