Skip to content

fix: approval prompts sent to another chat now enter that chat's history - #208204

Merged
obviyus merged 2 commits into
mainfrom
fix/visible-channel-notices
Nov 29, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/visible-channel-notices

Conversation

@obviyus

@obviyus obviyus commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Follows #208049, #208130 and #208169.

What Problem This Solves

When an agent run needs approval (exec, plugin or OpenClaw change) and Telegram or Signal shows the approval prompt in a different chat than the one that asked (for example the approver's DM, for a cron job, background run or another chat's turn), the user sees the prompt but that chat's agent has no record of it. Asking the DM agent "what did that approval ask?" gets a blank stare.

Cause: the Telegram and Signal approval adapters sent the prompt straight through their own platform clients (sendMessageTelegram, sendMessageSignal), bypassing core delivery, so the confirmed-send history owner (src/sessions/confirmed-visible-message.ts) never saw it.

User Impact

  • Telegram and Signal approval prompts for another conversation now enter the receiving chat's model history once, so the agent there can quote and explain them on the next turn.
  • A prompt in the chat whose own turn asked for approval adds no row (that turn already owns its history), so there is no duplicate.
  • Signal's approval outcome ("approved", "expired") is a new message (Signal cannot edit), so it is recorded the same way. Telegram edits its prompt in place; edits add no row.
  • What the user sees does not change: same text, buttons, topic/thread, reactions, and the same monitor endpoint for Signal. No config, schema, stored-row, protocol or SDK change.

Why This Change Was Made

The goal: every message a user sees is in that chat's model history, through one owner. The adapters now send through sendDurableMessageBatch (as other plugin sends already do) and the direct client calls are deleted, so the existing owner records the prompt. No new hook, flag, guard or state.

  • skipQueue: true: approval prompts are not replayed after a restart, same as before (a replayed prompt would carry dead buttons for an approval that no longer exists).
  • The requesting session is passed as the producer, so the owner's existing same-session rule skips the requesting chat.
  • Signal keeps the monitor's baseUrl/account through the send dependency, as before.
  • Side effect: message_sending hooks now see approval prompts, like every other core send.

Direct sends reviewed (classified, not moved)

  • Reply of the turn running in that chat (its turn owns history): Discord interaction replies (native-command-reply.ts), Telegram native command replies, Telegram system-agent approval outcome sent back to the origin chat.
  • Access control before a conversation exists (must never enter a transcript): Telegram pairing codes and "not allowed" (dm-access.ts), "You are not authorized to use this command." (bot-native-command-dispatch.ts), provider login device codes (bot-native-command-login.ts).
  • Last-resort failure notices: Telegram "Something went wrong…" after dispatch itself threw (bot-message.ts) and "Configured ACP binding is unavailable" (bot-native-command-dispatch.ts). They bypass core delivery on purpose so they still arrive when delivery is what failed. Default chosen: keep them direct.

docs/refactor/conversation-transcript-ownership.md now lists these classes.

Evidence

  • Red on base, green here (real core delivery, real history owner, SQLite session store; only the platform send function is mocked):

    • extensions/telegram/src/approval-handler.runtime.test.ts "records a DM approval prompt: another conversation's approval enters the approver chat once": base 0 rows, head exactly 1 row with the prompt. "…the requesting chat's approval stays with its own turn": 0 rows on both.
    • extensions/signal/src/approval-handler.runtime.test.ts "adds a prompt for another conversation's approval to the approver chat once": base 0 rows, head 1. "leaves a prompt in the requesting chat to that chat's own turn": 0 rows.
  • Existing Telegram approval cases (topics, Direct Messages topics, fan-out, terminal edits, origin fallback) stay green; their send assertions now check the routed target (telegram:<chat>:topic:<n>), which the real sender resolves.

  • Both test files moved to the extension-database-workers lane (forks pool), since history writes need the main-thread SQLite broker.

  • Real Telegram (Test Server, source Gateway, deterministic mock model, real transport and history). The DM user first got READY, so the DM session (agent:main:main) existed. Then gateway call agent {sessionKey: "agent:main:vcn-e2e"} ran with no channel delivery; the mock made one exec call with a marker, and Telegram exec approvals (approver = the DM user, target DM, ask always) showed the prompt with Allow Once / Deny buttons in the DM. After that, the user asked "What did the approval prompt say?" The prompt was left unanswered.

    Side Prompts in the DM DM history rows with marker Follow-up model request contains marker
    base b904594b0377 1 0 no
    head 5462cde7ee6a 1 1 yes

    On base the user saw the approval prompt, but the DM agent had no record of it. On head the DM agent's next request includes it. This proves delivery and history inclusion, not visual rendering.

Follow-ups (out of scope)

  • Approval prompts on Discord, Slack, Matrix, WhatsApp, iMessage, Microsoft Teams and Google Chat still send directly; each needs its native presentation (components, blocks, cards, reactions) through core delivery.
  • Matrix shared-DM context notice (m.notice; core delivery has no notice message type).
  • Storing not-recorded reasons (schema); inbound accepted ⇒ transcript; failed-delivery history and overlap dedupe.

Merge risk

Two-way door: a revert restores the direct sends. No stored format, schema or contract change. Blast radius: Telegram and Signal native approval prompt delivery (and Signal approval outcome messages).

…prover chat

- Send Telegram and Signal native approval prompts (and Signal's outcome messages) through core delivery, so the confirmed-send owner records them in the receiving chat's history.
- A prompt in the requesting chat stays with that chat's own turn (no duplicate row).
- List the remaining direct channel sends and their classes in the transcript ownership doc.
@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review started

This attempt replaced any previous blocked status for this revision.

View this run’s status.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: signal Channel integration: signal channel: telegram Channel integration: telegram size: M labels Nov 29, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 29, 2026
@obviyus
obviyus merged commit 94ee07a into main Nov 29, 2026
123 checks passed
@obviyus
obviyus deleted the fix/visible-channel-notices branch November 29, 2026 10:12
@obviyus

obviyus commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 94ee07a.

  • Bug: Telegram and Signal approval prompts reached the approver's chat but never entered that chat's model history, so the agent there could not see them.
  • Fix: both adapters now send prompts (and Signal's outcome messages) through core delivery, and the existing confirmed-send owner records them once. A prompt in the requesting chat adds no duplicate.
  • Proof: red-on-base history tests for both channels; real Telegram E2E: base 0 DM history rows, head 1, and the next model request includes the prompt.
  • Follow-ups: approval prompts on the other channels and Matrix's shared-DM notice still send directly.

tideclaw-bot pushed a commit that referenced this pull request Nov 29, 2026
…ory (#208204)

Follows #208049, #208130 and #208169.

## What Problem This Solves

When an agent run needs approval (exec, plugin or OpenClaw change) and Telegram or Signal shows the approval prompt in a different chat than the one that asked (for example the approver's DM, for a cron job, background run or another chat's turn), the user sees the prompt but that chat's agent has no record of it. Asking the DM agent "what did that approval ask?" gets a blank stare.

Cause: the Telegram and Signal approval adapters sent the prompt straight through their own platform clients (`sendMessageTelegram`, `sendMessageSignal`), bypassing core delivery, so the confirmed-send history owner (`src/sessions/confirmed-visible-message.ts`) never saw it.

## User Impact

- Telegram and Signal approval prompts for another conversation now enter the receiving chat's model history once, so the agent there can quote and explain them on the next turn.
- A prompt in the chat whose own turn asked for approval adds no row (that turn already owns its history), so there is no duplicate.
- Signal's approval outcome ("approved", "expired") is a new message (Signal cannot edit), so it is recorded the same way. Telegram edits its prompt in place; edits add no row.
- What the user sees does not change: same text, buttons, topic/thread, reactions, and the same monitor endpoint for Signal. No config, schema, stored-row, protocol or SDK change.

## Why This Change Was Made

The goal: every message a user sees is in that chat's model history, through one owner. The adapters now send through `sendDurableMessageBatch` (as other plugin sends already do) and the direct client calls are deleted, so the existing owner records the prompt. No new hook, flag, guard or state.

- `skipQueue: true`: approval prompts are not replayed after a restart, same as before (a replayed prompt would carry dead buttons for an approval that no longer exists).
- The requesting session is passed as the producer, so the owner's existing same-session rule skips the requesting chat.
- Signal keeps the monitor's `baseUrl`/`account` through the send dependency, as before.
- Side effect: `message_sending` hooks now see approval prompts, like every other core send.

### Direct sends reviewed (classified, not moved)

- **Reply of the turn running in that chat (its turn owns history):** Discord interaction replies (`native-command-reply.ts`), Telegram native command replies, Telegram system-agent approval outcome sent back to the origin chat.
- **Access control before a conversation exists (must never enter a transcript):** Telegram pairing codes and "not allowed" (`dm-access.ts`), "You are not authorized to use this command." (`bot-native-command-dispatch.ts`), provider login device codes (`bot-native-command-login.ts`).
- **Last-resort failure notices:** Telegram "Something went wrong…" after dispatch itself threw (`bot-message.ts`) and "Configured ACP binding is unavailable" (`bot-native-command-dispatch.ts`). They bypass core delivery on purpose so they still arrive when delivery is what failed. Default chosen: keep them direct.

`docs/refactor/conversation-transcript-ownership.md` now lists these classes.

## Evidence

- Red on base, green here (real core delivery, real history owner, SQLite session store; only the platform send function is mocked):
  - `extensions/telegram/src/approval-handler.runtime.test.ts` "records a DM approval prompt: another conversation's approval enters the approver chat once": base 0 rows, head exactly 1 row with the prompt. "…the requesting chat's approval stays with its own turn": 0 rows on both.
  - `extensions/signal/src/approval-handler.runtime.test.ts` "adds a prompt for another conversation's approval to the approver chat once": base 0 rows, head 1. "leaves a prompt in the requesting chat to that chat's own turn": 0 rows.
- Existing Telegram approval cases (topics, Direct Messages topics, fan-out, terminal edits, origin fallback) stay green; their send assertions now check the routed target (`telegram:<chat>:topic:<n>`), which the real sender resolves.
- Both test files moved to the `extension-database-workers` lane (forks pool), since history writes need the main-thread SQLite broker.
- Real Telegram (Test Server, source Gateway, deterministic mock model, real transport and history). The DM user first got READY, so the DM session (`agent:main:main`) existed. Then `gateway call agent {sessionKey: "agent:main:vcn-e2e"}` ran with no channel delivery; the mock made one `exec` call with a marker, and Telegram exec approvals (approver = the DM user, target DM, ask always) showed the prompt with Allow Once / Deny buttons in the DM. After that, the user asked "What did the approval prompt say?" The prompt was left unanswered.

  | Side | Prompts in the DM | DM history rows with marker | Follow-up model request contains marker |
  |---|---:|---:|---|
  | base `b904594b0377` | 1 | 0 | no |
  | head `5462cde7ee6a` | 1 | 1 | yes |

  On base the user saw the approval prompt, but the DM agent had no record of it. On head the DM agent's next request includes it. This proves delivery and history inclusion, not visual rendering.

## Follow-ups (out of scope)

- Approval prompts on Discord, Slack, Matrix, WhatsApp, iMessage, Microsoft Teams and Google Chat still send directly; each needs its native presentation (components, blocks, cards, reactions) through core delivery.
- Matrix shared-DM context notice (`m.notice`; core delivery has no notice message type).
- Storing not-recorded reasons (schema); inbound accepted ⇒ transcript; failed-delivery history and overlap dedupe.

## Merge risk

Two-way door: a revert restores the direct sends. No stored format, schema or contract change. Blast radius: Telegram and Signal native approval prompt delivery (and Signal approval outcome messages).

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 94ee07a)

Companion mentions reviewed for #208204: 34d4f8f improve: list Docker streams and flag unconfirmed cleanup in Doctor (#201292); 21786f6 refactor(ui): stop sending 28 additional unused labels to translators (#207982); 9cec330 refactor(workboard): group session tiles without rescanning each column (#207380); 16a2d4b refactor(ui): lowercase log search text only once (#207383)

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 29, 2026
)

Supersedes #207992.

## Problem

An isolated automation turn (`gateway call agent` with its own session key, `channel: telegram`, `to: <dm>`, `deliver: false`) sends a Telegram DM with the `message` tool. The user sees the message, replies, and the DM's assistant has no record of it.

Cause: `commitConfirmedVisibleMessage` decided "the producer's own turn already wrote this" by comparing the producer session's stored `delivery.context` with the send address (`createProducerMatcher`), and returned a silent skip. The gateway `agent` request stores its `channel`/`to` routing hint on the isolated session even with `deliver: false`, so the hint matched the DM address and the DM history write was dropped.

## Fix

- Own-turn is decided only by conversation identity: canonical store key of the producer === canonical store key of the resolved destination. The address matcher and both call sites are removed.
- Every remaining not-recorded outcome carries a diagnostic (`skipped()` now requires one).
- The unused `skipDestinationHistory` opt-out is removed (`deliver-contracts.ts`, `message.ts`, `deliver-core.ts`, its test).
- `docs/refactor/conversation-transcript-ownership.md` describes own-turn by key only.

Production diff: 5 files, net negative.

## User impact

A message the user saw from an automation or another session now lands in the destination chat's model history. A same-chat turn's own final reply still gets no second row. No config, schema, protocol or migration change.

## Evidence

- Red on base, green here: `src/sessions/confirmed-visible-message.integration.test.ts` "records an isolated producer's send despite matching DM routing hints=true". The test that asserted the old "context" skip is deleted.
- No duplicate on the real dispatch path (`src/auto-reply/reply/dispatch-visible-history.integration.test.ts`): Telegram DM with `dmScope` `main` and `per-channel-peer`, Telegram forum topic, Discord channel, Control UI/webchat. Each resolves the same outbound route key as the inbound session, so no key-parity fix was needed.
- Affected consumer tests (30 files) passed locally.
- Real Telegram (Test Server, real model), base `a65ac074b3d6`: the isolated producer's DM arrived once; the DM transcript and the DM agent's next model request did not contain it, and the agent answered with an older reply.
- Real Telegram, head `ee6eed48a208` (same entry point): `gateway call agent` with `sessionKey: agent:main:bedtime-e2e`, `channel: telegram`, `deliver: false`; the agent sent "It's 10:15 pm, time for bed. The amber bookmark can wait until morning." once with the `message` tool. The DM session (`agent:main:main`) then had that text as one assistant row (no duplicate). The user asked "what did you just send me?" and the DM agent answered: "I just sent: “It's 10:15 pm, time for bed. The amber bookmark can wait until morning.”"
- Local ClawSweeper review on `ee6eed48a208`: patch correct, zero findings.
- CI: every check passed except `check-lint-core-5`, which fails on three lint errors in Workboard e2e files from #207839 that are on `main` and not in this diff (#208070; override comment on this PR).

## Not changed here (decision recorded)

Plugin-action settlement (`outbound-send-service.ts` `onHandled`): a base test showed a plugin action that sends through durable delivery and also returns a native receipt can write two destination rows (different `deliveryId`s). Deleting the `onHandled` writer would drop history for third-party handlers that send natively and return only a receipt. Routing those through delivery settlement is a new design, so it is a follow-up, not part of this cut.

## Follow-ups

- Exactly-once native receipt settlement that keeps receipt-only plugin handlers.
- Registry-first destination resolver; sessions not created by inbound must not claim chat addresses (removes the "ambiguous" skip).
- Store the not-recorded reason on the delivery queue row (schema change).
- Route direct channel notices through the owner: Telegram `bot-message.ts`, `dm-access.ts`, native command replies; Discord `native-command-reply.ts`; Signal/Matrix approval handlers.
- Inbound "accepted ⇒ in transcript" for queue drop/summarize paths; failed-delivery and overlap-dedupe history on the agent side.

## Merge risk

Revert restores the old skip. Rows already appended stay.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 1782ab0)

Later same-path commits from the pinned scan (separate behavior unless named as folded/selected below): a20fd1c fix: avoid competing Gateway test boots and cold agent mutation imports (#208203); edb6820 fix: let the Gateway restart while boot plugin maintenance is running (#208074); 50d7708 fix: keep Claude fork compaction out of the parent chat (#208192); 94ee07a fix: approval prompts sent to another chat now enter that chat's history (#208204); b904594 fix: record an announced send in the chat it reached (#208169); 407b523 fix(slack): thread queued DM replies under the triggering message (#208133); 5b7efcd fix(outbound): record a plugin action's visible send once (#208130).
Later PR-number mentions: `16a2d4b59d75` refactor(ui): lowercase log search text only once (#207383), `21786f65ed93` refactor(ui): stop sending 28 additional unused labels to translators (#207982), `34d4f8f308ba` improve: list Docker streams and flag unconfirmed cleanup in Doctor (#201292), `5b7efcd4c02e` fix(outbound): record a plugin action's visible send once (#208130), `94ee07a60057` fix: approval prompts sent to another chat now enter that chat's history (#208204), `9cec330df50d` refactor(workboard): group session tiles without rescanning each column (#207380), `b904594b0377` fix: record an announced send in the chat it reached (#208169), `eb378faead30` fix(workboard): clear lint errors in the board settings modal (#208113) Later commit-SHA mentions: none

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 29, 2026
Follows #208049.

## Problem

A plugin `send` action can write the same visible message into the destination chat's model history twice.

Telegram's action handler sends through `sendDurableMessageBatch`. Durable delivery records the confirmed send (`deliver-core.ts` `recordConfirmedTranscript`, key `outbound-delivery:<queue id>:0`). The handler then returns a native receipt, and `outbound-send-service.ts` `onHandled` records it again (key `outbound-delivery:<deliveryIntentId ?? idempotencyKey ?? uuid>:0`). The two keys differ, so the destination gets two identical assistant rows. The model then sees one message the user saw once as two messages.

On real Telegram the second row appears when the destination resolves without ambiguity, for example when the producer session does not carry a `channel/to` hint for the DM. (In #208049's E2E the producer carried that hint, so the durable write was skipped as "multiple current destinations match" and only one row landed.)

## Fix

One plugin action is one send, recorded once.

- `executeSendAction` runs the plugin action inside `runPluginActionHistoryScope(…)`.
- `commitConfirmedVisibleMessage` (the history owner) marks the scope when it actually adds a row.
- The action's receipt commit (`onHandled`) skips when the scope is marked: the handler's core-delivery send already recorded the message.
- Core delivery keeps its own queue identity for the row, so restart recovery (which re-commits with the queue entry id) still finds the existing row.
- Receipt-only handlers (send natively, no core delivery) are unchanged: nothing marks the scope, and `onHandled` writes their one row.
- If the core-delivery commit is skipped (for example an ambiguous destination), the scope stays unmarked and `onHandled` still writes with the caller's route, as before.

Why a scope and not a new field: `ChannelMessageActionContext` has no delivery identity field, and each plugin forwards context fields to its runtime by hand (Telegram lists them in `channel-actions.ts`). Threading an id would be a new public Plugin SDK field that every third-party handler must forward. The scope reaches any handler that sends through core delivery, with no SDK change. No config, stored state, table or hook.

Review round 1 changed the mechanism: an earlier head replaced the core row's id with the action id, which broke dedupe on restart recovery (recovery commits under the queue entry id). This head keeps the queue id.

## User impact

A message sent through a plugin action (Telegram `message` tool sends, for example) appears once in the receiving chat's model history, exactly as delivered. No config, schema, protocol, stored-row or SDK change.

## Evidence

- Red on base, green here: `src/infra/outbound/outbound-send-service.integration.test.ts` "records a plugin action's durable send in destination history once" (base: two identical rows).
- Stays green: "records a receipt-only plugin action in destination history once".
- Consumer tests: 19 files passed locally (one `ocx test` set, vitest-source): the new test, `outbound-send-service{,.accepted-outcomes}.test.ts` (their module mocks now pass the scope through), `deliver.test.ts`, `deliver-confirmed-visible.test.ts`, `delivery-queue.transcript.test.ts`, `confirmed-visible-message.integration.test.ts`, `message-action-send{,.core,.media,.mirror-order,.validation}.test.ts`, subagent announce delivery/mirror tests, Telegram `action-runtime.test.ts` + `channel-actions.contract.test.ts`, Discord `actions/runtime.test.ts`, Slack `action-runtime.test.ts`, `test/qa-channel-message-tool-delivery.test.ts`.
- Real Telegram (Test Server, source Gateway) on head `c33cd7f46b40`: the DM user first got a reply ("READY"), so the DM session existed. Then `gateway call agent` ran with an isolated `sessionKey`, `deliver: false` and no `channel`/`to` hints. Its `message` tool sent one marker DM to the user. Results: the recorder saw 1 marker message, and the DM session (`agent:main:main`) had 1 assistant row for it. That row's key is the core-delivery queue id (`outbound-delivery:<uuid>:0`), so the handler's durable write recorded it and the receipt commit skipped. The Gateway logged no "multiple current destinations match" line, so the run took the path that wrote two rows before this fix. The model fixture was deterministic, so the tool call was predictable. Telegram transport and transcript were real.
- Local review: round 1 found the recovery-identity problem described above (fixed). Round 2 on `c33cd7f46b40`: patch correct, no findings.
- Rebased on main to pick up #208120: the base had #207738 without its PR-wrapper inventory fix, so `test/scripts/eager-import-closure.test.ts` was red.

## Follow-ups (out of scope)

- Registry-first destination resolver; remove the "ambiguous" skip.
- Store the not-recorded reason on the delivery queue row (schema change).
- Route direct channel notices through the history owner.
- Inbound "accepted ⇒ in transcript" guarantees.
- Failed-delivery history.

## Merge risk

Two-way door. Revert restores the duplicate row. No stored format change; the idempotency key format is the same, only which id fills it inside a plugin action. Blast radius: plugin-action sends that also go through core delivery (Telegram today).

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 5b7efcd)

No later same-path companion identified in the bounded scan.
Later PR-number mentions: `16a2d4b59d75` refactor(ui): lowercase log search text only once (#207383), `21786f65ed93` refactor(ui): stop sending 28 additional unused labels to translators (#207982), `34d4f8f308ba` improve: list Docker streams and flag unconfirmed cleanup in Doctor (#201292), `94ee07a60057` fix: approval prompts sent to another chat now enter that chat's history (#208204), `9cec330df50d` refactor(workboard): group session tiles without rescanning each column (#207380), `b904594b0377` fix: record an announced send in the chat it reached (#208169), `eb378faead30` fix(workboard): clear lint errors in the board settings modal (#208113) Later commit-SHA mentions: `16a2d4b59d75` refactor(ui): lowercase log search text only once (#207383), `21786f65ed93` refactor(ui): stop sending 28 additional unused labels to translators (#207982), `34d4f8f308ba` improve: list Docker streams and flag unconfirmed cleanup in Doctor (#201292), `9cec330df50d` refactor(workboard): group session tiles without rescanning each column (#207380), `b904594b0377` fix: record an announced send in the chat it reached (#208169)

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…ory (#208204)

Follows #208049, #208130 and #208169.

## What Problem This Solves

When an agent run needs approval (exec, plugin or OpenClaw change) and Telegram or Signal shows the approval prompt in a different chat than the one that asked (for example the approver's DM, for a cron job, background run or another chat's turn), the user sees the prompt but that chat's agent has no record of it. Asking the DM agent "what did that approval ask?" gets a blank stare.

Cause: the Telegram and Signal approval adapters sent the prompt straight through their own platform clients (`sendMessageTelegram`, `sendMessageSignal`), bypassing core delivery, so the confirmed-send history owner (`src/sessions/confirmed-visible-message.ts`) never saw it.

## User Impact

- Telegram and Signal approval prompts for another conversation now enter the receiving chat's model history once, so the agent there can quote and explain them on the next turn.
- A prompt in the chat whose own turn asked for approval adds no row (that turn already owns its history), so there is no duplicate.
- Signal's approval outcome ("approved", "expired") is a new message (Signal cannot edit), so it is recorded the same way. Telegram edits its prompt in place; edits add no row.
- What the user sees does not change: same text, buttons, topic/thread, reactions, and the same monitor endpoint for Signal. No config, schema, stored-row, protocol or SDK change.

## Why This Change Was Made

The goal: every message a user sees is in that chat's model history, through one owner. The adapters now send through `sendDurableMessageBatch` (as other plugin sends already do) and the direct client calls are deleted, so the existing owner records the prompt. No new hook, flag, guard or state.

- `skipQueue: true`: approval prompts are not replayed after a restart, same as before (a replayed prompt would carry dead buttons for an approval that no longer exists).
- The requesting session is passed as the producer, so the owner's existing same-session rule skips the requesting chat.
- Signal keeps the monitor's `baseUrl`/`account` through the send dependency, as before.
- Side effect: `message_sending` hooks now see approval prompts, like every other core send.

### Direct sends reviewed (classified, not moved)

- **Reply of the turn running in that chat (its turn owns history):** Discord interaction replies (`native-command-reply.ts`), Telegram native command replies, Telegram system-agent approval outcome sent back to the origin chat.
- **Access control before a conversation exists (must never enter a transcript):** Telegram pairing codes and "not allowed" (`dm-access.ts`), "You are not authorized to use this command." (`bot-native-command-dispatch.ts`), provider login device codes (`bot-native-command-login.ts`).
- **Last-resort failure notices:** Telegram "Something went wrong…" after dispatch itself threw (`bot-message.ts`) and "Configured ACP binding is unavailable" (`bot-native-command-dispatch.ts`). They bypass core delivery on purpose so they still arrive when delivery is what failed. Default chosen: keep them direct.

`docs/refactor/conversation-transcript-ownership.md` now lists these classes.

## Evidence

- Red on base, green here (real core delivery, real history owner, SQLite session store; only the platform send function is mocked):
  - `extensions/telegram/src/approval-handler.runtime.test.ts` "records a DM approval prompt: another conversation's approval enters the approver chat once": base 0 rows, head exactly 1 row with the prompt. "…the requesting chat's approval stays with its own turn": 0 rows on both.
  - `extensions/signal/src/approval-handler.runtime.test.ts` "adds a prompt for another conversation's approval to the approver chat once": base 0 rows, head 1. "leaves a prompt in the requesting chat to that chat's own turn": 0 rows.
- Existing Telegram approval cases (topics, Direct Messages topics, fan-out, terminal edits, origin fallback) stay green; their send assertions now check the routed target (`telegram:<chat>:topic:<n>`), which the real sender resolves.
- Both test files moved to the `extension-database-workers` lane (forks pool), since history writes need the main-thread SQLite broker.
- Real Telegram (Test Server, source Gateway, deterministic mock model, real transport and history). The DM user first got READY, so the DM session (`agent:main:main`) existed. Then `gateway call agent {sessionKey: "agent:main:vcn-e2e"}` ran with no channel delivery; the mock made one `exec` call with a marker, and Telegram exec approvals (approver = the DM user, target DM, ask always) showed the prompt with Allow Once / Deny buttons in the DM. After that, the user asked "What did the approval prompt say?" The prompt was left unanswered.

  | Side | Prompts in the DM | DM history rows with marker | Follow-up model request contains marker |
  |---|---:|---:|---|
  | base `b904594b0377` | 1 | 0 | no |
  | head `5462cde7ee6a` | 1 | 1 | yes |

  On base the user saw the approval prompt, but the DM agent had no record of it. On head the DM agent's next request includes it. This proves delivery and history inclusion, not visual rendering.

## Follow-ups (out of scope)

- Approval prompts on Discord, Slack, Matrix, WhatsApp, iMessage, Microsoft Teams and Google Chat still send directly; each needs its native presentation (components, blocks, cards, reactions) through core delivery.
- Matrix shared-DM context notice (`m.notice`; core delivery has no notice message type).
- Storing not-recorded reasons (schema); inbound accepted ⇒ transcript; failed-delivery history and overlap dedupe.

## Merge risk

Two-way door: a revert restores the direct sends. No stored format, schema or contract change. Blast radius: Telegram and Signal native approval prompt delivery (and Signal approval outcome messages).

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 94ee07a)

Release adaptation: None; source applies intact to current stable owner.

Companion audit: Use existing destination transcript owners for cross-chat Telegram and Signal approval posts. Preserve expiry and original settlement.

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 30, 2026
…ory (openclaw#208204)

Follows openclaw#208049, openclaw#208130 and openclaw#208169.

## What Problem This Solves

When an agent run needs approval (exec, plugin or OpenClaw change) and Telegram or Signal shows the approval prompt in a different chat than the one that asked (for example the approver's DM, for a cron job, background run or another chat's turn), the user sees the prompt but that chat's agent has no record of it. Asking the DM agent "what did that approval ask?" gets a blank stare.

Cause: the Telegram and Signal approval adapters sent the prompt straight through their own platform clients (`sendMessageTelegram`, `sendMessageSignal`), bypassing core delivery, so the confirmed-send history owner (`src/sessions/confirmed-visible-message.ts`) never saw it.

## User Impact

- Telegram and Signal approval prompts for another conversation now enter the receiving chat's model history once, so the agent there can quote and explain them on the next turn.
- A prompt in the chat whose own turn asked for approval adds no row (that turn already owns its history), so there is no duplicate.
- Signal's approval outcome ("approved", "expired") is a new message (Signal cannot edit), so it is recorded the same way. Telegram edits its prompt in place; edits add no row.
- What the user sees does not change: same text, buttons, topic/thread, reactions, and the same monitor endpoint for Signal. No config, schema, stored-row, protocol or SDK change.

## Why This Change Was Made

The goal: every message a user sees is in that chat's model history, through one owner. The adapters now send through `sendDurableMessageBatch` (as other plugin sends already do) and the direct client calls are deleted, so the existing owner records the prompt. No new hook, flag, guard or state.

- `skipQueue: true`: approval prompts are not replayed after a restart, same as before (a replayed prompt would carry dead buttons for an approval that no longer exists).
- The requesting session is passed as the producer, so the owner's existing same-session rule skips the requesting chat.
- Signal keeps the monitor's `baseUrl`/`account` through the send dependency, as before.
- Side effect: `message_sending` hooks now see approval prompts, like every other core send.

### Direct sends reviewed (classified, not moved)

- **Reply of the turn running in that chat (its turn owns history):** Discord interaction replies (`native-command-reply.ts`), Telegram native command replies, Telegram system-agent approval outcome sent back to the origin chat.
- **Access control before a conversation exists (must never enter a transcript):** Telegram pairing codes and "not allowed" (`dm-access.ts`), "You are not authorized to use this command." (`bot-native-command-dispatch.ts`), provider login device codes (`bot-native-command-login.ts`).
- **Last-resort failure notices:** Telegram "Something went wrong…" after dispatch itself threw (`bot-message.ts`) and "Configured ACP binding is unavailable" (`bot-native-command-dispatch.ts`). They bypass core delivery on purpose so they still arrive when delivery is what failed. Default chosen: keep them direct.

`docs/refactor/conversation-transcript-ownership.md` now lists these classes.

## Evidence

- Red on base, green here (real core delivery, real history owner, SQLite session store; only the platform send function is mocked):
  - `extensions/telegram/src/approval-handler.runtime.test.ts` "records a DM approval prompt: another conversation's approval enters the approver chat once": base 0 rows, head exactly 1 row with the prompt. "…the requesting chat's approval stays with its own turn": 0 rows on both.
  - `extensions/signal/src/approval-handler.runtime.test.ts` "adds a prompt for another conversation's approval to the approver chat once": base 0 rows, head 1. "leaves a prompt in the requesting chat to that chat's own turn": 0 rows.
- Existing Telegram approval cases (topics, Direct Messages topics, fan-out, terminal edits, origin fallback) stay green; their send assertions now check the routed target (`telegram:<chat>:topic:<n>`), which the real sender resolves.
- Both test files moved to the `extension-database-workers` lane (forks pool), since history writes need the main-thread SQLite broker.
- Real Telegram (Test Server, source Gateway, deterministic mock model, real transport and history). The DM user first got READY, so the DM session (`agent:main:main`) existed. Then `gateway call agent {sessionKey: "agent:main:vcn-e2e"}` ran with no channel delivery; the mock made one `exec` call with a marker, and Telegram exec approvals (approver = the DM user, target DM, ask always) showed the prompt with Allow Once / Deny buttons in the DM. After that, the user asked "What did the approval prompt say?" The prompt was left unanswered.

  | Side | Prompts in the DM | DM history rows with marker | Follow-up model request contains marker |
  |---|---:|---:|---|
  | base `44fae6be5bcd` | 1 | 0 | no |
  | head `5462cde7ee6a` | 1 | 1 | yes |

  On base the user saw the approval prompt, but the DM agent had no record of it. On head the DM agent's next request includes it. This proves delivery and history inclusion, not visual rendering.

## Follow-ups (out of scope)

- Approval prompts on Discord, Slack, Matrix, WhatsApp, iMessage, Microsoft Teams and Google Chat still send directly; each needs its native presentation (components, blocks, cards, reactions) through core delivery.
- Matrix shared-DM context notice (`m.notice`; core delivery has no notice message type).
- Storing not-recorded reasons (schema); inbound accepted ⇒ transcript; failed-delivery history and overlap dedupe.

## Merge risk

Two-way door: a revert restores the direct sends. No stored format, schema or contract change. Blast radius: Telegram and Signal native approval prompt delivery (and Signal approval outcome messages).

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: signal Channel integration: signal channel: telegram Channel integration: telegram clawsweeper:intake:bug Preliminary submission classification; full source review pending. docs Improvements or additions to documentation impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. P2 Normal backlog priority with limited blast radius. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant