Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

This reverts commit 833e700.

@vercel
Copy link

vercel bot commented Oct 11, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim (staging) Building Building Oct 11, 2025 1:03am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Oct 11, 2025 1:03am

@waleedlatif1 waleedlatif1 merged commit 41ec229 into main Oct 11, 2025
8 of 9 checks passed
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Summary

Reverts commit 833e700 which added Redis as a priority storage option for session data in better-auth.

Major changes:

  • Removed Redis secondary storage from better-auth session configuration in apps/sim/lib/auth.ts:62-72
  • Re-introduced complex fallback mechanism in OTP route that attempts to access inMemoryCache via (global as any).inMemoryCache
  • Restored in-memory cache in redis.ts but left it as module-scoped (not exported or attached to global)

Critical issue:
The OTP fallback code at apps/sim/app/api/chat/[identifier]/otp/route.ts:40-50 tries to access inMemoryCache through the global object, but inMemoryCache in redis.ts:14 is only module-scoped and never attached to global. This means the fallback will silently fail when Redis is unavailable, breaking OTP functionality for environments without Redis.

Confidence Score: 0/5

  • This PR contains a critical runtime bug that will break OTP authentication in non-Redis environments
  • The revert introduces broken code that attempts to access a module-scoped variable through the global object, which will always return undefined. This will cause OTP storage to silently fail when Redis is not available, breaking authentication flows.
  • apps/sim/app/api/chat/[identifier]/otp/route.ts requires immediate attention - the fallback cache access pattern is fundamentally broken

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/app/api/chat/[identifier]/otp/route.ts 1/5 Reverted to complex fallback mechanism with broken global cache access that will fail at runtime
apps/sim/lib/auth.ts 5/5 Removed Redis secondary storage configuration for better-auth sessions
apps/sim/lib/redis.ts 3/5 Re-added in-memory cache fallback but not exported or accessible from other modules

Sequence Diagram

sequenceDiagram
    participant Client
    participant OTPRoute
    participant Redis
    participant InMemoryCache
    participant BetterAuth
    participant Database

    Note over Client,Database: OTP Flow After Revert
    
    Client->>OTPRoute: Request OTP
    OTPRoute->>Database: Query chat config
    Database-->>OTPRoute: Chat details
    OTPRoute->>OTPRoute: Generate OTP code
    OTPRoute->>Redis: Check if available
    
    alt Redis Available
        Redis-->>OTPRoute: Client instance
        OTPRoute->>Redis: Store OTP
        Redis-->>OTPRoute: Stored
    else Redis Not Available
        Redis-->>OTPRoute: null
        OTPRoute->>InMemoryCache: Try global access
        Note over OTPRoute,InMemoryCache: Bug: cache not exported
        InMemoryCache-->>OTPRoute: undefined
    end
    
    OTPRoute->>Client: Success response
    
    Note over Client,Database: Session Storage After Revert
    
    Client->>BetterAuth: Auth request
    BetterAuth->>Database: Store in PostgreSQL only
    Note over BetterAuth: Redis secondary storage removed
    BetterAuth-->>Client: Session created
Loading

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +40 to +41
// Access the in-memory cache directly - hacky but works for fallback
const inMemoryCache = (global as any).inMemoryCache
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: accessing inMemoryCache via (global as any).inMemoryCache breaks because inMemoryCache in redis.ts is module-scoped, not attached to global

Suggested change
// Access the in-memory cache directly - hacky but works for fallback
const inMemoryCache = (global as any).inMemoryCache
// inMemoryCache is not accessible here - this code will not work
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/api/chat/[identifier]/otp/route.ts
Line: 40:41

Comment:
**logic:** accessing `inMemoryCache` via `(global as any).inMemoryCache` breaks because `inMemoryCache` in `redis.ts` is module-scoped, not attached to global

```suggestion
      // inMemoryCache is not accessible here - this code will not work
```

How can I resolve this? If you propose a fix, please make it concise.

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