Skip to content

fix(slack): prevent duplicate system event rendering#95445

Closed
moguangyu5-design wants to merge 1 commit into
openclaw:mainfrom
moguangyu5-design:fix/95323-slack-system-event-duplication
Closed

fix(slack): prevent duplicate system event rendering#95445
moguangyu5-design wants to merge 1 commit into
openclaw:mainfrom
moguangyu5-design:fix/95323-slack-system-event-duplication

Conversation

@moguangyu5-design

@moguangyu5-design moguangyu5-design commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

系统事件块在prompt中出现重复,导致Slack会话上下文膨胀和token浪费。同一turn内多次调用rebuildPromptBodies时,闭包外部的drainedSystemEventBlocks数组会累积之前的内容,造成重复渲染。

Evidence

Verifiable Behavior

[pnpm test] passed 1 Vitest shard in 23.39s
[session.test.ts] Tests 114 passed (114)
[get-reply-run.media-only.test.ts] Tests 82 passed (82)

Technical Evidence

  • Before: drainedSystemEventBlocks在闭包外部声明,跨调用累积
  • After: 移至函数内部,每次调用创建独立数组
  • Files Changed: src/auto-reply/reply/get-reply-run.ts (2 line moves)

Regression Risk

  • Low: 仅改变变量作用域,无API或数据模型变更
  • 所有相关测试通过,无broken imports或type errors
  • 完全向后兼容,可安全回滚

Why This Change Was Made

修复闭包作用域错误,确保每次prompt重建时系统事件列表是新鲜的,不携带历史累积。

User Impact

  • 减少prompt冗余,提高token使用效率
  • 防止因重复系统事件导致的上下文混乱
  • 无配置或操作变更,零用户学习成本

@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jun 21, 2026
@clawsweeper

clawsweeper Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

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

Close as superseded: the linked Slack duplicate-render issue is already owned by a viable runtime-context/modelPrompt fix, while this branch targets the drain accumulator and can drop one-shot system-event context during prompt refresh.

Root-cause cluster
Relationship: superseded
Canonical: #95349
Summary: This PR and the canonical candidate target the same linked Slack duplicate system-event report, but the canonical PR fixes the runtime-context/modelPrompt split while this PR changes the drain accumulator.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Close this branch in favor of reviewing and landing or declining #95349, then let the linked Slack duplicate-render issue close from that runtime-context/modelPrompt fix if it lands.

So I’m closing this here and keeping the remaining discussion on #95349.

Review details

Best possible solution:

Close this branch in favor of reviewing and landing or declining #95349, then let the linked Slack duplicate-render issue close from that runtime-context/modelPrompt fix if it lands.

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

Do we have a high-confidence way to reproduce the issue? Medium: the linked issue now includes a live 2026.6.10 Slack DM repro, and source inspection maps the duplicate render path, but I did not run a live Slack provider-payload capture in this read-only review.

Is this the best way to solve the issue?

Is this the best way to solve the issue? No. This PR changes the one-shot drain accumulator, while the narrow maintainable fix belongs at the runtime-context/modelPrompt split where the extracted event remains in the model-facing prompt.

Security review:

Security review cleared: The diff only changes prompt assembly variable scope and adds a comment-only test file; it does not touch secrets, dependencies, workflows, package metadata, or code-execution surfaces.

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy applied: Root and scoped agent-runner review guidance were read; the prompt/runtime-context path required a whole-path best-fix review instead of a diff-only verdict. (AGENTS.md:10, 78f7de01c1aa)
  • PR changes the accumulator layer: The PR moves drainedSystemEventBlocks inside rebuildPromptBodies; it does not change the downstream runtime-context/modelPrompt split where the duplicate label remains on current main. (src/auto-reply/reply/get-reply-run.ts:816, 0c749d9a6e09)
  • Current main preserves drained events across rebuilds: Current main keeps drainedSystemEventBlocks outside the rebuild helper and passes that same array into buildReplyPromptEnvelope, preserving events drained before a later rebuild. (src/auto-reply/reply/get-reply-run.ts:812, 78f7de01c1aa)
  • Refresh can rebuild after the first drain: Active run queue handling waits for the active run, then calls refreshPreparedState, which calls rebuildPromptBodies a second time before continuing the turn. (src/auto-reply/reply/get-reply-run.ts:1184, 78f7de01c1aa)
  • System-event drain is one-shot: drainFormattedSystemEvents consumes selected queued entries via consumeSelectedSystemEventEntries, so a later helper-local accumulator cannot recover the first call's consumed event block. (src/auto-reply/reply/session-system-events.ts:114, 78f7de01c1aa)
  • Current duplicate path is downstream: On current main, resolveRuntimeContextPromptParts extracts hidden runtime context but still returns modelPromptText unchanged when it differs from the visible prompt, matching the duplicate render path described by the linked issue. (src/agents/embedded-agent-runner/run/runtime-context-prompt.ts:137, 78f7de01c1aa)

Likely related people:

  • vincentkoc: Recent GitHub path history for runtime-context-prompt.ts shows multiple runtime-context helper maintenance commits near the affected splitter. (role: recent runtime-context contributor; confidence: high; commits: 7b9ddbda997a, 2a93d7b9c53f, e15dadec6451; files: src/agents/embedded-agent-runner/run/runtime-context-prompt.ts)
  • Alix-007: Commit history shows fix(agents): keep hook context prompt-local added the before-prompt-build model/transcript split behavior that the canonical fix repairs for system-event prefixes. (role: introduced hook prompt-local behavior; confidence: high; commits: 8b7a4826a1ff; files: src/agents/embedded-agent-runner/run/attempt.ts, src/agents/embedded-agent-runner/run/runtime-context-prompt.ts)
  • steipete: Recent history shows repeated Slack inbound context and prompt-prelude work adjacent to the system-event pipeline. (role: adjacent prompt and Slack context contributor; confidence: medium; commits: 1507a9701b83, efd1a9ace6f5, d7e24e024fc6; files: extensions/slack/src/monitor/message-handler/prepare.ts, src/auto-reply/reply/prompt-prelude.ts)
  • hugenshen: Authored the merged Slack/Teams preview-removal PR that the linked issue distinguishes from the remaining label-only double-render problem. (role: adjacent prior fix author; confidence: medium; commits: 47545e04c4bd; files: extensions/slack/src/monitor/message-handler/prepare.ts, extensions/msteams/src/monitor-handler/message-handler.ts)
  • joshavant: Recent live path history for get-reply-run.ts includes active-session rollover work touching the same reply-run surface where this PR changes accumulator scope. (role: recent auto-reply area contributor; confidence: medium; commits: 6f1076351cbe; files: src/auto-reply/reply/get-reply-run.ts)

Codex review notes: model internal, reasoning high; reviewed against 78f7de01c1aa.

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jun 21, 2026
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jun 21, 2026
Move drainedSystemEventBlocks declaration inside rebuildPromptBodies to
ensure each call creates an independent array. Previously the array was
declared in the outer scope, causing system events to accumulate across
multiple rebuildPromptBodies calls within the same turn, leading to
duplicate system event rendering in prompts.

Fixes openclaw#95323

Co-Authored-By: Claude Sonnet 4.6 <noreply.anthropic.com>
@moguangyu5-design
moguangyu5-design force-pushed the fix/95323-slack-system-event-duplication branch from cba0a80 to 0c749d9 Compare June 25, 2026 01:15
@clawsweeper clawsweeper Bot added status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 25, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. labels Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant