Skip to content

feat: controlplane improve composition queries - #2903

Merged
gausie merged 14 commits into
mainfrom
wilson/eng-9669-controlplane-improve-composition-queries
Jun 10, 2026
Merged

feat: controlplane improve composition queries#2903
gausie merged 14 commits into
mainfrom
wilson/eng-9669-controlplane-improve-composition-queries

Conversation

@wilsonrivera

@wilsonrivera wilsonrivera commented May 29, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Refactor
    • Reduced per-item database queries and streamlined feature-flag, composition, and schema-version flows for more predictable behavior and improved performance.
    • Consolidated schema/plugin/version handling with safer defaults and fewer follow-up lookups.
  • New Features
    • Added a batched subgraph name lookup to speed and simplify name resolution for large lists.

Checklist

Open Source AI Manifesto

This project follows the principles of the Open Source AI Manifesto. Please ensure your contribution aligns with its principles.

@wilsonrivera
wilsonrivera requested a review from a team as a code owner May 29, 2026 22:16

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Four controlplane repositories refactor DB access: SubgraphRepository adds a batched subgraph-name helper and normalizes proto field usage; FeatureFlagRepository bulk-joins schema/proto/plugin metadata and removes transaction-scoped writes; FederatedGraphRepository and GraphCompositionRepository move composition/schema-version writes off transaction callbacks and return a slimmer result for schema-version writes.

Changes

Repository Database Refactoring

Layer / File(s) Summary
Subgraph bulk-fetch helper and protobuf schema field naming
controlplane/src/core/repositories/SubgraphRepository.ts
New getSubgraphNameByIds batches ID-to-name lookups (chunks of 100). getSubgraphsMatching now selects protoSchema from schema.protobufSchemaVersions and ProtoSubgraph construction uses sg.protoSchema, with warnings when missing for grpc plugin/service types.
Feature flag subgraph resolution with joined schema/proto/plugin metadata
controlplane/src/core/repositories/FeatureFlagRepository.ts
Adds protobufSchemaVersions and pluginImageVersions imports. updateFeatureFlag marked async and label/subgraph writes run directly on this.db (transactional boundary removed). getFeatureSubgraphsByFeatureFlagId query LEFT JOINs schemaVersion, protobufSchemaVersions, and pluginImageVersions and maps joined columns into DTOs, avoiding per-row follow-up queries and using bulk subgraph-name fetch.
Composition and schema-version write flow refactoring
controlplane/src/core/repositories/FederatedGraphRepository.ts, controlplane/src/core/repositories/GraphCompositionRepository.ts
FederatedGraphRepository.addSchemaVersion made async, now selects federated-graph linkage fields, inserts schemaVersion, conditionally links via federatedGraphsToFeatureFlagSchemaVersions or updates federatedGraphs.composedSchemaVersionId, calls GraphCompositionRepository.addComposition (now persisted on this.db), and returns { composedSchemaVersionId, routerCompatibilityVersion }. Public composeAndDeployGraphs removed from FederatedGraphRepository.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes


Possibly related PRs

  • wundergraph/cosmo#2899: The main PR’s repository refactors around schema-version/proto-plugin handling and composition persistence (FeatureFlagRepository/FederatedGraphRepository/GraphCompositionRepository/SubgraphRepository) directly underpin the new batch-publish flow added by PR #2899 (publishFederatedSubgraphs composing/validating feature subgraphs and affected federated graphs).
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: controlplane improve composition queries' accurately describes the primary changes across multiple repository files, focusing on refactoring composition-related queries and removing transaction-scoped orchestration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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


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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
controlplane/src/core/repositories/FeatureFlagRepository.ts (1)

974-1035: 💤 Low value

Minor inconsistency in schemaVersionId field mapping.

The query selects both schemaVersionId: subgraphs.schemaVersionId (line 925) and svId: schemaVersion.id (line 932). In the DTO construction, schemaVersionId is set from graph.svId (line 1027), not from the originally selected schemaVersionId. While functionally equivalent due to the FK constraint, this differs from SubgraphRepository.getSubgraphsMatching which consistently uses sg.schemaVersionId.

Consider using the same source field for consistency:

