From 3d9eca97b260e82e459bd6b86fcdca629ee5a9aa Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Fri, 7 Aug 2026 09:05:39 +0200 Subject: [PATCH] fix: close streaming fence before ending block on call/default events The event handler was emitting [[[end]]] to close an assistant block without first closing an open streaming fence (code block). This left the log in a state where a [[[call:...]]] block appeared nested inside an unclosed assistant block, triggering a log structure violation. Now the call and default cases close streamingFence (like the tool case already did) before writing the [[[end]]] marker. --- fs/types.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/types.go b/fs/types.go index 779ff63..ffc6b94 100644 --- a/fs/types.go +++ b/fs/types.go @@ -290,6 +290,10 @@ func NewEventHandler(as *AgentLog) agent.EventHandler { case "call": if streamingRole != "" { + if streamingFence != "" { + as.AppendLog([]byte("\n" + streamingFence + "\n")) + streamingFence = "" + } as.AppendLog([]byte("\n" + format.EndTag + "\n")) streamingRole = "" } @@ -297,6 +301,10 @@ func NewEventHandler(as *AgentLog) agent.EventHandler { default: if streamingRole != "" { + if streamingFence != "" { + as.AppendLog([]byte("\n" + streamingFence + "\n")) + streamingFence = "" + } as.AppendLog([]byte("\n" + format.EndTag + "\n")) streamingRole = "" }