Skip to content

fix: tolerate unknown hook types in .NET and Go SDKs#1013

Open
Copilot wants to merge 5 commits intomainfrom
copilot/fix-copilot-session-hang-issue
Open

fix: tolerate unknown hook types in .NET and Go SDKs#1013
Copilot wants to merge 5 commits intomainfrom
copilot/fix-copilot-session-hang-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

When the CLI invokes a hook type the SDK doesn't recognize (e.g. postToolUseFailure), both the .NET and Go SDKs were returning an error over JSON-RPC. The CLI treated this as a fatal condition and shut down the session — appearing as a hang to the client.

Changes

  • dotnet/src/Session.cs: Default switch arm changed from throw new ArgumentException(...) to null — unknown hook types are silently ignored
  • dotnet/test/HookForwardCompatibilityTests.cs: Added unit tests using an in-process fake CLI server (connected via CliUrl) covering both "hooks registered but unknown type received" and "no hooks registered" scenarios
  • go/session.go: Default switch case changed from return nil, fmt.Errorf("unknown hook type: %s", ...) to return nil, nil — same behavior
  • go/session_test.go: Added TestSession_HookForwardCompatibility unit tests covering both "hooks registered but unknown type received" and "no hooks registered" scenarios

Node.js already handled this correctly (returns undefined for unmapped hook types); this brings .NET and Go to parity.

Copilot AI and others added 2 commits April 6, 2026 09:52
Agent-Logs-Url: https://github.com/github/copilot-sdk/sessions/0ea3d153-24a4-4136-807f-cb4fd9223da0

Co-authored-by: SteveSandersonMS <1101362+SteveSandersonMS@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/copilot-sdk/sessions/0ea3d153-24a4-4136-807f-cb4fd9223da0

Co-authored-by: SteveSandersonMS <1101362+SteveSandersonMS@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix dotnet SDK copilot session hang after postToolUseFailure fix: tolerate unknown hook types in .NET and Go SDKs Apr 6, 2026
Copilot AI requested a review from SteveSandersonMS April 6, 2026 09:57
@SteveSandersonMS
Copy link
Copy Markdown
Contributor

@copilot Why did you add so much stuff to Go? Is a new otel dependency really needed for this tiny change? Filter this PR down to the actual minimal change.

Agent-Logs-Url: https://github.com/github/copilot-sdk/sessions/fd4a2cd1-7805-4214-8268-d71285f1ecc0

Co-authored-by: SteveSandersonMS <1101362+SteveSandersonMS@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 6, 2026

@copilot Why did you add so much stuff to Go? Is a new otel dependency really needed for this tiny change? Filter this PR down to the actual minimal change.

Those changes were picked up accidentally when the Go toolchain resolved transitive dependencies. Reverted in 2624819 — the PR now only touches dotnet/src/Session.cs, go/session.go, and go/session_test.go.

@SteveSandersonMS SteveSandersonMS marked this pull request as ready for review April 6, 2026 12:57
@SteveSandersonMS SteveSandersonMS requested a review from a team as a code owner April 6, 2026 12:57
Copilot AI review requested due to automatic review settings April 6, 2026 12:57
@SteveSandersonMS
Copy link
Copy Markdown
Contributor

@copilot Any reason there isn't a .NET test like the Go one?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves forward compatibility of the .NET and Go SDKs when the Copilot CLI invokes a hook type the SDK doesn’t recognize, preventing JSON-RPC errors that can cause the CLI to terminate the session.

Changes:

  • .NET: unknown hook types no longer throw; they return null (ignored).
  • Go: unknown hook types no longer return an error; they return (nil, nil) (ignored).
  • Go: adds a unit test to ensure unknown hook types are ignored even when other hooks are registered.
Show a summary per file
File Description
go/session.go Stops treating unknown hook types as errors; ignores them instead.
go/session_test.go Adds regression coverage for forward-compatible hook dispatch behavior.
dotnet/src/Session.cs Stops throwing on unknown hook types; returns null so the RPC call succeeds.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 0

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 6, 2026

@copilot Any reason there isn't a .NET test like the Go one?

Added in 24c28e8. Since HandleHooksInvokeAsync is internal, the test uses an in-process fake CLI server (a TcpListener on a random port) connected via CliUrl. The fake server responds to ping and session.create, then calls hooks.invoke with an unknown type once the session is ready. If the SDK returns a JSON-RPC error, rpc.InvokeAsync throws RemoteRpcException and the test fails — confirming the fix is exercised.

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.

dotnet sdk copilot session hangs after postToolUseFailure

3 participants