Skip to content

fix(webhooks): cast json provider_config for atomic jsonb merge#5249

Merged
waleedlatif1 merged 1 commit into
stagingfrom
worktree-webhook-config-update-errors
Jun 28, 2026
Merged

fix(webhooks): cast json provider_config for atomic jsonb merge#5249
waleedlatif1 merged 1 commit into
stagingfrom
worktree-webhook-config-update-errors

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • updateWebhookProviderConfig built a DB-side merge with jsonb operators (COALESCE(provider_config, '{}'::jsonb) || $1::jsonb), but webhook.provider_config is a json column, not jsonb. Postgres can't apply jsonb merge operators to a json column, so every polling state write failed with could not convert type jsonb to json (42846).
  • The error was caught and swallowed, so it was silent (failed_count stayed 0) — but it broke historyId / lastCheckedTimestamp / pageToken / lastSeenGuids persistence for all polling webhooks (Gmail, RSS, Google Sheets/Drive, Outlook, IMAP) since the atomic-merge change landed.
  • Fix: cast the column to jsonb for the || / - merge, then cast the result back to json for storage. Matches the existing pattern already used for subscription.metadata (subscription.ts:82).
  • Verified no other json-column-vs-jsonb-operator misalignments exist in the codebase — every other jsonb-operator write targets a true jsonb column.

Type of Change

  • Bug fix

Testing

  • Added a regression test asserting the column is cast jsonjsonbjson.
  • Reproduced the original failure and validated the corrected merge expression directly against the production schema.
  • vitest (3/3 pass), biome, and tsc all clean.

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)

updateWebhookProviderConfig built a DB-side merge with jsonb operators
(COALESCE(provider_config, '{}'::jsonb) || $1::jsonb), but the
provider_config column is json, not jsonb. Postgres cannot apply jsonb
merge operators to a json column, so every polling state write failed
with "could not convert type jsonb to json" — silently breaking
historyId/lastCheckedTimestamp/pageToken/lastSeenGuids persistence for
all polling webhooks (Gmail, RSS, Google Sheets/Drive, Outlook, IMAP)
since the atomic-merge change landed.

Cast the column to jsonb for the || / - merge and cast the result back
to json for storage, matching the existing pattern in subscription.ts.
@vercel

vercel Bot commented Jun 28, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jun 28, 2026 12:06am

Request Review

@cursor

cursor Bot commented Jun 28, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches the shared DB path that persists polling cursor state for all polling providers; the change is small and aligned with an existing cast pattern, but failed writes previously failed silently.

Overview
Fixes silent failure of polling webhook state writes: updateWebhookProviderConfig now casts webhook.provider_config from jsonjsonb for COALESCE / || / - merges, then wraps the final value as ::json before the update—matching the existing billing metadata pattern.

The merge logic is unchanged (defined keys merged, undefined keys removed); only the SQL expression and docs are updated. Tests now record SQL template strings and add a regression case that the cast chain appears in generated SQL.

Reviewed by Cursor Bugbot for commit ef3381b. Configure here.

@greptile-apps

greptile-apps Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes provider config polling state writes for a json database column. The main changes are:

  • Casts webhook.provider_config to jsonb before merge and removal operators.
  • Casts the merged provider config result back to json before storage.
  • Adds a regression test for the generated cast shape.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
apps/sim/lib/webhooks/polling/utils.ts Casts provider config through jsonb for atomic merge/removal and back to json for assignment.
apps/sim/lib/webhooks/polling/utils.test.ts Captures SQL template strings in the mock and checks that the casted merge expression is generated.

Reviews (1): Last reviewed commit: "fix(webhooks): cast json provider_config..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 merged commit 3e03f8c into staging Jun 28, 2026
16 checks passed
@waleedlatif1 waleedlatif1 deleted the worktree-webhook-config-update-errors branch June 28, 2026 00:26
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.

1 participant