Problem
The agent_chat channel handler fails to deliver replies with permission denied for table agent_chat. Gateway log shows paired errors (Failed to send reply for message N + final reply failed) — 82 log lines over ~25h, first 2026-07-28 06:04:32 UTC, still firing at 2026-07-29 07:49 UTC (message 1003568). Subsystem: channels/agent_chat.
Root cause
insertOutboundMessage() in cognition/focus/agent_chat/src/channel.ts (~line 126) correctly routes the insert through send_agent_message(), but then sets reply_to via a direct UPDATE:
if (replyTo !== null) {
await client.query(
`UPDATE agent_chat SET reply_to = $1 WHERE id = $2`,
[replyTo, newId],
);
}
The agent_chat DML lockdown (SELECT-only grants + trigger blocking direct INSERT/UPDATE/DELETE; send_agent_message() is the sole write path) correctly rejects this UPDATE. Any reply that sets reply_to — i.e. every reply to an inbound agent_chat message — throws here.
Note: since send_agent_message() has already committed before the UPDATE throws, the message body is delivered but reply_to is never set and the handler reports the whole reply as failed (possible retry/duplicate risk + misleading errors).
Proposed fix direction
Either:
- Extend
send_agent_message() with an optional reply_to parameter (SECURITY DEFINER handles the write), or
- Add a companion
set_reply_to(chat_id, reply_to) SECURITY DEFINER function with sender validation, called from the handler.
Option 1 is cleaner — one atomic write path.
Discovery context
Found during Full System Diagnostic run #523 (2026-07-29, grade B-): PG log review flagged 41 recurring permission-denied write failures across a 25h window. Distinct from the 2026-07-16 transient (deliberate lockdown test) — this one does not self-resolve. Introspection traced it to the code path above. (First attempted filing against nova-cognition — repo is archived; cognition code now lives here.)
Problem
The agent_chat channel handler fails to deliver replies with
permission denied for table agent_chat. Gateway log shows paired errors (Failed to send reply for message N+final reply failed) — 82 log lines over ~25h, first 2026-07-28 06:04:32 UTC, still firing at 2026-07-29 07:49 UTC (message 1003568). Subsystem:channels/agent_chat.Root cause
insertOutboundMessage()incognition/focus/agent_chat/src/channel.ts(~line 126) correctly routes the insert throughsend_agent_message(), but then setsreply_tovia a direct UPDATE:The agent_chat DML lockdown (SELECT-only grants + trigger blocking direct INSERT/UPDATE/DELETE;
send_agent_message()is the sole write path) correctly rejects this UPDATE. Any reply that setsreply_to— i.e. every reply to an inbound agent_chat message — throws here.Note: since
send_agent_message()has already committed before the UPDATE throws, the message body is delivered butreply_tois never set and the handler reports the whole reply as failed (possible retry/duplicate risk + misleading errors).Proposed fix direction
Either:
send_agent_message()with an optionalreply_toparameter (SECURITY DEFINER handles the write), orset_reply_to(chat_id, reply_to)SECURITY DEFINER function with sender validation, called from the handler.Option 1 is cleaner — one atomic write path.
Discovery context
Found during Full System Diagnostic run #523 (2026-07-29, grade B-): PG log review flagged 41 recurring permission-denied write failures across a 25h window. Distinct from the 2026-07-16 transient (deliberate lockdown test) — this one does not self-resolve. Introspection traced it to the code path above. (First attempted filing against nova-cognition — repo is archived; cognition code now lives here.)