Skip to content

feat(agents): suppressPreToolText config + onBlockReply buffering - #19932

Closed
Milofax wants to merge 3 commits into
openclaw:mainfrom
Milofax:feat/suppress-pre-tool-text
Closed

Milofax wants to merge 3 commits into
openclaw:mainfrom
Milofax:feat/suppress-pre-tool-text

Conversation

@Milofax

@Milofax Milofax commented Feb 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a suppressPreToolText option to agent defaults that discards intermediate assistant text from tool-use turns (e.g. "Let me check that for you...") before they reach the channel. This is useful for Discord bots where pre-tool narration creates noise.

Changes

Commit 1: fix(agents): batch announces + suppress pre-tool text

  • New agents.defaults.suppressPreToolText config option (boolean, default: false)
  • Config flows through AgentDefaultsConfig → RunEmbeddedPiAgentParams → SubscribeEmbeddedPiSessionParams → subscribe state
  • emitBlockChunk() skips text emission when suppressPreToolText is enabled and the turn contains tool use
  • handleMessageEnd() / finalizeAssistantTexts() properly handle the suppress flag
  • Includes collectMode for subagent announce batching (related improvement)

Commit 2: fix(agents): buffer onBlockReply during streaming

  • Introduces pendingBlockReplies buffer in the subscribe handler
  • When suppressPreToolText is enabled, block replies are buffered during streaming
  • On message_end, if the message contains tool use, buffered replies are discarded
  • If no tool use, buffered replies are flushed normally
  • Prevents partial text from leaking to Discord before we know if tools will be invoked

Config example

agents:
  defaults:
    suppressPreToolText: true

Testing

  • 12 tests in pi-embedded-subscribe.suppress-pre-tool-text.test.ts
  • 4 tests in zod-schema.agent-defaults.suppress-pre-tool-text.test.ts
  • All 16 tests pass

Greptile Summary

This PR adds a suppressPreToolText config option that buffers onBlockReply payloads during assistant message streaming and discards them if the message ends with a tool call (stopReason === "toolUse"). This prevents intermediate narration like "Let me check that for you..." from reaching Discord/messaging channels. Final-answer turns are flushed normally.

The implementation touches the full config-to-subscribe pipeline: AgentDefaultsConfig -> FollowupRun -> RunEmbeddedPiAgentParams -> SubscribeEmbeddedPiSessionParams -> subscribe state, which is clean and consistent.

A secondary change fixes collect-mode subagent announce batching to always queue (even when the parent agent is idle), and bumps the default announce debounce from 1s to 3s.

  • suppressPreToolText correctly buffers and discards intermediate text, with verbose-mode bypass for debugging
  • assistantTexts splice logic removes intermediate texts from the accumulated array on tool-use turns
  • pendingBlockReplies buffer is properly initialized, reset on message boundaries, and flushed/discarded at the end of handleMessageEnd
  • Collect-mode early-return in subagent-announce.ts omits announceId from the queue item, which may weaken idempotency dedup (see inline comment)
  • 16 new tests cover the feature comprehensively across splice logic, streaming buffering, verbose mode, and both blockReplyBreak modes

Confidence Score: 4/5

  • This PR is safe to merge with one minor idempotency concern in the collect-mode announce path.
  • The core suppressPreToolText feature is well-implemented with proper buffering, flushing, and state management. The config pipeline is complete and consistent. Tests are thorough (16 new tests). The one issue is the missing announceId in the collect-mode early-return path in subagent-announce.ts, which could allow duplicate announces in edge cases. The default debounce change from 1s to 3s is a behavior change but low-risk.
  • src/agents/subagent-announce.ts — missing announceId in collect-mode queue item may weaken idempotency deduplication

Last reviewed commit: cd2462d

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L labels Feb 18, 2026

@greptile-apps greptile-apps 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.

19 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +386 to +401
if (queueSettings.mode === "collect") {
const origin = resolveAnnounceOrigin(entry, params.requesterOrigin);
enqueueAnnounce({
key: canonicalKey,
item: {
prompt: params.triggerMessage,
summaryLine: params.summaryLine,
enqueuedAt: Date.now(),
sessionKey: canonicalKey,
origin,
},
settings: queueSettings,
send: sendAnnounce,
});
return "queued";
}

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.

Missing announceId in collect-mode queue item

The new collect-mode early-return path omits announceId from the enqueued item, while the existing followup/steer/interrupt path at line 412 includes it. Without announceId, resolveQueueAnnounceId falls back to a timestamp-based legacy key using Date.now(), which is non-deterministic. If the same announcement is processed twice (e.g., retry or race), the timestamp values may differ, producing different idempotency keys and potentially allowing duplicate announces through the gateway dedup cache.

Consider adding announceId: params.announceId to the item object, matching the pattern used at line 412.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/subagent-announce.ts
Line: 386-401

