Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Must evict undo-redo stacks to 5 most recent edited workflows.

Type of Change

  • Bug fix

Testing

Tested manually

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)

@vercel
Copy link

vercel bot commented Nov 20, 2025

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

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Nov 20, 2025 8:08pm

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 20, 2025

Greptile Overview

Greptile Summary

Implements LRU (Least Recently Used) eviction policy for undo-redo stacks to prevent unbounded memory growth in localStorage.

Key changes:

  • Added MAX_STACKS constant (5) to limit number of workflow undo-redo stacks
  • Added lastUpdated timestamp tracking to each stack for LRU eviction
  • Implemented eviction logic that removes the oldest stack when creating a 6th stack
  • Added safeStorageAdapter to gracefully handle localStorage QuotaExceededError
  • Updated all stack operations (push, undo, redo) to maintain lastUpdated timestamps

The implementation correctly handles edge cases like existing stacks without lastUpdated (defaults to 0, evicted first) and maintains backward compatibility.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • the LRU eviction logic is correctly implemented (evicts only when creating a new stack beyond MAX_STACKS limit), localStorage error handling is robust, backward compatibility is maintained with default timestamp of 0 for old stacks
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/stores/undo-redo/store.ts 5/5 implemented LRU eviction policy for undo-redo stacks (max 5 workflows), added safe localStorage adapter to handle quota errors
apps/sim/stores/undo-redo/types.ts 5/5 added optional lastUpdated timestamp field to track most recently edited workflows for eviction

Sequence Diagram

sequenceDiagram
    participant User
    participant Store as UndoRedoStore
    participant Storage as safeStorageAdapter
    participant LS as localStorage

    User->>Store: push(workflowId, userId, entry)
    Store->>Store: Check if stackKeys.length >= MAX_STACKS
    alt Creating new stack when at limit
        Store->>Store: Find oldest stack by lastUpdated
        Store->>Store: Delete oldest stack
    end
    Store->>Store: Update/create stack with entry
    Store->>Store: Set lastUpdated = Date.now()
    Store->>Storage: setItem(state)
    alt localStorage has space
        Storage->>LS: localStorage.setItem()
    else QuotaExceededError
        Storage->>Storage: Log warning, continue
    end
    
    User->>Store: undo/redo operation
    Store->>Store: Update lastUpdated = Date.now()
    Store->>Storage: setItem(state)
    Storage->>LS: localStorage.setItem()
Loading

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.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@icecrasher321 icecrasher321 merged commit d7586cd into staging Nov 20, 2025
4 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/undo-redo-eviction branch November 22, 2025 03:52
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