Skip to content

v0.6.48: import csv into tables, subflow fixes, CSP updates #4204

Merged
waleedlatif1 merged 3 commits intomainfrom
staging
Apr 16, 2026
Merged

v0.6.48: import csv into tables, subflow fixes, CSP updates #4204
waleedlatif1 merged 3 commits intomainfrom
staging

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

icecrasher321 and others added 3 commits April 16, 2026 13:37
* feat(tables): import csv into existing tables

* update types

* address comments

* address comment
* fix(executor): subflow edge keys mismatch'

* improve style
* improvement(ui): remove React anti-patterns, fix CSP violations

* fix(ui): restore useMemo on existingKeys — it is observed by useAvailableResources

* improvement(ui): add RefreshCw icon, update Bell SVG, active state styling for header actions

* minor UI improvements
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 16, 2026

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

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Apr 16, 2026 9:01pm

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 16, 2026

PR Summary

Medium Risk
Introduces a new data-import API path (append/replace) and changes executor edge-reset semantics and container logging, which can affect workflow execution and table data integrity if incorrect; changes are covered by new targeted tests but touch core runtime paths.

Overview
Adds CSV/TSV import into existing tables via new POST /api/table/[tableId]/import-csv, including append/replace modes, optional explicit header→column mapping, row-limit checks, and client-friendly error handling; includes a full route test suite and a new ImportCsvDialog wired into table header + context menu.

Refactors CSV parsing/schema/mapping/coercion into shared lib/table/csv-import utilities and updates the “create table from CSV” route plus Copilot user_table import_file to reuse them (also extending the generated tool schemas with mode/mapping).

Fixes executor loop reset behavior by only reactivating deactivated edges where the source node is inside the reset set (avoiding substring-matching false positives), adds regressions, and ensures loop/parallel containers emit success completion events so trace spans can use user-configured container names.

Includes small UI/security polish: adds worker-src + extra connect-src hosts to CSP, removes unnecessary useCallback patterns / adds memo where appropriate, tweaks table/logs actions styling and icons (new RefreshCw, updated Bell), and minor input/dropdown alignment changes.

Reviewed by Cursor Bugbot for commit 6fd1767. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 16, 2026

Greptile Summary

This release bundles three improvements: CSV import into existing tables (append or replace with column mapping), a subflow edge-key bug fix that was stalling loops on subsequent iterations, and a batch of React anti-pattern cleanups (effect-to-render-phase state sync, memoized tab items, CSP additions).

The core logic is solid — replaceTableRows correctly uses a FOR UPDATE transaction lock, rowCount is computed via COUNT(*) so no explicit update is needed after a replace, and the edge-manager fix is correctly scoped to source-only edges with clear inline documentation.

Confidence Score: 5/5

Safe to merge — all findings are non-blocking style suggestions.

No P0 or P1 issues found. The replace-mode transaction is correctly locked and rowCount is dynamically computed so no stale-counter risk. The edge-manager fix is well-scoped and tested. Remaining comments are style cleanup (import paths, type deduplication, unnecessary dep).

apps/sim/hooks/queries/tables.ts (duplicated type declarations), apps/sim/app/workspace/[workspaceId]/tables/components/import-csv-dialog/import-csv-dialog.tsx (sub-module import path, mutateAsync dep)

Important Files Changed

Filename Overview
apps/sim/lib/table/csv-import.ts New shared CSV parsing library: parseCsvBuffer, inferSchemaFromCsv, validateMapping, buildAutoMapping, coerceRowsForTable — well-structured, handles BOM stripping, type coercion including JSON, and duplicate-target/required-column validation.
apps/sim/app/api/table/[tableId]/import-csv/route.ts New API route for importing CSV into an existing table (append or replace); validates mode, workspace ownership, archived status, mapping, and capacity before delegating to service functions.
apps/sim/lib/table/service.ts Adds replaceTableRows: acquires a FOR UPDATE lock on the table definition, deletes all rows, batch-inserts new rows in a single transaction. rowCount is a computed SQL COUNT so no explicit update is needed.
apps/sim/app/workspace/[workspaceId]/tables/components/import-csv-dialog/import-csv-dialog.tsx New dialog for column-mapping CSV into an existing table; parses file client-side for preview, shows mapping table with Combobox per column, validates required/duplicate targets, and shows capacity warnings before submitting.
apps/sim/executor/execution/edge-manager.ts Bug fix: clearDeactivatedEdgesForNodes now only removes edges where the node is the source (startsWith), not edges where it is the target (includes), preventing stalled loops when external-branch edges were incorrectly reactivated.
apps/sim/executor/utils/subflow-utils.ts New emitSubflowSuccessEvents helper consolidates the loop/parallel completion callback and BlockLog emission into one place, fixing missing top-level BlockLogs that caused trace-span names to fall back to counter-based defaults.
apps/sim/hooks/queries/tables.ts Adds useImportCsvIntoTable mutation; locally redeclares CsvHeaderMapping and CsvImportMode rather than importing them from @/lib/table where they are already exported.
apps/sim/lib/core/security/csp.ts Adds worker-src directive (self + blob), react-grab connect-src, dev-only ws://localhost:4722, and analytics.ahrefs.com for hosted environments.

Sequence Diagram

sequenceDiagram
    participant U as User (Browser)
    participant D as ImportCsvDialog
    participant API as POST /api/table/[tableId]/import-csv
    participant SVC as replaceTableRows / batchInsertRows
    participant DB as Database

    U->>D: Drop / select CSV file
    D->>D: parseCsvBuffer (client-side preview)
    D->>D: buildAutoMapping (auto-match headers → columns)
    D->>U: Show mapping table + mode toggle

    U->>D: Confirm (Append or Replace)
    D->>API: POST FormData {file, workspaceId, mode, mapping}
    API->>API: checkSessionOrInternalAuth
    API->>API: checkAccess (write permission)
    API->>API: parseCsvBuffer + validateMapping
    alt mode = append
        API->>SVC: batchInsertRows (chunked)
        SVC->>DB: INSERT rows
    else mode = replace
        API->>SVC: replaceTableRows
        SVC->>DB: SELECT FOR UPDATE (table definition)
        SVC->>DB: DELETE all rows
        SVC->>DB: INSERT new rows (batched)
    end
    API-->>D: {success, insertedCount, deletedCount, ...}
    D-->>U: toast + onImported callback
Loading

Reviews (1): Last reviewed commit: "improvement(ui): remove React anti-patte..." | Re-trigger Greptile

Comment on lines 781 to 782
}

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.

P2 Duplicated types already exported from @/lib/table

CsvHeaderMapping and CsvImportMode are declared locally here but are already exported from @/lib/table (via csv-import.ts). Importing from the canonical source prevents the two definitions from drifting.

Suggested change
}
export type { CsvHeaderMapping, CsvImportMode } from '@/lib/table'

Context Used: Import patterns for the Sim application (source)

Comment on lines +28 to +29
import { type CsvImportMode, useImportCsvIntoTable } from '@/hooks/queries/tables'

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.

P2 Bypass barrel export for @/lib/table

csv-import is re-exported through @/lib/table/index.ts, so the sub-module path can be replaced with the barrel. The same pattern appears in apps/sim/lib/copilot/tools/server/table/user-table.ts.

Suggested change
import { type CsvImportMode, useImportCsvIntoTable } from '@/hooks/queries/tables'
import { buildAutoMapping, parseCsvBuffer } from '@/lib/table'

Context Used: Import patterns for the Sim application (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +247 to +248
const appendCapacityDeficit = useMemo(() => {
if (!parsed || mode !== 'append') return 0
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.

P2 mutateAsync reference unnecessarily extracted into a dep

importMutation.mutateAsync is stable in TanStack Query v5, so extracting it to importCsv and including it in the useCallback dep array adds indirection without benefit. Call importMutation.mutateAsync directly inside the callback and omit it from deps.

Suggested change
const appendCapacityDeficit = useMemo(() => {
if (!parsed || mode !== 'append') return 0
const handleSubmit = useCallback(async () => {
if (!parsed || !canSubmit) return
setSubmitError(null)
try {
const result = await importMutation.mutateAsync({

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@waleedlatif1 waleedlatif1 merged commit 8a50f18 into main Apr 16, 2026
28 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.

2 participants