feat(tools): add LoggingAspect to execute_tool dispatch#3
Open
yijunyu wants to merge 1 commit intoemmarktech:mainfrom
Open
feat(tools): add LoggingAspect to execute_tool dispatch#3yijunyu wants to merge 1 commit intoemmarktech:mainfrom
yijunyu wants to merge 1 commit intoemmarktech:mainfrom
Conversation
Every tool invocation flows through execute_tool; annotating it with aspect_std::LoggingAspect creates a structured audit trail for the entire 20+ tool surface with one annotation. No behavioral change. Uses the log facade so downstream consumers pick the subscriber. Aspect weaving happens at compile time via the aspect-rs proc-macro -- zero runtime cost.
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
Annotates
pub fn execute_toolinrust/crates/tools/src/lib.rs— the single match dispatch every tool invocation flows through — withaspect_std::LoggingAspect, creating a structured audit trail for tool execution where none currently exists.Adds four small deps (
aspect-core,aspect-macros,aspect-std,log) to thetoolscrate. No behavioral change — aspect-rs weaves at compile time and this aspect is observation-only (entry/exit/error logging via thelogfacade).Logical diff: +7 lines (+4 in
Cargo.toml, +3 inlib.rs), plus Cargo.lock auto-update.Why
A static scan of the Rust crates on current
mainturned up zero uses oftracing::orlog::. Every tool invocation, provider call, and hook currently emits either nothing or a rawprintln!/eprintln!. For an agent harness that runsbash, writes files, and calls third-party LLMs, this is a concrete observability gap.This PR takes the smallest possible step: one annotation on the one function every tool already passes through. It:
bash,read_file,write_file,edit_file,glob_search,grep_search,WebFetch,WebSearch,Skill,Agent,ToolSearch,NotebookEdit,Sleep,Config,REPL,PowerShell,StructuredOutput,Brief,TodoWrite).logfacade so downstream consumers pick any subscriber (env_logger,simple_logger,tracing-log) without library-side lock-in.Why an aspect, not scattered
tracing::instrumenttracing::instrumentwould require either a pervasivetracingdep plus N call-site edits across the dispatch arms, or else manual wrapper boilerplate on every tool branch.#[aspect(...)]is one annotation on the one dispatch function. Future aspects (auth, rate-limit, timing, circuit-breaker) stack on the same function without rewriting the body — this is the pattern aspect-rs is built for.Test plan
cargo check -p tools— cleancargo test -p tools --lib— 27 passed; 1 pre-existing failure (tests::skill_loads_local_skill_prompt— reproduces on unmodifiedmain, unrelated to this change)cargo clippy -p tools --no-deps— no new warnings (4 pre-existing clippy warnings at lines 1812/1813/1825/2868 + runtime/config.rs:510, all unrelated)RUST_LOG=infoand verifyexecute_toolentry/exit lines appear for every tool callRUST_LOG) and verify zero log emission (log facade fast-path)Blast radius
log::log_enabled!()check per invocation when logging is filtered out; a formatted string emission when enabled. Tool invocations are already I/O-bound.git revert.Context
This PR is part of a broader crosscutting-concerns study on Rust agent-harness codebases. Upstream
ultraworkers/claw-codecurrently has external PRs disabled (viewerPermission: READ); this fork is the most suitable active target for the Rust variant. Full analysis with scattering/tangling tables is available on request.Follow-ups (not in this PR)
Each of these is a similarly minimal ~10-line PR once this lands:
LoggingAspectonapi::ProviderClient::send_messageaspect_std::TimingAspecton both — performance instrumentationaspect_std::RateLimitAspecton provider calls — closes the producer-side rate-limiting gap (currently only reactive to 429s)aspect_std::CircuitBreakerAspecton provider calls — replaces ad-hoc retry loops inapi/providers/anthropic.rsReferences
aspect-stdon crates.io: https://crates.io/crates/aspect-std