Repository navigation
feat(build): wire the planner into the request lifecycle - #3
Merged
Merged
Conversation
…dness
PgSelectStep's config hash covered schema/table/selected_cols/fk_col and
deliberately excluded tweaks ("tweaks are runtime, not plan-time"). But
tweaks are registered at plan time and carry WHERE/ORDER/LIMIT, and the
optimizer's deduplicate() merges steps on (type_id, deps, config_hash) —
so two steps over the same table with DIFFERENT filter arguments shared a
fingerprint, and the optimizer would collapse them and serve one field's
rows to the other field. Latent today (nothing constructs a plan yet);
live data-bleed the moment the plan path gains a caller.
The fix makes tweak identity part of the fingerprint, two ways:
apply_keyed(key, tweak) the caller declares the argument values the
tweak was built from; the key hashes into the
fingerprint in registration order. Same table +
same declared args => steps still dedupe (the
whole point of the optimizer); different args
=> never collide.
apply(tweak) unkeyed: the closure is opaque, its effect on
the SQL is unknowable, so the step's own id is
folded in, making the fingerprint unique. An
unkeyed step never deduplicates — safe by
default rather than fast by assumption.
Four regression tests pin the property: same-args dedupe, different-args
never collide, unkeyed poisons dedup, untweaked baseline still dedupes.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… + PlanExtension
The engine (magna-core), the batched steps (magna-dataplan), and the
register→execute→read bridge (PlanContext) were all complete and tested —
and nothing called them. The auto-generated resolvers bypass the planner
via QueryExecutor, and there was no async-graphql Extension anywhere that
would turn an incoming operation into a plan. This commit is that missing
piece, in the Grafast shape: plan the whole operation, run one DAG,
resolve fields from its results.
WHAT'S NEW
plan_extension.rs
PlanRegistry plan fns keyed by (type, field), populated at
schema-build time; empty registry ⇒ extension not
attached ⇒ unplanned schemas pay nothing.
PlanScope what a plan fn works against: allocates step ids,
registers steps into the operation's ONE shared plan
(which is what makes cross-field dedup structural).
PlanResults request-scoped handle; resolvers read their output by
response key (alias if present, else field name).
PlanExtension per-request lifecycle: prepare_request inserts the
results handle → parse_query captures the operation →
execute() walks root query selections, resolves field
arguments against variables, calls plan fns, executes
the plan, publishes outputs — then resolution runs.
ExtensionContext::plan_field(type, field, fn)
The embedder registration surface, available in every phase. The field
itself is still registered via query_field with a resolver that reads
PlanResults — planning supplies the data, not the schema entry.
OptimizedPlan.remap + PlanContext follows it
Dedup removed the duplicate step and rewrote graph edges, but DISCARDED
the removed→canonical remap — so get_result(deduped_id) returned None,
breaking result lookup for exactly the fields dedup helped. The remap
now survives into PlanContext and get_result forwards through it.
SCOPE (first pass, documented in the module)
Root query fields only; fragment-reached fields are not planned and must
error loudly rather than silently fall back. Mutations/subscriptions
unplanned. Nested selection planning (steps depending on parent output)
is the next stage, not this one.
PROOF (tests/plan_wiring.rs — no database)
· a field served entirely through the plan path
· { a: answer(n:7) b: answer(n:7) } → ONE step execution, BOTH fields
resolve (the remap fix, live)
· { a: answer(n:1) b: answer(n:2) } → two executions — different args
never share (the data-bleed guard from the fingerprint commit)
· variables resolve into plan arguments
· unplanned operations execute zero steps
Workspace: 405 passed, 0 failed.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The engine (
magna-core), the batched steps (magna-dataplan), and the register→execute→read bridge (PlanContext) were all complete and tested — and nothing called them. There was noasync_graphqlExtension anywhere that turned an incoming operation into a plan. This PR is that missing piece, in the Grafast shape: plan the whole operation, run one DAG, resolve fields from its results.Commit 1 —
fix(dataplan): tweak-aware step fingerprintsPgSelectStep's config hash excluded tweaks, but tweaks carry WHERE/ORDER/LIMIT and the optimizer merges steps on(type_id, deps, config_hash)— so two same-table steps with different filter arguments shared a fingerprint and would be collapsed, serving one field's rows to the other. Latent while nothing planned; live data-bleed the moment planning gained a caller (i.e., commit 2).apply_keyed(key, tweak)— caller declares the argument values; key hashes into the fingerprint in registration order. Same args ⇒ steps still dedupe; different args ⇒ never collide.apply(tweak)(unkeyed) — opaque closure, unknowable effect ⇒ the step's own id folds in, fingerprint unique, never dedupes. Safe by default.Commit 2 —
feat(build): the wiringPlanRegistry(type, field); empty ⇒ extension not attached ⇒ unplanned schemas pay nothingPlanScopePlanResultsPlanExtensionprepare_requestinserts the handle →parse_querycaptures the operation →executewalks root query selections, resolves args against variables, calls plan fns, executes the DAG, publishes — then resolution runsExtensionContext::plan_fieldPlus a latent bug the wiring exposed: dedup removed the duplicate step and rewrote graph edges but discarded the removed→canonical remap —
get_result(deduped_id)returnedNone, breaking result lookup for exactly the fields dedup helped.OptimizedPlannow carriesremap;PlanContext::get_resultforwards through it.Scope (first pass, documented in the module)
Root query fields only; fragment-reached fields are not planned and error loudly rather than silently falling back. Mutations/subscriptions unplanned. Nested selection planning (steps depending on parent output) is the next stage.
Proof —
tests/plan_wiring.rs, no database{ a: answer(n:7) b: answer(n:7) }→ one step execution, both fields resolve (remap fix, live){ a: answer(n:1) b: answer(n:2) }→ two executions — different args never share (the data-bleed guard)Workspace: 405 passed, 0 failed. (fmt/clippy CI lanes remain red from pre-existing
maindrift — untouched here, same as #2.)First consumer: fw-api's document roots (
fw-graphstep library over fw-store), landing next in the data repo.🤖 Generated with Claude Code