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
perf(agent): exponential backoff in polling to prevent forking storm (#41222)
Yunlu Wen679514d40a3f
diff --git a/dify-agent-runtime/internal/server/config.go b/dify-agent-runtime/internal/server/config.goindex c30ed34df70..bae1c56d93f 100644--- a/dify-agent-runtime/internal/server/config.go+++ b/dify-agent-runtime/internal/server/config.go@@ -24,6 +24,7 @@ const (DefaultGCIntervalSeconds = 60.0DefaultGCFinishedJobRetentionSeconds = 300.0DefaultPollInterval = 5 * time.Millisecond+ DefaultMaxPollInterval = 50 * time.MillisecondDefaultPipeMonitorInterval = 1 * time.SecondDefaultPipeReadyTimeout = 10 * time.SecondDefaultSQLiteBusyTimeoutMs = 5000@@ -53,6 +54,7 @@ type Config struct {MaxOutputLimitBytes intDefaultTerminateGraceSeconds float64PollInterval time.Duration+ MaxPollInterval time.DurationPipeMonitorInterval time.DurationPipeReadyTimeout time.DurationSQLiteBusyTimeoutMs int@@ -90,6 +92,7 @@ func DefaultConfig() (*Config, error) {MaxOutputLimitBytes: MaxOutputLimitBytes,DefaultTerminateGraceSeconds: DefaultTerminateGraceSeconds,PollInterval: DefaultPollInterval,+ MaxPollInterval: DefaultMaxPollInterval,PipeMonitorInterval: DefaultPipeMonitorInterval,PipeReadyTimeout: DefaultPipeReadyTimeout,SQLiteBusyTimeoutMs: DefaultSQLiteBusyTimeoutMs,diff --git a/dify-agent-runtime/internal/server/service.go b/dify-agent-runtime/internal/server/service.goindex 693d3c16fcc..24a21f5ee54 100644--- a/dify-agent-runtime/internal/server/service.go+++ b/dify-agent-runtime/internal/server/service.go@@ -349,6 +349,11 @@ func (s *Service) WaitJob(jobID string, req *WaitJobRequest) (*JobResult, error)lastGrowthAt = &now}+ // Poll with exponential backoff: start tight so short jobs return with low+ // latency, then grow the interval up to MaxPollInterval so long/idle waits+ // stop spawning a tmux liveness probe (fork) every few milliseconds.+ pollInterval := s.config.PollInterval+for {view, err := s.GetJobStatus(jobID)if err != nil {@@ -411,7 +416,8 @@ func (s *Service) WaitJob(jobID string, req *WaitJobRequest) (*JobResult, error)return s.jobResultFromView(view, row, window), nil}- time.Sleep(s.config.PollInterval)+ time.Sleep(pollInterval)+ pollInterval = min(pollInterval*2, s.config.MaxPollInterval)}}