mirror of
https://github.com/Mail-0/Zero.git
synced 2026-06-29 15:26:42 +00:00
# Refactored workflow processing with Durable Objects ## Description Refactored the workflow processing system to use Durable Objects for better concurrency and reliability. Created a new `WorkflowRunner` Durable Object that encapsulates the workflow execution logic, replacing the previous function-based approach. This change improves thread processing by providing better isolation and state management. The implementation includes: - A new `WorkflowRunner` Durable Object that handles main, zero, and thread workflows - Updated thread queue processing to use the Durable Object - Enhanced workflow engine with execution tracking to prevent duplicate processing - Added cleanup steps to properly manage workflow execution state ## Type of Change - ✨ New feature (non-breaking change which adds functionality) - ⚡ Performance improvement ## Areas Affected - [x] Email Integration (Gmail, IMAP, etc.) - [x] Data Storage/Management - [x] Deployment/Infrastructure ## Testing Done - [x] Manual testing performed ## Checklist - [x] I have performed a self-review of my code - [x] My changes generate no new warnings - [x] I have updated the documentation ## Additional Notes This change should significantly improve the reliability of thread processing by preventing race conditions and providing better isolation between workflow executions. The Durable Object approach also allows for better scaling as each workflow execution gets its own isolated environment. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Introduced a new workflow execution engine with the `WorkflowRunner` class for improved workflow management and error handling. * Added workflow execution tracking to prevent duplicate processing of threads, with automatic cleanup for re-execution. * Added new workflow functions to check and clean up workflow execution state. * **Improvements** * Enhanced workflow step execution logic with conditional and batched processing for better reliability and efficiency. * Updated configuration to support the new workflow runner across all environments. * **Chores** * Refactored and reorganized workflow-related code for better maintainability and structure. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
487 lines
12 KiB
JSON
487 lines
12 KiB
JSON
{
|
|
"$schema": "node_modules/wrangler/config-schema.json",
|
|
"name": "zero-server",
|
|
"compatibility_date": "2025-05-01",
|
|
"compatibility_flags": ["nodejs_compat"],
|
|
"main": "src/main.ts",
|
|
"env": {
|
|
"local": {
|
|
"ai": {
|
|
"binding": "AI",
|
|
},
|
|
"vectorize": [
|
|
{
|
|
"binding": "VECTORIZE",
|
|
"index_name": "threads-vector-staging",
|
|
},
|
|
{
|
|
"binding": "VECTORIZE_MESSAGE",
|
|
"index_name": "messages-vector-staging",
|
|
},
|
|
],
|
|
"r2_buckets": [
|
|
{
|
|
"binding": "THREADS_BUCKET",
|
|
"bucket_name": "threads-staging",
|
|
},
|
|
],
|
|
"durable_objects": {
|
|
"bindings": [
|
|
{
|
|
"name": "ZERO_AGENT",
|
|
"class_name": "ZeroAgent",
|
|
},
|
|
{
|
|
"name": "ZERO_MCP",
|
|
"class_name": "ZeroMCP",
|
|
},
|
|
{
|
|
"name": "ZERO_DB",
|
|
"class_name": "ZeroDB",
|
|
},
|
|
{
|
|
"name": "ZERO_DRIVER",
|
|
"class_name": "ZeroDriver",
|
|
},
|
|
{
|
|
"name": "THINKING_MCP",
|
|
"class_name": "ThinkingMCP",
|
|
},
|
|
{
|
|
"name": "WORKFLOW_RUNNER",
|
|
"class_name": "WorkflowRunner",
|
|
},
|
|
],
|
|
},
|
|
"queues": {
|
|
"producers": [
|
|
{
|
|
"queue": "thread-queue",
|
|
"binding": "thread_queue",
|
|
},
|
|
{
|
|
"queue": "subscribe-queue",
|
|
"binding": "subscribe_queue",
|
|
},
|
|
],
|
|
"consumers": [
|
|
{
|
|
"queue": "subscribe-queue",
|
|
},
|
|
{
|
|
"queue": "thread-queue",
|
|
},
|
|
],
|
|
},
|
|
"migrations": [
|
|
{
|
|
"tag": "v1",
|
|
"new_classes": ["DurableMailbox"],
|
|
},
|
|
{
|
|
"tag": "v2",
|
|
"new_sqlite_classes": ["ZeroAgent", "ZeroMCP"],
|
|
},
|
|
{
|
|
"tag": "v3",
|
|
"new_classes": ["ZeroDB"],
|
|
},
|
|
{
|
|
"tag": "v4",
|
|
"deleted_classes": ["DurableMailbox"],
|
|
},
|
|
{
|
|
"tag": "v5",
|
|
"new_sqlite_classes": ["ZeroDriver"],
|
|
},
|
|
{
|
|
"tag": "v6",
|
|
"new_sqlite_classes": ["ThinkingMCP"],
|
|
},
|
|
{
|
|
"tag": "v7",
|
|
"new_sqlite_classes": ["WorkflowRunner"],
|
|
},
|
|
],
|
|
|
|
"observability": {
|
|
"enabled": true,
|
|
},
|
|
"triggers": {
|
|
"crons": ["*/1 * * * *"],
|
|
},
|
|
"hyperdrive": [
|
|
{
|
|
"binding": "HYPERDRIVE",
|
|
"id": "57834ddb6716440496c8836f6d99bc9a",
|
|
"localConnectionString": "postgresql://postgres:postgres@localhost:5432/zerodotemail",
|
|
},
|
|
],
|
|
"vars": {
|
|
"NODE_ENV": "development",
|
|
"COOKIE_DOMAIN": "localhost",
|
|
"VITE_PUBLIC_BACKEND_URL": "http://localhost:8787",
|
|
"VITE_PUBLIC_APP_URL": "http://localhost:3000",
|
|
"JWT_SECRET": "secret",
|
|
"ELEVENLABS_API_KEY": "1234567890",
|
|
"DISABLE_CALLS": "true",
|
|
"VOICE_SECRET": "1234567890",
|
|
"GOOGLE_S_ACCOUNT": "{}",
|
|
"DROP_AGENT_TABLES": "false",
|
|
"THREAD_SYNC_MAX_COUNT": "5",
|
|
"THREAD_SYNC_LOOP": "false",
|
|
"DISABLE_WORKFLOWS": "false",
|
|
"AUTORAG_ID": "",
|
|
"USE_OPENAI": "true",
|
|
},
|
|
"kv_namespaces": [
|
|
{
|
|
"binding": "gmail_history_id",
|
|
"id": "4e814c70e35d413d99c923029928efae",
|
|
},
|
|
{
|
|
"binding": "gmail_processing_threads",
|
|
"id": "b7db3a98a80f4e16a8b6edc5fa8c7b76",
|
|
},
|
|
{
|
|
"binding": "subscribed_accounts",
|
|
"id": "7e6eadacf19c4c56a9ec3c357adb584a",
|
|
},
|
|
{
|
|
"binding": "connection_labels",
|
|
"id": "4d3a28d3265a4388aae2e9e9b534d019",
|
|
},
|
|
{
|
|
"binding": "prompts_storage",
|
|
"id": "620e710aaea744e59df4788f9ec18ff9",
|
|
},
|
|
{
|
|
"binding": "gmail_sub_age",
|
|
"id": "c55e692bb71d4e5bae23dded092b09d5",
|
|
},
|
|
{
|
|
"binding": "snoozed_emails",
|
|
"id": "f3a30ed7198542d890db172536bade33",
|
|
},
|
|
],
|
|
},
|
|
"staging": {
|
|
"triggers": {
|
|
"crons": ["0 0 * * *"],
|
|
},
|
|
"ai": {
|
|
"binding": "AI",
|
|
},
|
|
"vectorize": [
|
|
{
|
|
"binding": "VECTORIZE",
|
|
"index_name": "threads-vector-staging",
|
|
},
|
|
{
|
|
"binding": "VECTORIZE_MESSAGE",
|
|
"index_name": "messages-vector-staging",
|
|
},
|
|
],
|
|
"limits": {
|
|
"cpu_ms": 300000,
|
|
},
|
|
"durable_objects": {
|
|
"bindings": [
|
|
{
|
|
"name": "ZERO_AGENT",
|
|
"class_name": "ZeroAgent",
|
|
},
|
|
{
|
|
"name": "ZERO_MCP",
|
|
"class_name": "ZeroMCP",
|
|
},
|
|
{
|
|
"name": "ZERO_DB",
|
|
"class_name": "ZeroDB",
|
|
},
|
|
{
|
|
"name": "ZERO_DRIVER",
|
|
"class_name": "ZeroDriver",
|
|
},
|
|
{
|
|
"name": "THINKING_MCP",
|
|
"class_name": "ThinkingMCP",
|
|
},
|
|
{
|
|
"name": "WORKFLOW_RUNNER",
|
|
"class_name": "WorkflowRunner",
|
|
},
|
|
],
|
|
},
|
|
"r2_buckets": [
|
|
{
|
|
"binding": "THREADS_BUCKET",
|
|
"bucket_name": "threads-staging",
|
|
},
|
|
],
|
|
"queues": {
|
|
"producers": [
|
|
{
|
|
"queue": "thread-queue-staging",
|
|
"binding": "thread_queue",
|
|
},
|
|
{
|
|
"queue": "subscribe-queue-staging",
|
|
"binding": "subscribe_queue",
|
|
},
|
|
],
|
|
"consumers": [
|
|
{
|
|
"queue": "subscribe-queue-staging",
|
|
},
|
|
{
|
|
"queue": "thread-queue-staging",
|
|
},
|
|
],
|
|
},
|
|
"migrations": [
|
|
{
|
|
"tag": "v1",
|
|
"new_classes": ["DurableMailbox"],
|
|
},
|
|
{
|
|
"tag": "v2",
|
|
"new_sqlite_classes": ["ZeroAgent", "ZeroMCP"],
|
|
},
|
|
{
|
|
"tag": "v3",
|
|
"new_classes": ["ZeroDB"],
|
|
},
|
|
{
|
|
"tag": "v4",
|
|
"new_sqlite_classes": ["ZeroAgent"],
|
|
},
|
|
{
|
|
"tag": "v5",
|
|
"deleted_classes": ["DurableMailbox"],
|
|
},
|
|
{
|
|
"tag": "v6",
|
|
"new_sqlite_classes": ["ZeroDriver"],
|
|
},
|
|
{
|
|
"tag": "v7",
|
|
"new_sqlite_classes": ["ThinkingMCP"],
|
|
},
|
|
{
|
|
"tag": "v8",
|
|
"new_sqlite_classes": ["WorkflowRunner"],
|
|
},
|
|
],
|
|
"observability": {
|
|
"enabled": true,
|
|
},
|
|
"hyperdrive": [
|
|
{
|
|
"binding": "HYPERDRIVE",
|
|
"id": "57834ddb6716440496c8836f6d99bc9a",
|
|
"localConnectionString": "postgresql://postgres:postgres@localhost:5432/zerodotemail",
|
|
},
|
|
],
|
|
"vars": {
|
|
"NODE_ENV": "development",
|
|
"COOKIE_DOMAIN": "0.email",
|
|
"VITE_PUBLIC_BACKEND_URL": "https://sapi.0.email",
|
|
"VITE_PUBLIC_APP_URL": "https://staging.0.email",
|
|
"DISABLE_CALLS": "",
|
|
"DROP_AGENT_TABLES": "false",
|
|
"THREAD_SYNC_MAX_COUNT": "20",
|
|
"THREAD_SYNC_LOOP": "true",
|
|
"DISABLE_WORKFLOWS": "false",
|
|
},
|
|
"kv_namespaces": [
|
|
{
|
|
"binding": "gmail_history_id",
|
|
"id": "4e814c70e35d413d99c923029928efae",
|
|
},
|
|
{
|
|
"binding": "gmail_processing_threads",
|
|
"id": "b7db3a98a80f4e16a8b6edc5fa8c7b76",
|
|
},
|
|
{
|
|
"binding": "subscribed_accounts",
|
|
"id": "7e6eadacf19c4c56a9ec3c357adb584a",
|
|
},
|
|
{
|
|
"binding": "connection_labels",
|
|
"id": "4d3a28d3265a4388aae2e9e9b534d019",
|
|
},
|
|
{
|
|
"binding": "prompts_storage",
|
|
"id": "620e710aaea744e59df4788f9ec18ff9",
|
|
},
|
|
{
|
|
"binding": "gmail_sub_age",
|
|
"id": "c55e692bb71d4e5bae23dded092b09d5",
|
|
},
|
|
{
|
|
"binding": "snoozed_emails",
|
|
"id": "f3a30ed7198542d890db172536bade33",
|
|
},
|
|
],
|
|
},
|
|
"production": {
|
|
"triggers": {
|
|
"crons": ["0 0 * * *"],
|
|
},
|
|
"r2_buckets": [
|
|
{
|
|
"binding": "THREADS_BUCKET",
|
|
"bucket_name": "threads",
|
|
},
|
|
],
|
|
"ai": {
|
|
"binding": "AI",
|
|
},
|
|
"vectorize": [
|
|
{
|
|
"binding": "VECTORIZE",
|
|
"index_name": "threads-vector",
|
|
},
|
|
{
|
|
"binding": "VECTORIZE_MESSAGE",
|
|
"index_name": "messages-vector",
|
|
},
|
|
],
|
|
"observability": {
|
|
"enabled": true,
|
|
},
|
|
"hyperdrive": [
|
|
{
|
|
"binding": "HYPERDRIVE",
|
|
"id": "b1be316b45fb439a9e54b74ecc20aa21",
|
|
"localConnectionString": "postgresql://postgres:postgres@localhost:5432/zerodotemail",
|
|
},
|
|
],
|
|
"durable_objects": {
|
|
"bindings": [
|
|
{
|
|
"name": "ZERO_AGENT",
|
|
"class_name": "ZeroAgent",
|
|
},
|
|
{
|
|
"name": "ZERO_MCP",
|
|
"class_name": "ZeroMCP",
|
|
},
|
|
{
|
|
"name": "ZERO_DB",
|
|
"class_name": "ZeroDB",
|
|
},
|
|
{
|
|
"name": "ZERO_DRIVER",
|
|
"class_name": "ZeroDriver",
|
|
},
|
|
{
|
|
"name": "THINKING_MCP",
|
|
"class_name": "ThinkingMCP",
|
|
},
|
|
{
|
|
"name": "WORKFLOW_RUNNER",
|
|
"class_name": "WorkflowRunner",
|
|
},
|
|
],
|
|
},
|
|
"queues": {
|
|
"producers": [
|
|
{
|
|
"queue": "thread-queue-prod",
|
|
"binding": "thread_queue",
|
|
},
|
|
{
|
|
"queue": "subscribe-queue-prod",
|
|
"binding": "subscribe_queue",
|
|
},
|
|
],
|
|
"consumers": [
|
|
{
|
|
"queue": "subscribe-queue-prod",
|
|
},
|
|
{
|
|
"queue": "thread-queue-prod",
|
|
},
|
|
],
|
|
},
|
|
"migrations": [
|
|
{
|
|
"tag": "v1",
|
|
"new_classes": ["DurableMailbox"],
|
|
},
|
|
{
|
|
"tag": "v2",
|
|
"new_sqlite_classes": ["ZeroAgent", "ZeroMCP"],
|
|
},
|
|
{
|
|
"tag": "v3",
|
|
"new_classes": ["ZeroDB"],
|
|
},
|
|
{
|
|
"tag": "v4",
|
|
"new_sqlite_classes": ["ZeroAgent"],
|
|
},
|
|
{
|
|
"tag": "v5",
|
|
"deleted_classes": ["DurableMailbox"],
|
|
},
|
|
{
|
|
"tag": "v6",
|
|
"new_sqlite_classes": ["ZeroDriver"],
|
|
},
|
|
{
|
|
"tag": "v7",
|
|
"new_sqlite_classes": ["ThinkingMCP"],
|
|
},
|
|
{
|
|
"tag": "v8",
|
|
"new_sqlite_classes": ["WorkflowRunner"],
|
|
},
|
|
],
|
|
"vars": {
|
|
"NODE_ENV": "production",
|
|
"COOKIE_DOMAIN": "0.email",
|
|
"VITE_PUBLIC_BACKEND_URL": "https://api.0.email",
|
|
"VITE_PUBLIC_APP_URL": "https://0.email",
|
|
"DISABLE_CALLS": "true",
|
|
"DROP_AGENT_TABLES": "false",
|
|
"THREAD_SYNC_MAX_COUNT": "10",
|
|
"THREAD_SYNC_LOOP": "true",
|
|
"DISABLE_WORKFLOWS": "true",
|
|
},
|
|
"kv_namespaces": [
|
|
{
|
|
"binding": "gmail_history_id",
|
|
"id": "10005d74e84f4f18a17c9618d9e9cecf",
|
|
},
|
|
{
|
|
"binding": "gmail_processing_threads",
|
|
"id": "3348ff0976284269a8d8a5e6e4c04c56",
|
|
},
|
|
{
|
|
"binding": "subscribed_accounts",
|
|
"id": "5902b3b948ff4c4ba1aedbbbbe25503d",
|
|
},
|
|
{
|
|
"binding": "connection_labels",
|
|
"id": "9a13290a55ad4f62824c67005dd66f6f",
|
|
},
|
|
{
|
|
"binding": "prompts_storage",
|
|
"id": "2a4ebda553f3456085cfcf92cc0f570f",
|
|
},
|
|
{
|
|
"binding": "gmail_sub_age",
|
|
"id": "0591e91fffcc4675aaf00f909bee77d2",
|
|
},
|
|
{
|
|
"binding": "snoozed_emails",
|
|
"id": "f0952e9c3b024cb499c4b9dfe8bb603e",
|
|
},
|
|
],
|
|
},
|
|
},
|
|
}
|