Skip to content

fix(tui): filter metrics always zero in native tool execution path (#1939)#1946

Merged
bug-ops merged 4 commits intomainfrom
fix/1939-filter-metrics-zero
Mar 17, 2026
Merged

fix(tui): filter metrics always zero in native tool execution path (#1939)#1946
bug-ops merged 4 commits intomainfrom
fix/1939-filter-metrics-zero

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 17, 2026

Summary

  • filter_raw_tokens, filter_saved_tokens, and filter_applications metrics in the TUI dashboard always showed zero even when tool execution with output filtering occurred via the native path
  • Root cause: two "remaining tools" loops in crates/zeph-core/src/agent/tool_execution/native.rs (self-reflection Ok(true) and Err(e) branches) silently discarded FilterStats from parallel tool outputs without recording metrics
  • record_filter_metrics extracted to agent/utils.rs as a shared pub(super) helper; now called from all four metric-recording sites (3 native + 1 legacy)

Changes

  • crates/zeph-core/src/agent/tool_execution/native.rs: fixed both remaining-tools loops to extract filter_stats and call record_filter_metrics
  • crates/zeph-core/src/agent/utils.rs: new record_filter_metrics method (DRY consolidation)
  • crates/zeph-core/src/agent/tool_execution/legacy.rs: removed duplicate record_filter_metrics definition; delegates to utils.rs
  • crates/zeph-core/src/agent/tests.rs: two new regression tests

Test plan

  • cargo nextest run --config-file .github/nextest.toml -p zeph-core — 1939 tests pass
  • cargo clippy --workspace --features full -- -D warnings — clean
  • cargo +nightly fmt --check — clean
  • New test filter_stats_metrics_increment_on_normal_native_tool_path exercises the normal single-tool path
  • New test filter_stats_metrics_recorded_in_self_reflection_remaining_tools_loop directly exercises the fixed self-reflection remaining-tools branch

Closes #1939

bug-ops added 4 commits March 17, 2026 14:49
…ls loops

In the native tool execution path, two "remaining tools" loops (self-reflection
success path and error path) discarded filter_stats from tool outputs, sending
ToolOutputEvent with filter_stats: None and skipping metric updates. This caused
filter_raw_tokens, filter_saved_tokens, and filter_applications to remain zero
in the TUI even when tools produced filtered output.

Both loops now extract filter_stats from Ok(Some(out)) results, update
filter_* metrics (same pattern as the normal processing loop), and pass
inline_stats to ToolOutputEvent.

Adds a regression test that verifies filter_* metrics increment when the
native tool path processes a tool returning FilterStats.

Closes #1939
…reflection path test

Move the filter-stats metric update block into Agent::record_filter_metrics (utils.rs),
matching the existing method in legacy.rs which is now removed. All three call sites in
native.rs are replaced with self.record_filter_metrics(fs).

Add filter_stats_metrics_recorded_in_self_reflection_remaining_tools_loop test: two parallel
tool calls via native path, first returns [error] triggering self-reflection, second returns
FilterStats. Verifies filter_applications/filter_raw_tokens/filter_saved_tokens are recorded
from the remaining-tools loop — the code path fixed in #1939.

Closes review findings on fe715d9.
@github-actions github-actions bot added bug Something isn't working documentation Improvements or additions to documentation rust Rust code changes core zeph-core crate size/L Large PR (201-500 lines) and removed bug Something isn't working labels Mar 17, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 17, 2026 15:02
@bug-ops bug-ops merged commit 1576cdf into main Mar 17, 2026
20 checks passed
@bug-ops bug-ops deleted the fix/1939-filter-metrics-zero branch March 17, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core zeph-core crate documentation Improvements or additions to documentation rust Rust code changes size/L Large PR (201-500 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(tui): filter metrics (filter_raw_tokens, filter_saved_tokens, filter_applications) always zero

1 participant