Skip to content

fix: return proper type in calculateAndUpdateRequestCost early exit#915

Merged
ding113 merged 1 commit intodevfrom
claude-fix-pr-913-23082651541
Mar 14, 2026
Merged

fix: return proper type in calculateAndUpdateRequestCost early exit#915
ding113 merged 1 commit intodevfrom
claude-fix-pr-913-23082651541

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Mar 14, 2026

CI Auto-Fix

Original PR: #913
Failed CI Run: Non-Main Branch CI/CD

Error Fixed

File Error Fix
src/app/v1/_lib/proxy/response-handler.ts:3111 Type 'undefined' is not assignable to type return object Changed bare return; to return proper object structure

Analysis

The function calculateAndUpdateRequestCost has a return type of:

{
  costUsd: string | null;
  resolvedPricing: ResolvedPricing | null;
  longContextPricing: ResolvedLongContextPricing | null;
  longContextPricingApplied: boolean;
}

The early return at line 3111 was using a bare return; which returns undefined, but the function expects an object. The fix returns the same structure as other early returns in the function (lines 3058-3063, 3050-3053, 3168-3173).

Verification

  • bun run typecheck passes
  • No logic changes made - only fixed the return type
  • Change is minimal and targeted

Auto-generated by Claude AI

Greptile Summary

This PR fixes a type error in updateRequestCostFromUsage where a bare return; on the "no price data found" code path returned undefined instead of the expected { costUsd, resolvedPricing, longContextPricing, longContextPricingApplied } object. All three call sites (lines 1001, 2016, 3251) immediately access costUpdateResult.longContextPricingApplied, so the bare return would have caused a runtime TypeError when no pricing data was available for a model. The fix returns the same null-valued object structure used by the other early-return paths in the function.

  • Bug fixed: bare return; → proper object return in the "missing price data" branch of updateRequestCostFromUsage
  • No logic changes: the returned values (null / false) match the semantics of all other early exits in the function
  • Impact: prevents a runtime crash when a model has no price data configured

Confidence Score: 5/5

  • This PR is safe to merge — it fixes a clear type/runtime bug with a minimal, correct change.
  • The change is a one-line-to-five-line fix that replaces a bare return; with the correct object return type. It exactly matches the pattern of all other early returns in the same function. There are no logic changes, no new dependencies, and it fixes a real runtime crash path.
  • No files require special attention.

Important Files Changed

Filename Overview
src/app/v1/_lib/proxy/response-handler.ts Fixes a bare return; that returned undefined instead of the expected object, which would cause a runtime TypeError at all three call sites that immediately access .longContextPricingApplied on the result.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[updateRequestCostFromUsage called] --> B{usage exists?}
    B -- No --> R1["return { costUsd: null, ... }"]
    B -- Yes --> C{model available?}
    C -- No --> R2["return { costUsd: null, ... }"]
    C -- Yes --> D[Resolve pricing from DB]
    D --> E{priceData valid?}
    E -- "No (BUG FIX HERE)" --> F["return { costUsd: null, ... }"]
    E -- Yes --> G[Calculate cost]
    G --> H{cost > 0?}
    H -- Yes --> R3["return { costUsd: cost, resolvedPricing, ... }"]
    H -- No --> R4["return { costUsd: null, resolvedPricing, ... }"]
    
    style F fill:#90EE90,stroke:#333,stroke-width:2px
Loading

Last reviewed commit: 35848b7

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant