Skip to content

Blacksmith optimizations created based on Blacksmith support ticket 2052 with Waleed#2054

Closed
ConnorMul wants to merge 16 commits intosimstudioai:mainfrom
ConnorMul:blacksmith-optimizations
Closed

Blacksmith optimizations created based on Blacksmith support ticket 2052 with Waleed#2054
ConnorMul wants to merge 16 commits intosimstudioai:mainfrom
ConnorMul:blacksmith-optimizations

Conversation

@ConnorMul
Copy link
Copy Markdown

Summary

Brief description of what this PR does and why.

Fixes #(issue)

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

How has this been tested? What should reviewers focus on?

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)

Screenshots/Videos

waleedlatif1 and others added 16 commits October 11, 2025 22:23
…oai#1608)

* improvement(performance): remove unused source/target indices, add index on snapshot id (simstudioai#1603)

* fix(blog): rename building to blogs with redirect (simstudioai#1604)

* improvement(privacy-policy): updated privacy policy for google (simstudioai#1602)

* updated privacy policy for google

* update terms, privacy, and emails to incl address and update verbiage

* feat(guardrails): added guardrails block/tools and docs (simstudioai#1605)

* Adding guardrails block

* ack PR comments

* cleanup checkbox in dark mode

* cleanup

* fix supabase tools

* fix(inference-billing): fix inference billing when stream is true via API, add drag-and-drop functionality to deployed chat (simstudioai#1606)

* fix(inference): fix inference billing when stream is true via API

* add drag-and-drop to deployed chat

* feat(mistal): added mistral as a provider, updated model prices (simstudioai#1607)

* feat(mistal): added mistral as a provider, updated model prices

* remove the ability for a block to reference its own outluts

* fixed order of responses for guardrails block

* feat(versions): added the ability to rename deployment versions (simstudioai#1610)

* fix(vulns): fix various vulnerabilities and enhanced code security (simstudioai#1611)

* fix(vulns): fix SSRF vulnerabilities

* cleanup

* cleanup

* regen docs

* remove unused deps

* fix failing tests

* cleanup

* update deps

* regen bun lock
)

* fix(debug-mode): remove duplicate debug mode flag (simstudioai#1714)

* feat(i18n): update translations (simstudioai#1709)

* improvement(condition): added variable and envvar highlighting for condition input (simstudioai#1718)

* fix(dashboard): add additional context for paginated logs in dashboard, add empty state when selected cell has no data (simstudioai#1719)

* fix(dashboard): add additional context for paginated logs in dashboard, add empty state when selected cell has no data

* apps/sim

* renaming

* remove relative import

* feat(tools): added webflow OAuth + tools (simstudioai#1720)

* feat(tools): added webflow OAuth + tools

* remove itemId from delete item

* remove siteId

* added webhook triggers + oauth scopes + site/collection selector

* update sample payload for webflow triggers

* cleanup

* fix discord color

* feat(i18n): update translations (simstudioai#1721)

* improvement(schedule): fix UI bug with schedule modal (simstudioai#1722)
* fix(already-cancelled-sub): UI should allow restoring subscription

* restore functionality fixed

* fix
…e performance. please review before pushing to production
@vercel
Copy link
Copy Markdown

vercel Bot commented Nov 19, 2025

Someone is attempting to deploy a commit to the Sim Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Nov 19, 2025

Greptile Summary

  • Implemented Blacksmith CI/CD optimizations including Docker layer caching and Bun dependency caching across all workflows
  • Added cancelAtPeriodEnd field to subscription data model and improved restore subscription UX
  • Critical bug in billing portal query logic uses or() when it should use and() for the cancelAtPeriodEnd condition

Confidence Score: 2/5

  • This PR has a critical logic error in the billing portal that will cause incorrect subscription lookups
  • Score reflects that while the Blacksmith optimizations are well-implemented, there is a critical bug in apps/sim/app/api/billing/portal/route.ts where the query logic incorrectly uses or() instead of and() for the cancelAtPeriodEnd condition. This will match subscriptions that are either active OR have cancelAtPeriodEnd=true, when it should only match active subscriptions that have cancelAtPeriodEnd=true
  • Pay close attention to apps/sim/app/api/billing/portal/route.ts - the query logic must be fixed before merging

Important Files Changed

Filename Overview
docker/app.Dockerfile Reorganized layer ordering to maximize Docker cache hits by placing frequently-changing files last
apps/sim/app/api/billing/portal/route.ts Added query condition for subscriptions with cancelAtPeriodEnd=true, but logic appears flawed
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/subscription/components/cancel-subscription/cancel-subscription.tsx Improved restore subscription UX by removing tooltip and adding proper restore flow for both personal and org subscriptions

Sequence Diagram

sequenceDiagram
    participant User
    participant UI as "Cancel Subscription Component"
    participant API as "Better Auth API"
    participant DB as "Database"
    participant Stripe as "Stripe API"

    User->>UI: "Click Restore Button"
    UI->>UI: "Determine subscription type (personal/org)"
    UI->>API: "betterAuthSubscription.restore({referenceId, subscriptionId?})"
    API->>DB: "Query subscription by referenceId"
    DB-->>API: "Return subscription data"
    API->>Stripe: "Update subscription (cancel_at_period_end: false)"
    Stripe-->>API: "Return updated subscription"
    API->>DB: "Update cancelAtPeriodEnd = false"
    DB-->>API: "Confirm update"
    API-->>UI: "Return success"
    UI->>UI: "Refresh subscription state"
    UI->>User: "Show restored subscription"
Loading

Copy link
Copy Markdown
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.

17 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

Comment on lines +41 to +44
or(
eq(subscriptionTable.status, 'active'),
eq(subscriptionTable.cancelAtPeriodEnd, true)
)
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.

logic: Query logic incorrectly uses or() - subscriptions with cancelAtPeriodEnd=true should still have status='active', not be an alternative condition

Suggested change
or(
eq(subscriptionTable.status, 'active'),
eq(subscriptionTable.cancelAtPeriodEnd, true)
)
and(
eq(subscriptionTable.status, 'active'),
eq(subscriptionTable.cancelAtPeriodEnd, true)
)
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/api/billing/portal/route.ts
Line: 41:44

Comment:
**logic:** Query logic incorrectly uses `or()` - subscriptions with `cancelAtPeriodEnd=true` should still have `status='active'`, not be an alternative condition

```suggestion
            and(
              eq(subscriptionTable.status, 'active'),
              eq(subscriptionTable.cancelAtPeriodEnd, true)
            )
```

How can I resolve this? If you propose a fix, please make it concise.

@waleedlatif1
Copy link
Copy Markdown
Collaborator

@ConnorMul can we rebase, and I'll get this merged in right away. And make this PR against staging instead of against main. thanks!

@waleedlatif1
Copy link
Copy Markdown
Collaborator

merged in #2055

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