Skip to content

fix(resp3): accept push frames; count nil _ as miss in arbitrary command tracking - #435

Merged
fcostaoliveira merged 5 commits into
masterfrom
fix/resp3-push-and-nil-miss-tracking
Jun 2, 2026
Merged

fcostaoliveira merged 5 commits into
masterfrom
fix/resp3-push-and-nil-miss-tracking

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Jun 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Two RESP3 correctness bugs surfaced by the 2.4 readiness review (findings #25 and #27). This PR is targeted at milestone 2.4.

Bug #27 — RESP3 push type > silently dropped the connection

aggregate_type() in protocol.cpp accepted % (map), ~ (set), and | (attribute) for RESP3, but not > (push). When a Redis 7+ server emitted a server-pushed message (pubsub, keyspace notifications, client-tracking invalidation) on a --protocol=resp3 connection, the parser hit the "unsupported response" path and returned -1, dropping the connection.

Fix: Added > to aggregate_type(). Push frames are structurally identical to arrays (>N\r\n + N elements) so they are parsed and drained inline. A TODO is left for future out-of-band routing.

The existing fixture tests/fixtures/resp_payloads/resp3_push_unsolicited.bin (>2\r\n+pubsub\r\n+msg\r\n+OK\r\n) and test test_resp3_push_unsolicited in tests/test_resp_response_fuzzer.py already covered this case and will now pass.

Bug #25 — RESP3 nil _\r\n miscounted as hit in arbitrary-command miss tracking

Two miss-tracking sentinels in client.cpp only recognised RESP2 nil shapes:

  • SingleNullBulk handler (line ~801): checked $-1, *-1, *0 — but not RESP3 nil _. The RESP3 nil is parsed via single_type and stored verbatim as the status string "_", so it was classified as a hit.

  • ArrayPerElementNulls walker (line ~856): checked bel->value != NULL to detect a hit. RESP3 nil inside an mbulk is stored as a bulk_el with value=strdup("_") (non-NULL), so it was also classified as a hit.

Both paths silently understated the miss rate and suppressed --miss-rate-threshold warnings when running against RESP3 connections.

Fix:

  • Added "_" to the SingleNullBulk sentinel set.
  • Added a value_len==1 && value[0]=='_' check in the ArrayPerElementNulls walker.

New test: test_arbitrary_get_resp3_nil_counted_as_miss in tests/test_arbitrary_command_misses.py runs GET __key__ --protocol=resp3 against pre-populated keys and asserts Total Misses > 0. Gated by HELLO 3 capability detection so it skips cleanly on Redis < 6.

Test plan

  • test_resp3_push_unsolicited (existing, tests/test_resp_response_fuzzer.py) — was a confirmed bug, now passes with the aggregate_type() fix
  • test_arbitrary_get_resp3_nil_counted_as_miss (new, tests/test_arbitrary_command_misses.py) — asserts misses > 0 under --protocol=resp3; skips on Redis < 6
  • All existing test_arbitrary_command_misses.py tests continue to pass (no regression in RESP2 nil handling)
  • All existing test_resp_response_fuzzer.py fixtures continue to pass

🤖 Generated with Claude Code


Note

Medium Risk
Changes core RESP3 parsing and per-key miss accounting on live benchmark connections; incorrect push or null handling could skew stats or affect long-running RESP3 workloads, though scope is limited and covered by new tests.

Overview
This PR hardens RESP3 handling in the Redis protocol parser and in arbitrary-command miss tracking when --protocol=resp3 is used.

Push frames (>): The parser now treats RESP3 push aggregates like other aggregates instead of failing as unsupported. While a push is active, it drains the frame (advancing the read buffer) without writing status, mbulk trees, values, or hit counts into the in-flight command reply—so pubsub/keyspace/tracking pushes no longer tear down the connection or masquerade as command replies. A TODO remains for routing pushes to an out-of-band listener.

RESP3 null (_) in miss stats: SingleNullBulk miss detection now treats status "_" as a miss alongside $-1, *-1, and *0. For array walks, bulk_el::is_resp3_null is set only when the null type is parsed via single_type, so a real bulk string whose payload is a single _ is still counted as a hit.

Tests: Integration tests run GET under RESP3 (skipped when HELLO 3 is unavailable) to assert nil misses are recorded and literal "_" values are not.

Reviewed by Cursor Bugbot for commit 9183f52. Bugbot is set up for automated code reviews on this repo. Configure here.

…and tracking

Two RESP3 correctness bugs surfaced by the 2.4 readiness review.

#27: aggregate_type() lacked '>'. A server-pushed message (pubsub,
keyspace notifications, client tracking invalidation) on a RESP3
connection hit the "unsupported response" path and dropped the
connection. Now accepts and drains push frames inline.

#25: SingleNullBulk and ArrayPerElementNulls miss sentinels only
recognised RESP2 nil shapes ($-1/*-1/*0). RESP3 nil (_\r\n) was
miscounted as a hit, silently understating miss rate and
suppressing --miss-rate-threshold warnings.

Refs: 2.4 review findings #25 + #27

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@jit-ci

jit-ci Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

Comment thread client.cpp Resolved
… "_"

Bugbot flagged that the ArrayPerElementNulls walker used a content
heuristic (value_len==1 && value[0]=='_') that couldn't tell a
RESP3 null parsed via single_type from a real bulk value of literal
"_" parsed via blob_type. Both produce identical bulk_el.

Added bulk_el::is_resp3_null flag, set only when single_type
constructs the element for type byte '_'. Walker now reads the flag
directly instead of inferring from content. Test added that stores
"_" values and asserts they are NOT counted as misses.

Refs: bugbot LOW on PR #435

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Bugbot LOW addressed in f7cf37f: bulk_el now carries an is_resp3_null flag set at construction by single_type, replacing the content heuristic. Added test that stores literal "_" values and asserts they count as hits, not misses.

Reviewer caught that the prior commit accepted RESP3 push (>) into
aggregate_type() but didn't suppress its effect on m_last_response.
The push frame fully parsed AS a reply, response_ended() returned 1,
and memtier dequeued the push as the reply to the next in-flight
command -- corrupting latency attribution + hit/miss accounting.

Adds an m_push drain-mode flag:
- Set when a push aggregate is encountered at top level
- Suppresses every mutation to m_last_response while true
- Cleared in response_ended(), which returns false so the parser
  continues to read the actual reply
- Reset on rs_initial transition

Refs: 2.4 review of PR #435 (R1 CRITICAL).
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Review R1 (CRITICAL) addressed in cc0cdd7: added m_push drain-mode flag so push frames are read+discarded without mutating m_last_response. response_ended() now returns false on push completion so the parser keeps reading the actual reply.

Comment thread protocol.cpp Resolved
Bugbot caught that response_ended()'s m_push drain returned false
without resetting m_response_len. The accumulated push frame bytes
stayed in the counter and contaminated set_total_len() for the
actual reply, skewing bandwidth and per-op size statistics.

Resetting m_response_len to 0 at the push-drain-complete site
matches the behaviour at rs_initial (the only other site where
m_response_len is reset).

Refs: bugbot LOW on PR #435 (follow-up).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Bugbot LOW (push frame inflates reply size) addressed in d26f4dd: m_response_len is now reset to 0 when response_ended() clears m_push, so push bytes don't accumulate into the next reply's stats.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d26f4dd. Configure here.

Comment thread protocol.cpp Resolved
…ded()

Bugbot caught that if an attribute (|) appears nested inside a push
frame (>), and both complete at the same response_ended() call,
the m_attribute branch fired first and returned false, leaving
m_push set. The parser then consumed the actual command reply as
push-drain data, desynchronizing the connection.

response_ended() now clears whichever flags are set in a single
call and returns false if either was set.

Refs: bugbot LOW on PR #435 (follow-up).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Bugbot LOW (attribute-in-push) addressed in 9183f52: response_ended() now clears both m_push and m_attribute together when both reach completion at the same time.

@fcostaoliveira
fcostaoliveira merged commit 2f5d953 into master Jun 2, 2026
86 checks passed
fcostaoliveira added a commit to filipecosta90/memtier_benchmark that referenced this pull request Jun 2, 2026
Resolve conflicts after redis#432/redis#434/redis#435 landed on master.

Conflict in memtier_benchmark.cpp: adopt master's "must be a positive
integer" wording (standardized by redis#432) for the four negative-value
guard fprintf() calls added by this branch; both sides trigger on the
same code path and the test assertions only check the prefix, so either
wording is functionally correct.
fcostaoliveira added a commit that referenced this pull request Oct 25, 2026
…862)

test_arbitrary_get_resp3_nil_counted_as_miss and
test_arbitrary_get_resp3_literal_underscore_not_counted_as_miss always
skipped. Their local HELLO 3 probe ran on RLTest's protocol=2 client, where
redis-py's RESP2 parser raises InvalidResponse on the RESP3 map reply, and
a bare except turned that into a skip. RLTest counts skips as passes, so
the RESP3 nil-as-miss handling from #435 never ran in CI.

Use the shared server_supports_resp3(), which reads INFO server, and drop
its catch-all so a probe that cannot decide fails the test instead of
skipping it. Only servers older than Redis 6 skip.

Both tests use GET, which never reaches the ArrayPerElementNulls /
bulk_el::is_resp3_null path, so add an MGET resp3 test with a fixed key
layout (a value, a literal "_", two missing keys) that asserts the exact
hit/miss split and the per-position counts.

Fixes #861

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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