Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

waleedlatif1 and others added 6 commits December 20, 2025 13:33
…g indexes based on query insights (#2471)

* improvement(queries): added missing indexes

* add workspaceId to execution logs

* remove migration to prep merge

* regen migration

---------

Co-authored-by: Vikhyath Mondreti <vikhyath@simstudio.ai>
…plan (#2465)

* Add limit v1

* fix ui for copilot upgrade limit inline

* open settings modal

* Upgrade plan button

* Remove comments

* Ishosted check

* Fix hardcoded bumps

---------

Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com>
Co-authored-by: Waleed <walif6@gmail.com>
Co-authored-by: Vikhyath Mondreti <vikhyath@simstudio.ai>
* feat(audit): added audit log for billing line items

* remove migration

* reran migrations after resolving merge conflict

* ack PR comment
* feat(settings): added snap to grid slider to settings

* ack PR comments

* ack PR comment
@vercel
Copy link

vercel bot commented Dec 21, 2025

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Dec 21, 2025 1:21am

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 21, 2025

Greptile Summary

This release combines multiple features and performance improvements across the platform:

  • Performance optimization: Added workspaceId column to workflow_execution_logs with proper backfill, enabling direct filtering and removing expensive join operations through the workflow table
  • Billing audit trail: Created comprehensive usage_log table and API infrastructure to track individual line items for model usage (with token counts) and fixed charges, supporting detailed billing transparency
  • Copilot UX enhancement: Added inline usage limit increase UI that allows users to quickly upgrade their limit in $50 increments or navigate to subscription settings when hitting usage caps
  • Canvas feature: Implemented snap-to-grid functionality (0-50px) with new Slider component in settings, giving users fine-grained control over canvas snapping behavior
  • Bug fix: Resolved cmd-z after refocus issue in code editor by tracking edit state and preventing undo when no edits have been made since focus

All database migrations follow safe patterns with proper backfilling and indexing. The changes maintain backward compatibility and include appropriate error handling.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - well-structured changes with proper migrations and error handling
  • All changes follow established patterns, database migrations are properly designed with safe backfill operations, new features have appropriate fallbacks, and the code quality is consistent throughout. No security vulnerabilities or breaking changes detected.
  • No files require special attention

Important Files Changed

Filename Overview
packages/db/migrations/0127_flimsy_sister_grimm.sql Adds workspace_id column to workflow_execution_logs with proper backfill and indexing for improved query performance
packages/db/migrations/0128_swift_terrax.sql Creates usage_log table with proper enums, foreign keys, and indexes for billing line items tracking
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-message/components/usage-limit-actions.tsx Adds inline UI for increasing usage limits with options to upgrade or adjust limit by $50 increments
apps/sim/components/emcn/components/slider/slider.tsx New EMCN Slider component built on Radix UI with consistent styling matching other components
apps/sim/lib/billing/core/usage-log.ts Comprehensive usage logging system with model and fixed charge tracking, batch operations, and query functions for billing audit trail
apps/sim/lib/logs/execution/logger.ts Added workspaceId parameter throughout execution logging and integrated batch usage log creation for billing audit trail
apps/sim/app/api/logs/route.ts Optimized logs query to use workspaceId directly from execution logs instead of joining through workflow table

Sequence Diagram

sequenceDiagram
    participant User
    participant Frontend
    participant API
    participant DB
    participant Billing

    Note over User,Billing: Copilot Usage Limit Flow
    User->>Frontend: Use copilot
    Frontend->>API: POST /api/billing/update-cost
    API->>DB: Update user_stats
    API->>DB: Insert usage_log entry
    API->>Billing: checkAndBillOverageThreshold()
    alt Usage limit exceeded
        API-->>Frontend: 402 Payment Required
        Frontend->>User: Show usage limit actions
        User->>Frontend: Click $50 / $100 / Upgrade
        Frontend->>API: Update usage limit
        API->>DB: Update limit
        Frontend->>API: Retry original request
    end

    Note over User,DB: Workflow Execution with Logging
    User->>Frontend: Execute workflow
    Frontend->>API: POST /api/workflows/{id}/execute
    API->>DB: Start execution (with workspaceId)
    API->>DB: Create execution log entry
    Note over DB: workspaceId enables direct filtering
    API->>Billing: Update costs & log usage
    Billing->>DB: Batch insert usage_log entries
    API-->>Frontend: Execution complete

    Note over User,DB: Snap to Grid Feature
    User->>Frontend: Open settings
    Frontend->>API: GET /api/users/me/settings
    API->>DB: Fetch settings
    DB-->>Frontend: snapToGridSize: 0-50
    User->>Frontend: Adjust slider
    Frontend->>API: PATCH settings
    API->>DB: Update snap_to_grid_size
    Frontend->>Frontend: Apply to canvas
Loading

@waleedlatif1 waleedlatif1 merged commit 4827866 into main Dec 21, 2025
25 checks passed
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.

4 participants