Skip to content

fix: read HookResult modify action from tool:post events#4

Merged
bkrabach merged 1 commit intomainfrom
fix/hook-modify-tool-post
Feb 10, 2026
Merged

fix: read HookResult modify action from tool:post events#4
bkrabach merged 1 commit intomainfrom
fix/hook-modify-tool-post

Conversation

@bkrabach
Copy link
Copy Markdown
Collaborator

Summary

Fixes the orchestrator to read modified tool results from tool:post hook events. Previously, when a hook returned HookResult(action="modify", data={"result": ...}), the modified data was ignored and the original result.get_serialized_output() was used instead.

Problem

The hook protocol's modify action works correctly in the hook layer — hooks.emit() processes the modification and returns the updated data. But the orchestrator never checked if the data was modified, always using the original tool result.

This broke any hook that modifies tool output (truncation, sanitization, transformation). The hooks-tool-truncation module was completely ineffective because its modifications were silently discarded.

Fix

After hooks.emit("tool:post", ...), detect if the returned data differs from the original (identity comparison) and use the modified result when a hook has changed it. Falls back to get_serialized_output() when no modification occurred (backward compatible).

Testing

  • 3 new tests: modify replaces result, no-modify uses original, string result handling
  • 26/26 total tests pass
  • Shadow-validated across 7 repos (753/753 total)

🤖 Generated with Amplifier

When a hook returns action='modify' on tool:post, the orchestrator now
detects the modified data by comparing the returned result with the
original, and uses it instead of the original get_serialized_output().
This enables tool output truncation, sanitization, and transformation
hooks to work correctly.

🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier)

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
@bkrabach bkrabach merged commit aa37f4e into main Feb 10, 2026
1 check passed
@bkrabach bkrabach deleted the fix/hook-modify-tool-post branch February 10, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant