fix(core): parallelize apply_tier_results hooks and align WATCHED_SPANS names#6137
Merged
Merged
Conversation
…NS names apply_tier_results processed each tool result's RuntimeLayer::after_tool chain and PostToolUse hook firing sequentially, one index at a time, even though the tier's own tool execution already runs bounded-parallel. Layer and hook firing now run concurrently across a tier's indices via futures::future::join_all, bounded by the same max_parallel semaphore the tier's tool execution uses. MetricsBridge::WATCHED_SPANS named three spans that never matched a real tracing span, silently making their on_close handling dead code. Renamed agent.prepare_context and agent.tool_loop to their real span names, and removed agent.persist_message entirely — its real span fires many times per turn, so bridging it would report the wrong call's duration; that field stays manually-timed only. Closes #6128 Closes #6111
bug-ops
enabled auto-merge (squash)
July 12, 2026 14:49
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
apply_tier_results(crates/zeph-core/src/agent/tool_execution/tier_loop.rs) processed each tool result'sRuntimeLayer::after_toolchain andPostToolUsehook firing sequentially, one index at a time, even though the tier's own tool execution already runs bounded-parallel. A tier with manyPostToolUse-matching calls paid N sequential subprocess spawns after already paying for parallel tool execution. The layer/hook phase now runs concurrently across a tier's indices viafutures::future::join_all, bounded by the samemax_parallelsemaphore the tier's tool execution uses.MetricsBridge::WATCHED_SPANS(crates/zeph-core/src/metrics_bridge.rs,profilingfeature) named three spans (agent.prepare_context,agent.tool_loop,agent.persist_message) that never matched any realtracingspan, silently making theiron_closehandling dead code — onlyllm.chatwas ever observed. Renamed the first two to their real span names (core.context.prepare_context,core.tool.native_loop).agent.persist_messageis intentionally left unwatched: its real span fires many times per turn, so bridging it would report the wrong call's duration instead of the first user-message persist thatTurnTimings::persist_message_msis meant to measure — that field stays manually-timed only.Closes #6128
Closes #6111
Test plan
cargo +nightly fmt --checkcargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing" -- -D warningscargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing,profiling" -- -D warningscargo nextest run --config-file .github/nextest.toml --workspace --features "desktop,ide,server,chat,pdf,scheduler" --lib --bins— 13075 passed, 35 skipped, 0 failedcargo nextest run -p zeph-core --features profiling -E 'test(metrics_bridge) or test(apply_tier_results)'— 6/6 passedafter_tool_hooks_run_concurrently_across_tier_indices) verified non-flaky over 20 runsRUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --workspace --features "desktop,ide,server,chat,pdf,scheduler")CHANGELOG.mdupdated under[Unreleased].local/testing/playbooks/tier-apply-results-concurrency.mdand.local/testing/playbooks/metrics-bridge-watched-spans.mdadded (main repo).local/testing/coverage-status.mdupdated in place (main repo)Follow-up (non-blocking, noted by reviewer): a dedicated test for hook/layer failure isolation across concurrent indices would strengthen coverage; current isolation is structurally guaranteed (catch_unwind + fail-open hooks,
join_allnever short-circuits) and independently verified by two reviewers reading the code, but untested directly.