Skip to content

Bug: Race condition when cancelling task can corrupt conversation historyΒ #5333

@KJ7LNW

Description

@KJ7LNW

Version: v3.22.5
API Provider: anthropic
Model: sonnet-3.5

What happened?

Clicking the 'cancel' button while the model is responding can cause a race condition between an open and closed task while it tries to write. If the in-memory state is empty after cancelling, safeWriteJson will be given '[]' to write and clobber the file.

This results in the following error:

ERR [Extension Host] [Roo-Debug] readApiMessages: Found API conversation history file, 
but it's empty (parsed as []). TaskId: 68d5b8fb-1a53-45dd-9bf2-24934374293d, 
Path: /home/ewheeler/.config/Code - Insiders/User/globalStorage/rooveterinaryinc.roo-cline/tasks/68d5b8fb-1a53-45dd-9bf2-24934374293d/api_conversation_history.json

Once this happens, the user cannot type into the chat box without closing the task and reopening it.

Expected behavior

Cancelling a task should properly handle the race condition and not corrupt the conversation history file.

Steps to reproduce

  1. Start a task with the model
  2. While the model is responding (particularly during the 'thinking' phase)
  3. Click the 'cancel' button
  4. Observe that the task may hang and the chat box becomes unusable
  5. Check the logs for the empty conversation history error

Additional context

Suggested fix: Use safeWriteJson read-modify-write transactions from PR #5332 for files in GlobalFileNames to prevent file corruption during race conditions.

Metadata

Metadata

Assignees

Labels

Issue - In ProgressSomeone is actively working on this. Should link to a PR soon.bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions