v0.4.11: webhook, knowledgebase, billing fixes & redis for sessions#1597
v0.4.11: webhook, knowledgebase, billing fixes & redis for sessions#1597waleedlatif1 merged 8 commits intomainfrom
Conversation
waleedlatif1
commented
Oct 10, 2025
- fix(db): revert to dedicated sockets db connection establishment
- fix(env-vars): remove regex parsing from table subblock, add formatDisplayText to various subblocks that didn't have it (fix(env-vars): remove regex parsing from table subblock, add formatDisplayText to various subblocks that didn't have it #1582)
- feat(billing): bill by threshold to prevent cancellation edge case (feat(billing): bill by threshold to prevent cancellation edge case #1583)
- feat(deployed-chat): added file upload to workflow execute API, added to deployed chat, updated chat panel (feat(deployed-chat): added file upload to workflow execute API, added to deployed chat, updated chat panel #1588)
- feat(sessions): add redis as priority option for session data (feat(sessions): add redis as priority option for session data #1592)
- fix test webhook url (fix(webhooks): test url must be based on next public app url #1594)
- improvement(kb): encode non-ASCII headers for kb uploads (improvement(kb): encode non-ASCII headers for kb uploads #1595)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Greptile Overview
Summary
This release bundles multiple fixes and features including webhook URL configuration, knowledge base improvements, threshold-based billing, Redis session storage, and file upload support for workflow API execution.
Key Changes:
- Threshold billing system: Invoices are now generated incrementally when overage reaches $50 (configurable), preventing the edge case where users could cancel with large unpaid overages. Uses database row locking and Stripe idempotency keys to prevent race conditions and double billing.
- File uploads in workflow API: Added support for base64-encoded file uploads and URL pass-through in the workflow execute API, enabling file handling in deployed workflows and chat interfaces.
- Redis session storage: Optional Redis integration for session data storage with graceful fallback to database-only mode when Redis is unavailable.
- Webhook test URL fix: Changed from using
request.url.origintoNEXT_PUBLIC_APP_URLfor webhook test endpoints, fixing issues in environments where the origin differs from the public URL. - Knowledge base encoding: Fixed non-ASCII character handling in HTTP headers for file uploads by properly encoding headers.
- Environment variable simplification: Removed complex regex-based API key detection in the resolver, now using simple
{{VAR}}syntax consistently across all fields.
Integration Points:
The threshold billing system integrates with existing billing webhooks to avoid double-charging at period end by tracking billedOverageThisPeriod and only billing the remaining unbilled amount when subscriptions are cancelled or renewed.
Confidence Score: 4/5
- This PR is safe to merge with low risk - changes are well-structured with proper error handling
- Score reflects careful implementation of critical billing logic with database transactions and idempotency, though the breaking change in Redis fallback behavior and complexity of threshold billing warrant attention during deployment
- Pay close attention to
apps/sim/lib/billing/threshold-billing.tsandapps/sim/lib/redis.tsduring deployment - threshold billing needs monitoring and Redis fallback removal is a breaking change
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/lib/billing/threshold-billing.ts | 4/5 | New threshold billing system to prevent cancellation edge case by billing at $50 intervals - logic looks sound but watch for idempotency |
| apps/sim/lib/redis.ts | 4/5 | Removed in-memory fallback cache, now returns false/null when Redis unavailable - breaking change but intentional |
| apps/sim/app/api/workflows/[id]/execute/route.ts | 4/5 | Added file upload support to workflow execute API with base64 and URL processing - implementation looks solid |
| apps/sim/executor/resolver/resolver.ts | 5/5 | Simplified environment variable resolution by removing complex API key detection logic - cleaner approach |
| apps/sim/lib/billing/webhooks/subscription.ts | 5/5 | Updated subscription deletion to only bill remaining unbilled overage after threshold billing - prevents double billing |
| apps/sim/lib/billing/webhooks/invoices.ts | 5/5 | Added helper to get billed overage and reset billedOverageThisPeriod at period end - integrates with threshold billing |
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/table.tsx | 5/5 | Updated table to use formatDisplayText with accessiblePrefixes instead of regex parsing - cleaner implementation |
Sequence Diagram
sequenceDiagram
participant User
participant API as Workflow Execute API
participant Billing as update-cost route
participant Threshold as Threshold Billing
participant DB as Database
participant Stripe
User->>API: POST /api/workflows/{id}/execute
Note over API: Process file uploads (base64/URL)
API->>API: Check input format for file fields
API->>API: Upload files to S3/Azure
API->>API: Execute workflow
API->>Billing: Update usage costs
Billing->>DB: Increment currentPeriodCost
Billing->>Threshold: checkAndBillOverageThreshold(userId)
Threshold->>DB: Lock user stats (SELECT FOR UPDATE)
Threshold->>Threshold: Calculate unbilled overage
alt Unbilled overage >= $50
Threshold->>Stripe: Create invoice with idempotency key
Stripe-->>Threshold: Invoice created
Threshold->>DB: Increment billedOverageThisPeriod
Note over Threshold: Prevents double billing
else Unbilled overage < $50
Note over Threshold: Wait until threshold reached
end
Threshold-->>Billing: Complete
Billing-->>API: Cost updated
API-->>User: Execution result
Note over DB: At subscription period end
DB->>DB: Reset currentPeriodCost and billedOverageThisPeriod
Note over Stripe: On subscription cancellation
Stripe->>DB: Calculate remaining unbilled overage
Stripe->>Stripe: Create final invoice (only for unbilled amount)
79 files reviewed, 3 comments
|
|
||
| const amountCents = Math.round(amountToBill * 100) | ||
| const totalOverageCents = Math.round(currentOverage * 100) | ||
| const idempotencyKey = `threshold-overage:${customerId}:${stripeSubscriptionId}:${billingPeriod}:${totalOverageCents}:${amountCents}` |
There was a problem hiding this comment.
logic: Idempotency key includes both totalOverageCents and amountCents. If costs continue accumulating after a failed invoice attempt, the idempotency key will change and could create duplicate invoices. Consider using only billingPeriod and a sequence number.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/lib/billing/threshold-billing.ts
Line: 186:186
Comment:
**logic:** Idempotency key includes both `totalOverageCents` and `amountCents`. If costs continue accumulating after a failed invoice attempt, the idempotency key will change and could create duplicate invoices. Consider using only `billingPeriod` and a sequence number.
How can I resolve this? If you propose a fix, please make it concise.| } | ||
|
|
||
| /** | ||
| * Process API workflow files - handles both base64 ('file' type) and URL pass-through ('url' type) |
There was a problem hiding this comment.
style: Validation checks for data: and ;base64, but doesn't validate the base64 string itself. Malformed base64 will cause Buffer.from() to fail silently or produce incorrect data.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/api/workflows/utils.ts
Line: 44:47
Comment:
**style:** Validation checks for `data:` and `;base64,` but doesn't validate the base64 string itself. Malformed base64 will cause `Buffer.from()` to fail silently or produce incorrect data.
How can I resolve this? If you propose a fix, please make it concise.…splayText to various subblocks that didn't have it (#1582)
…1583) * feat(billing): bill by threshold to prevent cancellation edge case * fix org billing * fix idempotency key issue * small optimization for team checks * remove console log * remove unused type * fix error handling
… to deployed chat, updated chat panel (#1588) * feat(deployed-chat): updated chat panel UI, deployed chat and API can now accept files * added nested tag dropdown for files * added duplicate file validation to chat panel * update docs & SDKs * fixed build * rm extraneous comments * ack PR comments, cut multiple DB roundtrips for permissions & api key checks in api/workflows * allow read-only users to access deployment info, but not take actions * add downloadable file to logs for files passed in via API * protect files/serve route that is only used client-side --------- Co-authored-by: waleed <waleed>
* feat(sessions): add redis as priority option for session data * update chat client otp
* improvement(kb): encode non-ASCII headers for kb uploads * cleanup * increase timeouts to match trigger
…webhook registration (#1596) * fix(webhooks): use next public app url instead of request origin for webhook registration * ack PR comments * ci: pin Bun to v1.2.22 to avoid Bun 1.3 breaking changes