Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[Feature] SessionHooks should support multiple handlers per hook slot

Abierto
#961 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
38/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
csharp

Línea de trabajo

Comienza localizando SessionHooks y el comportamiento existente de invocación de hooks, especialmente OnPostToolUse y OnPreToolUse. Compara el comportamiento actual de single-delegate y multicast-delegate con el pipeline propuesto de UsePreToolUse y UsePostToolUse. Se considera terminado cuando los handlers pueden componerse en un orden explícito mientras inspeccionan, modifican, cortocircuitan o reenvían la ejecución de hooks sin sobrescribirla silenciosamente.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

At least in C#, SessionHooks properties (OnPostToolUse, OnPreToolUse, etc.) are single-assignment delegates. This makes it easy to accidentally clobber a previously-registered handler with =, and there is no SDK-level way to compose multiple handlers.

Why this matters for library authors

We are building a library on top of the SDK. Our framework needs to register its own hooks (for example, observing update_todo calls in a post-tool-use hook to persist state). But we also need to leave hook slots open for our downstream consumers to register their own hooks.

Today there is no safe way to do this. We can build our own closure-chaining helper (capture the existing delegate and wrap it), but since SessionHooks properties are public settable, any downstream consumer doing config.Hooks.OnPostToolUse = myHandler silently clobbers our framework hook. We cannot prevent that as a library because we do not control the downstream code.

Multicast delegates (+=) do not appear to work either, because await hooks.OnPostToolUse(...) only awaits the last delegate in the invocation list.

What would help

A middleware-style pipeline where each handler receives a next delegate and decides whether to call it, short-circuit, or modify the input/output. This gives callers full control over composition without the SDK needing different resolution rules for different hook types:

hooks.UsePreToolUse(async (input, invocation, next) => {
    // inspect, modify input, or short-circuit
    return await next(input, invocation);
});

hooks.UsePostToolUse(async (input, invocation, next) => {
    var result = await next(input, invocation);
    // observe, modify result, or replace it
    return result;
});

This is the same pattern as ASP.NET Core middleware and Akka message pipelines. It is simple to reason about, order is explicit, and each handler can decide independently whether to pass through or stop the chain. No special-case semantics per hook type needed.

Workaround

We worked around this by moving our observer to session.On() events instead of hooks, which works for our case but is not a general solution for hooks that need to mutate tool behavior.

Lenguaje dominante
Java
Estrellas
10.5k
Forks
1.5k
Merge medio
1 d 9 h
PR fusionados (30 d)
130

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de github/copilot-sdk

Todos los issues de github/copilot-sdk

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.