Skip to content

Revert "feat(hosted key): Add exa hosted key (#3221)"#3495

Merged
waleedlatif1 merged 1 commit intostagingfrom
fix/revert-exa-hosted-key
Mar 9, 2026
Merged

Revert "feat(hosted key): Add exa hosted key (#3221)"#3495
waleedlatif1 merged 1 commit intostagingfrom
fix/revert-exa-hosted-key

Conversation

@TheodoreSpeaks
Copy link
Collaborator

Summary

Exa hosted key requires a migration first. To unblock staging, reverting this change for now.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: revert

Testing

None. This should revert the state to pre-exa.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

@vercel
Copy link

vercel bot commented Mar 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Mar 9, 2026 5:25pm

Request Review

@cursor
Copy link

cursor bot commented Mar 9, 2026

PR Summary

Medium Risk
Medium risk because it changes tool execution/billing surfaces (removes hosted-key injection/retry/cost logging and drops toolCost aggregation) and tweaks DB token-bucket behavior, which could affect throttling and cost reporting.

Overview
Reverts the previously added Exa hosted-key support: Exa is removed from workspace BYOK provider lists/UI, Exa tools drop their hosting config and internal cost fields, and the hosted-key rate limiter module + related telemetry/test coverage are deleted.

Tool execution is simplified to always require an API key when marked required (no hosted-key fallback) and no longer retries on hosted-key 429s or logs fixed tool charges. Provider/execution cost reporting is adjusted to remove toolCost aggregation across tool loops, and the generic block handler now universally normalizes any output.cost into {cost, tokens, model} for logging; knowledge tool response transforms/tests are updated accordingly.

Separately, rate-limiter DB token-bucket updates no longer write -1 tokens on failed consumption.

Written by Cursor Bugbot for commit fe577b0. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

)::numeric
) - ${requestedTokens}::numeric
ELSE -1
ELSE ${rateLimitBucket.tokens}::numeric
Copy link

Choose a reason for hiding this comment

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

Rate limiter allows denied requests due to ELSE clause

High Severity

The ELSE branch in the token consumption SQL was changed from -1 to ${rateLimitBucket.tokens}::numeric. The allowed check on line 85 uses tokens >= 0. When a request is denied (insufficient tokens), the current token count (a non-negative value like 3) is now returned instead of -1, so allowed evaluates to true — effectively disabling rate limiting for all consumers of DbTokenBucket.

Fix in Cursor Fix in Web

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Current behavior. There is an issue, but will be addressed once this is un-reverted

@waleedlatif1 waleedlatif1 merged commit 635179d into staging Mar 9, 2026
12 checks passed
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 9, 2026

Greptile Summary