-        schemaVersionId: graph.svId ?? '',
+        schemaVersionId: graph.schemaVersionId ?? '',
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@controlplane/src/core/repositories/FeatureFlagRepository.ts` around lines 974
- 1035, The DTO maps schemaVersionId from graph.svId while the query also
returns graph.schemaVersionId (and SubgraphRepository uses sg.schemaVersionId);
change the mapping in FeatureFlagRepository where featureGraphsByFlag is built
(the push that spreads ...graph) to use graph.schemaVersionId (or normalize
earlier so a single field is used) instead of graph.svId to keep source
consistency with SubgraphRepository.getSubgraphsMatching and the selected query
fields.
controlplane/src/core/repositories/GraphCompositionRepository.ts (1)

124-137: 💤 Low value

Consider pre-computing schema version lookup map for clarity.

The repeated composedSubgraphs.indexOf(subgraph) lookups to access subgraphSchemaVersionIds are O(n) per call. While composition subgraph counts are typically small, building a Map<subgraphId, schemaVersionId> upfront would be clearer and more efficient.

♻️ Suggested improvement
+    const subgraphSchemaVersionMap = new Map(
+      composedSubgraphs.map((sg) => [sg.id, sg.schemaVersionId])
+    );
+
     const updatedSubgraphs = composedSubgraphs.filter((subgraph) => {
       const prevSubgraph = prevCompositionSubgraphs.find((prevSubgraph) => prevSubgraph.id === subgraph.id);
       return (
-        prevSubgraph && prevSubgraph.schemaVersionId !== subgraphSchemaVersionIds[composedSubgraphs.indexOf(subgraph)]
+        prevSubgraph && prevSubgraph.schemaVersionId !== subgraphSchemaVersionMap.get(subgraph.id)
       );
     });

     const unchangedSubgraphs = composedSubgraphs.filter((subgraph) =>
       prevCompositionSubgraphs.some(
         (prevSubgraph) =>
           prevSubgraph.id === subgraph.id &&
-          prevSubgraph.schemaVersionId === subgraphSchemaVersionIds[composedSubgraphs.indexOf(subgraph)],
+          prevSubgraph.schemaVersionId === subgraphSchemaVersionMap.get(subgraph.id),
       ),
     );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@controlplane/src/core/repositories/GraphCompositionRepository.ts` around
