Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

fix(devcontainer): fixed devcontainers (#1614)

fix(posthog): prevent redirects by whitelisting ingest route (#1615)

fix(kb): added tiktoken for embedding token estimation (#1616)

feat(helm): added pdb to helm (#1617)

fix(schedules): migrate to trigger dev (#1618)

fix(sdk): fixed TS SDK publishing job to use later Node version (#1619)

feat(helm): added cert-postgresql template to helm (#1620)

waleedlatif1 and others added 7 commits October 12, 2025 18:01
* fix(kb): added tiktoken for embedding token estimation

* added missing mock
* feat(helm): added pdb to helm

* add additional config
* feat(helm): added cert-postgresql template to helm

* use js-tiktoken (pure js) in favor of tiktoken (wasm)
* fix(schedules): add cron job auth like other cron routes

* migrate schedules to trigger dev

* remove executions check

* fix tests
@vercel
Copy link

vercel bot commented Oct 13, 2025

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

Project Deployment Preview Comments Updated (UTC)
docs Ready Ready Preview Comment Oct 13, 2025 9:16pm

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

This PR consolidates 7 bug fixes and feature additions across infrastructure, performance, and developer tooling:

Major Changes:

  • Schedule execution migration to trigger.dev: Refactored schedule execution from monolithic API route to task-based architecture with executeScheduleJob function, adding proper authentication via verifyCronAuth and supporting both trigger.dev and direct execution modes
  • Token-aware embedding batching: Replaced fixed 50-item batching with accurate token counting using tiktoken library, batching by 8000 tokens for more efficient API usage and preventing request failures
  • PostHog optimization: Disabled heavy features (pageleave, performance tracking, heatmaps, dead clicks) and narrowed autocapture scope; prevented redirect loops by excluding /ingest path from domain redirects
  • DevContainer improvements: Complete rewrite with proper docker-compose setup, non-root user configuration, automated dependency installation and database migrations
  • Helm enhancements: Added PodDisruptionBudget for high availability and PostgreSQL TLS certificate template for secure connections
  • SDK publishing fix: Upgraded Node.js to v22 in CI workflow to support File type

Key Improvements:

  • Better separation of concerns with schedule execution logic extracted to dedicated background task file
  • More accurate token counting prevents API errors and optimizes costs
  • Reduced PostHog overhead and eliminated redirect issues
  • Production-ready Kubernetes configurations for availability and security

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk - changes are well-isolated, focused bug fixes with one minor concern around error handling.
  • The PR demonstrates solid engineering practices with good separation of concerns, comprehensive error handling, and appropriate testing. The schedule execution refactoring properly extracts complex logic, the tiktoken integration uses established libraries correctly, and infrastructure changes follow Kubernetes best practices. Score is 4/5 rather than 5/5 due to one observation: the direct execution path uses fire-and-forget pattern (void executeScheduleJob) which could mask failures, though this appears intentional for the fallback mode.
  • No files require special attention - all changes are straightforward and well-implemented

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/app/api/schedules/execute/route.ts 4/5 Refactored to delegate schedule execution to trigger.dev tasks or direct execution via executeScheduleJob. Added verifyCronAuth check for security.
apps/sim/background/schedule-execution.ts 4/5 New file containing extracted schedule execution logic with comprehensive error handling, rate limiting, usage checks, and trigger.dev integration.
apps/sim/lib/tokenization/estimators.ts 5/5 Added tiktoken integration for accurate token counting with OpenAI models, including batching utilities and truncation functions.
apps/sim/lib/embeddings/utils.ts 5/5 Migrated from fixed-size batching (50 items) to token-aware batching (8000 tokens) using tiktoken for more efficient API usage.
apps/sim/lib/posthog/provider.tsx 5/5 Reduced PostHog feature set (disabled pageleave, performance tracking, heatmaps, dead clicks) and narrowed autocapture scope to improve performance.
apps/sim/next.config.ts 5/5 Added /ingest path to redirect exclusions to prevent PostHog analytics calls from being redirected to sim.ai domain.
.devcontainer/post-create.sh 5/5 Comprehensive setup script that handles dependency installation, database migrations, and shell configuration for development environment.
.github/workflows/publish-ts-sdk.yml 5/5 Updated Node.js version from earlier version to 22 to support File type used in SDK.
helm/sim/templates/poddisruptionbudget.yaml 5/5 New PodDisruptionBudget template for both app and realtime services to ensure high availability during cluster operations.
helm/sim/templates/certificate-postgresql.yaml 5/5 New certificate template for PostgreSQL TLS with cert-manager integration for secure database connections.

Sequence Diagram

sequenceDiagram
    participant Cron as Cron Job
    participant API as /api/schedules/execute
    participant TriggerDev as Trigger.dev
    participant Executor as Schedule Execution
    participant DB as Database
    participant RateLimit as Rate Limiter
    participant Billing as Billing Service
    participant Workflow as Workflow Executor
    
    Cron->>API: GET (scheduled trigger)
    API->>API: verifyCronAuth()
    API->>DB: Query due schedules
    DB-->>API: Return schedules list
    
    alt TRIGGER_DEV_ENABLED
        loop For each schedule
            API->>TriggerDev: tasks.trigger('schedule-execution', payload)
            TriggerDev-->>API: Task handle
        end
        API-->>Cron: 200 OK (queued)
        
        TriggerDev->>Executor: executeScheduleJob(payload)
        Executor->>DB: Load workflow & user data
        Executor->>RateLimit: Check rate limits
        Executor->>Billing: Check usage limits
        
        alt Limits OK
            Executor->>Workflow: Execute workflow
            Workflow-->>Executor: Execution result
            Executor->>DB: Update schedule (nextRunAt, lastRanAt)
            Executor->>DB: Update user stats
        else Rate limited
            Executor->>DB: Set nextRunAt (retry in 5 min)
        else Usage exceeded
            Executor->>DB: Calculate and set nextRunAt
        end
    else Direct execution
        loop For each schedule
            API->>Executor: executeScheduleJob(payload)
            Note over API,Executor: Fire and forget (void)
        end
        API-->>Cron: 200 OK (queued)
    end
Loading

30 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@icecrasher321 icecrasher321 merged commit 7f82ed3 into main Oct 13, 2025
21 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.

3 participants