Skip to content

fix(gateway): suppress NO_REPLY lead fragment in chat final message - #39350

Closed
MumuTW wants to merge 2 commits into
openclaw:mainfrom
MumuTW:fix/no-reply-fragment-leak
Closed

MumuTW wants to merge 2 commits into
openclaw:mainfrom
MumuTW:fix/no-reply-fragment-leak

Conversation

@MumuTW

@MumuTW MumuTW commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix NO_REPLY partial fragment ("NO") leaking into webchat UI when the final chat event is emitted
  • The delta throttle correctly suppresses lead fragments via isSilentReplyLeadFragment, but the final message emission only checked isSilentReplyText (exact token match) — a partial buffer like "NO" passed through as a visible final message
  • Add isSilentReplyPrefixText check to the final message guard, which correctly distinguishes uppercase-only protocol fragments ("NO", "NO_") from legitimate short replies ("No", "No problem")

Closes #39335

Test plan

  • Added test: partial "NO" in buffer at lifecycle end → final message is undefined
  • Existing test: mixed-case "No" reply is preserved in final
  • Existing test: full "NO_REPLY" sequence → final suppressed
  • pnpm vitest run src/gateway/server-chat.agent-events.test.ts — 23/23 pass
  • pnpm vitest run src/auto-reply/tokens.test.ts — 19/19 pass

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Mar 8, 2026
@greptile-apps

greptile-apps Bot commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a narrow but visible bug: when NO_REPLY streaming is cut short at lifecycle end, the partial fragment "NO" could leak into the webchat UI as the final chat message. The root cause was that the final-message guard in emitChatFinal only checked isSilentReplyText (exact-token match), while the delta-throttle path already had isSilentReplyLeadFragment for prefix detection. The fix adds isSilentReplyPrefixText — a case-sensitive prefix check already used elsewhere in the codebase — to the final-message condition.

Key points:

  • The choice of isSilentReplyPrefixText over the locally-defined isSilentReplyLeadFragment is intentional and correct: isSilentReplyLeadFragment normalizes to uppercase before comparison, so it would also suppress a legitimate lowercase "No" reply in the final message. isSilentReplyPrefixText enforces that the text must already be fully uppercase, preserving "No" / "No problem" while still catching "NO" / "NO_".
  • A dedicated regression test is added that exercises the exact failure path (partial "NO" in buffer → payload.message is undefined).
  • The fix is consistent with how isSilentReplyPrefixText is used in agent.ts, streaming-directives.ts, agent-runner-execution.ts, and reply/typing.ts.

Confidence Score: 5/5

  • This PR is safe to merge — it is a targeted, well-tested single-line guard addition with no side effects on the happy path.
  • The change is minimal (one import, one boolean sub-expression), the fix is consistent with how isSilentReplyPrefixText is applied across the rest of the codebase, and a direct regression test covers the exact failure scenario. Existing tests for "No" preservation and full "NO_REPLY" suppression continue to pass, confirming no regression on adjacent cases.
  • No files require special attention.

Last reviewed commit: abc06b7

@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: 03fef49d31

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gateway/server-chat.ts Resolved

@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: 1722130381

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gateway/server-chat.ts Resolved
@MumuTW

MumuTW commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

Gentle ping on this NO_REPLY fragment suppression fix. Happy to update if needed.

@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 Apr 23, 2026
@clawsweeper

clawsweeper Bot commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open: the branch is a focused fix for a real Gateway finalization gap that current main still has, but it needs a rebase and real WebChat/Gateway proof before merge.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

Do we have a high-confidence way to reproduce the issue?

Yes, source inspection gives a high-confidence path: send an assistant event whose buffered text is NO_, then end the lifecycle; current finalization disables lead-fragment suppression and can emit that fragment. I did not run tests because this review is read-only.

Is this the best way to solve the issue?

Yes for the narrow underscore-bearing boundary: carrying lead-fragment provenance into final suppression is a maintainable fix that avoids dropping intentional uppercase NO replies. The branch still needs rebase and real behavior proof before it is merge-ready.

Security review:

Security review cleared: Security review cleared: the diff adds in-memory Gateway chat suppression state and tests, with no concrete supply-chain or secret-handling regression found.

