Skip to content

feat(serverless): keep long-running invocations alive via periodic activation - #848

Merged
wylswz merged 3 commits into
langgenius:mainfrom
wylswz:feat/serverless-activation-keepalive
Nov 2, 2026
Merged

wylswz merged 3 commits into
langgenius:mainfrom
wylswz:feat/serverless-activation-keepalive

Conversation

@wylswz

@wylswz wylswz commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • With activation enabled, a long-running serverless invocation could be scaled to zero by the connector while it was still running. After the activation preflight succeeds, the daemon now calls POST /v1/activation/activate again on a fixed interval until the invocation finishes, which renews the plugin's activity lease.

  • New env var DIFY_PLUGIN_SERVERLESS_CONNECTOR_ACTIVATION_KEEPALIVE_INTERVAL (seconds, default 60). It only applies when DIFY_PLUGIN_SERVERLESS_CONNECTOR_ACTIVATION_ENABLED=true. The connector idle time should be at least 2× this interval.

  • Each keepalive call times out after one interval, so calls never overlap. Keepalive stops before the invocation ends, so no calls are made after the END message.

  • A failed keepalive is logged with log.Warn and does not fail the invocation.

  • Config validation now rejects a non-positive interval when activation is enabled. Docs (sri.md, sri_cn.md) and .env.example are updated.

  • A panic inside the keepalive goroutine is caught and logged, so it cannot crash the daemon. This goroutine does not go through routine.Submit.

Test plan

  • go build ./...
  • go vet ./internal/core/serverless_runtime/... ./internal/types/app/...
  • go test ./internal/core/serverless_runtime/... ./internal/types/app/... (new tests cover: repeated renewals during a long invocation, no calls after the invocation ends, a keepalive failure leaving the invocation intact, no calls when activation is disabled, a panic in the keepalive goroutine being recovered without crashing or hanging, and config validation)
  • Manual check on a cluster with activation enabled: confirm a long-running invocation is not scaled down

Generated with Devin

wylswz and others added 2 commits November 2, 2026 12:43
…tivation

Long-running serverless invocations could be scaled to zero by the connector
mid-flight. After a successful activation preflight, the daemon now re-calls
the connector's activate endpoint every
DIFY_PLUGIN_SERVERLESS_CONNECTOR_ACTIVATION_KEEPALIVE_INTERVAL seconds
(default 60) until the invocation finishes. Keepalive failures are logged and
never abort the invocation.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@wylswz
wylswz requested review from zhangx1n and a balanced review from Copilot November 2, 2026 06:27

Copilot AI left a comment

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.

🟡 Changes recommended

Defaulting replaces an explicitly configured zero keepalive interval with 60 before validation, bypassing the non-positive interval check during startup, while the test misses this parsing/defaulting sequence.

1 open issue
What changed in this PR

This PR adds periodic activation requests to keep long-running serverless plugin invocations from being scaled to zero.

Changes:

  • Adds a keepalive loop with cancellation, warning logs on failure, and panic recovery.
  • Introduces a configurable keepalive interval, defaulting to 60 seconds, with validation.
  • Adds lifecycle and configuration tests and updates English and Chinese documentation.
File Description
internal/​types/​app/​default.go Sets the default keepalive interval.
internal/​types/​app/​config.go Adds the interval setting and validation.
internal/​types/​app/​config_test.go Tests rejection of non-positive intervals.
internal/​core/​serverless_runtime/​type.go Passes the configured interval into the runtime.
internal/​core/​serverless_runtime/​io.go Starts and stops periodic activation during invocations.
internal/​core/​serverless_runtime/​io_test.go Tests renewals, shutdown, failures, disabled activation, and panic recovery.
docs/​runtime/​sri.md Documents keepalive configuration and behavior in English.
docs/​runtime/​sri_cn.md Documents keepalive configuration and behavior in Chinese.
.env.example Adds the keepalive environment variable and idle-time guidance.

Review effort: Balanced

Comment thread internal/types/app/default.go Resolved
…cts it

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@wylswz
wylswz requested a review from fatelei November 2, 2026 07:44

@zhangx1n zhangx1n left a comment

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.

LGTM

@wylswz
wylswz merged commit b7293cd into langgenius:main Nov 2, 2026
7 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.

3 participants