Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Feature] SessionHooks should support multiple handlers per hook slot

Aperta
#961 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
38/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
csharp

Direzione di ricerca

Inizia individuando SessionHooks e il comportamento esistente di invocazione degli hook, in particolare OnPostToolUse e OnPreToolUse. Confronta il comportamento attuale di single-delegate e multicast-delegate con la pipeline proposta UsePreToolUse e UsePostToolUse. Il lavoro è completato quando gli handler possono essere composti in un ordine esplicito, ispezionando, modificando, interrompendo anticipatamente o inoltrando l’esecuzione degli hook senza sovrascriverla silenziosamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Java
Stelle
10.5k
Fork
1.5k
Merge medio
1g 9h
PR unite (30g)
130

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di github/copilot-sdk

Tutte le issue di github/copilot-sdk

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.