Skip to content

Commit 36d1906

Browse files
stephentoubCopilot
andauthored
Add post-tool-use failure hooks (#1421)
* Add post-tool-use failure hook Expose postToolUseFailure hooks across SDKs, wire runtime hook dispatch, update docs, and add cross-language E2E coverage for failed tool results. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Format Python hook tests Apply ruff formatting to the post-tool-use failure hook unit tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address PR review feedback Fix Rust E2E formatting and update docs-maintenance Python validation paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix Python lint issues Sort hook exports and wrap the long E2E prompt string. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix failure hook snapshot text Match the bundled runtime's postToolUseFailure guidance label in the shared E2E snapshot. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix Rust hook E2E helper Make the Rust E2E RecordingHooks failure hook a no-op unless the failure hook is explicitly configured. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 183cc44 commit 36d1906

32 files changed

Lines changed: 1545 additions & 386 deletions

.github/agents/docs-maintenance.agent.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ cat nodejs/src/types.ts | grep -A 10 "export interface ExportSessionOptions"
344344
- `CopilotClient` constructor options: `cliPath`, `cliUrl`, `useStdio`, `port`, `logLevel`, `autoStart`, `env`, `githubToken`, `useLoggedInUser`
345345
- `createSession()` config: `model`, `tools`, `hooks`, `systemMessage`, `mcpServers`, `availableTools`, `excludedTools`, `streaming`, `reasoningEffort`, `provider`, `infiniteSessions`, `customAgents`, `workingDirectory`
346346
- `CopilotSession` methods: `send()`, `sendAndWait()`, `getMessages()`, `disconnect()`, `abort()`, `on()`, `once()`, `off()`
347-
- Hook names: `onPreToolUse`, `onPostToolUse`, `onUserPromptSubmitted`, `onSessionStart`, `onSessionEnd`, `onErrorOccurred`
347+
- Hook names: `onPreToolUse`, `onPostToolUse`, `onPostToolUseFailure`, `onUserPromptSubmitted`, `onSessionStart`, `onSessionEnd`, `onErrorOccurred`
348348

349349
#### Python Validation
350350

@@ -353,16 +353,16 @@ cat nodejs/src/types.ts | grep -A 10 "export interface ExportSessionOptions"
353353
grep -E "^\s+async def [a-z]" python/copilot/client.py python/copilot/session.py
354354

355355
# Key types
356-
cat python/copilot/types.py | grep -A 20 "class CopilotClientOptions"
357-
cat python/copilot/types.py | grep -A 30 "class SessionConfig"
358-
cat python/copilot/types.py | grep -A 15 "class SessionHooks"
356+
cat python/copilot/client.py | grep -A 20 "class _CopilotClientOptions"
357+
cat python/copilot/client.py | grep -A 80 "async def create_session"
358+
cat python/copilot/session.py | grep -A 15 "class SessionHooks"
359359
```
360360

361361
**Must match (snake_case):**
362362
- `CopilotClient` options: `cli_path`, `cli_url`, `use_stdio`, `port`, `log_level`, `auto_start`, `env`, `github_token`, `use_logged_in_user`
363363
- `create_session()` config keys: `model`, `tools`, `hooks`, `system_message`, `mcp_servers`, `available_tools`, `excluded_tools`, `streaming`, `reasoning_effort`, `provider`, `infinite_sessions`, `custom_agents`, `working_directory`
364364
- `CopilotSession` methods: `send()`, `send_and_wait()`, `get_messages()`, `disconnect()`, `abort()`, `export_session()`
365-
- Hook names: `on_pre_tool_use`, `on_post_tool_use`, `on_user_prompt_submitted`, `on_session_start`, `on_session_end`, `on_error_occurred`
365+
- Hook names: `on_pre_tool_use`, `on_post_tool_use`, `on_post_tool_use_failure`, `on_user_prompt_submitted`, `on_session_start`, `on_session_end`, `on_error_occurred`
366366

367367
#### Go Validation
368368

@@ -380,7 +380,7 @@ cat go/types.go | grep -A 15 "type SessionHooks struct"
380380
- `ClientOptions` fields: `CLIPath`, `CLIUrl`, `UseStdio`, `Port`, `LogLevel`, `AutoStart`, `Env`, `GithubToken`, `UseLoggedInUser`
381381
- `SessionConfig` fields: `Model`, `Tools`, `Hooks`, `SystemMessage`, `MCPServers`, `AvailableTools`, `ExcludedTools`, `Streaming`, `ReasoningEffort`, `Provider`, `InfiniteSessions`, `CustomAgents`, `WorkingDirectory`
382382
- `Session` methods: `Send()`, `SendAndWait()`, `GetMessages()`, `Disconnect()`, `Abort()`, `ExportSession()`
383-
- Hook fields: `OnPreToolUse`, `OnPostToolUse`, `OnUserPromptSubmitted`, `OnSessionStart`, `OnSessionEnd`, `OnErrorOccurred`
383+
- Hook fields: `OnPreToolUse`, `OnPostToolUse`, `OnPostToolUseFailure`, `OnUserPromptSubmitted`, `OnSessionStart`, `OnSessionEnd`, `OnErrorOccurred`
384384

385385
#### .NET Validation
386386

@@ -398,7 +398,7 @@ cat dotnet/src/Types.cs | grep -A 15 "public class SessionHooks"
398398
- `CopilotClientOptions` properties: `CliPath`, `CliUrl`, `UseStdio`, `Port`, `LogLevel`, `AutoStart`, `Environment`, `GithubToken`, `UseLoggedInUser`
399399
- `SessionConfig` properties: `Model`, `Tools`, `Hooks`, `SystemMessage`, `McpServers`, `AvailableTools`, `ExcludedTools`, `Streaming`, `ReasoningEffort`, `Provider`, `InfiniteSessions`, `CustomAgents`, `WorkingDirectory`
400400
- `CopilotSession` methods: `SendAsync()`, `SendAndWaitAsync()`, `GetMessagesAsync()`, `DisposeAsync()`, `AbortAsync()`, `ExportSessionAsync()`
401-
- Hook properties: `OnPreToolUse`, `OnPostToolUse`, `OnUserPromptSubmitted`, `OnSessionStart`, `OnSessionEnd`, `OnErrorOccurred`
401+
- Hook properties: `OnPreToolUse`, `OnPostToolUse`, `OnPostToolUseFailure`, `OnUserPromptSubmitted`, `OnSessionStart`, `OnSessionEnd`, `OnErrorOccurred`
402402

403403
#### Common Sample Errors to Check
404404

0 commit comments

Comments
 (0)