Repository navigation
feat(serverless): keep long-running invocations alive via periodic activation - #848
Merged
wylswz merged 3 commits intoNov 2, 2026
Merged
Conversation
…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>
Contributor
There was a problem hiding this comment.
🟡 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
…cts it Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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/activateagain 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, default60). It only applies whenDIFY_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.Warnand 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.exampleare 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)Generated with Devin