Skip to content

fix(core): two ordering/lookup bugs the first real consumer hit - #4

Merged
srmcguirt merged 1 commit into
mainfrom
fix/executor-remap
Aug 1, 2026
Merged

srmcguirt merged 1 commit into
mainfrom
fix/executor-remap

Conversation

@srmcguirt

Copy link
Copy Markdown
Member

Building a document layer on the planner (fw-graph — leaves fetch, an assembly step composes) surfaced two defects that only appear once steps have dependencies and deduplication removes one of them. Both were invisible while nothing planned.

1. The executor ignored the dedup remap

A step owns its dependency ids. Dedup removes the duplicate and rebuilds graph edges, but surviving steps still name the id they were built with. The executor looked those raw ids up in outputs, so an assembler whose dependency was deduplicated away found nothing.

Worse, the lookup was:

.filter_map(|id| outputs.get(id).cloned())

— silently dropping a missing dependency. StepInputs is positional and steps downcast by position, so a drop shifted every later input down one slot and handed a step the wrong value at the wrong type. The symptom surfaced three layers away as a downcast failure in a GraphQL resolver.

Dependency ids are now resolved through remap before lookup, and a genuinely missing output is a hard error naming both steps.

2. Unary hoisting violated topological order

hoist_unary_steps partitioned into unary/non-unary and concatenated. Its own comment asserted:

A unary step should never depend on a non-unary step (that would make it batch-dependent). We verify this at placement time.

Nothing verified it — and the assumption is false in practice. A document assembler is unary (one document) and legitimately depends on a batched, therefore non-unary, read. Concatenation placed the assembler before its input.

Hoisting now places a unary step only once every dependency it names is already placed, deferring the rest in their existing (topologically valid) order. Valid topological order by construction; independent unary steps still move forward.

Regression test

an_assembler_whose_dependency_was_deduped_still_gets_its_input builds the exact shape — two roots, a shared leaf that dedupes, per-root assemblers depending on it. The leaf is deliberately non-unary: the realistic case is a batched PgSelectStep under a unary assembler, and that combination pins both fixes at once.

Plus an optimizer-level invariant test: every remap target survives, every remap source is gone, and no step is ordered before a dependency.

Workspace: 407 passed, 0 failed.

🤖 Generated with Claude Code

Building a document layer on the planner (fw-graph: leaves fetch, an
assembly step composes) surfaced two defects that only appear once steps
have DEPENDENCIES and deduplication removes one of them. Both were
invisible while nothing planned.

1. THE EXECUTOR IGNORED THE DEDUP REMAP

   A step OWNS its dependency ids. Dedup removes the duplicate and rebuilds
   graph EDGES, but surviving steps still name the id they were built with.
   The executor looked those raw ids up in `outputs`, so an assembler whose
   dependency was deduplicated away found nothing.

   Worse, the lookup was `filter_map(|id| outputs.get(id).cloned())` —
   silently DROPPING a missing dependency. `StepInputs` is positional and
   steps downcast by position, so a drop shifted every later input down one
   slot and handed a step the wrong value at the wrong type. The symptom
   surfaced three layers away as a downcast failure in a GraphQL resolver.

   Dependency ids are now resolved through `remap` before lookup, and a
   genuinely missing output is a hard error naming both steps.

2. UNARY HOISTING VIOLATED TOPOLOGICAL ORDER

   `hoist_unary_steps` partitioned into unary/non-unary and concatenated.
   Its own comment asserted "a unary step should never depend on a
   non-unary step... We verify this at placement time" — nothing verified
   it, and the assumption is false in practice: a document assembler is
   unary (one document) and legitimately depends on a BATCHED, therefore
   non-unary, read. Concatenation placed the assembler before its input.

   Hoisting now places a unary step only once every dependency it names is
   already placed, deferring the rest in their existing (topologically
   valid) order. The result is a valid topological order by construction,
   and independent unary steps still move forward.

REGRESSION TEST

`an_assembler_whose_dependency_was_deduped_still_gets_its_input` builds the
exact shape: two roots, a shared leaf that dedupes, and per-root assemblers
depending on it. The leaf is deliberately NON-unary — the realistic case, a
batched PgSelectStep under a unary assembler — so the test pins both fixes
at once. Plus an optimizer-level invariant test asserting every remap target
survives, every remap source is gone, and no step is ordered before a
dependency.

Workspace: 407 passed, 0 failed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Aug 1, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f6516ea

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@srmcguirt
srmcguirt merged commit ffb0ba4 into main Aug 1, 2026
2 of 4 checks passed
@srmcguirt
srmcguirt deleted the fix/executor-remap branch August 1, 2026 15:40
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