Repository navigation
Description
Bug: Stop hook never fires in 2.6.0 (regression from 2.5.3)
Summary
In @moonshot-ai/[email protected] the Stop external hook is never executed. The same configuration works in 2.5.2 and 2.5.3. Other hook events (e.g. SessionStart) still fire in 2.6.0, so this is specific to the Stop code path.
Reproduction
- Configure a hook in
config.toml:
[[hooks]]
event = "Stop"
command = "echo STOP_HOOK_FIRED >> /tmp/kimi-stop.log"
[[hooks]]
event = "SessionStart"
command = "echo SESSION_START_FIRED >> /tmp/kimi-stop.log"- Run headless:
kimi -p "Reply with exactly: OK"- Check
/tmp/kimi-stop.log:
| Version | SessionStart | Stop |
|---|---|---|
| 2.5.2 | ✅ fires | ✅ fires |
| 2.5.3 | ✅ fires | ✅ fires |
| 2.6.0 | ✅ fires | ❌ never fires |
This also means the Stop-hook continuation flow (stopHookContinuationUsed, blocking the stop and injecting the reason as a user message) is dead code in 2.6.0.
Root cause
AgentExternalHooksService.registerLoopHooks guards the Stop trigger with:
this._register(loop.hooks.onDidFinishStep.register("externalHooks", async (ctx, next) => {
await next();
if (ctx.finishReason === "tool_calls" || ctx.finishReason === "filtered" || loop.snapshot().hasPendingRequests) return;
const reason = await this.runStop(ctx);
...In 2.6.0, AgentLoopService.hasPendingRequests() (agent-core-v2 loop) gained a new clause:
hasPendingRequests() {
if (this.disposing) return false;
return this.pendingSubmissions.length > 0
|| this.pendingNotifications.length > 0
|| (this.loop?.state.inbox.normal.length ?? 0) > 0
|| (this.loop?.state.inbox.notify.length ?? 0) > 0
|| (this.loop?.state.completionPending ?? false)
|| (this.loop?.state.resetting ?? false)
|| this.loop !== void 0 && this.loop.state.status !== "idle"; // <-- new in 2.6.0
}But onDidFinishStep handlers run inside the still-running turn (from AgentTurnProjection.stepStopping, before the loop transitions back to idle). So at the moment the guard is evaluated, loop.state.status !== "idle" is always true → hasPendingRequests() is always true → runStop() is never called.
Instrumented run of the published 2.6.0 bundle confirming this:
[TRACE] onDidFinishStep finishReason=completed snapshot={"state":"running","activeTurnId":0,"activePromptId":"msg_...","queue":[],"notificationCount":0,"paused":false,"hasPendingRequests":true,"turn":{"turnId":0,"phase":"running","step":1,...}}
Queue is empty, nothing is pending — hasPendingRequests is true solely because the turn is still running while the hook executes. In 2.5.3 hasPendingRequests() did not include the loop-status clause, so the guard passed and the Stop hook fired.
Suggested fix
Either drop the loop.state.status !== "idle" clause from hasPendingRequests() (or exclude it from what the Stop guard consults), or run the Stop hook trigger after the loop has settled to idle. A regression test that a configured Stop hook fires once per completed turn would cover this.
Environment
@moonshot-ai/kimi-code2.6.0 (npm tarball, also reproduced against the release published 2026-11-12T10:11Z)- macOS (Darwin 25.6.0), Node 24/26
- Reproduced in headless
-pmode; the guard is shared by the interactive TUI path, so it should be affected identically.
Activity
wintrover commentedon Nov 13, 2026
Title: Corroboration: 2.6.0 native Linux — StopFailure still fires on failed turns (turn-level dispatch alive, only normal-completion Stop is dead)
Body:
Corroborating this regression with controlled reproductions on 2.6.0 (Linux x86_64, native install, WezTerm terminal):
AXIOM_KIMI_COMPLETION_GATE=1, isolatedKIMI_CODE_HOME): PreToolUse/PostToolUse hooks fire normally, the turn ends cleanly (turn.ended+prompt.completed), zero Stop events, zerostop_hooksystem-trigger injections, TodoList item left open.filteredendings still triggering StopFailure, but as a test expectation): StopFailure still fires on failed turns — a TUI turn failing on an upstream HTTP 404 dispatched StopFailure normally. So turn-level dispatch wiring is alive; only the normal-completion Stop path is dead. That is consistent with thehasPendingRequests()counting the in-flight turn, as PR fix(agent-core-v2): fire external Stop hooks on completed turns #4902 describes.-pprobe design on 2.2.0 produced the fullstop_hooksystem-trigger injection with the exit-2 continuation flow (stopHookContinuationUsed) — so this is a 2.6.0 regression, not a probe artifact.The probe harness is small (a pty/print driver plus hook observers); happy to share details if useful. Watching #4902 closely — thanks for the fix work.
ufna commentedon Nov 13, 2026
Stop hook regression: confirmation on Kimi Code 2.6.1 and 2.6.2
This is additional evidence for #4884, rather than a new issue.
A successful main turn records
turn.endedwithreason: "completed", but its configuredStophook never runs. Other hooks execute through the same script. This also prevents a terminal wrapper that registers hooks from observing completion.Environment
Minimal reproduction
Create
/tmp/kimi-hook-repro/log-event.py:Add these rules to the test copy's
config.toml:Start a new interactive session with a working model configuration. Submit:
Reply with OK only. Do not call tools.Let the response finish without submitting another message.Compare the event log with the main agent's
wire.jsonl.Expected
The logger receives
Stopwhen the main turn successfully finishes, as it does on 2.5.3.Actual
The logger receives
SessionStart,UserPromptSubmitandTurnStarted, but noStop. The main wire contains a completed terminal event. A reduced example, with unrelated fields omitted, is:{"type":"turn.prompt","agentId":"main","turnId":0} {"type":"turn.ended","agentId":"main","turnId":0,"reason":"completed"}The answer is already visible and the native TUI has returned to its composer. There is no hook execution error in the diagnostic log. The same executable hook command works for the other events.
The relevant bundled dispatch path is
registerLoopHooks→onDidFinishStep→runStop. This reproduction confirms the completion-without-Stop symptom reported in #4884 on later 2.6.x releases; it does not require inferring completion from reply text.EgoEg commentedon Nov 17, 2026
Still reproduces on 2.6.2 (Homebrew, macOS arm64) — and not only in
-pmode.A debug hook that just logs the event name was registered for
SessionStart,UserPromptSubmit,TurnStarted,Stop,StopFailure,SessionEnd,Notification,Interrupt:Stopkimi -p "say ok"kimi -pkimi -pmcp.jsonremoved)kimi -p+ extra hooksSessionEndandNotificationnever eitherSo plan mode and failing MCP servers (pending notifications) are ruled out.
wire.jsonlrecordsturn.endednormally, but the externalStophook never runs;SessionEnddoes not run on-pexit either.Impact: orchestrators that rely on
Stopto detect turn completion (e.g. Orca) show Kimi as "working" forever after it finishes.sailist commentedon Nov 25, 2026
Closing this as fixed by #4956 / #4995 (
fix(agent-core-v2): run external Stop hooks after turn completion), which shipped in v2.6.3+.Stophooks are now triggered fromnotifyTurnEndedafter the loop settles back toidle, instead of being blocked byhasPendingRequestsalways evaluating totrueinsideonDidFinishStep.(Note: a separate print-mode-specific race where
kimi -pexits before a queued blocking Stop hook finishes is tracked in #5032.)