What I checked:

  • stale F-rated PR: PR was opened 2026-03-08T01:37:58Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is missing and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • liuxiaopai-ai: Commit bf0653846e66 added the Gateway NO_REPLY lead-fragment suppression and the adjacent agent-event tests that this PR extends. (role: introduced current lead-fragment suppression behavior; confidence: high; commits: bf0653846e66; files: src/gateway/server-chat.ts, src/gateway/server-chat.agent-events.test.ts)
  • steipete: Commit 5f2273e81efc unified chat display projection into the current live-chat-projector.ts path used by finalization. (role: recent Gateway chat projection contributor; confidence: high; commits: 5f2273e81efc; files: src/gateway/live-chat-projector.ts, src/gateway/server-chat.ts)
  • Pinghuachiu: Commit 68630a9e6ddf added related Gateway suppression for announce/reply skip control tokens in the same display boundary. (role: adjacent control-token suppression contributor; confidence: medium; commits: 68630a9e6ddf; files: src/gateway/control-reply-text.ts, src/gateway/server-chat.agent-events.test.ts)
  • vincentkoc: They pushed the current narrow repair commit to this PR and have recent adjacent Gateway stream work, making them a practical follow-up owner for the rebase. (role: branch repair contributor and recent Gateway contributor; confidence: medium; commits: 2a5aec27ee69, 013939cfc7c2; files: src/gateway/server-chat.ts, src/gateway/server-chat-state.ts, src/gateway/live-chat-projector.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 9ff1a4371f68.

@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Apr 26, 2026
@vincentkoc

Copy link
Copy Markdown
Member

ProjectClownfish pushed a narrow repair to this branch so the original contributor path can stay canonical.

Source PR: #39350
Validation: pnpm -s vitest run src/gateway/server-chat.agent-events.test.ts; pnpm check:changed
Contributor credit is preserved in the branch history and PR context.

@aisle-research-bot

aisle-research-bot Bot commented Apr 27, 2026 •

Copy link
Copy Markdown

🔒 Aisle Security Analysis

We found 1 potential security issue(s) in this PR:

# Severity Title
1 🟡 Medium Cross-session state collision via user-controlled clientRunId in suppressedLeadFragmentRuns
1. 🟡 Cross-session state collision via user-controlled clientRunId in suppressedLeadFragmentRuns
Property Value
Severity Medium
CWE CWE-362
Location src/gateway/server-chat.ts:663-720

Description

suppressedLeadFragmentRuns is keyed by clientRunId and consulted to suppress output. However clientRunId is derived from p.idempotencyKey (a client-provided value) in server-methods/chat.ts.

This creates a cross-session/cross-tenant interference risk:

  • Input: clientRunId = p.idempotencyKey is user-controlled.
  • State: suppressedLeadFragmentRuns is a process-wide Set<string> keyed only by that ID.
  • Effect: If two users/sessions pick (or are forced into) the same idempotency key, suppression state can bleed across runs, causing incorrect UI behavior (silent suppression) and state integrity issues.

Vulnerable code (state keyed solely by clientRunId):

chatRunState.suppressedLeadFragmentRuns.add(clientRunId);
...
const shouldSuppressLeadFragment = chatRunState.suppressedLeadFragmentRuns.has(clientRunId);

Because the ID is not namespaced by sessionKey (or another authenticated/unique server-generated run identifier), collisions are possible and can be attacker-induced by choosing an idempotency key that matches another in-flight run.

Recommendation

Namespace suppression state by an authenticated/unique run identifier, not a client-supplied idempotency key.

Options:

  1. Key by (sessionKey, clientRunId) (preferred if clientRunId must remain client-supplied):
const key = `${sessionKey}:${clientRunId}`;
chatRunState.suppressedLeadFragmentRuns.add(key);
...
const shouldSuppressLeadFragment = chatRunState.suppressedLeadFragmentRuns.has(key);
  1. Use a server-generated unique run id for all internal maps/sets (and keep idempotencyKey only for dedupe), ensuring no cross-user collisions.

Also validate/normalize idempotencyKey (length/charset) and consider enforcing randomness/UUID format to reduce collision and abuse potential.


Analyzed PR: #39350 at commit 2a5aec2

Last updated on: 2026-04-27T22:47:51Z

@tetesh

tetesh commented May 13, 2026

Copy link
Copy Markdown

Up

@clawsweeper clawsweeper Bot added the P2 Normal backlog priority with limited blast radius. label May 16, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 16, 2026
@clawsweeper clawsweeper Bot added impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. and removed impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. labels May 17, 2026
@clawsweeper

clawsweeper Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@clawsweeper

clawsweeper Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] NO_REPLY fragment leaks to webchat UI

3 participants