Skip to content

fix(channels): collapse cumulative commentary snapshots onto one line - #116272

Merged
obviyus merged 3 commits into
mainfrom
fix/commentary-cumulative-snapshots
Jul 30, 2026
Merged

obviyus merged 3 commits into
mainfrom
fix/commentary-cumulative-snapshots

Conversation

@obviyus

@obviyus obviyus commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

With streaming.progress.commentary enabled, a single model preamble rendered as three overlapping 💬 lines in the Telegram draft. Recorded live before this change:

Working
💬 Checking the workspace before answering.
💬 Checking the workspace before answering.Checking the
💬 Checking the workspace before answering.Checki

Providers stream commentary as cumulative snapshots. The draft line id was derived from the commentary text itself (commentary:${normalized}), so every snapshot minted a new id and mergeChannelProgressDraftLine appended another line instead of replacing the previous one.

A second defect made the first one invisible on the default path: resolveChannelStreamingProgressCommentary guessed "partial" when streaming.mode was unset. Since Telegram's default became progress, progress.commentary: true was a silent no-op — the documented lane never activated at all.

Why This Change Was Made

Documented intent is one interleaved 💬 line per preamble item (docs/concepts/progress-drafts.md:259-269). The reasoning lane immediately above already solves the same snapshot-growth problem by remembering its open line, so this mirrors that shape rather than inventing a mechanism.

Id-less commentary now remembers its open line and reuses that id when the next snapshot is a prefix of it in either direction: cumulative growth updates in place, genuinely distinct commentary still appends. Because merge replaces at the existing index, a line that has been overtaken by newer tool lines keeps its position.

The continuation check requires non-empty sanitized text. Without that guard a directive-only snapshot ([[reply_to_current]], NO_REPLY-shaped — the repo already fixtures this) matches via prior.startsWith("") and clears the visible line. Only an explicit itemId retraction removes a line, matching the preamble precedent that rejected input keeps the previous valid value.

User Impact

Operators running progress.commentary: true get the documented single interleaved line instead of stacked duplicates — and on Telegram's current default they get the lane at all, where before the setting did nothing. No config surface added, changed, or retired.

resolveChannelStreamingProgressCommentary gains a third optional parameter. Omitting it preserves the previous configured-mode reading exactly, so a third-party caller of the two-argument form is unaffected; the compositor passes its resolved mode, matching what resolveChannelStreamingPreviewToolProgress already does.

Evidence

Live on real Telegram, same scenario the audit recorded three lines for, via $telegram-e2e-userbot with E2E_TELEGRAM_PROVIDER_API=openai-completions:

Before After
💬 lines 3 1
Receipt 💬 1 note 💬 1 note
3222ms  message  Working | 💬 Checking the workspace before answering.
4669ms  edit     Working | 💬 Checking the workspace before answering. | 🛠️ Exec …
9393ms  message  OPENCLAW_E2E_DRAFTPROOF
10342ms edit     💬 1 note · 🛠️ 1 tool call · ⏱️ 8s

The single line survives the later tool-line edit in position, and the note count is unchanged.

Unit coverage (60 tests): three cumulative id-less snapshots → one line whose text is the final snapshot; two unrelated id-less texts → two lines; an id-less line updated after a tool line keeps its position; a directive-only snapshot leaves the line untouched and returns false with no extra update; existing itemId replace and retract still pass. Plus a regression test that the commentary gate honors the caller's mode.

The activation fix was necessary for the first fix to be observable: an earlier run on the default path recorded no 💬 line at all.

Known gaps

A third defect in this feature is deliberately not fixed here: with commentary: true on an openai-responses provider the preamble vanishes entirely, because the headline steps aside for the commentary lane (as documented) while that transport never tags commentary. Separate change, separate evidence.

Delegated the duplication fix to grok-4.5 under a bounded brief; I reviewed the diff, found and had it correct the sanitize-to-empty regression, then added the activation fix and the mode-gate test myself.

🤖 Generated with Claude Code

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Jul 30, 2026
@obviyus
obviyus marked this pull request as ready for review July 30, 2026 06:56
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. labels Jul 30, 2026
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Jul 30, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 30, 2026, 3:25 AM ET / 07:25 UTC.

ClawSweeper review

What this changes

The branch makes cumulative, id-less commentary snapshots update one progress-draft line and passes the channel’s resolved streaming mode into commentary gating.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

The direct channel-progress fix is coherent, tested, and backed by real Telegram output; no patch defect was found. This PR should remain open for a human decision on whether the optional resolved-mode argument is an acceptable exported plugin-SDK contract, especially because it carries the protected maintainer label.

Priority: P2
Reviewed head: 66f80ecda1ecc2d7a814db99ae0fd133ddbf3ea2
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-evidenced repair with a remaining maintainer-owned API compatibility decision.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body provides a real Telegram before/after transcript showing the duplicate-line symptom, the single-line result, and the final receipt; no additional contributor proof is required.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides a real Telegram before/after transcript showing the duplicate-line symptom, the single-line result, and the final receipt; no additional contributor proof is required.
Evidence reviewed 5 items Cumulative snapshot handling: The compositor changes id-less commentary identity from text-derived IDs to a remembered open-line ID for prefix-related sanitized snapshots, so growing snapshots replace in place while distinct text can append.
Mode-gate correction: The commentary resolver accepts an optional caller-resolved mode, and the compositor supplies its resolved mode; this aligns the commentary gate with the sibling preview-tool-progress gate when a channel defaults streaming mode to progress.
Focused regression coverage: The branch adds coverage for cumulative and distinct id-less commentary, stable placement after tool lines, sanitize-to-empty handling, and resolved-mode gating.
Findings None None.
Security None None.

How this fits together

Channel streaming configuration determines whether commentary is shown, then the progress-draft compositor turns provider commentary and tool updates into an editable channel draft. This change affects the intermediate draft that Telegram and other progress-draft channels render before the final receipt.

flowchart LR
  A[Provider commentary snapshots] --> B[Channel streaming configuration]
  B --> C[Resolved channel mode]
  C --> D[Commentary gate]
  D --> E[Progress draft compositor]
  E --> F[Channel draft message]
  F --> G[Final compact receipt]
Loading

Decision needed

Question Recommendation
Should the public channel-streaming resolver permanently accept a caller-resolved optional mode, or should this default-resolution information remain behind a different SDK boundary? Accept the additive resolver contract: Keep the optional mode argument, as it aligns commentary gating with the existing preview-tool-progress pattern and lets each channel supply its own resolved default.

Why: The implementation is compatible for existing two-argument callers and mirrors a sibling helper, but the generated SDK baseline confirms a durable exported contract change that cannot be settled by tests alone.

Before merge

  • Resolve merge risk (P1) - The optional third parameter changes an exported channel-streaming utility. Existing two-argument callers remain compatible, but maintainers should explicitly accept the long-term SDK contract before merge.
  • Resolve merge risk (P1) - The PR fixes the direct progress-draft path; the contributor identifies a pre-existing Telegram ACP parent-stream mode-default gap that remains outside this narrowly scoped change and should be tracked separately if it is not already.
  • Complete next step (P2) - A maintainer must decide whether the optional exported resolver parameter is the desired plugin-SDK contract before this otherwise sound PR can merge.
Agent review details

Security

None.

PR surface

Source +52, Tests +153, Generated 0. Total +205 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 56 4 +52
Tests 2 153 0 +153
Docs 0 0 0 0
Config 0 0 0 0
Generated 1 3 3 0
Other 0 0 0 0
Total 5 212 7 +205

Review metrics

Metric Value Why it matters
Public channel-streaming API 1 optional parameter added The generated SDK baseline changes because the resolver now exposes caller-resolved mode selection as part of its contract.

Merge-risk options

Maintainer options:

  1. Accept the SDK contract before merge (recommended)
    Confirm that channel callers should provide the resolved mode for unset streaming configuration, then retain the optional parameter and baseline update.
  2. Keep the resolver surface unchanged
    Ask for a narrow refactor that supplies the resolved mode without adding a parallel exported API parameter.

Technical review

Best possible solution:

Accept the additive resolved-mode API only if maintainers want channel callers to own unset-mode defaults; then merge this focused compositor repair and track the separate ACP default-resolution gap independently.

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

Yes, at source level: the prior text-derived id makes cumulative commentary snapshots create distinct draft lines, and the PR supplies both focused coverage and a real Telegram before/after transcript. I did not execute the Telegram scenario in this read-only review.

Is this the best way to solve the issue?

Yes for the direct progress-draft path: remembering the active id-less commentary line matches the existing reasoning-line approach and preserves distinct commentary entries. The remaining question is the exported resolver contract, not the local replacement logic.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded channel-progress correctness repair with a compatibility decision, not an emergency availability or data-loss regression.
  • merge-risk: 🚨 compatibility: An exported plugin-SDK resolver gains a new optional mode argument whose ownership and permanence need maintainer acceptance.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides a real Telegram before/after transcript showing the duplicate-line symptom, the single-line result, and the final receipt; no additional contributor proof is required.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides a real Telegram before/after transcript showing the duplicate-line symptom, the single-line result, and the final receipt; no additional contributor proof is required.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The changed behavior is directly visible in Telegram draft rendering and can be demonstrated in a short Telegram Desktop recording if maintainers want additional visual confirmation.

Evidence

What I checked:

  • Cumulative snapshot handling: The compositor changes id-less commentary identity from text-derived IDs to a remembered open-line ID for prefix-related sanitized snapshots, so growing snapshots replace in place while distinct text can append. (src/channels/progress-draft-compositor.ts:162, 66f80ecda1ec)
  • Mode-gate correction: The commentary resolver accepts an optional caller-resolved mode, and the compositor supplies its resolved mode; this aligns the commentary gate with the sibling preview-tool-progress gate when a channel defaults streaming mode to progress. (src/channels/streaming.ts:826, 66f80ecda1ec)
  • Focused regression coverage: The branch adds coverage for cumulative and distinct id-less commentary, stable placement after tool lines, sanitize-to-empty handling, and resolved-mode gating. (src/channels/progress-draft-compositor.test.ts:331, 66f80ecda1ec)
  • Real behavior evidence: The PR body records a real Telegram before/after run: three overlapping commentary lines before the change and one retained commentary line after it, followed by the expected compact receipt. (66f80ecda1ec)
  • SDK contract signal: The generated plugin-SDK baseline changes for channel streaming exports, confirming that the optional resolver argument is an externally visible surface rather than only a local compositor refactor. Public docs: docs/.generated/plugin-sdk-api-baseline.sha256. (docs/.generated/plugin-sdk-api-baseline.sha256:34, 66f80ecda1ec)

Likely related people:

  • steipete: The affected code is core channel-streaming and plugin-SDK surface area; the required decision is whether to accept its exported compatibility contract rather than whether the narrow compositor logic works. (role: likely channel-runtime decision owner; confidence: low; files: src/channels/streaming.ts, src/channels/progress-draft-compositor.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-07-30T07:15:43.272Z sha cb31bc8aebaddeda66da9a40f3448c416dea26b4 :: needs maintainer review before merge. :: none

obviyus added 3 commits July 30, 2026 09:20
Providers stream commentary as growing snapshots, and the draft line id was
derived from the text itself, so every snapshot minted a new id and appended a
line. One preamble rendered as three overlapping 💬 lines on Telegram.

Id-less commentary now remembers its open line and reuses that id when the next
snapshot is a prefix of it in either direction, so cumulative growth updates in
place while genuinely distinct commentary still appends. The continuation check
requires non-empty sanitized text, otherwise a directive-only snapshot would
match via `prior.startsWith("")` and clear the visible line — only an explicit
itemId retraction removes one.

Also: resolveChannelStreamingProgressCommentary guessed "partial" when
streaming.mode was unset, which since the Telegram default flip made
progress.commentary a silent no-op on the default path. It now takes the caller's
resolved mode, matching the tool-progress resolver.

Live proof on real Telegram, same scenario the audit recorded three lines for:
one 💬 line, surviving a later tool-line edit in position, receipt unchanged at
`💬 1 note`.
The line id was a four-level nested ternary mixing three distinct rules: an
explicit item id owns its line, sanitized-to-nothing addresses no line, and a
continuing snapshot reuses the open line. resolveCommentaryLineId states each as
its own early return, so the sanitize-to-empty case reads as a rule rather than a
branch that happens to fall through.

Also reuse the already-computed bare text instead of a second stripLaneItalics
pass per push.
@obviyus
obviyus force-pushed the fix/commentary-cumulative-snapshots branch from cb31bc8 to 66f80ec Compare July 30, 2026 07:20
@obviyus

obviyus commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

Working the three rank-up moves.

1. Accept the additive resolver contract. Accepted, and it is parity rather than a new pattern: resolveChannelStreamingPreviewToolProgress already carries the same optional resolved-mode parameter with the same two-argument compatibility behavior (src/channels/streaming.ts:802), added for the identical reason. Only the caller knows which default applies when streaming.mode is unset, because channels pick their own — Discord and Telegram resolve progress, Slack and Mattermost partial. Leaving commentary alone would have kept two sibling gates in the same file disagreeing about who owns default-mode resolution. Two-argument callers keep the previous configured-mode reading exactly.

2. Activation change across callers. Three call sites exist for the resolver:

  • src/channels/progress-draft-compositor.ts:165 — passes its resolved mode. This is the fix.
  • src/plugin-sdk/channel-outbound.ts:106 — re-export only, no call.
  • src/agents/acp-spawn-parent-stream.ts:178 — two-argument form, unchanged by this PR.

The ACP caller pre-resolves the mode into the entry before calling, so the two-argument form is correct there — but only for one channel. applyParentPreviewStreamModeDefault (src/agents/acp-spawn-parent-stream.ts:127-133) stamps mode: "progress" when channelId === "discord" and returns the entry untouched otherwise.

That hardcode predates Telegram's default becoming progress. On a Telegram ACP sub-agent parent stream the entry has no mode, so the resolver falls back to partial and commentary relay stays off even with progress.commentary: true — the same silent no-op this PR fixes on the direct path, in a sibling that this PR does not touch. It is pre-existing on main, not introduced here, and fixing it properly means replacing a hardcoded channel id in core with a seam that lets a channel declare its own default stream mode. That is an owner-boundary design change, so it is filed as follow-up rather than folded into a commentary-dedup PR.

3. Rebase. Rebased onto latest main; focused suites still green (40 + 20).

@obviyus
obviyus merged commit 7c47e4a into main Jul 30, 2026
120 checks passed
@obviyus
obviyus deleted the fix/commentary-cumulative-snapshots branch July 30, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant