Skip to content

feat: migrate workflows from database to file-based architecture#910

Merged
larryro merged 9 commits into
mainfrom
feat/file-based-workflows
Mar 29, 2026
Merged

feat: migrate workflows from database to file-based architecture#910
larryro merged 9 commits into
mainfrom
feat/file-based-workflows

Conversation

@larryro
Copy link
Copy Markdown
Collaborator

@larryro larryro commented Mar 29, 2026

Summary

  • Replace database-backed workflow storage with filesystem JSON files: workflow definitions, steps, and configurations are now read from and written to JSON files on disk instead of Convex database tables
  • Remove all DB-backed CRUD modules: wf_definitions, wf_step_defs, workflows/definitions/, workflows/steps/, and legacy trigger mutations/queries deleted (~2,900 lines removed)
  • Migrate all references from record IDs to file-based slugs: agent tools, approval cards, triggers, scheduler, and execution engine updated to use workflowSlug/stepSlug identifiers
  • Add workflow history viewing, diffing, and restore: replace publish/unpublish with a history dropdown showing snapshots and JSON diff dialog
  • Server-side template installation: templates listed from filesystem with installed flag, replacing client-side GitHub fetching and hardcoded template constants
  • Docker support: workflow templates seeded into images on build, synced to data volume on startup

Test plan

  • Verify workflow CRUD (create, read, update, delete) works end-to-end with file-based storage
  • Verify workflow execution engine runs workflows from file definitions
  • Verify trigger creation/deletion with slug-based mutations
  • Verify workflow history dropdown shows snapshots and diff dialog works
  • Verify template installation marks workflows as installed
  • Verify Docker build seeds templates correctly
  • Run existing test suites (compute_step_order, create_bound_workflow_tool, execute_approved_workflow_run, execute_approved_workflow_update, etc.)

Summary by CodeRabbit

  • New Features

    • Workflow history: view JSON diffs and restore previous versions.
    • Workflow templates: browse, install, and seed built-in templates.
    • File-based workflows with human-friendly slugs used in URLs and links.
  • Improvements

    • Unified workflow listing with category folders, client-side search, and clearer metadata.
    • Simplified enable/disable toggle and streamlined start/trigger flows.
    • Workflow items now appear in chat where applicable.
  • Chores

    • Added safe file storage, atomic saves, and history retention for workflows.

larryro added 7 commits March 29, 2026 07:45
Flatten workflow JSON schema (remove workflowConfig/stepsConfig nesting),
add file I/O utilities, slug-based trigger lookups, file workflow data
source, and update frontend automation pages to support file-backed
workflow configuration.
…tools

Migrate workflow update/approval system from database record references
(workflowId, stepRecordId, workflowVersionNumber) to file-based identifiers
(workflowSlug, stepSlug, workflowVersion). Tools now read/write workflow
JSON files via file_actions instead of querying DB tables directly.

- Update save_workflow_definition_tool to read workflow files instead of DB
- Update update_workflow_step_tool to resolve steps from file config
- Update internal_mutations to accept slug-based args
- Update internal_actions to patch steps by slug in file config
- Update approval card UI to display slug-based metadata
- Add step order field and sort keys alphabetically in example workflow
- Add compute_step_order helper with tests
- Update all related tests for file-based architecture
Complete the file-based workflow migration by deleting the database-backed
CRUD modules (wf_definitions, wf_step_defs, workflows/definitions,
workflows/steps, workflows/triggers mutations/queries) and updating
the frontend, engine, scheduler, and triggers to use file-based slugs.
Replace publish/unpublish actions in automation navigation with a
history dropdown that lists snapshots, opens a JSON diff dialog, and
allows restoring previous versions. Dispatch workflow-updated events
from approval cards so the detail page refetches after changes.
Replace client-side template fetching from GitHub with a server-side
installWorkflow action that sets an `installed` flag on workflow configs.
Templates are now listed from the filesystem and filtered by install
status, removing the need for hardcoded template constants, the
fetch-workflow-template utility, and the Vite dev server middleware.
- Fix missing slugToUrlParam() in 3 navigation locations that broke
  routing for folder-based workflow slugs containing slashes
- Fix event subscription duplicate check to include organizationId,
  preventing cross-tenant collisions
- Replace deprecated getAvailableWorkflows query (reading empty legacy
  table) with file-based action so agent tool selector shows workflows
- Fix readJsonFile() masking all errors as 'not_found' — now properly
  distinguishes EACCES/EPERM as 'inaccessible'
- Add workflow slug validation to trigger create mutations
- Remove unused orgSlug parameter from trigger create mutation args
- Rename createdWorkflowId to createdWorkflowSlug for consistency
- Fix outdated JSDoc referencing workflowId instead of workflowSlug
Workflow templates were missing in Docker because the file-based migration
only wired up local dev (scripts/dev.ts). This mirrors the existing agents
pattern: copy builtin templates into the image, seed them to the data
volume on startup (skipping user-modified or installed workflows), and
sync WORKFLOWS_DIR to Convex env vars.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 29, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 69dd9fc9-6276-4519-ab10-64a1d94d48e0

📥 Commits

Reviewing files that changed from the base of the PR and between 0c259ce and 614c64b.

⛔ Files ignored due to path filters (1)
  • services/platform/convex/_generated/api.d.ts is excluded by !**/_generated/**
📒 Files selected for processing (188)
  • examples/agents/workflow-assistant.json
  • examples/workflows/.gitignore
  • examples/workflows/circuly/sync-customers.json
  • examples/workflows/circuly/sync-products.json
  • examples/workflows/circuly/sync-subscriptions.json
  • examples/workflows/general/conversation-auto-archive.json
  • examples/workflows/general/conversation-sync.json
  • examples/workflows/general/customer-status-assessment.json
  • examples/workflows/general/document-rag-sync.json
  • examples/workflows/general/product-relationship-analysis.json
  • examples/workflows/gmail/email-sync.json
  • examples/workflows/onedrive/sync.json
  • examples/workflows/outlook/email-sync.json
  • examples/workflows/shopify/sync-customers.json
  • examples/workflows/shopify/sync-products.json
  • services/platform/Dockerfile
  • services/platform/app/features/agents/hooks/queries.ts
  • services/platform/app/features/automations/components/automation-active-toggle.test.tsx
  • services/platform/app/features/automations/components/automation-active-toggle.tsx
  • services/platform/app/features/automations/components/automation-ai-chat-panel.tsx
  • services/platform/app/features/automations/components/automation-assistant.tsx
  • services/platform/app/features/automations/components/automation-create-dialog.tsx
  • services/platform/app/features/automations/components/automation-history-diff-dialog.tsx
  • services/platform/app/features/automations/components/automation-navigation.tsx
  • services/platform/app/features/automations/components/automation-row-actions.tsx
  • services/platform/app/features/automations/components/automation-sidepanel.tsx
  • services/platform/app/features/automations/components/automation-steps.tsx
  • services/platform/app/features/automations/components/automation-tester.tsx
  • services/platform/app/features/automations/components/automations-table.tsx
  • services/platform/app/features/automations/components/workflow-template-grid.tsx
  • services/platform/app/features/automations/constants/workflow-templates.ts
  • services/platform/app/features/automations/executions/executions-table.tsx
  • services/platform/app/features/automations/hooks/file-mutations.ts
  • services/platform/app/features/automations/hooks/file-queries.ts
  • services/platform/app/features/automations/hooks/mutations.ts
  • services/platform/app/features/automations/hooks/queries.ts
  • services/platform/app/features/automations/hooks/use-assistant-chat.ts
  • services/platform/app/features/automations/hooks/use-automations-table-config.tsx
  • services/platform/app/features/automations/hooks/use-workflow-config-context.tsx
  • services/platform/app/features/automations/triggers/components/event-create-dialog.tsx
  • services/platform/app/features/automations/triggers/components/events-section.tsx
  • services/platform/app/features/automations/triggers/components/schedule-create-dialog.tsx
  • services/platform/app/features/automations/triggers/components/schedules-section.tsx
  • services/platform/app/features/automations/triggers/components/webhooks-section.tsx
  • services/platform/app/features/automations/triggers/hooks/mutations.ts
  • services/platform/app/features/automations/triggers/hooks/queries.ts
  • services/platform/app/features/automations/triggers/hooks/slug-mutations.ts
  • services/platform/app/features/automations/triggers/triggers.tsx
  • services/platform/app/features/automations/utils/__tests__/fetch-workflow-template.test.ts
  • services/platform/app/features/automations/utils/fetch-workflow-template.ts
  • services/platform/app/features/chat/components/workflow-creation-approval-card.tsx
  • services/platform/app/features/chat/components/workflow-run-approval-card.tsx
  • services/platform/app/features/chat/components/workflow-update-approval-card.tsx
  • services/platform/app/routes/dashboard/$id/automations/$amId.tsx
  • services/platform/app/routes/dashboard/$id/automations/$amId/configuration.tsx
  • services/platform/app/routes/dashboard/$id/automations/$amId/executions.tsx
  • services/platform/app/routes/dashboard/$id/automations/$amId/triggers.tsx
  • services/platform/app/routes/dashboard/$id/automations/index.tsx
  • services/platform/convex/agent_tools/workflows/__tests__/create_bound_workflow_tool.test.ts
  • services/platform/convex/agent_tools/workflows/__tests__/execute_approved_workflow_run.test.ts
  • services/platform/convex/agent_tools/workflows/__tests__/execute_approved_workflow_update.test.ts
  • services/platform/convex/agent_tools/workflows/__tests__/run_workflow_tool.test.ts
  • services/platform/convex/agent_tools/workflows/__tests__/save_workflow_definition_tool.test.ts
  • services/platform/convex/agent_tools/workflows/__tests__/update_workflow_step_tool.test.ts
  • services/platform/convex/agent_tools/workflows/create_bound_workflow_tool.ts
  • services/platform/convex/agent_tools/workflows/helpers/read_active_version_steps.ts
  • services/platform/convex/agent_tools/workflows/helpers/read_all_workflows.ts
  • services/platform/convex/agent_tools/workflows/helpers/read_version_history.ts
  • services/platform/convex/agent_tools/workflows/helpers/read_workflow_examples.ts
  • services/platform/convex/agent_tools/workflows/helpers/read_workflow_structure.ts
  • services/platform/convex/agent_tools/workflows/helpers/types.ts
  • services/platform/convex/agent_tools/workflows/internal_actions.ts
  • services/platform/convex/agent_tools/workflows/internal_mutations.ts
  • services/platform/convex/agent_tools/workflows/run_workflow_tool.ts
  • services/platform/convex/agent_tools/workflows/save_workflow_definition_tool.ts
  • services/platform/convex/agent_tools/workflows/update_workflow_step_tool.ts
  • services/platform/convex/agent_tools/workflows/workflow_read_tool.ts
  • services/platform/convex/agents/file_actions.ts
  • services/platform/convex/agents/file_utils.ts
  • services/platform/convex/agents/queries.ts
  • services/platform/convex/approvals/types.ts
  • services/platform/convex/auth.ts
  • services/platform/convex/integrations/find_related_automations.ts
  • services/platform/convex/lib/agent_chat/internal_actions.ts
  • services/platform/convex/lib/file_io.ts
  • services/platform/convex/lib/rls/helpers/access_control.ts
  • services/platform/convex/lib/rls/helpers/rls_rules.ts
  • services/platform/convex/wf_definitions/internal_mutations.ts
  • services/platform/convex/wf_definitions/internal_queries.ts
  • services/platform/convex/wf_definitions/mutations.ts
  • services/platform/convex/wf_definitions/queries.ts
  • services/platform/convex/wf_executions/actions.ts
  • services/platform/convex/wf_executions/internal_mutations.ts
  • services/platform/convex/wf_executions/mutations.ts
  • services/platform/convex/wf_executions/queries.ts
  • services/platform/convex/wf_step_defs/actions.ts
  • services/platform/convex/wf_step_defs/audit.ts
  • services/platform/convex/wf_step_defs/internal_mutations.ts
  • services/platform/convex/wf_step_defs/internal_queries.ts
  • services/platform/convex/wf_step_defs/mutations.ts
  • services/platform/convex/wf_step_defs/queries.ts
  • services/platform/convex/workflow_engine/helpers/data_source/database_workflow_data_source.ts
  • services/platform/convex/workflow_engine/helpers/data_source/file_workflow_data_source.ts
  • services/platform/convex/workflow_engine/helpers/engine/execute_workflow_start.ts
  • services/platform/convex/workflow_engine/helpers/engine/index.ts
  • services/platform/convex/workflow_engine/helpers/engine/load_database_workflow.ts
  • services/platform/convex/workflow_engine/helpers/engine/load_file_workflow.ts
  • services/platform/convex/workflow_engine/helpers/engine/start_workflow_from_file.ts
  • services/platform/convex/workflow_engine/helpers/engine/start_workflow_handler.ts
  • services/platform/convex/workflow_engine/helpers/graph/compute_step_order.test.ts
  • services/platform/convex/workflow_engine/helpers/graph/compute_step_order.ts
  • services/platform/convex/workflow_engine/helpers/scheduler/get_last_execution_time.ts
  • services/platform/convex/workflow_engine/helpers/scheduler/get_scheduled_workflows.ts
  • services/platform/convex/workflow_engine/helpers/scheduler/has_running_execution.test.ts
  • services/platform/convex/workflow_engine/helpers/scheduler/has_running_execution.ts
  • services/platform/convex/workflow_engine/helpers/scheduler/scan_and_trigger.ts
  • services/platform/convex/workflow_engine/helpers/step_execution/types.ts
  • services/platform/convex/workflow_engine/internal_queries.ts
  • services/platform/convex/workflows/definitions/activate_version.ts
  • services/platform/convex/workflows/definitions/create_draft_from_active.ts
  • services/platform/convex/workflows/definitions/create_workflow.ts
  • services/platform/convex/workflows/definitions/create_workflow_draft.ts
  • services/platform/convex/workflows/definitions/create_workflow_with_steps.ts
  • services/platform/convex/workflows/definitions/delete_workflow.test.ts
  • services/platform/convex/workflows/definitions/delete_workflow.ts
  • services/platform/convex/workflows/definitions/duplicate_workflow.ts
  • services/platform/convex/workflows/definitions/get_active_version.ts
  • services/platform/convex/workflows/definitions/get_automations_cursor.ts
  • services/platform/convex/workflows/definitions/get_draft.ts
  • services/platform/convex/workflows/definitions/get_version_by_number.ts
  • services/platform/convex/workflows/definitions/get_workflow.ts
  • services/platform/convex/workflows/definitions/get_workflow_by_name.ts
  • services/platform/convex/workflows/definitions/get_workflow_with_first_step.ts
  • services/platform/convex/workflows/definitions/helpers.ts
  • services/platform/convex/workflows/definitions/list_automations.ts
  • services/platform/convex/workflows/definitions/list_automations_paginated.ts
  • services/platform/convex/workflows/definitions/list_versions.ts
  • services/platform/convex/workflows/definitions/list_workflows.ts
  • services/platform/convex/workflows/definitions/list_workflows_with_best_version.ts
  • services/platform/convex/workflows/definitions/publish_draft.ts
  • services/platform/convex/workflows/definitions/republish_workflow.ts
  • services/platform/convex/workflows/definitions/save_manual_configuration.test.ts
  • services/platform/convex/workflows/definitions/save_manual_configuration.ts
  • services/platform/convex/workflows/definitions/save_workflow_with_steps.ts
  • services/platform/convex/workflows/definitions/types.ts
  • services/platform/convex/workflows/definitions/unpublish_workflow.ts
  • services/platform/convex/workflows/definitions/update_draft.ts
  • services/platform/convex/workflows/definitions/update_workflow.ts
  • services/platform/convex/workflows/definitions/update_workflow_status.ts
  • services/platform/convex/workflows/definitions/validators.ts
  • services/platform/convex/workflows/executions/types.ts
  • services/platform/convex/workflows/file_actions.ts
  • services/platform/convex/workflows/file_utils.ts
  • services/platform/convex/workflows/schema.ts
  • services/platform/convex/workflows/steps/create_step.ts
  • services/platform/convex/workflows/steps/delete_step.ts
  • services/platform/convex/workflows/steps/get_ordered_steps.ts
  • services/platform/convex/workflows/steps/helpers.ts
  • services/platform/convex/workflows/steps/list_workflow_steps.ts
  • services/platform/convex/workflows/steps/types.ts
  • services/platform/convex/workflows/steps/update_step.ts
  • services/platform/convex/workflows/steps/validators.ts
  • services/platform/convex/workflows/triggers/api_http.ts
  • services/platform/convex/workflows/triggers/http_actions.ts
  • services/platform/convex/workflows/triggers/internal_mutations.ts
  • services/platform/convex/workflows/triggers/internal_queries.ts
  • services/platform/convex/workflows/triggers/process_event.ts
  • services/platform/convex/workflows/triggers/queries.ts
  • services/platform/convex/workflows/triggers/schema.ts
  • services/platform/convex/workflows/triggers/slug_mutations.ts
  • services/platform/convex/workflows/triggers/slug_queries.ts
  • services/platform/convex/workflows/validators.ts
  • services/platform/docker-entrypoint.sh
  • services/platform/env.sh
  • services/platform/lib/permissions/ability.ts
  • services/platform/lib/shared/schemas/wf_definitions.ts
  • services/platform/lib/shared/schemas/workflows.ts
  • services/platform/lib/utils/workflow-slug.ts
  • services/platform/messages/en.json
  • services/platform/scripts/dev.ts
  • services/platform/stress-tests/run-stress-test.ts
  • services/platform/stress-tests/scenarios/concurrent-starts.ts
  • services/platform/stress-tests/scenarios/loop-contention.ts
  • services/platform/stress-tests/scenarios/payload-pressure.ts
  • services/platform/stress-tests/scenarios/scheduler-overlap.ts
  • services/platform/stress-tests/scenarios/shard-comparison.ts
  • services/platform/stress-tests/scenarios/sustained-load.ts
  • services/platform/vite.config.ts

📝 Walkthrough

Walkthrough

This PR migrates workflows from a DB-backed model to file-backed workflows and slugs. It adds safe file I/O, history, serialization/validation (workflow JSON schema), file actions (read/list/save/install/duplicate/rename/restore) and internal actions for execution. It removes many Convex DB queries/mutations and step/definition helpers, updates engine/start paths to use file-based flows and new startWorkflowFromFile, and updates frontend hooks/components to use workflow slugs and file-based hooks. Environment, Docker, seed logic, examples, types, and approval metadata were updated; legacy DB tables/exports are annotated deprecated or removed.

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/file-based-workflows

larryro added 2 commits March 29, 2026 20:13
Remove unnecessary type assertions, fix unused variables/imports/params,
add error causes to re-thrown errors, and migrate stress tests from
removed startWorkflow mutation to startWorkflowFromFile action.
@larryro larryro merged commit b2f5310 into main Mar 29, 2026
16 of 17 checks passed
@larryro larryro deleted the feat/file-based-workflows branch March 29, 2026 12:18
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