Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • change algo to compute colors based on hash of execution id and pointer from bottom

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 Jan 14, 2026

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 14, 2026 7:55pm

@waleedlatif1 waleedlatif1 changed the title fix(terminal-colors): change algo to compute colors based on hash of execution id and pointer from bottom fix(terminal): change algo to compute colors based on hash of execution id and pointer from bottom Jan 14, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 14, 2026

Greptile Summary

Replaced simple index-based color assignment with offset-tracking algorithm to preserve execution colors when old entries are trimmed from the terminal.

Key Changes

  • Color persistence logic: New algorithm tracks an offset that increments when executions are removed, ensuring remaining executions keep their assigned colors
  • Color palette expansion: Increased from 6 to 8 colors (added Teal and Rose) for better differentiation
  • Code organization: Extracted timestamp formatting to shared formatTimeWithSeconds utility in formatting.ts
  • Color data structure: Changed from {text: string} objects to plain color strings

How It Works

The algorithm builds an array of execution IDs from oldest to newest, compares it with the previous state, and when old executions are trimmed, increments the color offset by the number of removed executions. This ensures that if execution A had color green, it keeps green even after older executions B and C are removed from the display.

Confidence Score: 4/5

  • This PR is safe to merge with low risk - implements a well-contained color persistence algorithm with clear logic
  • The changes are focused and localized to color assignment logic with good code organization (extracting formatting utility). The offset-based algorithm is sound for preserving colors when executions are trimmed. Minor point deduction for lack of automated tests to verify the color persistence behavior across different trimming scenarios.
  • No files require special attention - changes are straightforward refactoring with clear intent

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsx Refactored color assignment from simple index mapping to offset-based algorithm; extracted timestamp formatting to shared utility; expanded color palette from 6 to 8 colors
apps/sim/lib/core/utils/formatting.ts Added formatTimeWithSeconds utility function with optional timezone parameter to replace inline formatting logic

Sequence Diagram

sequenceDiagram
    participant Store as Terminal Store
    participant Terminal as Terminal Component
    participant ColorMap as executionColorMap (useMemo)
    participant ColorState as colorStateRef
    participant UI as Run ID Display

    Store->>Terminal: allWorkflowEntries updates
    Note over Terminal: Entries may be trimmed<br/>when limit exceeded
    
    Terminal->>ColorMap: Trigger useMemo recalculation
    
    ColorMap->>ColorMap: Build currentIds array<br/>(oldest to newest)
    Note over ColorMap: Loop entries backward,<br/>collect unique execution IDs
    
    ColorMap->>ColorState: Read previous state<br/>(prevIds, prevOffset)
    
    alt Old executions trimmed
        ColorMap->>ColorMap: Check if prevIds[0] != currentIds[0]
        ColorMap->>ColorMap: Calculate trimmedCount = indexOf(currentOldest)
        ColorMap->>ColorMap: Update newOffset = (prevOffset + trimmedCount) % 8
    else No trimming
        ColorMap->>ColorMap: Keep prevOffset unchanged
    end
    
    ColorMap->>ColorMap: Assign colors:<br/>RUN_ID_COLORS[(newOffset + i) % 8]
    
    ColorMap->>ColorState: Save new state<br/>(currentIds, newOffset)
    
    ColorMap->>Terminal: Return executionColorMap
    
    Terminal->>UI: Render run IDs with colors
    UI->>ColorMap: getRunIdColor(executionId, colorMap)
    ColorMap->>UI: Return color string (e.g., '#4ADE80')
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

@waleedlatif1
Copy link
Collaborator Author

@greptile

@waleedlatif1 waleedlatif1 merged commit 468ec2e into staging Jan 14, 2026
11 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/terminal-colors branch January 14, 2026 20:06
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