fix(history): don't parse tool_result as ItemStartedEvent in deferred dequeue#1
Open
Antisophy wants to merge 1 commit into
Open
Conversation
… dequeue After a queue dequeue, the deferred branch assumed the next type:"user" line is the steering echo and parsed it strictly as ItemStartedEvent. When a turn was interrupted mid-tool-use, that line is a tool_result, which translates to an item/result event whose tool_result field ItemStartedEvent doesn't declare, throwing an uncaught Exception that crashes history loading and prevents the task from ever opening. Peek at the translated event type with a @JSONPartial probe and only run the ItemStartedEvent parse/inject path for item/started; otherwise pass the events through unchanged and stay deferred for the real echo. ItemStartedEvent stays strict so item/result round-trips don't drop tool_result.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Opening a task whose history has a steering message immediately followed by a
tool_resultcrashes the server with an uncaughtobject.Exception(exit 1).ensureHistoryLoadedthrows on every click, so the task's history never loads.Abbreviated stack trace:
Root cause
In the deferred-dequeue branch, after a queue
dequeuethe code treats the nexttype:"user"line as the steering echo and parses it strictly asItemStartedEvent. But when the turn was interrupted mid-tool-use, that line is atool_result, whichtranslateHistoryLineturns into anitem/resultevent whosetool_resultfieldItemStartedEventdoesn't declare.ItemStartedEventis parsed strictly, so the unknown field throws and the exception is uncaught.Fix
Peek at the translated event's
typewith a@JSONPartialprobe and only run theItemStartedEventparse/inject path when it'sitem/started. Otherwise emit the translated events unchanged and stay deferred for the real echo.ItemStartedEventis left strict so round-tripping anitem/resultthrough it can't silently droptool_result.Repro
A Claude history file with these three lines; open the task in the UI:
{"type":"queue-operation","operation":"enqueue","timestamp":"2026-06-11T06:00:00Z","sessionId":"S","content":"are you under control?"} {"type":"queue-operation","operation":"dequeue","timestamp":"2026-06-11T06:00:01Z","sessionId":"S"} {"parentUuid":"p","isSidechain":false,"type":"user","message":{"role":"user","content":[{"tool_use_id":"toolu_1","type":"tool_result","content":"ok"}]}}