ExportXMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Integration
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Problem

      ExpressionContext::isHybridSearch() is inherited by sub-pipeline expression contexts (expression_context_builder.cpp). Any code that routes on it cannot distinguish "my own pipeline is hybrid search" from "I am merely nested inside a hybrid search pipeline."

      The clearest instance: DocumentSourceLookUp's serialization swap (document_source_lookup.cpp, gated on _fromNsIsAView && _fromExpCtx->isHybridSearch()) replaces the lookup's resolved pipeline with the serialized introspection pipeline and recomputes join placement. An ordinary \$lookup on a view nested inside a \$rankFusion/\$scoreFusion pipeline enters this block purely by flag inheritance and gets hybrid-only machinery applied to it.

      Evidence (SERVER-136369 PR review, Nov 2026)

      Four separate review findings trace to this one misroute. One has a verified repro: an ordinary localField/foreignField \$lookup on a view inside a \$rankFusion pipeline, with a nested \$unionWith targeting a different view — the \$unionWith is serialized in resolved form and the per-document re-parse reads the wrong collection (wrong results: documents from the outer view's backing collection appear).

      The code's own restriction comment says plain \$search/\$vectorSearch stages must never go through this serialization (their injected 'view' field fails validateViewNotSetByUser, error 5491300, on re-parse). The inherited flag defeats that intent.

      Fix direction

      Route on the lookup's own hybrid-ness — a signal already computed in the same constructor (subpipelineIsHybrid / isHybridSearchPipeline(ownPipeline), which recognizes only \$rankFusion/\$scoreFusion) — instead of the inherited flag. A one-line prototype of this gate on the SERVER-136369 v9.0 code is implemented and green across that PR's regression suite (view applied to every fusion input, 3-level nested lookups, non-idempotent views, mongot e2e); the first instance lands with SERVER-136369.

      Generalize from there: audit the other consumers of isHybridSearch() / isHybridSearchPipeline() (~10 sites) for the same inherited-context misroute, and prefer the explicit \$_internalHybridSearch marker over the flag as the routing signal.

      This is the bug-class fix independent of feature-flag-removal timing; the flag-to-marker migration at flag removal is tracked separately (SERVER-121094).

            Assignee:
            Finley Lau
            Reporter:
            Will Buerger
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: