Run tool start callbacks after pre-tool hooks (#38568)

## What changed

- Invoke `ToolLifecycleContributor::on_tool_start` only after pre-tool hooks
  have finalized the invocation.
- Pass hook-rewritten arguments and the post-hook conversation snapshot to the
  callback.
- Skip the start callback when a hook denies execution or supplies input that
  cannot be applied.

## Testing

Add lifecycle tests covering rewritten input, hook-added context, denied tool
calls, and invalid rewritten input.

GitOrigin-RevId: 936efaf4a8c35321f9982ff2a33bb8bece1ebf39
This commit is contained in:
felixxia-oai authored and copyberry committed 2026-08-14 12:21:08 +00:00
1 parent aa905bb962
commit d40dfcc3c7
4 files changed
+197 -8

No files matched your search

+2 -2
View File
@@ -566,8 +566,6 @@ impl ToolRegistry {
return Err(err);
}
notify_tool_start(&invocation).await;
if let Some(pre_tool_use_payload) = tool.pre_tool_use_payload(&invocation) {
match run_pre_tool_use_hooks(
&invocation.session,
@@ -614,6 +612,8 @@ impl ToolRegistry {
}
}
notify_tool_start(&invocation).await;
if let Some(command) = shell_script_for_invocation(&invocation) {
let parsed = parse_shell_script(&command);
let mut categories = parsed.iter().map(|command| match command {