Bug
Recurring corruption where a tool_use block gets persisted to session JSONL but its matching tool_result does not (likely due to crash/timeout mid-tool-call). This makes every subsequent API call to that session fail Anthropic's message validation:
messages.251: `tool_use` ids were found without `tool_result` blocks immediately after: call95378438
Once corrupted, the session is permanently broken — gateway restarts don't help because the history is persisted to disk. The only fix is manually deleting/moving the session JSONL file, which loses all conversation history.
Occurrences
- 2026-02-10: Session
session:agent:kalki:main:thread:986992, orphaned toolu_01XXejQsDDVRysXnYjVyJmue at messages.322
- 2026-02-17: Session
kalki-bd/9397c2ef...topic-1771220855, orphaned call95378438 at messages.251
Proposed Fix
Add a validation/repair layer that runs before sending messages to the API:
- On session load: Scan for
tool_use blocks without a matching tool_result in the next message
- Auto-repair: Inject a synthetic
tool_result with an error like "Tool call interrupted — session recovered"
- Log a warning when auto-repair kicks in so it's visible in diagnostics
This should be a lightweight pass over the message array before API submission — no need to modify the JSONL on disk.
Workaround
Move/delete the corrupted session JSONL file and restart the gateway. The agent starts a fresh session but loses all prior context.
Bug
Recurring corruption where a
tool_useblock gets persisted to session JSONL but its matchingtool_resultdoes not (likely due to crash/timeout mid-tool-call). This makes every subsequent API call to that session fail Anthropic's message validation:Once corrupted, the session is permanently broken — gateway restarts don't help because the history is persisted to disk. The only fix is manually deleting/moving the session JSONL file, which loses all conversation history.
Occurrences
session:agent:kalki:main:thread:986992, orphanedtoolu_01XXejQsDDVRysXnYjVyJmueat messages.322kalki-bd/9397c2ef...topic-1771220855, orphanedcall95378438at messages.251Proposed Fix
Add a validation/repair layer that runs before sending messages to the API:
tool_useblocks without a matchingtool_resultin the next messagetool_resultwith an error like"Tool call interrupted — session recovered"This should be a lightweight pass over the message array before API submission — no need to modify the JSONL on disk.
Workaround
Move/delete the corrupted session JSONL file and restart the gateway. The agent starts a fresh session but loses all prior context.