rqe-iterator-suspend-resume

Guides implementing and reviewing suspend/resume revalidation on RediSearch Rust query-engine iterators.

6.2k|596|Updated May 5, 2016
One-click install
npx skills add https://github.com/RediSearch/RediSearch --skill rqe-iterator-suspend-resume
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rqe-iterator-suspend-resume
Source: https://github.com/RediSearch/RediSearch/tree/main/src/redisearch_rs/rqe_iterators/.skills/rqe-iterator-suspend-resume
Command: npx skills add https://github.com/RediSearch/RediSearch --skill rqe-iterator-suspend-resume

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Adding or reviewing the Box<Self>-based suspend/resume (revalidation) mechanism on RediSearch query-engine iterators in Rust involves subtle memory-safety rules—allocation reuse, layout invariants, vtable-correct child transitions, and teardown on abort—where mistakes cause undefined behavior. This Skill encodes those rules as a checklist and reference so implementations and PR reviews stay sound.

Core Features & Use Cases

  • Implementation checklist: Step-by-step rules for adding suspend/resume to leaf and generic wrapper iterators, including the non-negotiable allocation-reuse rule and the #[repr(C)] single-struct ref_mode pattern.
  • Review checklist: A concrete list of invariants to verify in PRs touching boxed.rs, child-slot helpers, layout-invariant proofs, and aggregate result rebuilding.
  • Pitfall catalog: Documents the type-erased vtable pitfall, the Option<I> niche-layout hazard, exhaustion semantics, panic-safety windows, and aggregate entry provenance rules.
  • Use Case: When porting an iterator from legacy revalidate to the new suspend/resume traits, follow the guide to derive resume decisions from the existing revalidate, add the const layout proof, and write round-trip tests with a type-erased child.

Quick Start

Ask the assistant to review my PR that adds suspend/resume to a query-engine iterator using the rqe-iterator-suspend-resume checklist.

Frequently Asked Questions about rqe-iterator-suspend-resume

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add suspend/resume to a RediSearch Rust query-engine iterator?

Model the iterator as one #[repr(C)] struct parametrized by an Active/Suspended ref_mode marker, reuse the heap allocation via Box::into_raw and Box::from_raw with a pointer cast, and derive resume decisions from the existing revalidate implementation. Add a standalone const layout-invariant proof and round-trip tests.

How do I review a PR touching RQE iterator suspend/resume machinery?

Use the review checklist: verify allocation reuse, child transitions routed through suspend_child_slot_in_place/resume_child_slot_in_place, every child slot transitioned including exhausted ones, teardown without dropping moved-from children, and behavioral parity between resume and the legacy revalidate.

Why can't a generic wrapper whole-box cast its type-erased child?

Type-erased active and suspended children are different Box<dyn ...> types with different vtables, so a byte reinterpretation leaves the active vtable in a value typed as suspended, causing undefined behavior on the next dispatch. Children must be transitioned through the boxed.rs helper functions instead.

Why must suspend/resume reuse the same heap allocation?

The FFI wrapper caches a raw pointer into the iterator and delegating wrappers hand out pointers into child storage, so the box address must survive the whole cycle. Rebuilding with Box::new would dangle those cached pointers.

Can I use Option<I> for an optional child slot in a suspendable iterator?

No. Option<I>'s niche optimization makes its layout depend on I, so it is not transmute-stable across the active-to-suspended swap. Use a dedicated #[repr(C)] enum such as OptionalChild or MaybeEmptyOption instead.

What tests are required for a new suspend/resume implementation?

Require a suspend-to-resume round-trip test including a type-erased child for wrappers, a box-address-stability assertion, and a steerable mock to exercise Moved, Aborted, and Err branches. The mock's suspended type must carry the real 'query lifetime rather than 'static.