Skip to content

feat(agents): add replyMode tool-only to suppress auto-delivery - #57914

Closed
qualiobra wants to merge 8 commits into
openclaw:mainfrom
qualiobra:feature/reply-mode-tool-only
Closed

qualiobra wants to merge 8 commits into
openclaw:mainfrom
qualiobra:feature/reply-mode-tool-only

Conversation

@qualiobra

Copy link
Copy Markdown

Summary

  • Problem: When an agent processes inbound messages in a shared-session setup (e.g., a single WhatsApp number serving multiple contacts), every text block the model produces gets auto-delivered as a separate message. This includes internal narration between tool calls, which leaks to end users.
  • Why it matters: In shared-session WhatsApp setups, plain-text auto-replies leak to unintended recipients. Prompt engineering alone cannot reliably prevent models from producing intermediate text. There is currently no gateway-level mechanism to suppress it.
  • What changed: Added a new replyMode option ("auto" | "tool-only") to agents.defaults. When set to "tool-only", auto-delivery of assistant text is suppressed at three enforcement points in dispatch-from-config.ts. Only explicit message tool sends reach the channel.
  • What did NOT change (scope boundary): No changes to the message tool itself, no changes to media delivery (media payloads are still delivered even in tool-only mode), no changes to any other dispatch paths (Telegram, Slack, Discord have their own dispatchers).

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Root Cause / Regression History (if applicable)

N/A — this is a new feature, not a regression fix.

Regression Test Plan (if applicable)

N/A — new feature. However, the enforcement is narrow enough that a unit test in dispatch-from-config.test.ts mocking cfg.agents.defaults.replyMode = "tool-only" and asserting that onToolResult / onBlockReply / final-reply-loop produce no outbound calls would be the appropriate coverage.

User-visible / Behavior Changes

  • New config option: agents.defaults.replyMode ("auto" | "tool-only", default "auto")
  • When set to "tool-only":
    • onToolResult: text-only payloads are suppressed (media payloads still delivered)
    • onBlockReply: all streaming blocks are suppressed
    • Final replies loop: iterates an empty array (no auto-delivery)
  • Default is "auto" — zero behavior change for existing users

Diagram (if applicable)

Before (auto):
[model text block] -> onBlockReply -> channel delivery (always)
[model final reply] -> replies loop -> channel delivery (always)

After (tool-only):
[model text block] -> onBlockReply -> SUPPRESSED
[model final reply] -> replies loop -> SUPPRESSED
[message tool send] -> web-outbound -> channel delivery (unchanged)
[media payload] -> onToolResult -> channel delivery (unchanged)

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: Windows 11
  • Runtime: Node.js v22.17.1
  • Model: anthropic/claude-opus-4-6
  • Integration: WhatsApp (Baileys)
  • Config: { "agents": { "defaults": { "replyMode": "tool-only" } } }

Steps

  1. Set agents.defaults.replyMode to "tool-only" in openclaw.json
  2. Restart gateway
  3. Send a message to the agent via WhatsApp
  4. Agent processes the message, uses message tool to reply

Expected

  • Only the explicit message tool sends reach WhatsApp
  • No intermediate narration text blocks are delivered

Actual

  • Confirmed: only message tool sends are delivered. Zero narration leakage.

Evidence

  • Running in production on a WhatsApp shared-session setup since 2026-02-09 (fork patch)
  • Zero narration leaks since enabling replyMode: "tool-only"
  • Before this patch: 5-7 spurious messages per turn (narration, tool errors, internal reasoning)

Human Verification (required)

  • Verified scenarios: WhatsApp DM with single shared session, multiple contacts. Agent uses message tool for all outbound. No auto-delivered text blocks.
  • Edge cases checked: media payloads (images, audio) still auto-deliver correctly in tool-only mode. TTS payloads via message tool work. Reasoning payloads (already suppressed by existing guard) remain suppressed.
  • What I did NOT verify: Telegram, Discord, Slack dispatch paths (they use their own dispatchers, not this code path). Test suite not run (pre-existing upstream CI failures in tsgo unrelated to this change).

AI Disclosure

  • This PR is AI-assisted (Claude Opus 4.6 via OpenClaw agent)
  • Fully tested in production for 7+ weeks
  • I understand what the code does
  • Codex review not available (contributor, not maintainer)

Review Conversations

  • I will reply to or resolve every bot review conversation addressed in this PR.
  • I will leave unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? New optional config key agents.defaults.replyMode (default "auto")
  • Migration needed? No

Risks and Mitigations

  • Risk: User sets "tool-only" but agent prompt does not include message tool instructions, resulting in silent agent.
    • Mitigation: Default is "auto" (zero behavior change). Documentation should note that "tool-only" requires the agent to use the message tool explicitly.

Adds a new replyMode option to agent defaults that suppresses
automatic text delivery (block replies, streaming, and final replies).
Only explicit message tool sends are delivered.

Use case: shared-session setups (e.g. single WhatsApp number) where
plain-text auto-replies could leak to unintended recipients.

Three enforcement points in dispatch-from-config.ts:
- onToolResult: skip text-only payloads (media still delivered)
- onBlockReply: skip all streaming blocks
- final replies loop: iterate empty array in tool-only mode

Closes #32884
Closes #50207
@qualiobra

Copy link
Copy Markdown
Author

Related Issues

This PR addresses the core problem described across several open issues:

How this PR relates

This implements what #25592 commenters called Option 3 (explicit send semantics) — the agent's bare text output is suppressed when
eplyMode: "tool-only"\ is set, and only explicit \message\ tool sends reach the channel.

It's been running in production on a WhatsApp shared-session setup since February 9, 2026 — zero narration leaks across 7+ weeks of daily use with Claude Opus 4.6.

What this does NOT solve

@greptile-apps

greptile-apps Bot commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces a new agents.defaults.replyMode config option ("auto" | "tool-only") that suppresses auto-delivery of assistant text blocks in shared-session setups (e.g. a single WhatsApp number serving multiple contacts), allowing only explicit message tool sends to reach the channel.

Key changes:

  • dispatch-from-config.ts: Three enforcement points added — onToolResult (text-only payloads suppressed, media preserved), onBlockReply (all streaming blocks suppressed), and the final-replies loop (replaced with empty iteration when tool-only)
  • types.agent-defaults.ts: New optional replyMode field with thorough JSDoc
  • zod-schema.agent-defaults.ts: New schema entry with .optional().default("auto")

Findings:

  • The dispatch logic is architecturally sound. The message tool delivers text via runMessageAction (web-outbound), not through onToolResult or onBlockReply, so it is correctly unaffected by the guards.
  • There is a minor type inconsistency: the Zod schema uses .optional().default("auto") (output is always "auto" | "tool-only"), while the TypeScript interface declares replyMode?: "auto" | "tool-only" (allows undefined). Every other comparable field in this schema uses only .optional() without a .default(). The inconsistency is harmless at runtime due to the ?? "auto" fallbacks, but it diverges from established patterns and may cause confusion for future readers.

Confidence Score: 5/5

  • Safe to merge — the change is backward-compatible, defaults are preserved, and the sole finding is a minor schema/type inconsistency with no runtime impact.
  • The only issue found is a P2 style inconsistency in the Zod schema (.optional().default("auto") vs. .optional() used by all comparable fields, and the resulting mismatch with the hand-written TypeScript type). There are no P0 or P1 issues. The core logic correctly avoids suppressing explicit message tool sends, media payloads pass through as documented, and the default "auto" value guarantees zero behavior change for existing users.
  • src/config/zod-schema.agent-defaults.ts — minor .default("auto") inconsistency relative to the rest of the schema.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/config/zod-schema.agent-defaults.ts
Line: 168

Comment:
**Zod schema type inconsistency with TypeScript declaration**

`.optional().default("auto")` changes the Zod output type to `"auto" | "tool-only"` (never `undefined`), but `AgentDefaultsConfig` in `types.agent-defaults.ts` declares the field as `replyMode?: "auto" | "tool-only"` (optionally `undefined`). This creates a mismatch between the Zod-inferred type and the hand-written TypeScript type.

Every other similar optional field in this schema (e.g. `verboseDefault`, `elevatedDefault`, `blockStreamingDefault`) uses just `.optional()` with no `.default()`. The inconsistency means:
- Code reading from a Zod-parsed config can assume `replyMode` is always `"auto"` or `"tool-only"`, yet the TypeScript type says it may be `undefined`.
- The `?? "auto"` fallbacks in `dispatch-from-config.ts` become redundant (though harmless) after Zod parsing.

To stay consistent with the rest of the schema, either drop `.default("auto")`:

```suggestion
    replyMode: z.enum(["auto", "tool-only"]).optional(),
```

…and keep the `?? "auto"` guards in `dispatch-from-config.ts` as-is, OR keep `.default("auto")` and remove the `?` from the TypeScript type declaration in `types.agent-defaults.ts` so both agree that the field is always present after parsing.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "feat(agents): add replyMode tool-only to..." | Re-trigger Greptile

Comment thread src/config/zod-schema.agent-defaults.ts Outdated
elevatedDefault: z
.union([z.literal("off"), z.literal("on"), z.literal("ask"), z.literal("full")])
.optional(),
replyMode: z.enum(["auto", "tool-only"]).optional().default("auto"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Zod schema type inconsistency with TypeScript declaration

.optional().default("auto") changes the Zod output type to "auto" | "tool-only" (never undefined), but AgentDefaultsConfig in types.agent-defaults.ts declares the field as replyMode?: "auto" | "tool-only" (optionally undefined). This creates a mismatch between the Zod-inferred type and the hand-written TypeScript type.

Every other similar optional field in this schema (e.g. verboseDefault, elevatedDefault, blockStreamingDefault) uses just .optional() with no .default(). The inconsistency means:

  • Code reading from a Zod-parsed config can assume replyMode is always "auto" or "tool-only", yet the TypeScript type says it may be undefined.
  • The ?? "auto" fallbacks in dispatch-from-config.ts become redundant (though harmless) after Zod parsing.

To stay consistent with the rest of the schema, either drop .default("auto"):

Suggested change
replyMode: z.enum(["auto", "tool-only"]).optional().default("auto"),
replyMode: z.enum(["auto", "tool-only"]).optional(),

…and keep the ?? "auto" guards in dispatch-from-config.ts as-is, OR keep .default("auto") and remove the ? from the TypeScript type declaration in types.agent-defaults.ts so both agree that the field is always present after parsing.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/config/zod-schema.agent-defaults.ts
Line: 168

Comment:
**Zod schema type inconsistency with TypeScript declaration**

`.optional().default("auto")` changes the Zod output type to `"auto" | "tool-only"` (never `undefined`), but `AgentDefaultsConfig` in `types.agent-defaults.ts` declares the field as `replyMode?: "auto" | "tool-only"` (optionally `undefined`). This creates a mismatch between the Zod-inferred type and the hand-written TypeScript type.

Every other similar optional field in this schema (e.g. `verboseDefault`, `elevatedDefault`, `blockStreamingDefault`) uses just `.optional()` with no `.default()`. The inconsistency means:
- Code reading from a Zod-parsed config can assume `replyMode` is always `"auto"` or `"tool-only"`, yet the TypeScript type says it may be `undefined`.
- The `?? "auto"` fallbacks in `dispatch-from-config.ts` become redundant (though harmless) after Zod parsing.

To stay consistent with the rest of the schema, either drop `.default("auto")`:

```suggestion
    replyMode: z.enum(["auto", "tool-only"]).optional(),
```

…and keep the `?? "auto"` guards in `dispatch-from-config.ts` as-is, OR keep `.default("auto")` and remove the `?` from the TypeScript type declaration in `types.agent-defaults.ts` so both agree that the field is always present after parsing.

How can I resolve this? If you propose a fix, please make it concise.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c87b7d3460

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +670 to +671
if ((cfg.agents?.defaults?.replyMode ?? "auto") === "tool-only" && !hasMedia) {
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Allow exec-approval payloads through tool-only gate

When agents.defaults.replyMode is set to "tool-only", this early return suppresses every non-media onToolResult payload before resolveToolDeliveryPayload runs, which bypasses the existing channelData.execApproval exception path. In approval-required flows, the pending-approval prompt is text/interactive without media, so users never receive the approval message and cannot approve/deny the command, leaving those tool runs blocked.

Useful? React with 👍 / 👎.

Addresses Greptile review: every other optional field in the schema
uses just .optional() without .default(). The ?? 'auto' fallbacks in
dispatch-from-config.ts already handle the undefined case correctly.
@qualiobra

Copy link
Copy Markdown
Author

Good catch on the .default("auto") inconsistency. Fixed in 2993dba — dropped .default("auto") to match the pattern used by all other optional fields in the schema (verboseDefault, elevatedDefault, blockStreamingDefault, etc.). The ?? "auto" fallbacks in dispatch-from-config.ts handle the undefined case correctly.

When replyMode is tool-only, the early return in onToolResult suppresses
every non-media payload before resolveToolDeliveryPayload runs. This
bypasses the existing channelData.execApproval exception path, so users
never receive exec approval prompts and commands stay blocked forever.

Fix: check for execApproval in channelData before suppressing, same
pattern already used downstream in resolveToolDeliveryPayload.

Addresses review feedback on PR #57914.
@qualiobra

Copy link
Copy Markdown
Author

Fixed in 86eee89 — exec-approval payloads now pass through the tool-only gate.

The onToolResult handler now checks for payload.channelData.execApproval before suppressing delivery. This uses the same pattern already present downstream in resolveToolDeliveryPayload.

What changed:

  • Added isExecApproval check that mirrors the existing logic at line ~634
  • Guard is now: tool-only && !hasMedia && !isExecApproval
  • Exec approval prompts are delivered normally even in tool-only mode
  • All other text-only payloads remain suppressed as intended

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86eee89012

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +677 to +678
if ((cfg.agents?.defaults?.replyMode ?? "auto") === "tool-only" && !hasMedia && !isExecApproval) {
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Permit exec-unavailable prompts in tool-only mode

This guard drops all text-only tool results in tool-only mode unless channelData.execApproval is present, which unintentionally suppresses exec-approval unavailable notifications emitted by buildExecApprovalUnavailableReplyPayload (those payloads are text-only). In approval-required environments where no approval route exists (or only approver DMs were sent), users now receive no explanation and command attempts appear to fail silently, which breaks command UX and troubleshooting.

Useful? React with 👍 / 👎.

@qualiobra

Copy link
Copy Markdown
Author

Update: The exec-approval-unavailable payload issue flagged in review has been addressed in a separate upstream PR: #60445

That PR adds channelData.execApprovalUnavailable to all return paths of buildExecApprovalUnavailableReplyPayload and updates resolveToolDeliveryPayload to recognize it.

Once #60445 is merged, this PR's tool-only gate (onToolResult) should be updated to also check for execApprovalUnavailable alongside execApproval. The updated gate would be:

const cd =
  payload.channelData &&
  typeof payload.channelData === "object" &&
  !Array.isArray(payload.channelData)
    ? payload.channelData
    : undefined;
const isExecApprovalPayload =
  (cd?.execApproval && typeof cd.execApproval === "object") ||
  (cd?.execApprovalUnavailable && typeof cd.execApprovalUnavailable === "object");
if ((cfg.agents?.defaults?.replyMode ?? "auto") === "tool-only" && !hasMedia && !isExecApprovalPayload) {
  return;
}

This keeps the two PRs independent and mergeable in any order.

Update the tool-only replyMode gate to also pass through payloads
with channelData.execApprovalUnavailable, matching the marker added
in #60445. Without this, approval-unavailable notifications are
silently dropped in tool-only mode, causing a total blackout.

Co-authored-by: Aurora <[email protected]>
@qualiobra

Copy link
Copy Markdown
Author

Updated the tool-only gate to recognize channelData.execApprovalUnavailable (the marker added in #60445).

The gate now checks for both execApproval and execApprovalUnavailable before suppressing a payload, preventing the total blackout scenario where approval-unavailable notifications were silently dropped.

@qualiobra

Copy link
Copy Markdown
Author

Addressed review feedback:

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d170ba1e2e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +774 to +778
const isToolOnlyMode = (cfg.agents?.defaults?.replyMode ?? "auto") === "tool-only";

let queuedFinal = false;
let routedFinalCount = 0;
for (const reply of replies) {
for (const reply of isToolOnlyMode ? [] : replies) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enforce tool-only mode before ACP dispatch

replyMode: "tool-only" is only applied in the non-ACP delivery loop (isToolOnlyMode ? [] : replies), but tryDispatchAcpReply(...) can return earlier in the same function; in ACP-enabled sessions this bypasses all new suppression logic and still delivers projected block/final text. That means users who enable tool-only mode to prevent narration leakage in shared sessions will still leak assistant text whenever the turn is handled by ACP.

Useful? React with 👍 / 👎.

tryDispatchAcpReply runs before the tool-only gates, so ACP-enabled
sessions bypass all replyMode suppression. This adds replyMode
awareness to the ACP delivery coordinator:

- Filter in deliver(): suppress block payloads and text-only final
  payloads when replyMode is tool-only, while allowing tool summaries,
  media, and error payloads through
- Guard identity notices emission in tool-only mode
- Guard finalizeAcpTurnOutput to prevent wasted TTS synthesis
- Pass replyMode to both main and tail ACP dispatch calls
- Fix missing suppressUserDelivery in tail dispatch (pre-existing bug)

Co-authored-by: Aurora <[email protected]>
@qualiobra

Copy link
Copy Markdown
Author

New commit: enforce tool-only mode in ACP dispatch path

Addresses Codex review finding: tryDispatchAcpReply ran before the tool-only gates, so ACP-enabled sessions bypassed all replyMode suppression.

What changed (3 files, +33 lines, 6 new tests):

  1. dispatch-acp-delivery.ts — added replyMode param to createAcpDispatchDeliveryCoordinator. Filter in deliver():

    • Suppresses block payloads in tool-only mode
    • Suppresses text-only final payloads (no media, not error)
    • Allows tool summaries, media-bearing finals, and error finals through
  2. dispatch-acp.ts — threaded replyMode through:

    • Identity notice emission gated off in tool-only
    • finalizeAcpTurnOutput early-returns in tool-only (prevents wasted TTS synthesis)
  3. dispatch-from-config.ts — passes replyMode to both ACP dispatch call sites. Also fixes pre-existing bug: tail dispatch was missing suppressUserDelivery.

Tests: 6 new test cases covering the tool-only filter matrix (block suppressed, tool delivered, text-only final suppressed, media final delivered, error final delivered, auto mode preserved).

AI-assisted (Aurora + Claude Opus 4.6). Adversarial review completed (2 rounds, GPT 5.4).

@qualiobra

Copy link
Copy Markdown
Author

All review conversations addressed

Bot Finding Status Fix
Greptile P2 Zod schema .default("auto") inconsistency ✅ Fixed Commit ced82ce — removed .default()
Codex P1 exec-approval payloads blocked by tool-only gate ✅ Fixed Commit 6bebe23 — checks both execApproval and execApprovalUnavailable
Codex P1 exec-unavailable prompts blocked ✅ Fixed Same commit + upstream PR #60445 adds the marker
Codex P1 ACP dispatch bypasses tool-only ✅ Fixed Commit 5f0255a — replyMode threaded through ACP path, 6 new tests

All findings have been addressed. Resolving these review conversations.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f0255a7ab

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +196 to +200
if (params.replyMode === "tool-only") {
if (kind === "block") {
return false;
}
if (kind === "final") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Suppress ACP tool summaries in tool-only mode

When agents.defaults.replyMode is "tool-only", this guard suppresses only block and text-only final payloads, so all kind === "tool" payloads still get delivered. In ACP flows, createAcpReplyProjector emits status/tool-call summary text through deliver("tool", ...), so ACP-enabled sessions continue auto-sending generated narration/status text instead of only explicit message tool sends. This leaks text in the exact shared-session scenario tool-only is meant to protect.

Useful? React with 👍 / 👎.

ACP projector emits status narration and tool call summaries via
deliver("tool", ...). These are auto-generated text that should be
suppressed in tool-only mode, not real tool execution results.

Addresses Codex P1 review finding on PR #57914.

Co-authored-by: Aurora <[email protected]>
@qualiobra

Copy link
Copy Markdown
Author

Fixed in latest push — ACP tool summaries now suppressed in tool-only mode.

The deliver() filter in createAcpDispatchDeliveryCoordinator now also suppresses kind === "tool" payloads when replyMode === "tool-only". ACP tool deliveries are auto-generated narration/status text (tool call summaries, status updates), not real tool results — they don't contain exec-approval or media.

Test added verifying the suppression + orthogonality with shouldSendToolSummaries.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 518d5e80bd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

let queuedFinal = false;
let routedFinalCount = 0;
for (const reply of replies) {
for (const reply of isToolOnlyMode ? [] : replies) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Deliver media/error finals in tool-only mode

When agents.defaults.replyMode is "tool-only", this loop is forced to iterate over [], so all non-ACP final replies are skipped before sendFinalPayload runs. That unintentionally drops legitimate final payloads that carry mediaUrl/mediaUrls or isError (for example media directives or user-facing failure messages produced by the normal getReplyFromConfig path), so users can get a silent turn instead of the expected media/error output; ACP delivery already has explicit media/error exceptions, so this creates an inconsistent regression specific to the non-ACP path.

Useful? React with 👍 / 👎.

@qualiobra

Copy link
Copy Markdown
Author

Selective final replies filter for tool-only mode

Pushed 9fe3a83 — addresses the Codex review finding about the too-narrow predicate.

What changed

  1. New shared helper src/auto-reply/reply/tool-only-filter.ts — isNonTextVisibleFinal() predicate that returns true when a payload carries media, error, interactive blocks, or channelData.

  2. Non-ACP path (dispatch-from-config.ts) — replaced the blanket isToolOnlyMode ? [] : replies skip with a selective continue using the shared helper. Text-only finals are suppressed; everything else passes through.

  3. ACP path (dispatch-acp-delivery.ts) — replaced the inline hasMedia || isError check with isNonTextVisibleFinal(payload), adding coverage for interactive blocks and channelData.

  4. Tests — 12 unit tests for the predicate + 2 new integration tests in the ACP delivery suite (interactive-only and channelData-only finals in tool-only mode).

Why

The previous filter was too narrow in both paths:

  • Non-ACP: skipped ALL finals (including media/error/interactive/channelData)
  • ACP: only allowed media and error finals through

Interactive-only finals (buttons/selects without text) and channelData-only finals (channel-specific rich content) are legitimate user-visible output that should not be suppressed.

Co-authored-by: Aurora [email protected]

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9fe3a83dfa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@@ -165,6 +165,7 @@ export const AgentDefaultsSchema = z
elevatedDefault: z
.union([z.literal("off"), z.literal("on"), z.literal("ask"), z.literal("full")])
.optional(),
replyMode: z.enum(["auto", "tool-only"]).optional(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Regenerate config baseline after adding replyMode schema key

This schema addition changes the public config surface, but the generated baseline artifacts were not updated in the same commit. As a result, the config drift gate (pnpm config:docs:check, used in workflow sanity checks) will detect docs/.generated/config-baseline.json / .jsonl drift and fail until those files are regenerated and committed alongside the schema change.

Useful? React with 👍 / 👎.

Replace the blanket isToolOnlyMode ? [] : replies skip with a
selective filter using a shared isNonTextVisibleFinal() helper.
Text-only finals are suppressed while media, error, interactive,
and channelData finals pass through.

Applied to both non-ACP and ACP delivery paths for consistency.

Addresses Codex review finding on PR #57914.

Co-authored-by: Aurora <[email protected]>
@qualiobra
qualiobra force-pushed the feature/reply-mode-tool-only branch from 9fe3a83 to c8d92eb Compare April 3, 2026 22:02

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c8d92eb33d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +680 to +684
(cd?.execApproval && typeof cd.execApproval === "object") ||
(cd?.execApprovalUnavailable && typeof cd.execApprovalUnavailable === "object");
if (
(cfg.agents?.defaults?.replyMode ?? "auto") === "tool-only" &&
!hasMedia &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Allow exec-unavailable text payloads in tool-only mode

In tool-only mode this guard only exempts tool results with media or channelData.execApproval*, so plain-text exec-approval-unavailable notices are still dropped and the user gets no feedback when a command requires approval but no approval route is available. Fresh evidence: emitToolResultOutput calls onToolResult(buildExecApprovalUnavailableReplyPayload(...)), and buildExecApprovalUnavailableReplyPayload returns text-only payloads (no channelData), so isExecApprovalPayload is false and the early return suppresses the message.

Useful? React with 👍 / 👎.

@qualiobra

Copy link
Copy Markdown
Author

Addressing latest Codex review findings

P2 — Config baseline drift: Will regenerate docs/.generated/config-baseline.* with the new replyMode schema key.

P1 — exec-unavailable text payloads: This is already addressed by the companion PR #60445, which adds channelData.execApprovalUnavailable to those payloads. This PR's gate (commit 6bebe23) recognizes that marker. The two PRs work together — without #60445's marker, yes, the payload would be text-only and suppressed. That's by design: #60445 is the prerequisite.

TTS finding from our own adversarial review: Suppressing TTS synthesis of text-only finals in tool-only mode is intentional behavior. TTS audio is the same information as text — if text leaks to the wrong recipient, audio would too. The message tool handles explicit audio delivery to the correct recipient.

sweetpi pushed a commit to sweetpi/openclaw that referenced this pull request Apr 5, 2026
ericyoshida pushed a commit to ventopayai/openclaw that referenced this pull request Apr 23, 2026
When replyMode is tool-only, the early return in onToolResult suppresses
every non-media payload before resolveToolDeliveryPayload runs. This
bypasses the existing channelData.execApproval exception path, so users
never receive exec approval prompts and commands stay blocked forever.

Fix: check for execApproval in channelData before suppressing, same
pattern already used downstream in resolveToolDeliveryPayload.

Addresses review feedback on PR openclaw#57914.
ericyoshida added a commit to ventopayai/openclaw that referenced this pull request Apr 23, 2026
…port

feat(agents): backport replyMode "tool-only" from upstream openclaw#57914
@clawsweeper

clawsweeper Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

Current main already covers the PR’s intended safe-delivery behavior through the shipped source-delivery/send-policy path instead of a new agents.defaults.replyMode field. Direct/shared-session setups can suppress automatic source delivery while the agent still processes the turn and explicit message tool sends remain available; group/channel rooms also default to message-tool-only visible replies.

Best possible solution:

Close this PR as implemented by the existing source-delivery controls. Keep the current session.sendPolicy and sourceReplyDeliveryMode path as the single core mechanism, and handle any remaining UX/docs polish as targeted follow-up rather than adding a parallel agents.defaults.replyMode config surface.

What I checked:

  • Automatic delivery suppression is resolved before all reply paths: dispatchReplyFromConfig resolves sendPolicy and sourceReplyPolicy before plugin binding, fast abort, hook dispatch, normal block/tool/final delivery, with an inline note that automatic replies/notices/indicators are blocked while explicit message tool sends remain available. (src/auto-reply/reply/dispatch-from-config.ts:579, f256eeba431b)
  • Direct chats can be put into message-tool-only behavior via policy: resolveSourceReplyVisibilityPolicy supports an explicit message_tool_only request for direct chats, and sendPolicy can deny automatic delivery independently of agent processing. (src/auto-reply/reply/source-reply-delivery-mode.ts:38, f256eeba431b)
  • Tests cover the observable behavior requested by the PR: The dispatch tests verify that sendPolicy: deny still calls the reply resolver while suppressing final, tool-result, and block deliveries, and separately verify sourceReplyDeliveryMode: "message_tool_only" keeps source delivery private while processing continues. (src/auto-reply/reply/dispatch-from-config.test.ts:3897, f256eeba431b)
  • Public config/docs expose the shipped controls: Docs show session.sendPolicy rules by channel/chat type for direct/group/channel sessions, and group/channel rooms default to messages.groupChat.visibleReplies: "message_tool", requiring message(action=send) for visible room output. Public docs: docs/gateway/config-agents.md. (docs/gateway/config-agents.md:1170, f256eeba431b)
  • Release history records the implementation path: The changelog says sendPolicy: "deny" no longer blocks inbound processing and suppresses outbound delivery for observer-style setups in v2026.4.14; it also records the later group/channel message-tool default in the v2026.4.27 notes. (CHANGELOG.md:1954, f256eeba431b)
  • Security/supply-chain pass: The provided PR file list only touches reply dispatch/config TypeScript and tests. It does not add workflows, dependencies, lockfile changes, install scripts, downloaded artifacts, package publishing metadata, or secret-handling changes. (c8d92eb33ddf)

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Codex review notes: model gpt-5.5, reasoning high; reviewed against f256eeba431b; fix evidence: release v2026.4.14, commit f256eeba431b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant