Skip to content

fix(ai-gateway): keep data-collecting models out of Auto Efficient under data collection deny - #6728

Merged
chrarnoldus merged 3 commits into
mainfrom
fix/auto-data-collection-deny
Sep 25, 2026
Merged

chrarnoldus merged 3 commits into
mainfrom
fix/auto-data-collection-deny

Conversation

@chrarnoldus

Copy link
Copy Markdown
Contributor

Summary

kilo-auto/efficient and kilo-auto/balanced could route to a model that only has data-collecting endpoints (for example meta/muse-spark-1.3-contributor) even when the organization or request denies data collection. OpenRouter then rejects the request because no endpoint matches the data policy.

  • Data-collection metadata from OpenRouter: buildDataCollectionRequiredModelIds derives the exact model variants that train on prompts at every provider from the stored models-by-provider snapshot. That snapshot contains OpenRouter's per-endpoint data_policy, normalized with withWorstProviderDataPolicy and applyFreeEndpointDataPolicy, and the change reuses getSnapshotModelVariantId and modelTrains. The set is cached with the existing models-by-provider index loader.
  • Auto routing: when the effective privacy has data_collection: 'deny' or zdr: true (checked with isDataCollectionExplicitlyDisallowed), the gateway adds routing candidates that require data collection to deniedModelIds for the auto-routing worker. A candidate counts as requiring data collection if it is in that set or matches the existing hasBestEffortGuessDataCollectionRequirement check.
  • mayTrainOnYourPrompts: catalog models are now flagged when they are free or train on prompts at every provider. Before, only free models were flagged. Muse Spark Contributor now shows the data-collection disclosure, and the Teams data_collection: 'deny' catalog filter hides it.

A model where only some providers train is not flagged. Under deny it can still be served through a non-training provider, so hiding it would be wrong.

Verification

  • apps/web typecheck (tsgo) passes.
  • Unit tests added for the snapshot-derived set, candidate filtering, the gateway passing denials (org deny, request deny, request ZDR, allowed), and catalog mayTrainOnYourPrompts. CI runs them.

Failure UX: a deny-list request no longer fails at OpenRouter after routing picks a model that can't serve it; the worker picks an eligible model up front. Genuine failures don't wait any longer: the extra lookup reuses cached data and runs in parallel with the policy lookup.

…der data collection deny

Derive the set of models that train on prompts at every provider from the
OpenRouter models-by-provider snapshot, deny those routing candidates to the
auto-routing worker when the effective privacy denies data collection or
requires ZDR, and use the same set for mayTrainOnYourPrompts in the catalog.
@chrarnoldus chrarnoldus self-assigned this Sep 25, 2026
@kilo-code-bot

kilo-code-bot Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The incremental change makes a failed snapshot read expire immediately so the auto router retries on the next call instead of caching an empty data-collection deny set for the TTL; the new regression test covers the retry path, and no new issues were found in the changed lines.

Files Reviewed (4 files)
  • apps/web/src/lib/ai-gateway/auto-routing-denied-models.test.ts
  • apps/web/src/lib/ai-gateway/providers/openrouter/index.test.ts
  • apps/web/src/lib/ai-gateway/providers/openrouter/models-by-provider-index.server.test.ts
  • apps/web/src/lib/ai-gateway/providers/openrouter/models-by-provider-index.server.ts
Previous Review Summary (commit 4b6a556)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 4b6a556)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1

Fix these issues in Kilo Cloud

Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/app/api/openrouter/[...path]/route.ts 396 ZDR requests are gated through a training-only deny set, so retain-only models are not denied

SUGGESTION

File Line Issue
apps/web/src/lib/ai-gateway/providers/openrouter/models-by-provider-index.server.ts 155 A failed/empty snapshot read caches an empty deny set for the TTL (fail-open)
Files Reviewed (8 files)
  • apps/web/src/app/api/openrouter/[...path]/route.ts - 1 issue
  • apps/web/src/app/api/openrouter/[...path]/route.test.ts - 0 issues
  • apps/web/src/lib/ai-gateway/auto-routing-denied-models.ts - 0 issues
  • apps/web/src/lib/ai-gateway/auto-routing-denied-models.test.ts - 0 issues
  • apps/web/src/lib/ai-gateway/providers/openrouter/index.ts - 0 issues
  • apps/web/src/lib/ai-gateway/providers/openrouter/index.test.ts - 0 issues
  • apps/web/src/lib/ai-gateway/providers/openrouter/models-by-provider-index.server.ts - 1 issue
  • apps/web/src/lib/ai-gateway/providers/openrouter/models-by-provider-index.server.test.ts - 0 issues

Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

chrarnoldus and others added 2 commits September 25, 2026 14:09
Do not cache a failed models-by-provider snapshot read for the TTL, so an
empty data-collection set falls back to best-effort checks only until the
next call. Use the global jest in tests whose jest.mock factories must be
hoisted above imports.
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.

2 participants