Skip to content

feat(engine): plan-time schedule-tree scheduler + runtime dataflow executor#1535

Draft
jensneuse wants to merge 5 commits into
masterfrom
feat/schedule-tree-dataflow-executor
Draft

feat(engine): plan-time schedule-tree scheduler + runtime dataflow executor#1535
jensneuse wants to merge 5 commits into
masterfrom
feat/schedule-tree-dataflow-executor

Conversation

@jensneuse

Copy link
Copy Markdown
Member

feat(engine): plan-time schedule-tree scheduler + runtime dataflow executor

Two independent, default-off engine execution improvements that collapse
federated query latency to the dependency-graph critical path under skewed
subgraph latency, plus hot-path allocation reductions.
Measured on the gateways-benchmark workload (one slow subgraph):
−37% median latency for either feature vs the shipping wave executor.

What's in here (4 commits)

  1. perf(resolve): pre-size buffers and slab-allocate parallel fetch results
    Single-slab result allocation in resolveParallel, HTTP request buffer
    pre-sizing, singleflight key buffer reuse, resolvable field-path buffer
    pre-sizing. Verified at parity on a flags-off A/B (+1.2%, within noise).

  2. feat(postprocess): dominance-based schedule-tree scheduler (WithBuildScheduleTree)
    Ports the improve-query-order scheduler with two load-bearing fixes found
    by adversarial review against real planner output:

    • validateParallelLeaves trusts FetchID dependency edges ONLY. The
      path-containment heuristics false-positive on the canonical federation
      plan (a fetch attaching under an ancestor-provided subtree is independent
      of a sibling merging into a prefix path — the planner emits explicit
      edges when a dependency is real, e.g. deps [1,2] on the fetch that
      actually reads sibling data) and panicked every affected request.
    • buildScheduleTreeProcessor never panics: any scheduler/validator error
      falls back to the legacy orderSequenceByDependencies +
      createParallelNodes pipeline, planning exactly as with the option off.
      Includes the property/scenario suites, a 13-fetch real-plan schedule pin
      (TestBuildScheduleTreeRealGatewaysBenchmarkPlan), and the ADR.
  3. feat(resolve): 3-phase prepare/load/merge protocol for nested schedule trees
    The executor support for nested plans, with three deviations, each pinned
    by a regression test that fails if the deviation is reverted:

    • flat Parallels inside a nested tree route through the locked nested path
      (useMergeMu || gate) — fixes a verified data race;
    • skip-on-errored-dependency gated on useMergeMu — flat-plan error-path
      bytes stay identical to the legacy executor;
    • pooled batch tools registered for Put BEFORE the prepare-error return —
      fixes a pooled-arena leak on failed batch prepares.
  4. feat(resolve): dataflow executor (ResolverOptions.EnableDataflowExecution)
    Per-FetchID dependency gating for flat query plans: each fetch's network
    load starts when its OWN dependencies have merged. Nine falsifiable
    invariants documented in the file header; the load-bearing ones:

    • every arena access runs on the coordinator goroutine (workers execute
      only the arena-free source load) — no mutex, race-free by construction;
    • the three audited error sinks are swap-captured per leaf and replayed in
      leaf order — error/extension output is byte-identical to the wave
      executor;
    • dispatch pops the global leaf-index minimum, so pre-fetch hook call order
      (authorizer/rate-limiter) matches wave spawn order whenever the DAG
      permits;
    • nested (schedule-tree) plans are structurally rejected and fall back —
      the two features compose safely.

Default-off guarantee

With both options off, behavior is byte-identical and at performance parity:

  • byte-identity gate: one sha256 across all four flag modes, 50 requests each;
  • flags-off A/B vs the unmodified base: within noise;
  • the full -race suites for resolve/postprocess/graphql_datasource pass with
    zero exclusions, including -count=50 stress on the byte-identity and race
    stress tests.

Known properties (documented in code)

  • Nested executor appends errors/extensions in completion order across
    parallel branches (error-path only; tree-order sink staging is the named
    follow-up, and the dataflow executor already implements that staging).
  • Dataflow merge-CONFLICT error attribution on type-conflicting sibling data
    (invalid federation data) follows completion order.

