Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
feat: sandbox retention basic settings (#29842)
hj2446c9a59a3128
diff --git a/.devcontainer/post_create_command.sh b/.devcontainer/post_create_command.shindex a26fd076eda..ce9135476fa 100755--- a/.devcontainer/post_create_command.sh+++ b/.devcontainer/post_create_command.sh@@ -6,7 +6,7 @@ cd web && pnpm installpipx install uvecho "alias start-api=\"cd $WORKSPACE_ROOT/api && uv run python -m flask run --host 0.0.0.0 --port=5001 --debug\"" >> ~/.bashrc-echo "alias start-worker=\"cd $WORKSPACE_ROOT/api && uv run python -m celery -A app.celery worker -P threads -c 1 --loglevel INFO -Q dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor\"" >> ~/.bashrc+echo "alias start-worker=\"cd $WORKSPACE_ROOT/api && uv run python -m celery -A app.celery worker -P threads -c 1 --loglevel INFO -Q dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor,retention\"" >> ~/.bashrcecho "alias start-web=\"cd $WORKSPACE_ROOT/web && pnpm dev\"" >> ~/.bashrcecho "alias start-web-prod=\"cd $WORKSPACE_ROOT/web && pnpm build && pnpm start\"" >> ~/.bashrcecho "alias start-containers=\"cd $WORKSPACE_ROOT/docker && docker-compose -f docker-compose.middleware.yaml -p dify --env-file middleware.env up -d\"" >> ~/.bashrcdiff --git a/.vscode/launch.json.template b/.vscode/launch.json.templateindex cb934d01b50..bdded1e73e3 100644--- a/.vscode/launch.json.template+++ b/.vscode/launch.json.template@@ -37,7 +37,7 @@"-c","1","-Q",- "dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor",+ "dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor,retention","--loglevel","INFO"],diff --git a/api/.env.example b/api/.env.exampleindex 43fe76bb112..b87d9c7b029 100644--- a/api/.env.example+++ b/api/.env.example@@ -690,3 +690,8 @@ ANNOTATION_IMPORT_RATE_LIMIT_PER_MINUTE=5ANNOTATION_IMPORT_RATE_LIMIT_PER_HOUR=20# Maximum number of concurrent annotation import tasks per tenantANNOTATION_IMPORT_MAX_CONCURRENT=5++# Sandbox expired records clean configuration+SANDBOX_EXPIRED_RECORDS_CLEAN_GRACEFUL_PERIOD=21+SANDBOX_EXPIRED_RECORDS_CLEAN_BATCH_SIZE=1000+SANDBOX_EXPIRED_RECORDS_RETENTION_DAYS=30diff --git a/api/README.md b/api/README.mdindex 2dab2ec6e6c..794b05d3af9 100644--- a/api/README.md+++ b/api/README.md@@ -84,7 +84,7 @@1. If you need to handle and debug the async tasks (e.g. dataset importing and documents indexing), please start the worker service.```bash-uv run celery -A app.celery worker -P threads -c 2 --loglevel INFO -Q dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor+uv run celery -A app.celery worker -P threads -c 2 --loglevel INFO -Q dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor,retention```Additionally, if you want to debug the celery scheduled tasks, you can run the following command in another terminal to start the beat service:diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.pyindex e16ca52f462..1e1f4ed02ed 100644--- a/api/configs/feature/__init__.py+++ b/api/configs/feature/__init__.py@@ -1270,6 +1270,21 @@ class TenantIsolatedTaskQueueConfig(BaseSettings):)+class SandboxExpiredRecordsCleanConfig(BaseSettings):+ SANDBOX_EXPIRED_RECORDS_CLEAN_GRACEFUL_PERIOD: NonNegativeInt = Field(+ description="Graceful period in days for sandbox records clean after subscription expiration",+ default=21,+ )+ SANDBOX_EXPIRED_RECORDS_CLEAN_BATCH_SIZE: PositiveInt = Field(+ description="Maximum number of records to process in each batch",+ default=1000,+ )+ SANDBOX_EXPIRED_RECORDS_RETENTION_DAYS: PositiveInt = Field(+ description="Retention days for sandbox expired workflow_run records and message records",+ default=30,+ )++class FeatureConfig(# place the configs in alphabet orderAppExecutionConfig,@@ -1295,6 +1310,7 @@ class FeatureConfig(PositionConfig,RagEtlConfig,RepositoryConfig,+ SandboxExpiredRecordsCleanConfig,SecurityConfig,TenantIsolatedTaskQueueConfig,ToolConfig,diff --git a/api/docker/entrypoint.sh b/api/docker/entrypoint.shindex 6313085e640..5a69eb15acb 100755--- a/api/docker/entrypoint.sh+++ b/api/docker/entrypoint.sh@@ -34,10 +34,10 @@ if [[ "${MODE}" == "worker" ]]; thenif [[ -z "${CELERY_QUEUES}" ]]; thenif [[ "${EDITION}" == "CLOUD" ]]; then# Cloud edition: separate queues for dataset and trigger tasks- DEFAULT_QUEUES="dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow_professional,workflow_team,workflow_sandbox,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor"+ DEFAULT_QUEUES="dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow_professional,workflow_team,workflow_sandbox,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor,retention"else# Community edition (SELF_HOSTED): dataset, pipeline and workflow have separate queues- DEFAULT_QUEUES="dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor"+ DEFAULT_QUEUES="dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor,retention"fielseDEFAULT_QUEUES="${CELERY_QUEUES}"@@ -69,6 +69,53 @@ if [[ "${MODE}" == "worker" ]]; thenelif [[ "${MODE}" == "beat" ]]; thenexec celery -A app.celery beat --loglevel ${LOG_LEVEL:-INFO}++elif [[ "${MODE}" == "job" ]]; then+ # Job mode: Run a one-time Flask command and exit+ # Pass Flask command and arguments via container args+ # Example K8s usage:+ # args:+ # - create-tenant+ # - [email protected]+ #+ # Example Docker usage:+ # docker run -e MODE=job dify-api:latest create-tenant --email [email protected]++ if [[ $# -eq 0 ]]; then+ echo "Error: No command specified for job mode."+ echo ""+ echo "Usage examples:"+ echo " Kubernetes:"+ echo " args: [create-tenant, --email, [email protected]]"+ echo ""+ echo " Docker:"+ echo " docker run -e MODE=job dify-api create-tenant --email [email protected]"+ echo ""+ echo "Available commands:"+ echo " create-tenant, reset-password, reset-email, upgrade-db,"+ echo " vdb-migrate, install-plugins, and more..."+ echo ""+ echo "Run 'flask --help' to see all available commands."+ exit 1+ fi++ echo "Running Flask job command: flask $*"++ # Temporarily disable exit on error to capture exit code+ set +e+ flask "$@"+ JOB_EXIT_CODE=$?+ set -e++ if [[ ${JOB_EXIT_CODE} -eq 0 ]]; then+ echo "Job completed successfully."+ else+ echo "Job failed with exit code ${JOB_EXIT_CODE}."+ fi++ exit ${JOB_EXIT_CODE}+elseif [[ "${DEBUG}" == "true" ]]; thenexec flask run --host=${DIFY_BIND_ADDRESS:-0.0.0.0} --port=${DIFY_PORT:-5001} --debugdiff --git a/dev/start-worker b/dev/start-workerindex a01da11d86e..78766201885 100755--- a/dev/start-worker+++ b/dev/start-worker@@ -37,6 +37,7 @@ show_help() {echo " pipeline - Standard pipeline tasks"echo " triggered_workflow_dispatcher - Trigger dispatcher tasks"echo " trigger_refresh_executor - Trigger refresh tasks"+ echo " retention - Retention tasks"}# Parse command line arguments@@ -105,10 +106,10 @@ if [[ -z "${QUEUES}" ]]; then# Configure queues based on editionif [[ "${EDITION}" == "CLOUD" ]]; then# Cloud edition: separate queues for dataset and trigger tasks- QUEUES="dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow_professional,workflow_team,workflow_sandbox,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor"+ QUEUES="dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow_professional,workflow_team,workflow_sandbox,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor,retention"else# Community edition (SELF_HOSTED): dataset and workflow have separate queues- QUEUES="dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor"+ QUEUES="dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor,retention"fiecho "No queues specified, using edition-based defaults: ${QUEUES}"diff --git a/docker/.env.example b/docker/.env.exampleindex dd0d083da36..e7eba46c5c8 100644--- a/docker/.env.example+++ b/docker/.env.example@@ -1479,4 +1479,9 @@ ANNOTATION_IMPORT_RATE_LIMIT_PER_HOUR=20ANNOTATION_IMPORT_MAX_CONCURRENT=5# The API key of amplitude-AMPLITUDE_API_KEY=\ No newline at end of file+AMPLITUDE_API_KEY=++# Sandbox expired records clean configuration+SANDBOX_EXPIRED_RECORDS_CLEAN_GRACEFUL_PERIOD=21+SANDBOX_EXPIRED_RECORDS_CLEAN_BATCH_SIZE=1000+SANDBOX_EXPIRED_RECORDS_RETENTION_DAYS=30diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yamlindex aca43258806..23aa8372290 100644--- a/docker/docker-compose.yaml+++ b/docker/docker-compose.yaml@@ -663,6 +663,9 @@ x-shared-env: &shared-api-worker-envANNOTATION_IMPORT_RATE_LIMIT_PER_HOUR: ${ANNOTATION_IMPORT_RATE_LIMIT_PER_HOUR:-20}ANNOTATION_IMPORT_MAX_CONCURRENT: ${ANNOTATION_IMPORT_MAX_CONCURRENT:-5}AMPLITUDE_API_KEY: ${AMPLITUDE_API_KEY:-}+ SANDBOX_EXPIRED_RECORDS_CLEAN_GRACEFUL_PERIOD: ${SANDBOX_EXPIRED_RECORDS_CLEAN_GRACEFUL_PERIOD:-21}+ SANDBOX_EXPIRED_RECORDS_CLEAN_BATCH_SIZE: ${SANDBOX_EXPIRED_RECORDS_CLEAN_BATCH_SIZE:-1000}+ SANDBOX_EXPIRED_RECORDS_RETENTION_DAYS: ${SANDBOX_EXPIRED_RECORDS_RETENTION_DAYS:-30}services:# Init container to fix permissions