From 2c5bc242a8a99e3b863c247f70b26f5883333677 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Sat, 6 Jun 2026 21:29:52 +0900 Subject: feat(kernel-runtime,session-orchestrator): emit turn lifecycle events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close a gap found live: neither transport emitted turn-start/done/turn-sealed (the wire defined them; nothing fired them). turn-sealed is the FE's cache-commit signal (frontend-design §6.3); done ends the stream. - kernel-runtime: runTurn emits turn-start first and done (with finishReason) last, on every exit path (stop/tool-calls/max-steps/error/aborted). - session-orchestrator: emits turn-sealed after conversationStore.append succeeds (the kernel touches no DB, so the post-persist seal is the orchestrator's). Not emitted if append throws. No contract change (all three wire types already existed). Verified live: HTTP /chat and WS chat both stream turn-start … done turn-sealed. typecheck clean, 494 vitest + 80 bun, biome clean. --- packages/kernel/src/runtime/run-turn.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'packages/kernel/src/runtime/run-turn.ts') diff --git a/packages/kernel/src/runtime/run-turn.ts b/packages/kernel/src/runtime/run-turn.ts index 6b07e24..1e98351 100644 --- a/packages/kernel/src/runtime/run-turn.ts +++ b/packages/kernel/src/runtime/run-turn.ts @@ -5,11 +5,13 @@ import type { EventEmitter, RunTurnInput, RunTurnResult } from "../contracts/run import type { ToolCall, ToolContract } from "../contracts/tool.js"; import { createStepDispatcher, type StepDispatcher } from "./dispatch.js"; import { + doneEvent, errorEvent, reasoningDeltaEvent, textDeltaEvent, toolCallEvent, toolResultEvent, + turnStartEvent, usageEvent, } from "./events.js"; @@ -346,6 +348,8 @@ export async function runTurn(input: RunTurnInput): Promise { // Track open tool-call spans across steps so we can close them on abort const toolSpans = new Map(); + input.emit(turnStartEvent(conversationId, turnId)); + try { for (let step = 0; step < MAX_STEPS; step++) { if (signal.aborted) { @@ -422,6 +426,8 @@ export async function runTurn(input: RunTurnInput): Promise { } } + input.emit(doneEvent(conversationId, turnId, finishReason)); + return { messages: resultMessages, usage: totalUsage, finishReason }; } -- cgit v1.2.3