Review provenance

The implementation survived three adversarial codex review cycles to
GATE-CLEAN during development plus a final whole-branch review (GATE-CLEAN);
every P1 found along the way is fixed and pinned by an empirically falsified
regression test.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 72a8cf90-2a12-4900-8bec-0da5607fb108

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/schedule-tree-dataflow-executor

Comment @coderabbitai help to get the list of available commands and usage tips.

jensneuse and others added 5 commits June 11, 2026 18:16
Port of the fork's hot-path pre-sizing (818aaa2): single-slab result
allocation in resolveParallel, HTTP request buffer pre-sizing, singleflight
key buffer reuse, and resolvable field-path buffer pre-sizing.
Verified at parity on the flags-off A/B benchmark gate.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ScheduleTree)

Ports the improve-query-order scheduler with two load-bearing deviations,
both found by adversarial review against real planner output:
1. validateParallelLeaves trusts FetchID dependency edges ONLY. The upstream
   path-containment heuristics false-positive on the canonical federation
   plan (a fetch attaching under an ancestor-provided subtree is independent
   of a sibling merging into a prefix path; the planner emits explicit edges
   when a dependency is real) and panicked every affected request.
2. buildScheduleTreeProcessor never panics: any scheduler/validator error
   falls back to the legacy orderSequenceByDependencies+createParallelNodes
   pipeline, planning exactly as with the option off.
Includes the property/scenario suites, a 13-fetch real-plan schedule pin,
and the ADR.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…e trees

Ports the improve-query-order loader protocol with three deviations, each
pinned by a regression test:
1. resolveParallelWithCtx routes flat Parallels through the locked nested
   path whenever useMergeMu is set — upstream's bare shape check lets a flat
   Parallel inside a nested tree merge lock-free against locked sibling
   merges (verified data race; TestLoaderNestedTreeFlatParallelTakesLockedPath
   fails under -race if the gate is reverted, verified empirically).
2. shouldSkipErroredDependencyLocked is gated on useMergeMu so flat-plan
   error-path bytes stay identical to the legacy executor.
3. The pooled batch tools are registered for Put BEFORE the prepare-error
   return; upstream leaks the pooled arena on every failed batch prepare.
Also documents the nested executor's completion-order sink-append property
and its tree-order staging follow-up.

Sink audit re-run against master: the three order-bearing sinks
(resolvable.errors, ctx.subgraphErrors, resolvable.subgraphExtensions) are
written only from merge-phase functions; resolvable.go's growth since v2.4.1
added no new writers; executeSourceLoad remains arena-free.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…r-owned arena

Replaces the per-wave barrier with per-FetchID dependency gating for flat
query plans (default off; ResolverOptions.EnableDataflowExecution). Each
fetch's network load starts when its OWN dependencies have merged, which
collapses wall-clock latency to the dependency-graph critical path under
skewed subgraph latency (measured -37% on the gateways-benchmark workload).
Correctness by construction, with nine falsifiable invariants documented in
the file header: every arena access runs on the coordinator goroutine
(workers execute only the arena-free source load); the three audited error
sinks are swap-captured per leaf and replayed in leaf order, making
error/extension output byte-identical to the wave executor; dispatch pops
the global leaf-index minimum so pre-fetch hook order matches wave spawn
order whenever the DAG permits; nested (schedule-tree) plans are
structurally rejected and fall back to the wave executor.
Both dispatch-order falsification checks verified on this base: FIFO pop and
FetchID-order pop each make TestDataflowPreFetchHookOrder fail.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jensneuse jensneuse force-pushed the feat/schedule-tree-dataflow-executor branch from c3d7be0 to f75f280 Compare June 11, 2026 16:18
jensneuse added a commit to wundergraph/cosmo that referenced this pull request Jun 11, 2026
Pins both router modules to
github.com/wundergraph/graphql-go-tools/v2@v2.4.6-0.20260611164326-f75f280f48dd
(wundergraph/graphql-go-tools#1535: schedule-tree scheduler + dataflow
executor, rebased on v2.4.5/go-arena v1.3.0). To be moved to a tagged release
once that PR merges.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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