Skip to content

v0.6.43: mothership billing idempotency, env var resolution fixes #4165

Merged
waleedlatif1 merged 4 commits intomainfrom
staging
Apr 14, 2026
Merged

v0.6.43: mothership billing idempotency, env var resolution fixes #4165
waleedlatif1 merged 4 commits intomainfrom
staging

Conversation

@icecrasher321
Copy link
Copy Markdown
Collaborator

@icecrasher321 icecrasher321 commented Apr 14, 2026

TheodoreSpeaks and others added 2 commits April 14, 2026 17:15
* fix(billing): add idempotency to billing

* Only release redis lock if billed
* fix(triggers): env var resolution in provider configs

* throw on errored resolution
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 14, 2026 10:18pm

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 14, 2026

PR Summary

Medium Risk
Touches billing usage recording to prevent double-charging and changes webhook execution input shaping via provider-config env var resolution; mistakes could block usage updates or break webhook triggers.

Overview
Adds optional idempotencyKey handling to POST /api/billing/update-cost, atomically claiming a billing-scoped key and returning 409 on duplicates; on failure it now releases the claim only if usage was not committed to avoid double-billing.

Fixes webhook trigger executions to resolve {{ENV_VAR}} references inside stored providerConfig before calling provider formatInput, with a small wrapper that rethrows errors with provider/webhook context. Adds focused Vitest coverage for the new env resolver and the webhook-execution wrapper.

Reviewed by Cursor Bugbot for commit 7529a75. Configure here.

@icecrasher321 icecrasher321 changed the title v0.6.44: mothership billing idempotency, env var resolution fixes v0.6.43: mothership billing idempotency, env var resolution fixes Apr 14, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 14, 2026

Greptile Summary

This PR adds idempotency to the billing update-cost API route (atomic claim/release pattern with a 1-hour TTL) and fixes env var resolution in webhook provider configs by resolving {{VAR}} references before passing the webhook record to handler.formatInput. Both changes are paired with focused unit tests.

Confidence Score: 5/5

Safe to merge — all changes are correct, well-tested, and follow project conventions with no blocking issues.

Both features are implemented correctly. The billing idempotency uses the atomic claim/release pattern properly: pre-commit failures release the key so the caller can retry, post-commit failures retain it to prevent double-billing, and duplicates within the 1-hour TTL receive 409. The env-resolver functions are clean, type-safe, and covered by tests. No P0 or P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/app/api/billing/update-cost/route.ts Adds optional idempotency key support: atomically claims before processing, releases on pre-commit failure, and retains on post-commit failure to prevent double-billing. Logic is correct.
apps/sim/lib/core/idempotency/service.ts Adds a public release() wrapper for the private deleteKey() method and exports a new billingIdempotency instance with a 1-hour TTL. Changes are minimal and correct.
apps/sim/lib/webhooks/env-resolver.ts Adds normalizeWebhookProviderConfig, resolveWebhookProviderConfig, and resolveWebhookRecordProviderConfig to resolve env var references inside webhook provider configs. Clean generic design with proper null handling.
apps/sim/background/webhook-execution.ts Exports resolveWebhookExecutionProviderConfig (wrapper with contextual errors) and calls it on the fetched webhook record before handing it to handler.formatInput, fixing env var resolution in provider configs.
apps/sim/lib/webhooks/env-resolver.test.ts Well-structured tests covering deep env var resolution and record cloning. Correctly mocks getEffectiveDecryptedEnv via vi.hoisted pattern per project standards.
apps/sim/background/webhook-execution.test.ts Tests success and failure paths of resolveWebhookExecutionProviderConfig. Correctly uses vi.hoisted and verifies the contextual error message format on failure.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Route as update-cost route
    participant Idempotency as billingIdempotency
    participant DB as recordUsage / DB

    Caller->>Route: POST /api/billing/update-cost (idempotencyKey?)
    Route->>Idempotency: atomicallyClaim('update-cost', key)
    alt key already exists
        Idempotency-->>Route: claimed=false
        Route-->>Caller: 409 Duplicate request
    else first time
        Idempotency-->>Route: claimed=true (in-progress stored)
        Route->>DB: recordUsage(...)
        alt recordUsage succeeds
            DB-->>Route: ok (usageCommitted=true)
            Route->>DB: checkAndBillOverageThreshold(...)
            alt threshold check succeeds
                Route-->>Caller: 200 success (key stays in-progress until TTL)
            else threshold check fails
                Route->>Idempotency: retain claim (prevent double-billing)
                Route-->>Caller: 500 error
            end
        else recordUsage fails
            Route->>Idempotency: release(normalizedKey) — retry allowed
            Route-->>Caller: 500 error
        end
    end
Loading

Reviews (1): Last reviewed commit: "fix(triggers): env var resolution in pro..." | Re-trigger Greptile

…API docs (#4161)

* fix(google-drive): add auto export format and Azure storage debug logging

* chore: remove Azure storage debug logging

* fix(google-drive): use status-based fallback instead of string matching for export errors

* fix(google-drive): validate export formats against Drive API docs, remove fallback

* fix(google-drive): use value function for dropdown default

* fix(google-drive): add text/markdown to valid export formats for Google Docs

* fix(google-drive): correct ODS MIME type for Sheets export format
)

* fix(security): resolve ReDoS vulnerability in function execute tag pattern

Simplified regex to eliminate overlapping quantifiers that caused exponential
backtracking on malformed input without closing delimiter.

* feat(jira): support raw ADF document objects in description and environment fields

Add toAdf() helper that passes through ADF objects as-is or wraps plain
text in a single-paragraph ADF doc. Update write and update routes to
use it, replacing inline ADF wrapping. Update Zod schema to accept
string or object for description. Fully backward compatible — plain
text still works, but callers can now pass rich ADF with expand nodes,
tables, code blocks, etc.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(jira): handle partial ADF nodes and non-ADF objects in toAdf()

Wrap partial ADF nodes (type + content but not doc) in a doc envelope.
Fall back to JSON.stringify for non-ADF objects instead of String()
which produces [object Object].

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* lint

* fix(jira): handle JSON-stringified ADF in toAdf() for variable resolution

The executor's formatValueForBlock() JSON.stringify's object values when
resolving <Block.output> references. This means an ADF object from an
upstream Agent block arrives at the route as a JSON string. toAdf() now
detects JSON strings containing valid ADF documents or nodes and parses
them back, ensuring rich formatting is preserved through the pipeline.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* lint changes

* fix(jira): update environment Zod schema to accept ADF objects

Match the description field schema change — environment also passes
through toAdf() so its Zod schema must accept objects too.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* updated lobkc

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@waleedlatif1 waleedlatif1 merged commit 3a1b1a8 into main Apr 14, 2026
24 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