Skip to content

[MOD-14074] Shard-level FAIL timeout for FT.HYBRID - #8657

Merged
lerman25 merged 16 commits into
masterfrom
omerl-hybrid-shard-fail
Mar 25, 2026
Merged

lerman25 merged 16 commits into
masterfrom
omerl-hybrid-shard-fail

Conversation

@lerman25

@lerman25 lerman25 commented Mar 10, 2026 •

Copy link
Copy Markdown
Collaborator

Describe the changes in the pull request

Current: FT.HYBRID queries with ON_TIMEOUT fail policy do not properly handle timeouts at the shard level when running with background workers.

Change: Implements shard-level fail timeout policy for Hybrid Search by adding timeout/reply callbacks to HybridRequest similar to the pattern used in #8609 (coordinator level) and #8420 (shard level for Search/Aggregate). Key changes include:

  • Added HybridQueryTimeoutFailCallback and HybridQueryReplyCallback for standalone mode
  • Added HybridQueryCursorReplyCallback for internal (_FT.HYBRID) cursor replies
  • Stored cursors array in HybridRequest for reply callback path
  • Added debug pause hooks for testing timeout during cursor storage

Outcome: FT.HYBRID queries respect ON_TIMEOUT fail policy at the shard level, returning a timeout error instead of hanging when timeouts occur during multi-threaded execution.

Which additional issues this PR fixes

  1. MOD-14074

Main objects this PR modified

  1. src/hybrid/hybrid_exec.c - Added timeout/reply callbacks and cursor storage logic
  2. src/hybrid/hybrid_request.h - Added cursors array field to HybridRequest
  3. src/info/info_redis/block_client.c/h - Generified BlockClientCtx for reuse
  4. tests/pytests/test_blocked_client_timeout.py - Added FT.HYBRID timeout tests

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

Release Notes

  • This PR requires release notes
  • This PR does not require release notes

Note

Medium Risk
Touches blocked-client timeout/reply callback wiring and cross-thread cleanup for FT.HYBRID, which is concurrency-sensitive and could cause leaks or double-frees if wrong. Test coverage is expanded but failures would affect query execution under timeout conditions.

Overview
Implements shard-level ON_TIMEOUT fail handling for FT.HYBRID when running in background workers by adding dedicated timeout/reply callbacks and synchronizing cursor creation/cleanup via a new HybridRequest cursor mutex + stored cursor list.

Generalizes blocked-client setup by replacing BlockQueryClientWithTimeout’s AREQ-specific signature with a BlockClientCtx (privdata + callbacks + AST + free hook), updating search/aggregate and hybrid callers accordingly. Adds ENABLE_ASSERT-only debug commands to pause before/after hybrid cursor storage to deterministically test timeout races, and extends pytest coverage to include FT.HYBRID shard timeout and new cursor-storage pause scenarios.

Written by Cursor Bugbot for commit ca439a6. This will update automatically on new commits. Configure here.

@lerman25
lerman25 changed the base branch from master to omerl-move-reply-to-callback March 10, 2026 16:43
@jit-ci

jit-ci Bot commented Mar 10, 2026 •

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

@lerman25 lerman25 added the enforce:sanitize Run sanitizer flow even on draft pull request label Mar 10, 2026
@lerman25 lerman25 changed the title Omerl hybrid shard fail [MOD-14074] Shard-level FAIL timeout for FT.HYBRID Mar 10, 2026
@lerman25
lerman25 force-pushed the omerl-hybrid-shard-fail branch from 3b9e23e to 8b60161 Compare March 11, 2026 09:22
Base automatically changed from omerl-move-reply-to-callback to master March 11, 2026 11:43
@lerman25
lerman25 force-pushed the omerl-hybrid-shard-fail branch from 8b60161 to ee38fe4 Compare March 11, 2026 12:25
@lerman25
lerman25 marked this pull request as ready for review March 11, 2026 19:25
Comment thread src/hybrid/hybrid_exec.c
replyWithCursors(ctx, req->cursors);
array_free(req->cursors);
req->cursors = NULL;
return REDISMODULE_OK;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reply callback crashes on NULL cursors after timeout

High Severity

HybridQueryCursorReplyCallback accesses req->cursors without checking for NULL or whether timeout already occurred. If HybridQueryTimeoutFailCallback fires first on the main thread (freeing cursors and setting req->cursors = NULL), and then the reply callback fires after UnblockClient is called by the background thread, replyWithCursors will call array_len(NULL) which dereferences an invalid negative-offset pointer, causing a segfault. A timedOut or NULL-cursors guard is needed before the replyWithCursors call.

Additional Locations (1)
Fix in Cursor Fix in Web

@codecov

codecov Bot commented Mar 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.95918% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.70%. Comparing base (44a6d48) to head (ca439a6).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
src/hybrid/hybrid_exec.c 67.28% 35 Missing ⚠️
src/debug_commands.c 80.32% 12 Missing ⚠️
src/coord/hybrid/dist_hybrid.c 0.00% 4 Missing ⚠️
src/aggregate/aggregate_exec.c 84.61% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8657      +/-   ##
==========================================
+ Coverage   81.65%   81.70%   +0.05%     
==========================================
  Files         463      463              
  Lines       63375    63567     +192     
  Branches    20787    20785       -2     
==========================================
+ Hits        51747    51938     +191     
- Misses      11417    11419       +2     
+ Partials      211      210       -1     
Flag Coverage Δ
flow 83.65% <72.95%> (+0.02%) ⬆️
unit 50.57% <1.53%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/hybrid/hybrid_exec.c
if (!req->storedReplyState.hasStoredResults) {
// Background thread didn't store results - some early error occurred.
if (QueryError_HasError(&req->storedReplyState.err)) {
QueryErrorsGlobalStats_UpdateError(QueryError_GetCode(&req->storedReplyState.err), 1, COORD_ERR_WARN);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wrong error stats category in standalone reply callback

Medium Severity

HybridQueryReplyCallback uses COORD_ERR_WARN when updating error stats, but this callback is explicitly for "non-internal hybrid requests (STANDALONE)" as stated in the comment on line 822. Standalone shard-level errors need SHARD_ERR_WARN. The sibling HybridQueryCursorReplyCallback (line 809) and HybridQueryTimeoutFailCallback (line 785) both correctly use SHARD_ERR_WARN. The analogous QueryReplyCallback in aggregate_exec.c uses !IsInternal(req) which evaluates to SHARD_ERR_WARN for non-internal requests.

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Standalone shards are considered as coordinator in the info metrics

Comment thread src/hybrid/hybrid_exec.c Resolved
Comment thread src/hybrid/hybrid_exec.c
HybridRequest_UnlockCursors(hreq);

// Reply with timeout error
QueryErrorsGlobalStats_UpdateError(QUERY_ERROR_CODE_TIMED_OUT, 1, SHARD_ERR_WARN);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Timeout callback uses wrong error metric for standalone mode

Medium Severity

HybridQueryTimeoutFailCallback hardcodes SHARD_ERR_WARN when reporting timeout errors, but this callback is shared between internal (shard) and standalone modes. For standalone, errors need to be classified as COORD_ERR_WARN per the documented convention ("Standalone shards are considered as coordinator in the info metrics"). The existing QueryTimeoutFailCallback in aggregate_exec.c correctly uses !IsInternal(req) to differentiate, and the PR's own HybridQueryReplyCallback correctly uses COORD_ERR_WARN for standalone. This causes timeout errors in standalone FT.HYBRID to be misattributed to shard-level metrics instead of coordinator-level metrics.

Additional Locations (1)
Fix in Cursor Fix in Web

Comment thread src/hybrid/hybrid_exec.c Resolved
Comment thread src/hybrid/hybrid_exec.c Resolved
@lerman25
lerman25 force-pushed the omerl-hybrid-shard-fail branch from 0c81b7d to 0eccfc3 Compare March 13, 2026 01:12
@lerman25
lerman25 requested a review from nafraf March 17, 2026 13:01
Comment thread src/hybrid/hybrid_exec.c Resolved
Comment thread src/hybrid/hybrid_exec.c Resolved
Comment thread src/hybrid/hybrid_exec.c Resolved
@lerman25
lerman25 requested a review from nafraf March 25, 2026 10:09

@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.

There are 4 total unresolved issues (including 3 from previous reviews).

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.

Comment thread src/hybrid/hybrid_exec.c Resolved
@lerman25
lerman25 force-pushed the omerl-hybrid-shard-fail branch from 3688d0b to 3bda58f Compare March 25, 2026 15:53
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
8.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@lerman25
lerman25 enabled auto-merge March 25, 2026 17:12
@lerman25
lerman25 added this pull request to the merge queue Mar 25, 2026
Merged via the queue into master with commit cff9108 Mar 25, 2026
48 of 50 checks passed
@lerman25
lerman25 deleted the omerl-hybrid-shard-fail branch March 25, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enforce:sanitize Run sanitizer flow even on draft pull request size:L size:M size:XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants