Skip to content

fix(resolve): guard OnFinished against nil loaderHookContext on skipped fetches#1394

Merged
jensneuse merged 5 commits intomasterfrom
jensneuse/nil-hookctx-guard
Feb 19, 2026
Merged

fix(resolve): guard OnFinished against nil loaderHookContext on skipped fetches#1394
jensneuse merged 5 commits intomasterfrom
jensneuse/nil-hookctx-guard

Conversation

@jensneuse
Copy link
Copy Markdown
Member

@jensneuse jensneuse commented Feb 19, 2026

Summary by CodeRabbit

  • Tests

    • Added integration tests validating correct federation behavior when parent data is null, ensuring child fetches are properly skipped.
    • Expanded test coverage for loader hook lifecycle across serial and parallel execution paths.
  • Bug Fixes

    • Corrected loader hook finalization to ensure callback hooks are only invoked when appropriate, preventing unexpected behavior in skipped fetch scenarios.

Fixes a panic where LoaderHooks.OnFinished was called with a nil context.Context when a fetch was skipped (e.g. null parent data, auth rejection, rate limiting). The nil guard is now consolidated in a callOnFinished helper that covers all four fetch paths: SingleFetch, EntityFetch, BatchEntityFetch, and the parallel merge loop. Tests were added for each path, the LoaderHooks interface now documents the OnLoad/OnFinished contract, and an integration test verifies the skip behaviour end-to-end.

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.

jensneuse and others added 4 commits February 19, 2026 07:40
…ed fetches

When a fetch is skipped (e.g. null parent data), executeSourceLoad never
runs, leaving loaderHookContext nil. OnFinished was called with this nil
context, causing a panic in the router's header propagation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…lel, entity, and batch entity fetch paths

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ipped fetches

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ped-fetch tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@StarpTech StarpTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread execution/federationtesting/skipped_fetch_test.go Outdated
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 19, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

This PR adds integration and unit test coverage for skipped fetch behavior when a parent entity is null, refactors loader hook finalization to only call OnFinished when hooks were actually invoked, and updates test helpers accordingly.

Changes

Cohort / File(s) Summary
Integration Test for Skipped Fetch
execution/federationtesting/skipped_fetch_test.go
New integration test validating that downstream subgraphs are not invoked when a parent entity is null, using mock Users and Reviews subgraphs with call count tracking.
Loader Hook Lifecycle Refactoring
v2/pkg/engine/resolve/loader.go
Refactors OnFinished hook invocation with a new callOnFinished helper that only triggers hooks when loaderHookContext exists, ensuring consistency with skip conditions and preventing OnFinished from being called on skipped fetches.
Loader Hooks Test Coverage Expansion
v2/pkg/engine/resolve/loader_hooks_test.go
Expands test coverage with multiple test cases validating that OnFinished is not called in skipped fetch scenarios (null parent) across serial and parallel code paths; updates NewTestLoaderHooks() signature to return pointer type.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a nil guard for OnFinished to handle skipped fetches.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jensneuse/nil-hookctx-guard

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

@jensneuse jensneuse merged commit f79d071 into master Feb 19, 2026
11 checks passed
@jensneuse jensneuse deleted the jensneuse/nil-hookctx-guard branch February 19, 2026 10:10
jensneuse pushed a commit that referenced this pull request Feb 19, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.0.0-rc.252](v2.0.0-rc.251...v2.0.0-rc.252)
(2026-02-19)


### Features

* forward headers to grpc subgraphs
([#1382](#1382))
([8459b34](8459b34))


### Bug Fixes

* **resolve:** fix flaky singleflight deduplication tests
([#1393](#1393))
([4105082](4105082))
* **resolve:** guard OnFinished against nil loaderHookContext on skipped
fetches
([#1394](#1394))
([f79d071](f79d071))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
jensneuse pushed a commit that referenced this pull request Feb 19, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.8.1](execution/v1.8.0...execution/v1.8.1)
(2026-02-19)


### Bug Fixes

* **resolve:** fix flaky singleflight deduplication tests
([#1393](#1393))
([4105082](4105082))
* **resolve:** guard OnFinished against nil loaderHookContext on skipped
fetches
([#1394](#1394))
([f79d071](f79d071))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

3 participants