Skip to content

fix(formatting): consolidate duration formatting into shared utility - #3118

Merged
waleedlatif1 merged 6 commits into
stagingfrom
fix/tracespans
Feb 3, 2026
Merged

fix(formatting): consolidate duration formatting into shared utility#3118
waleedlatif1 merged 6 commits into
stagingfrom
fix/tracespans

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Fixed trace span showing untruncated duration (e.g., 0.44229199923574924ms0.44ms)
  • Consolidated all formatDuration implementations into single shared utility
  • Removed duplicate code from terminal, logs, copilot, and notification files

Type of Change

  • Bug fix

Testing

Tested manually, all 46 unit tests pass

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

vercelBot commented Feb 2, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
ProjectDeploymentActionsUpdated (UTC)
docsSkippedSkippedFeb 3, 2026 7:44am

Request Review

@greptile-apps

greptile-appsBot commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR successfully consolidates duplicate formatDuration implementations scattered across the codebase into a single, robust shared utility in lib/core/utils/formatting.ts. The refactor eliminates code duplication while fixing the trace span display bug where untruncated durations like 0.44229199923574924ms were shown instead of properly formatted values like 0.44ms.

Key Changes

  • New shared utility: Enhanced formatDuration function that handles string and numeric inputs, sub-millisecond precision, and formatting from milliseconds to hours
  • Removed duplicates: Eliminated 5 separate formatDuration implementations from terminal, logs, copilot, notification, and tool-call files
  • Preserved behavior: Carefully maintained original formatting behavior in copilot components (minimum 1s display) through pre-rounding
  • Consistent precision: Added configurable precision option used throughout (precision: 1 for notifications/UI, precision: 2 for logs/terminal)
  • Clean imports: All imports follow the established absolute import pattern from @/lib/core/utils/formatting

Confidence Score: 5/5

  • This PR is safe to merge with no identified risks
  • Excellent refactoring that consolidates duplicate code without changing behavior. All original formatting logic is preserved, imports follow style guidelines, and the fix addresses the reported bug.
  • No files require special attention

Important Files Changed

FilenameOverview
apps/sim/lib/core/utils/formatting.tsAdded shared formatDuration utility with support for string/number inputs, sub-millisecond precision, and minutes/hours formatting
apps/sim/app/workspace/[workspaceId]/logs/utils.tsRemoved duplicate formatDuration implementation, updated formatLatency to use shared utility with precision: 2
apps/sim/background/workspace-notification-delivery.tsRemoved duplicate formatDuration implementation, updated all calls to use shared utility with precision: 1
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsxUpdated import to use shared formatDuration utility, added precision: 2 to all calls

Sequence Diagram

sequenceDiagram
participant UI as UI Components
participant Terminal as Terminal
participant Logs as Logs UI
participant Copilot as Copilot/Tool Call
participant Notification as Notification Service
participant Formatter as formatDuration Utility
Note over UI,Formatter: Duration Formatting Flow
Terminal->>Formatter: formatDuration(durationMs, {precision: 2})
Formatter-->>Terminal: "0.44ms" or "1.23s"
Logs->>Formatter: formatDuration(duration, {precision: 2})
Formatter-->>Logs: "500ms" or "2.50s"
Copilot->>Copilot: Round to min 1s: Math.max(1000, Math.round(ms/1000)*1000)
Copilot->>Formatter: formatDuration(roundedMs)
Formatter-->>Copilot: "1s", "2s", etc.
Notification->>Formatter: formatDuration(totalDurationMs, {precision: 1})
Formatter-->>Notification: "500ms", "1.2s", or "2.5m"
Note over Formatter: Logic:<br/>- Sub-millisecond: 2 decimal places<br/>- < 1000ms: round to integer<br/>- < 60s: format with precision<br/>- >= 60s: minutes/hours
Loading

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Comment threadapps/sim/components/ui/tool-call.tsx
Comment threadapps/sim/background/workspace-notification-delivery.ts
@waleedlatif1

Copy link
Copy Markdown
CollaboratorAuthor

@greptile

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Comment threadapps/sim/lib/core/utils/formatting.ts Outdated

@cursorcursorBot left a comment

Copy link
Copy Markdown

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 3 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment threadapps/sim/app/workspace/[workspaceId]/logs/utils.ts Outdated
@waleedlatif1
waleedlatif1 merged commit f21fe23 into stagingFeb 3, 2026
12 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/tracespans branch February 3, 2026 07:57
@waleedlatif1
waleedlatif1 restored the fix/tracespans branch February 3, 2026 21:03
royceP2 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Mar 3, 2026
…imstudioai#3118)
* fix(formatting): consolidate duration formatting into shared utility
* fix(formatting): preserve original precision and rounding behavior
* fix(logs): add precision to logs list duration formatting
* fix(formatting): use parseFloat to preserve fractional milliseconds
* feat(ee): add enterprise modules (simstudioai#3121)
* fix(formatting): return null for missing values, strip trailing zeros
Sign up for freeto 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.

1 participant

@waleedlatif1