Comment:
**Missing `announceId` in collect-mode queue item**

The new collect-mode early-return path omits `announceId` from the enqueued item, while the existing followup/steer/interrupt path at line 412 includes it. Without `announceId`, `resolveQueueAnnounceId` falls back to a timestamp-based legacy key using `Date.now()`, which is non-deterministic. If the same announcement is processed twice (e.g., retry or race), the timestamp values may differ, producing different idempotency keys and potentially allowing duplicate announces through the gateway dedup cache.

Consider adding `announceId: params.announceId` to the item object, matching the pattern used at line 412.

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

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Feb 28, 2026
@Milofax

Milofax commented Mar 4, 2026

Copy link
Copy Markdown
Contributor Author

Still relevant — removing stale label. Will rebase if needed.

Milofax and others added 3 commits March 8, 2026 01:08
…Text

The splice in finalizeAssistantTexts() only removed entries from the
internal assistantTexts array — by that point emitBlockChunk() had
already fired onBlockReply() which sent text to Discord immediately.

Buffer onBlockReply payloads when suppressPreToolText is active, flush
on final answer (stopReason !== "toolUse"), discard on tool-use turns.
@hnykda

hnykda commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Yeah, I am running this, as it's super annoying

hnykda added a commit to hnykda/openclaw that referenced this pull request Mar 13, 2026
…enclaw#19932)

Buffer all onBlockReply payloads during each assistant turn; at message_end,
discard the buffer when stopReason === "toolUse" (tool-calling turn) or flush
it when stopReason === "stop" (final answer). Handles both text_end (streaming)
and message_end (non-streaming) delivery paths.

Adds EmbeddedPiSubscribeState.suppressPreToolText (enabled whenever onBlockReply
is registered) and pendingBlockReplies buffer. Both the outer emitBlockReplySafely
in subscribeEmbeddedPiSession (streaming/text_end path) and the local one in
handleMessageEnd (message_end path) buffer through pendingBlockReplies.

Regression test covers text_end mode (streaming), message_end mode, and
multiple intermediate turns all suppressed before a single final delivery.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
hnykda added a commit to hnykda/openclaw that referenced this pull request Mar 13, 2026
…scard (openclaw#19932)

The previous suppression fix buffered onBlockReply calls and discarded
them for toolUse turns — preventing intermediate text from being streamed
to Mattermost as separate messages. But the texts were already pushed to
state.assistantTexts in emitBlockChunk before the stopReason was known.
This meant they survived in the final reply payload (hasSentPayload
deduplication can't filter them because they never touched the pipeline).

Fix: capture preTurnAssistantTextBaseline at the start of handleMessageEnd
(before finalizeAssistantTexts updates it), and when discarding for
toolUse, splice assistantTexts back to that baseline and reset the
baseline. Adds a regression test verifying intermediate texts are absent
from assistantTexts after a toolUse turn.
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Mar 17, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added stale Marked as stale due to inactivity and removed stale Marked as stale due to inactivity labels Mar 23, 2026
hnykda added a commit to hnykda/openclaw that referenced this pull request Mar 25, 2026
…enclaw#19932)

Buffer all onBlockReply payloads during each assistant turn; at message_end,
discard the buffer when stopReason === "toolUse" (tool-calling turn) or flush
it when stopReason === "stop" (final answer). Handles both text_end (streaming)
and message_end (non-streaming) delivery paths.

Adds EmbeddedPiSubscribeState.suppressPreToolText (enabled whenever onBlockReply
is registered) and pendingBlockReplies buffer. Both the outer emitBlockReplySafely
in subscribeEmbeddedPiSession (streaming/text_end path) and the local one in
handleMessageEnd (message_end path) buffer through pendingBlockReplies.

Regression test covers text_end mode (streaming), message_end mode, and
multiple intermediate turns all suppressed before a single final delivery.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
hnykda added a commit to hnykda/openclaw that referenced this pull request Mar 25, 2026
…scard (openclaw#19932)

The previous suppression fix buffered onBlockReply calls and discarded
them for toolUse turns — preventing intermediate text from being streamed
to Mattermost as separate messages. But the texts were already pushed to
state.assistantTexts in emitBlockChunk before the stopReason was known.
This meant they survived in the final reply payload (hasSentPayload
deduplication can't filter them because they never touched the pipeline).

Fix: capture preTurnAssistantTextBaseline at the start of handleMessageEnd
(before finalizeAssistantTexts updates it), and when discarding for
toolUse, splice assistantTexts back to that baseline and reset the
baseline. Adds a regression test verifying intermediate texts are absent
from assistantTexts after a toolUse turn.
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Mar 30, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #pr-thunderdome-dangerzone on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

@openclaw-barnacle openclaw-barnacle Bot closed this Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: L stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants