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.
This commit is contained in:
Levi Neely 2026-08-07 09:05:39 +02:00
parent c7f1bec71c
commit 3d9eca97b2
1 changed files with 8 additions and 0 deletions

View File

@ -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 = ""
}