Medium: lost chat-group creation response duplicates folders on retry
Severity
Medium — retrying a chat-group creation whose HTTP 201 was lost creates duplicate folders, even though the first group was committed. A post-commit list/read failure produces the same behavior.
Affected code
create_chat_group, chats.py:166–187 chooses a fresh server-sideuuid4()for every POST, commits viadeps.chats.create_group(), and then makes an independent, fallibledeps.chats.list_groups()read to formulate the response.App.createGroup, App.tsx:636–649 has no stable request key or reconciliation on an ambiguous error. The UI can invite another attempt.storage.py:1968–1980inserts a new row and position each time; there is no unique-name constraint or request-ID association.
Reproduction
- POST
/api/v1/chat-groupswith{"name":"Research"}. Let SQLite commit the group, then drop the 201 response (or fault-inject an exception in the subsequentlist_groupscall). - Browser sees a failed creation and no group ID, though the first Research folder exists.
- Retry the same action. Actual: a second Research folder with a different ID and new position is committed.
- Expected: exact retry resolves the first created group, without duplicates; a genuinely new user action can still deliberately create a same-named folder if supported.
Suggested fix / regression
Accept a bounded client-generated request_id and use a deterministic target UUID or durable operation mapping, similar to the now-idempotent chat fork in #400. Persist an ambiguous pending create intent until reconciled, and test post-insert response failure plus identical POST replay with SQLite and in-memory repositories. Ensure a new key still intentionally produces a new group.
Reviewed revision: e824fe2dcba0d1be127c9fff165f776186dc37e9. Static transaction/response path; fault-injection test not executed.
Additional related endpoint found during the follow-up audit: POST /api/v1/chats in routers/chats.py:101–119 has the same post-commit failure / lost-201 duplication pattern as group creation: each retry generates a fresh server-side uuid4().hex, commits create_chat, then performs a separate fallible get_chat read. A dropped 201 or readback error leaves the caller without an ID; a retry creates another empty conversation. The current React UI normally admits new conversations via idempotent /generations, so this primarily affects standalone API clients. Consider treating both POST /chats and POST /chat-groups under this issue's shared idempotent-create acceptance contract, with separate regression cases. Not opening a separate ticket to avoid duplicating the same class of issue.