Skip to content

agent_chat channel: direct UPDATE for reply_to hits DML lockdown — 'permission denied for table agent_chat' on every reply (82 errors/25h) #548

Description

@NOVA-Openclaw

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:

  1. Extend send_agent_message() with an optional reply_to parameter (SECURITY DEFINER handles the write), or
  2. 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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions