TurnStarted hook can run after the same turn's Stop hook (fire-and-forget vs awaited)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 85/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- cli
Direzione di ricerca
Inizia da packages/agent-core-v2/src/features/externalHooks/agent/agentExternalHooksService.ts: esamina notifyTurnStarted (dispatch di TurnStarted senza attenderne il completamento) e onDidFinishStep (dispatch di Stop con attesa tramite runner.triggerBlock). Implementa una delle due correzioni proposte: instrada TurnStarted attraverso il percorso con attesa, come UserPromptSubmit, oppure passa l’event.turnId esistente a runStop affinché i payload degli hook di fine turno lo includano. Esegui la suite di test external hooks per confermare che gli eventi di un singolo turno siano ordinati correttamente e riportino identificatori corrispondenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What version of Kimi Code is running?
2.1.1 (npm @moonshot-ai/kimi-code). The code path is unchanged on main at 21406fb.
Which open platform/subscription were you using?
A local OpenAI-compatible test server (custom provider)
Which model were you using?
A scripted test model that answers immediately
What platform is your computer?
Windows 10 (10.0.19045), x64
What issue are you seeing?
External hook events for one turn can reach hook commands in the wrong order. On a fast turn, the TurnStarted hook runs after the Stop hook of the same turn.
In packages/agent-core-v2/src/features/externalHooks/agent/agentExternalHooksService.ts, TurnStarted goes through fireAndForget (notifyTurnStarted), while Stop is awaited (runner.triggerBlock in onDidFinishStep). Both start a separate process, and nothing orders the fire-and-forget one before the awaited one. When the model answers in well under a second, the Stop process often finishes first.
A consumer that tracks turns from hooks then sees "turn ended" followed by "turn started" and is left thinking a turn is still running. Stop carries no turnId, so the consumer can't tell that the late TurnStarted belongs to the turn that already ended.
What steps can reproduce the bug?
- In
config.toml, add two[[hooks]]entries,TurnStartedandStop. Each runs a command that appends the event name and a high-resolution timestamp to the same file (for example, an HTTP POST to a local listener that logs arrival order). - Use a provider that answers immediately (a local stub or a trivial prompt on a fast model).
- Send several short prompts in the interactive TUI.
- Check the log. For some turns,
Stopis logged beforeTurnStarted.
We saw this with hooks that POST to a loopback HTTP listener (curl, cmd.exe on Windows). On sub-second turns, the late TurnStarted regularly arrived after Stop.
What is the expected behavior?
For a given turn, TurnStarted is delivered before Stop/StopFailure/Interrupt. If keeping it fire-and-forget matters, then Stop, StopFailure and Interrupt should carry the same turnId that TurnStarted has, so consumers can match the events and drop a stale start.
Additional information
Context: we run Kimi Code in a desktop app (NeuroSquad) and show each session's status from its hooks. For turns the user types, we rely on UserPromptSubmit (awaited). TurnStarted is the only start signal for turns nobody typed (background task notifications, schedules), and that's where the reordering leaves a session stuck at "working".
Two possible fixes: dispatch TurnStarted through the awaited path like UserPromptSubmit (it doesn't block), or add turnId to the end-of-turn payloads (notifyTurnEnded already has event.turnId; runStop doesn't pass it).
- Lingua principale
- TypeScript
- Stelle
- 7.8k
- Fork
- 1.3k
- Merge medio
- 1g 1h
- PR unite (30g)
- 156
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di MoonshotAI/kimi-code
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 60/100
MoonshotAI/kimi-code#4225 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
MoonshotAI/kimi-code#4177 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
MoonshotAI/kimi-code#4170 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
MoonshotAI/kimi-code#4147 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
MoonshotAI/kimi-code#4146 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di MoonshotAI/kimi-code
Issue simili
-
fix(frontend): correct VITE_IS_DEVELPOMENT typo in shared/app.ts and align dev environment flagsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
vicharanashala/ajrasakha#1439 ·
I maintainer di solito rispondono entro 1 giorno
-
Add: TV5Monde AsieApertaapproved check:passed streams:add
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
backnotprop/plannotator#1932 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 62/100
ibm-granite/granite.build#504 ·
I maintainer di solito rispondono entro 2 giorni
-
reproduced
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
anomalyco/opencode#55676 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno