中断工具调用后重试会复用旧 seq,导致会话日志损坏无法打开(seq gap in committed region) #4598
## 问题描述
当工具调用在执行途中被中断(interrupt/cancel),随后用户恢复会话并重试该工具时,重试产生的事件会**复用崩溃恢复占位事件的 seq**,而不是从 `lastSeq + 1` 继续。结果会话日志出现 seq 回退,下次加载直接失败,整个会话无法打开:
Error: corrupt session log: seq gap in committed region at line 1649 tool/result (isError: "The tool call was interrupted...") → seq N index 5254 seq=5254 tool/call (工具开始) |
Replies: 2 comments
|
#4662 is this bug, with a fuller reconstruction and a published fix branch — worth reading together with this thread. The piece that thread supplies, and which is hard to see from a single log, is that two processes are involved rather than one. Your timeline reads naturally as "the retry reused old seqs", but the events after the closers — Each validates its batch against its own in-memory cursor ( That also explains why this is hard to hit deliberately and then suddenly reproducible: it needs one The fix on #4662 serializes appends with a cross-process writer lock and, while holding it, requires the batch to continue the durable tail — rejecting a stale-cursor append with a diagnostic rather than writing overlapping seqs. Reject-never-repair is the right call: a process whose cursor is behind must resume the session, not patch the file. I have that branch running and it holds; review notes, including a performance fix for the tail read, are on that thread. |
#4662 is this bug, with a fuller reconstruction and a published fix branch — worth reading together with this thread.
The piece that thread supplies, and which is hard to see from a single log, is that two processes are involved rather than one. Your timeline reads naturally as "the retry reused old seqs", but the events after the closers —
tool/result→step/end→step/start— are the original in-flight turn continuing, not a retry. One process recovers the session and commits the synthetic closers while the other, still live, later commits the same tool call's real result starting from its own cursor.Each validates its batch against its own in-memory cursor (
appendCorechecksevent.seq…