Skip to content

[MOD-16989] Split RequestSyncCtx into embedded RequestSyncState and heap BlockedRequestCtx wrapper (step 0) - #10336

Merged
GuyAv46 merged 8 commits into
masterfrom
guyav-blocked-client-refactor-step0
Jul 21, 2026
Merged

GuyAv46 merged 8 commits into
masterfrom
guyav-blocked-client-refactor-step0

Conversation

@GuyAv46

@GuyAv46 GuyAv46 commented Jul 2, 2026 •

Copy link
Copy Markdown
Collaborator

Describe the changes in the pull request

Step 0 of the blocked-client / cross-thread ownership refactor designed in #9426 (refreshed there against post-RETURN_STRICT master).

  1. Current: RequestSyncCtx is embedded inside every AREQ / HybridRequest and conflates three jobs: the request's lifetime refcount, the per-request timeout signal (timedOut + abort-wake channel), and the top-level RETURN_STRICT result-production coordination (claim CAS, claim-lost flag, done-latch, safe-loader-GIL handshake).
  2. Change: split it in two, inverting containment:
    • RequestSyncState stays embedded on every request (hybrid sub-AREQs included): only timedOut + the abort-wake channel.
    • BlockedRequestCtx is a new heap-allocated wrapper that owns the top-level AREQ/HybridRequest and hosts the RETURN_STRICT coordination block verbatim. Requests reach it via a non-owning req->brc back-pointer, so all handshake call-sites keep their signatures.
    • The wrapper temporarily carries the refcount (AREQ_IncrRef/AREQ_DecrRef delegate through req->brc); it is removed in a later step when the wrapper becomes blocked-client privdata with single-owner transfer semantics.
    • Cursor-backing hybrid sub-AREQs get their own wrapper at HybridRequest_StartCursors time — a RETURN_STRICT FT.CURSOR READ on a sub-cursor runs the claim handshake against the read AREQ's wrapper, which would otherwise be NULL.
    • safeLoaderHoldingGIL becomes a counter on the wrapper: hybrid tail + subquery safe loaders now share one wrapper, and with a bool one loader's ExitGIL would erase another's "parked at the GIL gate" mark, letting the strict timeout callback deadlock in Wait.
  3. Outcome: pure refactor, no behavior change. RETURN_STRICT semantics are untouched (hosted, not redesigned — see the design's §4.3). Verified: full DEBUG build; 895/895 C/C++ unit tests; test_blocked_client_timeout.py (54/54), test_hybrid_timeout.py (30/30), test_cursors.py (28/28).

Which additional issues this PR fixes

  1. MOD-16691 (implementation; design: MOD-15430)
  2. Design: Design Refactor for the Multi-threaded Lifetime of a Query - [MOD-15430] #9426

Main objects this PR modified

  1. RequestSyncCtx → RequestSyncState (embedded) + BlockedRequestCtx (heap wrapper), src/aggregate/aggregate.h / aggregate_request.c
  2. AREQ / HybridRequest (syncCtx slimmed, brc back-pointer)
  3. RETURN_STRICT handshake call-sites (aggregate_exec.c, hybrid_exec.c, dist_aggregate.c, dist_hybrid.c, coord_request_ctx.c, rpnet.c, result_processor.c)

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

🤖 Generated with Claude Code

GuyAv46 and others added 3 commits July 2, 2026 17:39
- Rename embedded sync state from RequestSyncCtx to RequestSyncState
  (fields: timedOut, abortWakeChannel, abortWakeLock)
- Add heap-allocated RequestSyncCtx wrapper owning the top-level query
  (kind + AREQ/HybridRequest union, aggregate-results coordination
  fields, refcount)
- Add back-pointer rsc (non-owning) on AREQ and HybridRequest
- Implement RequestSyncCtx_NewAREQ / RequestSyncCtx_NewHybrid /
  RequestSyncCtx_Free constructors/destructor
- Add RequestSyncCtx_IncrRef / RequestSyncCtx_DecrRef refcount helpers
- Rewrite AREQ_IncrRef / AREQ_DecrRef / HybridRequest_IncrRef /
  HybridRequest_DecrRef to delegate to the wrapper
- Make AREQ_Free public (called by DecrRef on last drop)
- Migrate aggregate-coordination field accesses to req->rsc->...
- Insert RequestSyncCtx_New* calls at all top-level query creation sites
  (aggregate_exec, reply_empty, aggregate_debug, dist_aggregate,
  hybrid_request)
- Fix stale RequestSyncCtx_* call names -> RequestSyncState_* in
  dist_aggregate.c, rpnet.c, dist_hybrid.c
- Add #include hybrid/hybrid_request.h to aggregate_request.c
- Fix __atomic_* int* cast for _Atomic(int) refcount field
After the split, the heap wrapper's job is ownership plus the
blocked-client cycle handle — not synchronization — so the sync name
stays with the embedded slice (RequestSyncState) and the wrapper takes
a name matching the Blocked* / *Ctx conventions. Back-pointer field
renamed rsc -> brc. Pure mechanical rename; Rust doc comments that
referenced the timedOut flag now point at RequestSyncState.

Co-Authored-By: Claude Fable 5 <[email protected]>
A shard _FT.HYBRID ... WITHCURSOR creates one cursor per subquery with
cursor->execState pointing at the sub-AREQ. A RETURN_STRICT FT.CURSOR
READ on such a cursor runs the claim/done-latch handshake against the
read AREQ's wrapper (req->brc->requiresAggregateResultsSync,
AREQ_TryClaimAggregateResults, AREQ_ResetForCursorReadReturnStrict) —
which was NULL for sub-AREQs, a guaranteed crash on the strict hybrid
sub-cursor read path.

Wrap each cursor-backing sub-AREQ at HybridRequest_StartCursors time,
preserving today's per-sub-AREQ handshake granularity. Ownership is
unchanged: the hybrid request still owns the sub-AREQ, and the wrapper
is freed with it (HybridRequest_Free -> AREQ_DecrRef ->
BlockedRequestCtx_Free). Non-cursor sub-AREQs stay unwrapped.

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions github-actions Bot added the size:L label Jul 2, 2026
@jit-ci

jit-ci Bot commented Jul 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

@GuyAv46
GuyAv46 requested a review from lerman25 July 6, 2026 07:55
@GuyAv46 GuyAv46 changed the title [MOD-15430] Split RequestSyncCtx into embedded RequestSyncState and heap BlockedRequestCtx wrapper (step 0) [MOD-16691] Split RequestSyncCtx into embedded RequestSyncState and heap BlockedRequestCtx wrapper (step 0) Jul 6, 2026
@GuyAv46
GuyAv46 marked this pull request as ready for review July 6, 2026 09:15
@codecov

codecov Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.44751% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.34%. Comparing base (20b0cd6) to head (d80d886).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/aggregate/aggregate_request.c 98.93% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10336      +/-   ##
==========================================
+ Coverage   82.32%   82.34%   +0.01%     
==========================================
  Files         570      570              
  Lines       76921    76962      +41     
  Branches    31836    31836              
==========================================
+ Hits        63328    63371      +43     
+ Misses      13297    13295       -2     
  Partials      296      296              
Flag Coverage Δ
flow 83.83% <99.44%> (+0.01%) ⬆️
unit 53.64% <28.17%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

…1 atomics

- AREQ_RequiresThreadsSyncResults asserts req->brc != NULL (debug-only)
  instead of silently dereferencing: every request reaching the strict-sync
  protocol is wrapped by construction, and that stays true at the refactor's
  end state, so an unwrapped caller is a bug we want to catch loudly.
- BlockedRequestCtx_NewAREQ/NewHybrid assert the request is not already
  wrapped (double-wrap would silently leak the first wrapper); drop the
  now-redundant call-site assert in HybridRequest_StartCursors.
- Drop the BlockedRequestCtx wrappers in reply_empty.c: these transient AREQs
  only flow through the reply-only chunk sender and AREQ_DecrRef, which both
  handle unwrapped requests (as coord_aggregate_query_reply_empty already
  demonstrated).
- Use C11 atomic_fetch_add/sub_explicit on the wrapper refcount instead of
  __atomic builtins through a qualifier-stripping cast, matching the file's
  existing atomics idiom. (Refcount is removed entirely in Step 2.)

Co-Authored-By: Claude Fable 5 <[email protected]>
@GuyAv46
GuyAv46 requested a review from BenGoldberger July 12, 2026 14:28
# Conflicts:
#	src/aggregate/aggregate_request.c
#	src/redisearch_rs/rqe_iterators/src/utils/timeout.rs

@lerman25 lerman25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some inital comments.
Let's discuss this in-person

Comment thread src/coord/dist_aggregate.c Resolved
Comment thread src/aggregate/aggregate.h Resolved
Comment thread src/aggregate/aggregate_exec.c Resolved
The type was renamed to RequestSyncState in this PR but the instances
kept the old name. Also rename RPSafeLoader's BlockedRequestCtx pointer
(formerly also named syncCtx) to brc, matching the AREQ back-pointer
convention, since it is a wrapper pointer and not a RequestSyncState.

Co-Authored-By: Claude Fable 5 <[email protected]>
@GuyAv46 GuyAv46 changed the title [MOD-16691] Split RequestSyncCtx into embedded RequestSyncState and heap BlockedRequestCtx wrapper (step 0) [MOD-16989] Split RequestSyncCtx into embedded RequestSyncState and heap BlockedRequestCtx wrapper (step 0) Jul 20, 2026
@GuyAv46
GuyAv46 requested review from lerman25 and removed request for BenGoldberger July 21, 2026 09:08

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e9b976f60f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread deps/VectorSimilarity Resolved
@sonarqubecloud

Copy link
Copy Markdown

@lerman25 lerman25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lets go!

@GuyAv46
GuyAv46 added this pull request to the merge queue Jul 21, 2026
Merged via the queue into master with commit c67c210 Jul 21, 2026
47 checks passed
@GuyAv46
GuyAv46 deleted the guyav-blocked-client-refactor-step0 branch July 21, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants