agentscope-ai / agentscope-ai/QwenPaw

[Question]: Session list corruption causes 500 error when editing chats.json — no backup/validation mechanism exists

Ouverte
#3,178 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
question
Langage dominant
Python
Étoiles
34.9k
Forks
3.1k
Merge moyen
1 j 15 h
PR mergées (30 j)
225

Description

I was troubleshooting an issue where QQ messages were appearing in two places simultaneously — both in a QQ channel tab and in a console channel tab. After investigation, I found the root cause in chats.json:

A chat entry with "channel": "console" had its "session_id" pointing to a QQ session ("qq:02D7899C983DADDE4D5C32CCD7867815"), causing QQ messages to sync to both the correct QQ tab and an incorrect console tab.

To fix this, I deleted that problematic entry from chats.json using the edit_file tool with only the object text as old_text.

However, the deleted entry was the last item in the "chats" array. By removing only the object itself without removing the trailing comma from the previous item, the JSON became structurally invalid:

json
// Before deletion (simplified):
{
"chats": [
{ ... previous item ... },
{ ... item to delete (last one) ... } ← had no trailing comma
]
}

// After my edit — only the object was removed:
{
"chats": [
{ ... previous item ... },

] ← leftover comma makes JSON invalid
}

Result:
-GET /api/chats returned 500 Internal Server Error
-All Copaw clients (desktop, web, QQ) became completely unresponsive
-I was completely locked out — every client returned 500 and I could not communicate with the agent to investigate or fix anything
-I had to use a separate AI agent (WorkBuddy) to diagnose the issue. WorkBuddy identified that chats.json was broken at lines 90-92, caused by a leftover comma after my edit
-The JSON was then manually repaired by removing the dangling comma

Root cause analysis:
-CoPaw has no backup mechanism for chats.json. Any direct edit to this critical file without a backup creates a single point of failure.
-No write-time validation — after an edit, Copaw does not validate that chats.json is still valid JSON before the API serves it.
-The tool should handle comma cleanup — when deleting an array element, the tool should automatically detect position (first/middle/last) and handle surrounding commas accordingly, rather than relying on the user to manually construct correct JSON.
-The consequences of this particular failure were catastrophic — a single malformed JSON entry in a non-critical operation disabled ALL communication channels (desktop, web, QQ). There was no degradation, no fallback — total outage.

Expected behavior:
-The edit tool should automatically handle comma placement when deleting array elements
-Copaw should maintain a backup of chats.json before any write operation
-Copaw should validate JSON structure after any write and auto-rollback if invalid

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.