This PR reverts the Exa hosted key feature (#3221) to unblock staging while a required database migration is prepared. The revert removes the hosted key injection pipeline, rate-limiter infrastructure, BYOK Exa support, telemetry events, and __costDollars cost-tracking from all four Exa tools. It also ships a new cost-restructuring enhancement in GenericBlockHandler (extracting cost, tokens, and model from knowledge tool outputs) together with corresponding test coverage, and simplifies the raw cost pass-through in knowledge/search.ts and knowledge/upload_chunk.ts.

Key changes:

  • Removes injectHostedKeyIfNeeded, executeWithRetry, processHostedKeyCost, reportCustomDimensionUsage, stripInternalFields, and applyHostedKeyCostToResult from tools/index.ts
  • Deletes the entire lib/core/rate-limiter/hosted-key/ module (rate limiter, types, tests)
  • Removes hosting config from all four Exa tools (search, answer, get_contents, find_similar_links) and drops __costDollars from their responses
  • Removes exa from VALID_PROVIDERS in the BYOK API route and from the BYOK settings UI
  • Removes sumToolCosts and toolCost accumulation from all 11 provider implementations
  • Adds cost restructuring in GenericBlockHandler and 215 lines of new tests for knowledge block cost tracking
  • Introduces duplicate BYOKProviderId type declarations in byok-keys.ts and lib/api-key/byok.ts (previously a single import from tools/types.ts)
  • Changes toolResults from Record<string, unknown>[] to any[], weakening type safety
  • Changes FixedUsageMetadata from Record<string, unknown> to Record<string, never> and removes its parameter usage

Confidence Score: 4/5

  • This PR is safe to merge — it correctly reverts the Exa hosted key feature with comprehensive cleanup. Three style/maintenance concerns identified do not affect runtime behavior.
  • The revert is comprehensive and internally consistent: all callers of removed APIs are cleaned up across all 11 providers and downstream utilities. The additional GenericBlockHandler cost-tracking code is well-tested. However, three style-level issues remain: (1) duplicated BYOKProviderId type definition across two files, (2) type regression in toolResults from Record<string, unknown>[] to any[], and (3) unused FixedUsageMetadata type now set to Record<string, never>. These should be addressed post-merge to maintain type safety and prevent future drift.
  • apps/sim/hooks/queries/byok-keys.ts and apps/sim/lib/api-key/byok.ts (consolidate BYOKProviderId), apps/sim/providers/types.ts (restore toolResults type), apps/sim/lib/billing/core/usage-log.ts (clarify or remove FixedUsageMetadata).

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[executeTool called] --> B{Tool has hosting config?}
    B -- "YES (removed)" --> C["injectHostedKeyIfNeeded (deleted)"]
    C --> D{BYOK key available?}
    D -- Yes --> E[Use user BYOK key]
    D -- No --> F[Acquire hosted key via RateLimiter]
    F --> G{Rate limited?}
    G -- Yes --> H[Throw 429 / fire telemetry]
    G -- No --> I[Inject hosted API key]
    I --> J["executeWithRetry (deleted)"]
    J --> K[executeToolRequest]
    K --> L["applyHostedKeyCostToResult (deleted)"]
    L --> M["stripInternalFields (deleted)"]
    M --> N[Return result]

    B -- "NO / after revert" --> O[executeToolRequest directly]
    O --> N2[Return result]

    style C fill:#f88,stroke:#c00
    style D fill:#f88,stroke:#c00
    style E fill:#f88,stroke:#c00
    style F fill:#f88,stroke:#c00
    style G fill:#f88,stroke:#c00
    style H fill:#f88,stroke:#c00
    style I fill:#f88,stroke:#c00
    style J fill:#f88,stroke:#c00
    style L fill:#f88,stroke:#c00
    style M fill:#f88,stroke:#c00
    style O fill:#9f9,stroke:#060
    style N2 fill:#9f9,stroke:#060
Loading

Last reviewed commit: fe577b0


const logger = createLogger('BYOKKeysQueries')

export type BYOKProviderId = 'openai' | 'anthropic' | 'google' | 'mistral'
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicated BYOKProviderId type definition. This type is now declared identically in both apps/sim/hooks/queries/byok-keys.ts and apps/sim/lib/api-key/byok.ts. Previously it lived in a single place (tools/types.ts) and was imported where needed. With two independent definitions, a future provider addition would require updating both files — and the two definitions could silently drift apart.

Consider keeping one authoritative declaration (e.g., in lib/api-key/byok.ts) and importing it in this file:

Suggested change
export type BYOKProviderId = 'openai' | 'anthropic' | 'google' | 'mistral'
import type { BYOKProviderId } from '@/lib/api-key/byok'

}
toolCalls?: FunctionCallResponse[]
toolResults?: Record<string, unknown>[]
toolResults?: any[]
Copy link
Contributor

Choose a reason for hiding this comment

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

Type regression: toolResults weakened to any[]. Previously typed as Record<string, unknown>[] — meaningful structure enforced by the type system. Changing it to any[] removes that constraint and can suppress downstream type errors when iterating tool results.

Since ToolResponse.output is Record<string, any>, the array element type could simply match:

Suggested change
toolResults?: any[]
toolResults?: Record<string, any>[]

*/
export type FixedUsageMetadata = Record<string, unknown>
export type FixedUsageMetadata = Record<string, never>

Copy link
Contributor

Choose a reason for hiding this comment

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

FixedUsageMetadata is now Record<string, never> — an object type with no valid key-value pairs, effectively making it unusable as a data container. The metadata parameter was also removed from LogFixedUsageParams, so this type is no longer used as a function parameter.

Since metadata is now hardcoded to null in logFixedUsage, consider either removing FixedUsageMetadata from the codebase entirely, or adding a clarifying comment if you want to preserve it as a placeholder for future extensibility:

Suggested change
export type FixedUsageMetadata = Record<string, never> // Currently unused; reserved for future fixed-charge metadata

@TheodoreSpeaks TheodoreSpeaks deleted the fix/revert-exa-hosted-key branch March 9, 2026 17:33
TheodoreSpeaks pushed a commit that referenced this pull request Mar 10, 2026
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