lines 124 - 137, In GraphCompositionRepository, the filters that compute
updatedSubgraphs and unchangedSubgraphs repeatedly call
composedSubgraphs.indexOf(subgraph) to index into subgraphSchemaVersionIds (O(n)
per lookup); precompute a Map from subgraph id to schemaVersionId (e.g., build
subgraphSchemaVersionById from composedSubgraphs and subgraphSchemaVersionIds
before the filters) and then use that map inside the updatedSubgraphs and
unchangedSubgraphs predicates to compare prevSubgraph.schemaVersionId against
the mapped schemaVersionId, removing the indexOf calls and improving clarity and
performance.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@controlplane/src/core/repositories/FederatedGraphRepository.ts`:
- Around line 785-790: In FederatedGraphRepository.ts (around the insert that
writes to federatedGraphsToFeatureFlagSchemaVersions), remove the empty-string
fallback for baseCompositionSchemaVersionId and instead ensure a real UUID is
provided: check federatedGraph.composedSchemaVersionId before calling
this.db.insert in the method performing the insert (the block using
federatedGraphsToFeatureFlagSchemaVersions and variables schemaVersionId,
federatedGraph, featureFlagId); if composedSchemaVersionId is null/undefined
either skip this insert for that federatedGraph or throw/return a clear error so
baseCompositionSchemaVersionId is always assigned the actual
composedSchemaVersionId UUID (no '').
- Around line 736-810: The feature-flag branch is inserting an empty string into
federatedGraphsToFeatureFlagSchemaVersions.baseCompositionSchemaVersionId which
violates the FK (column is notNull); in addSchemaVersion change the value
written for baseCompositionSchemaVersionId to a valid UUID when
federatedGraph.composedSchemaVersionId is missing (e.g. use
federatedGraph.composedSchemaVersionId ?? insertedVersion[0].insertedId) or
conditionally omit/adjust the insert so only a valid schemaVersion id is stored;
update the insertion in the isFeatureFlagComposition branch where
federatedGraphsToFeatureFlagSchemaVersions is written to reference
baseCompositionSchemaVersionId and ensure insertedVersion is used as fallback.

---

Nitpick comments:
In `@controlplane/src/core/repositories/FeatureFlagRepository.ts`:
- Around line 974-1035: The DTO maps schemaVersionId from graph.svId while the
query also returns graph.schemaVersionId (and SubgraphRepository uses
sg.schemaVersionId); change the mapping in FeatureFlagRepository where
featureGraphsByFlag is built (the push that spreads ...graph) to use
graph.schemaVersionId (or normalize earlier so a single field is used) instead
of graph.svId to keep source consistency with
SubgraphRepository.getSubgraphsMatching and the selected query fields.

In `@controlplane/src/core/repositories/GraphCompositionRepository.ts`:
- Around line 124-137: In GraphCompositionRepository, the filters that compute
updatedSubgraphs and unchangedSubgraphs repeatedly call
composedSubgraphs.indexOf(subgraph) to index into subgraphSchemaVersionIds (O(n)
per lookup); precompute a Map from subgraph id to schemaVersionId (e.g., build
subgraphSchemaVersionById from composedSubgraphs and subgraphSchemaVersionIds
before the filters) and then use that map inside the updatedSubgraphs and
unchangedSubgraphs predicates to compare prevSubgraph.schemaVersionId against
the mapped schemaVersionId, removing the indexOf calls and improving clarity and
performance.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5414b1e4-bddc-45f1-b0ae-3ecd2a06539a

📥 Commits

Reviewing files that changed from the base of the PR and between 254810f and c53fe46.

📒 Files selected for processing (4)
  • controlplane/src/core/repositories/FeatureFlagRepository.ts
  • controlplane/src/core/repositories/FederatedGraphRepository.ts
  • controlplane/src/core/repositories/GraphCompositionRepository.ts
  • controlplane/src/core/repositories/SubgraphRepository.ts

Comment thread controlplane/src/core/repositories/FederatedGraphRepository.ts
Comment thread controlplane/src/core/repositories/FederatedGraphRepository.ts
Comment thread controlplane/src/core/repositories/FeatureFlagRepository.ts
@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.00000% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.54%. Comparing base (b9405fa) to head (d7bfd52).

Files with missing lines Patch % Lines
...lplane/src/core/repositories/SubgraphRepository.ts 85.91% 10 Missing ⚠️
...ane/src/core/repositories/FeatureFlagRepository.ts 88.88% 7 Missing ⚠️
.../src/core/repositories/FederatedGraphRepository.ts 96.92% 2 Missing ⚠️
...rc/core/repositories/GraphCompositionRepository.ts 98.01% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2903      +/-   ##
==========================================
+ Coverage   65.13%   65.54%   +0.41%     
==========================================
  Files         327      327              
  Lines       47138    46882     -256     
  Branches     5241     5242       +1     
==========================================
+ Hits        30703    30731      +28     
+ Misses      16411    16127     -284     
  Partials       24       24              
Files with missing lines Coverage Δ
.../src/core/repositories/FederatedGraphRepository.ts 70.51% <96.92%> (+14.82%) ⬆️
...rc/core/repositories/GraphCompositionRepository.ts 98.31% <98.01%> (-0.02%) ⬇️
...ane/src/core/repositories/FeatureFlagRepository.ts 88.50% <88.88%> (-0.10%) ⬇️
...lplane/src/core/repositories/SubgraphRepository.ts 88.70% <85.91%> (-0.20%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread controlplane/src/core/repositories/SubgraphRepository.ts Outdated
Comment thread controlplane/src/core/repositories/SubgraphRepository.ts
Comment thread controlplane/src/core/repositories/FeatureFlagRepository.ts
Comment thread controlplane/src/core/repositories/FeatureFlagRepository.ts
@wilsonrivera
wilsonrivera requested review from Aenimus and comatory June 8, 2026 18:31
@gausie
gausie enabled auto-merge (squash) June 10, 2026 15:11
@gausie
gausie merged commit deb6f17 into main Jun 10, 2026
15 of 18 checks passed
@gausie
gausie deleted the wilson/eng-9669-controlplane-improve-composition-queries branch June 10, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants