fix(chat): group-message FK violation + receipt-cursor stall

Group inserts were using recipient_id=0 as a "no recipient" sentinel,
which fails the tenants FK (foreign_keys is ON) and 500s on every
group send. Use the sender's own id as the placeholder instead;
group GET queries already key off room_uid so there's no self-message
artefact from the value.

Also exclude group rows from /api/chat/sent so the client's
last_sent_relay_id cursor doesn't stall on group sends that never
reach seen=1 (group receipts aren't tracked in v1).

Client-side: surface a clearer error when a room create hits a 404
on the relay — almost always means the relay is running pre-group
code and needs a restart.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
thandClaude Opus 4.6 committed 2026-04-15 20:57:18 +02:00
1 parent 0fd97e5d71
commit 6aa555cc6a
2 files changed
+20 -8

No files matched your search

+10 -2
View File
@@ -530,7 +530,8 @@ PluginManager::instance()->onApiRoute(function (string $route, string $method) {
// Client-generated UID, same convention as collab buckets.
$uid = bin2hex(random_bytes(8));
$ch = curl_init(rtrim($r['url'], '/') . '/api/chat/rooms');
$relayUrl = rtrim($r['url'], '/') . '/api/chat/rooms';
$ch = curl_init($relayUrl);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
@@ -547,7 +548,14 @@ PluginManager::instance()->onApiRoute(function (string $route, string $method) {
curl_close($ch);
if ($status !== 200) {
$err = json_decode($response, true);
chatJson(['ok' => false, 'error' => $err['error'] ?? "relay HTTP $status"]);
$detail = $err['error'] ?? "relay HTTP $status";
// 404 on this path almost always means the relay is running a
// pre-group-chat build. Surface that explicitly so the user
// doesn't go hunting for data issues.
if ($status === 404) {
$detail = "relay does not know /api/chat/rooms — it's likely running old code. Restart the relay after pulling the latest commits.";
}
chatJson(['ok' => false, 'error' => $detail, 'url' => $relayUrl, 'relay_status' => $status]);
}
$data = json_decode($response, true) ?: [];
// Mirror locally right away so the next conversations list shows