Skip to content

fix(realtime): scope batch-add upserts to the caller's workflow - #8894

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/realtime-upsert-workflow-scope
Oct 10, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
fix/realtime-upsert-workflow-scope

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Block, edge, and subflow ids are global primary keys, so the ON CONFLICT (id) DO UPDATE in batch-add-blocks / batch-add-edges could update a row that belongs to a different workflow than the socket's
  • Added upsertWorkflowRows: setWhere: workflow_id = <socket workflow> confines the update to the caller's workflow, and a RETURNING id count check aborts the transaction when a conflict was skipped instead of dropping rows silently
  • All seven upsert sites (blocks, default loop/parallel subflows, payload loops/parallels, edges in both handlers) go through the helper; default subflow rows are now one batched upsert instead of one per container block
  • Same-workflow re-adds (undo/redo) still upsert; every client add path generates fresh ids, so legitimate traffic never hits the new rejection

Type of Change

  • Bug fix (security)

Testing

  • E2E against a real Postgres with the full schema, calling persistWorkflowOperation: block, edge, and loop ids owned by another workflow are rejected and the other workflow's rows are unchanged; a rejected batch commits none of its own rows; a normal add plus a same-workflow re-add still works. On the pre-fix code all six cross-workflow checks fail (other workflow's rows overwritten)
  • apps/realtime type-check, biome, src/database vitest

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Block, edge, and subflow ids are global primary keys, so the
ON CONFLICT (id) DO UPDATE in batch-add-blocks and batch-add-edges could
overwrite a row owned by another workflow. Route every upsert through
upsertWorkflowRows, which confines the update to the socket's workflow
with setWhere and aborts the transaction when RETURNING shows a skipped
conflict.
@vercel

vercel Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 10, 2026 7:56pm UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Critical impact] The PR appears safe to merge; no actionable issues remain.

Summary

The PR prevents batch adds from overwriting rows owned by another workflow.

  • Realtime adds only change rows in the caller’s workflow.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Batch add] --> B[Insert workflow rows]
  B --> C{ID already exists?}
  C -->|No| D[Insert row]
  C -->|Same workflow| E[Update row]
  C -->|Other workflow| F[Skip update]
  D --> G{Returned count matches input?}
  E --> G
  F --> G
  G -->|Yes| H[Continue transaction]
  G -->|No| I[Throw and roll back]
Loading

Reviews (2) · Last reviewed commit: "fix(realtime): type the scoped upsert he..." · Reviewed by Greptile

Comment thread apps/realtime/src/database/operations.ts Outdated
Comment thread apps/realtime/src/database/operations.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 25f5cd4 into staging Oct 10, 2026
48 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/realtime-upsert-workflow-scope branch October 10, 2026 20:21

This branch was previously deployed

1 inactive deployment
Preview — ec84c553 Deployed Oct 10, 2026 by vercel[bot]
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