feat(dify-agent): add an opt-in Rust local runtime canary - #41070
Open
pineapple880066 wants to merge 7 commits into
Open
feat(dify-agent): add an opt-in Rust local runtime canary#41070pineapple880066 wants to merge 7 commits into
pineapple880066 wants to merge 7 commits into
Conversation
pineapple880066
force-pushed
the
agent/rust-local-runtime-canary
branch
from
August 21, 2026 13:40
f7d7f77 to
07914d4
Compare
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.
Important
Fixes #<issue number>.Note
This supersedes #40477. That PR was closed after its head diverged from the latest
main; GitHub would not reopen it after the branch was rebased and force-pushed. This PR contains the same reviewed direction, rebased ontoa9b8c84e9be41376c04901e81ce690f35c1ffe86, plus the latest shellctl compatibility and test updates.Summary
Fixes #39976.
This adds an opt-in Rust implementation of the local
dify-agentruntime as a guarded canary. Go remains the default implementation and the compatibility fallback. The Rust service is isolated behind a separate Compose overlay and deterministic percentage rollout, so the change can be evaluated incrementally without replacing existing Go-owned sessions.The implementation targets runtime overhead only: local shell/file execution, process supervision, state handling, and data movement. It does not claim to improve LLM/provider, database, vector-store, or frontend latency.
What changed
shellctl, runner, runner-exit, and sanitizer components.rust+references for sticky routing across the complete Binding/Workspace/Home Snapshot lifecycle.mode=ptycompatibility plusmode=stdio, including separate stdout/stderr capture and explicit rejection of unsupported stdin.TMPDIR,TMP, andTEMPinto the workspace and created/workspacein the Rust image.Rollout and rollback
DIFY_AGENT_RUNTIME_RUST_CANARY_PERCENTcan be raised gradually.0immediately stops assigning new sessions to Rust.rust+sessions remain sticky, so the Rust service should stay up until those references drain.Current-tip paired Linux container A/B
The final-source Go and Rust images were tested on Linux arm64 for five alternating paired rounds, with 50 jobs per round, 2 CPUs, and a 1 GiB memory limit. The benchmark was run from a clean clone at
07914d47673493da07bef6cd2b62e79fd17d31e8; the subsequent tip changes only ShellCheck-safe quoting in an integration runner and leaves the benchmarked runtime and harness content unchanged. Ratios and reductions below are medians of the paired per-round ratios, not ratios calculated from the displayed marginal medians.Startup and health-preflight confidence intervals cross zero and should be treated as parity; the measurable gains are lower steady-state memory and lower local job overhead.
Full Agent v2 shadow A/B
A non-disruptive 20-pair Agent v2 shadow test on a deployed Linux host also exercised binding creation, run, 32 KiB read, and destroy through the real lifecycle. It measured a full-session median of 1999.212 ms for Go and 670.795 ms for Rust (2.980x, 66.4% lower; paired 95% bootstrap CI for the reduction: 65.8%–67.4%). This deployment used source
8e74d..., older than the current tip, so it is supporting end-to-end evidence rather than the current-tip microbenchmark.Validation on the rebased tip
cargo fmt --check,cargo clippy --locked --all-targets -- -D warnings, andcargo test --lockedin the official Linux Rust container; 23 unit tests passed.go test -race -count=1 ./...in the official Linux Go container andgolangci-lint2.12.2; all packages passed with 0 lint issues.make integrationfrom a clean source archive; all 40 Go/Rust acceptance groups passed, covering PTY/stdio, isolation/no-isolation, restart recovery, concurrency, Landlock, validation, and lifecycle behavior.dify-agentsource and test. The clean-clone suite, run with importlib mode to avoid upstream same-name test-module collection collisions, completed with 809 passed and 34 skipped; its sole network-isolated dependency-install case passed separately with network enabled. The only full-tree type error also reproduces onmainin an unchanged integration test.docker compose config --quiet.sh -n.No Dify API or frontend code is changed by this PR.
Screenshots
Not applicable; this is a backend runtime and rollout change.
Checklist
dify-agent, Compose, benchmark, and integration checks are listed above.From Codex