Skip to content

feat: implement ptq rpc and index schemas - #3138

Draft
wilsonrivera wants to merge 4 commits into
mainfrom
wilson/cosmo-335-cosmo-cloud-prompt-to-query-via-mcp-product
Draft

feat: implement ptq rpc and index schemas#3138
wilsonrivera wants to merge 4 commits into
mainfrom
wilson/cosmo-335-cosmo-cloud-prompt-to-query-via-mcp-product

Conversation

@wilsonrivera

@wilsonrivera wilsonrivera commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Added prompt-to-query functionality for generating GraphQL operations from natural-language prompts.
    • Added support for reporting generated queries, operation types, and unsatisfied requirements.
    • Added schema indexing to improve prompt-based query generation.
    • Added optional service configuration and a feature flag, disabled by default.
  • Documentation
    • Expanded service contracts and configuration examples for query generation.

Checklist

Open Source AI Manifesto

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

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1b3a278e-0d6b-4313-96d0-49223fea9b8d

📥 Commits

Reviewing files that changed from the base of the PR and between b9c52bf and c9d6d43.

📒 Files selected for processing (2)
  • controlplane/src/core/services/PromptToQueryService.ts
  • router/pkg/controlplane/selfregister/self_register_test.go
💤 Files with no reviewable changes (1)
  • controlplane/src/core/services/PromptToQueryService.ts

Walkthrough

The change adds a GenerateQuery NodeService RPC, protobuf and Connect definitions, prompt-to-query configuration, query generation logic, feature access checks, schema indexing, and composition-flow wiring.

Changes

Prompt-to-Query integration

Layer / File(s) Summary
GenerateQuery protocol contract
proto/wg/cosmo/node/v1/node.proto, connect/src/wg/cosmo/node/v1/node_pb.ts, connect/src/wg/cosmo/node/v1/node-NodeService_connectquery.ts
Adds query-generation messages, operation types, the unary NodeService.GenerateQuery RPC, and generated Connect bindings.
Service configuration and feature wiring
controlplane/.env.example, controlplane/src/core/env.schema.ts, controlplane/src/index.ts, controlplane/src/core/build-server.ts, controlplane/src/core/routes.ts, controlplane/src/types/index.ts, controlplane/src/core/repositories/OrganizationRepository.ts
Adds endpoint configuration, build and router options, the feature identifier, and the disabled organization feature default.
Query generation RPC and service
controlplane/src/core/services/PromptToQueryService.ts, controlplane/src/core/bufservices/NodeService.ts, router/pkg/controlplane/selfregister/self_register_test.go
Adds validation, feature checks, retrying HTTP calls, response mapping, error handling, schema indexing, the authenticated RPC handler, and test-handler support.
Composition indexing integration
controlplane/src/core/services/CompositionService.ts, controlplane/src/core/composition/composer.ts, controlplane/src/core/bufservices/{contract,feature-flag,federated-graph,graph,monograph,subgraph}/*
Initializes and passes PromptToQueryService through composition flows, indexes composed schemas, and updates all composition call sites. deleteFeatureFlag also removes a redundant transaction-scoped repository construction.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 implementation of the PTQ RPC and schema indexing changes.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Router-nonroot image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-860e18ffc48f006fe941945fccf3dce51a7b3cd2-nonroot

@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 46.09375% with 138 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.85%. Comparing base (64eaf60) to head (c9d6d43).
⚠️ Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
...rolplane/src/core/services/PromptToQueryService.ts 32.27% 107 Missing ⚠️
controlplane/src/core/bufservices/NodeService.ts 12.50% 14 Missing ⚠️
...oto/wg/cosmo/node/v1/nodev1connect/node.connect.go 66.66% 6 Missing ⚠️
controlplane/src/index.ts 0.00% 4 Missing ⚠️
...e/bufservices/federated-graph/migrateFromApollo.ts 0.00% 2 Missing ⚠️
...rvices/graph/setGraphRouterCompatibilityVersion.ts 0.00% 2 Missing ⚠️
.../src/core/bufservices/monograph/updateMonograph.ts 0.00% 2 Missing ⚠️
...ne/src/core/repositories/OrganizationRepository.ts 0.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (46.09%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3138       +/-   ##
===========================================
- Coverage   62.37%   43.85%   -18.52%     
===========================================
  Files         262     1072      +810     
  Lines       31003   140577   +109574     
  Branches        0     7361     +7361     
===========================================
+ Hits        19337    61655    +42318     
- Misses      10158    77071    +66913     
- Partials     1508     1851      +343     
Files with missing lines Coverage Δ
...ne/src/core/bufservices/contract/createContract.ts 73.96% <100.00%> (ø)
...ne/src/core/bufservices/contract/updateContract.ts 72.72% <100.00%> (ø)
...core/bufservices/feature-flag/createFeatureFlag.ts 77.00% <100.00%> (ø)
...core/bufservices/feature-flag/deleteFeatureFlag.ts 87.37% <100.00%> (ø)
...core/bufservices/feature-flag/enableFeatureFlag.ts 77.87% <100.00%> (ø)
...e/bufservices/feature-flag/recomposeFeatureFlag.ts 96.66% <100.00%> (ø)
...core/bufservices/feature-flag/updateFeatureFlag.ts 81.15% <100.00%> (ø)
...ufservices/federated-graph/createFederatedGraph.ts 72.22% <100.00%> (ø)
.../bufservices/federated-graph/moveFederatedGraph.ts 86.26% <100.00%> (ø)
...ufservices/federated-graph/updateFederatedGraph.ts 86.53% <100.00%> (ø)
... and 22 more

... and 781 files 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.

@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: 3

🧹 Nitpick comments (2)
controlplane/src/core/bufservices/NodeService.ts (1)

71-71: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add explicit handler types.

Line 71 relies on contextual types for req and ctx. Add explicit parameter types and a return type for generateQuery.

As per coding guidelines, use explicit type annotations for function parameters and return types in TypeScript.

🤖 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/bufservices/NodeService.ts` at line 71, Update the
generateQuery method signature in NodeService to add explicit TypeScript types
for both req and ctx parameters and its return type, using the existing request,
context, and response types established by the service rather than relying on
contextual inference.

Source: Coding guidelines

controlplane/src/core/services/PromptToQueryService.ts (1)

135-135: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Declare the return type.

Add : Promise<void> to indexSchema.

As per coding guidelines, “Use explicit type annotations for function parameters and return types in TypeScript.”

🤖 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/services/PromptToQueryService.ts` at line 135, Update
the PromptToQueryService.indexSchema method to include an explicit return type
annotation of Promise<void>. Keep the existing async behavior and implementation
unchanged, and apply the annotation directly on indexSchema so it matches the
TypeScript return-type guideline.

Source: Coding guidelines

🤖 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/bufservices/NodeService.ts`:
- Line 85: Update the request flow in NodeService around
ptqService.generateQuery to resolve the requested schemaHash against
authContext.federatedGraphId and authContext.organizationId, authorize that
association, and pass only the validated graph-bound hash to
PromptToQueryService instead of forwarding the caller-controlled value directly.

In `@controlplane/src/core/env.schema.ts`:
- Around line 233-236: Update the PROMPT_TO_QUERY_SERVICE_ENDPOINT schema
definition in env.schema.ts to accept only HTTPS URLs, replacing the current
generic URL validation while preserving its optional behavior.

In `@controlplane/src/core/services/PromptToQueryService.ts`:
- Line 113: Remove the unconditional console.log call in PromptToQueryService’s
response-parsing flow. Do not emit parser output for valid responses; if logging
invalid-response details is required, route it through this.logger with
controlled failure metadata instead.

---

Nitpick comments:
In `@controlplane/src/core/bufservices/NodeService.ts`:
- Line 71: Update the generateQuery method signature in NodeService to add
explicit TypeScript types for both req and ctx parameters and its return type,
using the existing request, context, and response types established by the
service rather than relying on contextual inference.

In `@controlplane/src/core/services/PromptToQueryService.ts`:
- Line 135: Update the PromptToQueryService.indexSchema method to include an
explicit return type annotation of Promise<void>. Keep the existing async
behavior and implementation unchanged, and apply the annotation directly on
indexSchema so it matches the TypeScript return-type guideline.
🪄 Autofix

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: a20cbab0-fe77-48fa-8838-9ce1ba16ccb2

📥 Commits

Reviewing files that changed from the base of the PR and between 2f50ab8 and b9c52bf.

⛔ Files ignored due to path filters (4)
  • connect-go/gen/proto/wg/cosmo/node/v1/node.pb.go is excluded by !**/*.pb.go, !**/gen/**
  • connect-go/gen/proto/wg/cosmo/node/v1/nodev1connect/node.connect.go is excluded by !**/gen/**
  • router/gen/proto/wg/cosmo/node/v1/node.pb.go is excluded by !**/*.pb.go, !**/gen/**
  • router/gen/proto/wg/cosmo/node/v1/nodev1connect/node.connect.go is excluded by !**/gen/**
📒 Files selected for processing (34)
  • connect/src/wg/cosmo/node/v1/node-NodeService_connectquery.ts
  • connect/src/wg/cosmo/node/v1/node_pb.ts
  • controlplane/.env.example
  • controlplane/src/core/bufservices/NodeService.ts
  • controlplane/src/core/bufservices/contract/createContract.ts
  • controlplane/src/core/bufservices/contract/updateContract.ts
  • controlplane/src/core/bufservices/feature-flag/createFeatureFlag.ts
  • controlplane/src/core/bufservices/feature-flag/deleteFeatureFlag.ts
  • controlplane/src/core/bufservices/feature-flag/enableFeatureFlag.ts
  • controlplane/src/core/bufservices/feature-flag/recomposeFeatureFlag.ts
  • controlplane/src/core/bufservices/feature-flag/updateFeatureFlag.ts
  • controlplane/src/core/bufservices/federated-graph/createFederatedGraph.ts
  • controlplane/src/core/bufservices/federated-graph/migrateFromApollo.ts
  • controlplane/src/core/bufservices/federated-graph/moveFederatedGraph.ts
  • controlplane/src/core/bufservices/federated-graph/updateFederatedGraph.ts
  • controlplane/src/core/bufservices/graph/recomposeGraph.ts
  • controlplane/src/core/bufservices/graph/setGraphRouterCompatibilityVersion.ts
  • controlplane/src/core/bufservices/monograph/publishMonograph.ts
  • controlplane/src/core/bufservices/monograph/updateMonograph.ts
  • controlplane/src/core/bufservices/subgraph/deleteFederatedSubgraph.ts
  • controlplane/src/core/bufservices/subgraph/moveSubgraph.ts
  • controlplane/src/core/bufservices/subgraph/publishFederatedSubgraph.ts
  • controlplane/src/core/bufservices/subgraph/publishFederatedSubgraphs.ts
  • controlplane/src/core/bufservices/subgraph/updateSubgraph.ts
  • controlplane/src/core/build-server.ts
  • controlplane/src/core/composition/composer.ts
  • controlplane/src/core/env.schema.ts
  • controlplane/src/core/repositories/OrganizationRepository.ts
  • controlplane/src/core/routes.ts
  • controlplane/src/core/services/CompositionService.ts
  • controlplane/src/core/services/PromptToQueryService.ts
  • controlplane/src/index.ts
  • controlplane/src/types/index.ts
  • proto/wg/cosmo/node/v1/node.proto

opts.billingDefaultPlanId,
);

return ptqService.generateQuery(req.schemaHash, req.prompt);

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.

🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

ast-grep outline controlplane/src/core/bufservices/NodeService.ts --items all

rg -n -C 5 'schemaHash|schemaSha|indexId|EnsureIndex|indexSchema|GenerateQuery' controlplane connect proto
rg -n -C 5 'authenticateRouter|federatedGraphId|organizationId' controlplane/src

Repository: wundergraph/cosmo

Length of output: 50374


Authorization Bypass (CWE-639): Authorization Bypass Through User-Controlled Key (IDOR)

Reachability: External · Exploitability: Moderate

Reachability path
● Entry
  connect/src/wg/cosmo/node/v1/node-NodeService_connectquery.ts:15
  generateQuery
│
▼
● Sink
  controlplane/src/core/bufservices/NodeService.ts

Bind schemaHash to the authenticated router graph.

generateQuery scopes only the feature check to authContext.organizationId and forwards the caller-controlled hash as indexId. Resolve and authorize the hash for authContext.federatedGraphId and authContext.organizationId before calling PromptToQueryService.

🤖 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/bufservices/NodeService.ts` at line 85, Update the
request flow in NodeService around ptqService.generateQuery to resolve the
requested schemaHash against authContext.federatedGraphId and
authContext.organizationId, authorize that association, and pass only the
validated graph-bound hash to PromptToQueryService instead of forwarding the
caller-controlled value directly.

Comment on lines +233 to +236
/**
* Prompt-to-Query
*/
PROMPT_TO_QUERY_SERVICE_ENDPOINT: z.string().url().optional(),

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.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- references ---'
rg -n -C 5 --glob '!node_modules' --glob '!dist' --glob '!build' \
  'PROMPT_TO_QUERY_SERVICE_ENDPOINT|Prompt.?to.?Query|prompt.?to.?query' .

printf '%s\n' '--- candidate files ---'
git ls-files | rg -i 'prompt|query|env|docker|helm|kubernetes|compose|deployment|readme|config' | head -200

Repository: wundergraph/cosmo

Length of output: 19182


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- PromptToQueryService structure ---'
ast-grep outline controlplane/src/core/services/PromptToQueryService.ts

printf '%s\n' '--- service implementation ---'
sed -n '1,190p' controlplane/src/core/services/PromptToQueryService.ts

printf '%s\n' '--- HTTP client and promptToQuery wiring ---'
rg -n -C 8 --glob '*.ts' --glob '*.tsx' \
  'promptToQuery|serviceAddress|httpClient|GenerateQuery|YokoService' controlplane/src

printf '%s\n' '--- configuration examples and deployment references ---'
rg -n -C 6 --glob '!node_modules' --glob '!dist' --glob '!build' \
  'PROMPT_TO_QUERY_SERVICE_ENDPOINT|prompt-to-query|Prompt To Query' \
  controlplane docker docker-compose.yml docker-compose.full.yml docker-compose.cosmo.yml \
  .github docs-website 2>/dev/null || true

Repository: wundergraph/cosmo

Length of output: 50374


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- exact endpoint configuration references ---'
rg -n -C 8 --glob '!node_modules' --glob '!dist' --glob '!build' \
  'PROMPT_TO_QUERY_SERVICE_ENDPOINT' controlplane .github docs-website docker docker-compose.yml docker-compose.full.yml docker-compose.cosmo.yml

printf '%s\n' '--- PTQ method callers and request entry points ---'
rg -n -C 6 --glob '*.ts' --glob '*.tsx' \
  '\.generateQuery\(|generateQuery\(|\.indexSchema\(|indexSchema\(' controlplane/src

printf '%s\n' '--- deployment transport controls near controlplane configuration ---'
rg -n -C 5 --glob '*.yaml' --glob '*.yml' --glob '*.md' --glob '*.env.example' \
  'PROMPT_TO_QUERY|controlplane.*(url|host)|https://|http://' \
  .github docs-website controlplane docker docker-compose.yml docker-compose.full.yml docker-compose.cosmo.yml 2>/dev/null | head -300

Repository: wundergraph/cosmo

Length of output: 29384


Security Misconfiguration (CWE-319): Cleartext Transmission of Sensitive Information

Reachability: Internal

Reachability path
● Entry
  controlplane/src/index.ts:83
  envVariables
│
▼
● Sink
  controlplane/src/core/env.schema.ts

Require HTTPS for PROMPT_TO_QUERY_SERVICE_ENDPOINT.

The PTQ client sends prompts and schema data through Axios. The schema accepts http://, which can expose this data on untrusted networks. Require HTTPS or enforce a private, authenticated network boundary.

🤖 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/env.schema.ts` around lines 233 - 236, Update the
PROMPT_TO_QUERY_SERVICE_ENDPOINT schema definition in env.schema.ts to accept
only HTTPS URLs, replacing the current generic URL validation while preserving
its optional behavior.

Comment thread controlplane/src/core/services/PromptToQueryService.ts Outdated
@github-actions

Copy link
Copy Markdown

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions Bot added the Stale label Aug 20, 2026
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.

1 participant