Skip to content

TEMP: add debug logging for API conversation history issues #4312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

KJ7LNW
Copy link
Collaborator

@KJ7LNW KJ7LNW commented Jun 4, 2025

Context

This PR adds detailed debug logging to the readApiMessages function to help diagnose "Unexpected: No existing API conversation history" errors.

Implementation

Added logging for three scenarios:

  1. When the API conversation history file exists but contains an empty array
  2. When the old history file exists but contains an empty array
  3. When neither history file is found (already implemented)

How to Test

When encountering the "Unexpected: No existing API conversation history" error, check the Developer Tools console (Help > Toggle Developer Tools > Console tab) for debug messages with the format:
[Roo-Debug] readApiMessages: ...

These logs will show the taskId and file path, helping to diagnose the issue.

Screenshots

N/A - Console logging only

Get in Touch

Discord: KJ7LNW

does not completely fix #4311 but it may provide debug output that may help us fix it from other users.


Important

Adds debug logging to readApiMessages for diagnosing empty or missing API conversation history files.

  • Debug Logging:
    • Adds debug logging in readApiMessages for empty API conversation history files.
    • Logs when apiConversationHistory file is empty.
    • Logs when claude_messages.json file is empty.
    • Logs when neither file is found (existing behavior).
  • Function:
    • Modifies readApiMessages in apiMessages.ts to include new logging scenarios.

This description was created by Ellipsis for 49a68c1. You can customize this summary. It will automatically update as commits are pushed.

Add detailed logging to readApiMessages function to help diagnose
"Unexpected: No existing API conversation history" errors.

The logs will show:
- When the history file exists but contains an empty array
- When the old history file exists but contains an empty array
- When neither history file is found

This will help diagnose issues like the one in #4311 where the
API conversation history file gets truncated to an empty array
during task resumption with orchestrator tasks.

Fixes: #4311
Signed-off-by: Eric Wheeler <[email protected]>
@KJ7LNW KJ7LNW requested review from mrubens and cte as code owners June 4, 2025 04:57
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Jun 4, 2025
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jun 4, 2025
Add error handling for JSON parsing failures in readApiMessages:
- Wrap JSON.parse calls in try/catch blocks for both current and legacy history files
- Add detailed error logging with taskId and file paths
- Return empty arrays when parsing fails to maintain function contract
- Improve existing debug logging for empty history arrays
- Handle file unlinking even when parsing fails

This prevents crashes from malformed JSON in history files and provides
better debugging information when API conversation history is corrupted.
Related to issue #4311.

Signed-off-by: Eric Wheeler <[email protected]>
@KJ7LNW KJ7LNW force-pushed the debug-api-conversation-history branch from 21a8167 to 9d19c68 Compare June 4, 2025 05:22
@hannesrudolph hannesrudolph marked this pull request as draft June 4, 2025 19:12
@hannesrudolph hannesrudolph changed the title fix: add debug logging for API conversation history issues TEMP: add debug logging for API conversation history issues Jun 4, 2025
@hannesrudolph hannesrudolph moved this from Triage to PR [Draft / In Progress] in Roo Code Roadmap Jun 4, 2025
@hannesrudolph
Copy link
Collaborator

See notes on the issue as to why I moved this to draft

@KJ7LNW
Copy link
Collaborator Author

KJ7LNW commented Jun 5, 2025

You can leave us in draft if you want, this is not something I am going to put more work into. I just wanted to provide the steps I took for troubleshooting and case it helps someone else along the way.

These debug prints are non-intrusive, uncommon, only trigger upon error, and only serve to help troubleshoot this problem if somebody else hits it.

IMHO, PRs like this should be merged quickly to help future troubleshooting by others. (Someday if I clean up and delete the branch, then this research could be lost.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR - Draft / In Progress size:M This PR changes 30-99 lines, ignoring generated files.
Projects
Status: PR [Draft / In Progress]
Development

Successfully merging this pull request may close these issues.

bug: API conversation history file truncated to empty array during task resume
3 participants