fix(llm,mcp,core): add embed timeout and track JoinHandles in ShadowSentinel#4588
Merged
Conversation
…entinel Closes #4566 — RouterProvider::spawn_asi_update and EmbeddingAnomalyGuard::check_async now wrap embed() calls with tokio::time::timeout(embed_timeout_ms). On Elapsed the task returns early (same as embed error path); no ASI window update or anomaly event is emitted. EmbeddingAnomalyGuard gains an embed_timeout_ms field (default 5000 ms) with a with_embed_timeout() builder. Closes #4570 — ShadowSentinel::check_tool_call and record_tool_event no longer drop JoinHandles. A bounded Mutex<JoinSet<()>> (cap MAX_PENDING_WRITES = 32) replaces the two let _ = tokio::spawn(...) sites. spawn_persist() reaps completed handles with try_join_next (non-blocking) before spawning; if still at capacity the new task is skipped with a debug log. drain_pending() (blocking) is called in Agent::shutdown() to flush remaining writes.
6cf44a3 to
52bbfbb
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.
Summary
fix(llm): spawn_asi_update embed() call has no timeout — can block router turn indefinitely #4566 —
RouterProvider::spawn_asi_updateandEmbeddingAnomalyGuard::check_asyncnowwrap embed calls with
tokio::time::timeout(embed_timeout_ms). On timeout the task returnsearly (same path as embed error); no ASI window update or anomaly event is emitted. Prevents
indefinite task accumulation when the embedding provider stalls under load.
arch(shadow_sentinel): fire-and-forget tokio::spawn handles not tracked (probe persist + tool_event) #4570 —
ShadowSentinelno longer dropsJoinHandles from its two fire-and-forgetpersist tasks. Both spawn sites use a bounded
Mutex<JoinSet<()>>(cap 32). Completed handlesare reaped non-blockingly via
try_join_next()before each spawn; if still at capacity thenew task is dropped with a debug log.
drain_pending()flushes remaining writes atAgent::shutdown().Changed files
crates/zeph-llm/src/router/mod.rsspawn_asi_updatecrates/zeph-mcp/src/embedding_guard.rsembed_timeout_msfield + timeout incheck_asynccrates/zeph-core/src/agent/shadow_sentinel.rsJoinSet,spawn_persist,drain_pendingcrates/zeph-core/src/agent/mod.rsdrain_pending().awaitinAgent::shutdown()Test plan
cargo +nightly fmt --check— cleancargo clippy --workspace -- -D warnings— cleanRUSTFLAGS="-D warnings" cargo check --workspace --all-targets— cleancargo doc --no-deps -p zeph-llm -p zeph-mcp -p zeph-core— no broken linksCloses #4566
Closes #4570