Skip to content

fix(feishu): prevent duplicate tails with preview and block streaming - #192482

Merged
obviyus merged 4 commits into
mainfrom
fix/feishu-streaming-tail-192446
Nov 4, 2026
Merged

obviyus merged 4 commits into
mainfrom
fix/feishu-streaming-tail-192446

Conversation

@obviyus

@obviyus obviyus commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #192446

What Problem This Solves

Fixes: Feishu's completed streaming card repeats its last block when cumulative previews and completed-block streaming are enabled together. Reported by @MarMarLabs.

User Impact

User impact: the completed card retains the answer once instead of appending the already-previewed tail again. No configuration, public API, or persistence changes are required.

Why This Change Was Made

The dispatcher now consumes completed blocks against the latest preview in source order, within the existing assistant-message boundary. It tries an exact match at the consumed offset first, then allows separator whitespace omitted by sentence chunking. Independent blocks still append, and a genuinely repeated block beyond the consumed preview remains visible. It never guesses from suffix overlap.

The retained preview and consumed offset survive CardKit closeout but reset at the assistant-message boundary. This removes delta-text equality suppression without adding a second assembler or a global normalizer. Production +17 lines; tests -1 line against the merge base, with no test-line allocation.

Evidence

Original paired transport receipt · current merged-head validation.

  • Built Gateway, normal Feishu account startup, signed webhook ingress, a deterministic streamed model response, and actual Feishu SDK/CardKit HTTP requests to a task-owned HTTPS fixture: main twice ended with 1,784 characters and two tail markers; the original candidate twice ended with the exact 1,730-character answer and one tail marker. After integrating current main's elapsed-time backoff change, the new exact head repeats that byte-exact, one-tail result in a fresh real-path turn.
  • Non-streaming replies and single-block replies are unchanged, twice on each original ref. The repeated-paragraph control retains both complete copies, twice on each original ref; its canonical CardKit bytes are identical across those paired runs.
  • Three focused Feishu suites: 122 tests passed again after integration. The covered-tail and sentence-gap regressions fail on main. Changed-file formatting and lint pass; the merged candidate build passes.
  • Scope/gap: the fixture is not an authenticated Feishu tenant or client screenshot. It also exposes inherited CardKit close/reopen fanout and repeated-paragraph ordering on main; this patch does not claim to repair those behaviors. Both repeated copies remain present, but their inherited ordering is not a correctness claim of this PR.

Merge danger: two-way door; reverting fully restores prior behavior, with no migration or stored-state change. Blast radius is Feishu's streaming text assembly, especially the opt-in combination of partial previews and completed blocks.

@clawsweeper

clawsweeper Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added channel: feishu Channel integration: feishu size: S labels Nov 4, 2026
@obviyus

obviyus commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

Built-Gateway proof for #192446

Base: f0ebd97d16b097f0349bf537d0ce0543c3b13aea
Candidate: 6c6969ed3bae72f32b29f76e7443326251811fc4

Executed in a secretless official node:24.22.1 Linux/arm64 container. Both trees were installed and built. The final candidate run checked its generated build identity against the full SHA. Every Gateway used its own explicit profile, home, state directory, config path, database and workspace; the resolved paths were checked through the built CLI and authenticated Gateway handshake before ingress.

Actual path

Signed Feishu im.message.receive_v1 webhook → normal account admission and binding → real OpenClaw agent runtime → deterministic OpenAI-compatible SSE fixture → core preview/block/coalescing pipeline → real Feishu dispatcher → real Lark SDK and CardKit HTTP requests → fixture's retained card state at streaming close.

The HTTPS fixture uses a task-generated CA certificate trusted only for the proof process. Its Docker bridge address is a real non-reserved address on a task-owned internal network; certificate verification and the shipped SSRF guard remain enabled. There is no production-source bypass, direct dispatcher invocation, manually assembled callback pipeline, or live tenant credential in the final runs. The model fixture sends 48-character SSE deltas at 70ms intervals. Partial streaming and completed blocks are enabled, with 80/180-character paragraph chunking and small coalescing limits to produce multiple real completed blocks.

Results, two independent Gateway turns per row and per ref

Input / mode Main Candidate
1,730-character multi-block answer final closed card 1,784 chars, tail marker 2, twice final closed card exactly equals model answer, 1,730 chars, tail marker 1, twice
One 25-character block exact same 25-character closed card, twice exact same card, twice
Streaming off one static reply with the full answer, twice identical static reply content, twice
Two genuinely identical complete paragraphs both complete copies retained both complete copies retained; same canonical 325-character card bytes as main, twice

The exact extra 54 characters on main were a completed suffix already present in the preview:

This is deterministic streaming evidence.

TAIL192446.

The candidate's final card has that block once, not a suffix-based suppression of arbitrary new text.

Inherited limitation, not hidden by the oracle: the aggressive block configuration causes multiple CardKit close/reopen cycles on both refs (13 for the long answer and four for the repeated-paragraph input). This PR fixes the extra tail within the completed card; it does not claim that the entire turn has only one card. The repeated-paragraph run also exposes inherited ordering: its canonical card places the tail between the two full paragraph copies, identically on main and head. The control proves no repeated paragraph was lost, not that this unrelated ordering is correct. No native Feishu client rendering or authenticated tenant behavior is claimed.

Supporting regressions

node scripts/run-vitest.mjs run --project extension-feishu \
  extensions/feishu/src/reply-dispatcher.test.ts \
  extensions/feishu/src/delivery-trace.test.ts \
  extensions/feishu/src/streaming-card.test.ts
Candidate: 3 files passed; 122 tests passed.

node scripts/run-vitest.mjs run --project extension-feishu \
  extensions/feishu/src/reply-dispatcher.test.ts -t 'covered tail|sentence gap'
Main: both introduced behavior regressions fail.

The same table retains corrected snapshots, private reasoning removal, independent additive blocks, repeated covered blocks and block-only repeated blocks. Changed-file Oxfmt and Oxlint pass. Test delta is -1, production delta +17, with no ratchet allocation.

Two earlier local approaches passed the smaller tests but did not fix the real Gateway path. A proof-only observational module-load hook on the earlier candidate logged the real assembly inputs and established that paragraph blocks retain separators while sentence chunks can omit them. That diagnostic hook is outside the PR, was not used in either final baseline or candidate matrix, and does not supply or alter any accepted proof result. The final correction first matches exact bytes at the consumed offset, then skips only an unmatched whitespace gap; it never searches suffixes. All Gateway, model fixture and Feishu fixture processes shut down after their runs.

@obviyus
obviyus marked this pull request as ready for review November 4, 2026 02:30
@obviyus

obviyus commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 4, 2026
@clawsweeper

clawsweeper Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The Feishu dispatcher consumes completed blocks already represented in cumulative previews while preserving independent and genuinely repeated blocks.

Example: A preview contains "First.\n\nLast." and completed blocks arrive as "First." then "\n\nLast.".

  • Before: The closed card contains "First.\n\nLast.\n\nLast.".
  • After: The closed card contains "First.\n\nLast.".

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused owner-local repair with shipped-entry-point proof, meaningful regressions, preserved historical contracts, and no actionable findings; ordinary CI remains pending.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied receipts exercise signed Feishu webhook ingress through a built Gateway, real agent pipeline, dispatcher, and SDK/CardKit HTTP requests to an HTTPS fixture; the reviewed head closes with the exact 1,730-character answer and one tail marker. Paired controls preserve non-streaming replies, single blocks, and genuine repeats. Authenticated tenant rendering is outside this assembly proof, and inherited card fanout and paragraph ordering are explicitly disclosed.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Feishu users see the last answer block repeated in the completed streaming card when previews and completed blocks are enabled together.
Reason: The collaborator-authored direction repairs documented output behavior with a narrow change and retains existing fallback contracts.

Merge readiness

✅ Ready for maintainer review

This PR provides a focused repair for duplicate Feishu streaming tails still present on current main; no actionable introduced defects were found.

Priority: P2
Reviewed head: 5b8acc8e80968a6c8e7f79bf6215670b0e83f4b3

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Feishu reply dispatcher receives assistant previews and completed blocks from core, assembles visible text, and sends updates and final content through the CardKit transport.

flowchart LR
  A[Agent stream] --> B[Core preview and block pipeline]
  B --> C[Feishu reply dispatcher]
  C --> D[Ordered preview cursor]
  D --> E[Streaming card session]
  E --> F[CardKit HTTP requests]
Loading

Technical review

Best possible solution:

Keep ordered preview consumption in the existing Feishu dispatcher, preserving additive fallback text and assistant-message boundaries.

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

Current-main source shows the duplicate-tail path, and the supplied paired Gateway receipt reproduces it through the real transport; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch is a small owner-local repair: it consumes exact source-ordered contributions, tolerates omitted separator whitespace, and preserves independent blocks without suffix-overlap guessing.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1139abee8063.

Provenance checked

  • Block-only fallback and snapshot/delta assembly keeps the original intent (e6f34b2: Retain block text at idle when runtimes supply no corresponding preview or final payload.)
  • Exact-equality suppression changes intended behavior with a stated reason (c51caca: Narrow unused private adapter options while preserving delivery behavior; this PR explains why equality suppression must be snapshot-only to retain genuine repeated blocks.)
  • Assistant-message snapshot boundaries keeps the original intent (860a4de: Preserve prose written before tool calls and remove unreliable length and overlap guesses.)
  • Consolidated dispatcher regression table keeps the original intent (b56ae70: Consolidate equivalent fixtures while retaining distinct behavior coverage; the updated table preserves prior controls and adds distinct consumption failures.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 860a4de adds extensions/feishu/src/reply-dispatcher.ts:1381 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 860a4ded04d7; files: extensions/feishu/src/reply-dispatcher.ts)
  • Vincent Koc: Raw commit 84a22a6 adds extensions/feishu/src/reply-dispatcher.ts:289 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 84a22a64bef0; files: extensions/feishu/src/reply-dispatcher.ts)
  • Sid: Raw commit e6f34b2 adds extensions/feishu/src/reply-dispatcher.ts:171 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: e6f34b25aadc; files: extensions/feishu/src/reply-dispatcher.ts)

PR surface

Source +17, Tests -1. Total +16 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 19 2 +17
Tests 1 16 17 -1
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 35 19 +16

Review metrics

Metric Value Why it matters
Production versus test LOC Production +19/-2; tests +16/-17 The small production increase retains the preview and consumed position in the existing owner; regression coverage expands without net test growth.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Persistent duplicated card text affects Feishu's opt-in combination of previews and completed-block streaming.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-04T02:34:47.269Z sha 6c6969e :: needs maintainer review before merge. :: none

Reviewed November 3, 2026, 9:48 PM ET / November 4, 2026, 02:48 UTC (Revision 2).

@obviyus

obviyus commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

Current-main integration receipt

New exact head: 5b8acc8e80968a6c8e7f79bf6215670b0e83f4b3.

Merged the freshly fetched origin/main after the landing stale check. The Feishu owner integrated cleanly: upstream changed streaming-start backoff to performance.now() and updated its clock test. Those changes are retained; the ordered preview/block cursor is unchanged.

On this exact merged head, in the retained secretless node:24.22.1 container:

  • Rebuilt the candidate, with the generated build identity checked against the complete new SHA.
  • Reran the three focused Feishu suites: 122 tests passed across 3 files. Changed-file Oxfmt and Oxlint pass.
  • Reran one uninstrumented real-path candidate turn, as requested: signed Feishu webhook → normal account admission → built Gateway and real agent stream → HTTPS Feishu/CardKit fixture. The last closed card equals the complete provider answer byte-for-byte: 1,730 characters; one TAIL192446. marker. No duplicate 54-character tail.

The original main-twice/candidate-twice matrix and unchanged controls remain documented in #192482 (comment). Its disclosed inherited card lifecycle and repeated-paragraph ordering limitations are unchanged; this integration does not broaden the claim. All proof processes were shut down after the run.

@obviyus

obviyus commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 4, 2026
@clawsweeper clawsweeper Bot removed the clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. label Nov 4, 2026
@obviyus
obviyus merged commit 6a4638c into main Nov 4, 2026
113 checks passed
@obviyus
obviyus deleted the fix/feishu-streaming-tail-192446 branch November 4, 2026 02:55
@obviyus

obviyus commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 6a4638c. Feishu streamed replies no longer repeat their last block.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 4, 2026
…openclaw#192482)

fix(feishu): don't repeat the last streamed block in the final card

Fixes openclaw#192446.

In Feishu streaming, the final card could include the last block twice: once from the cumulative preview and again as an additive block, so replies ended with a duplicated paragraph. The final text now matches each block against the preview: first at the exact cursor, then with whitespace-gap normalization only if the exact match fails. Already-consumed text is not added again, and genuinely repeated paragraphs are kept. Non-streaming and single-block replies are unchanged.

Evidence: signed Feishu webhook, built Gateway, the real agent streaming pipeline and an HTTPS CardKit fixture. Main produced 1,784 characters with two copies of the tail, twice; with this change the exact 1,730-character answer with one tail was produced twice, and again after merging current main. Non-streaming, single-block and repeated-paragraph controls were unchanged. Card fanout and reordering behavior is not changed or claimed fixed here. Details: openclaw#192482 (comment) and openclaw#192482 (comment).

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 14, 2026
…191585)

Feishu core delivers attachment blocks even when text block streaming is disabled. Admit captioned media to the existing caption and native attachment delivery path instead of returning before either send.

The 89 additional regression-test lines exercise the real dispatcher queue, caption sender and image uploader through a mocked Feishu SDK client in preview modes off and partial, without an injected final reply or production test seams.

Co-authored-by: forrystudio <[email protected]>
(cherry picked from commit 569ca48)

Release adaptation: inline the existing public-SDK runtime fixture because
reply-dispatcher.test-support.ts is absent on this release baseline. Keep
real dispatcher, caption sender, media classifier and uploader coverage.

Companion audit: later #192469 (monotonic retry window) and #192482
(preview tail deduplication) do not affect captioned non-streaming admission;
not applicable to this fix. #197656 removes obsolete allocation records;
retain the allocation for this release's existing ratchet. No PR-number
follow-ups found through 7bccde6. Existing dispatcher producers, senders
and reply-runtime exports are present-equivalent; no storage changes.

Proof: git diff --check passed. Focused Vitest/typecheck/lint unavailable:
this isolated worktree has no node_modules; no dependencies were installed.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
(cherry picked from commit 52e15d4e681397a7b596b5252688376a9979897d)
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…openclaw#192482)

fix(feishu): don't repeat the last streamed block in the final card

Fixes openclaw#192446.

In Feishu streaming, the final card could include the last block twice: once from the cumulative preview and again as an additive block, so replies ended with a duplicated paragraph. The final text now matches each block against the preview: first at the exact cursor, then with whitespace-gap normalization only if the exact match fails. Already-consumed text is not added again, and genuinely repeated paragraphs are kept. Non-streaming and single-block replies are unchanged.

Evidence: signed Feishu webhook, built Gateway, the real agent streaming pipeline and an HTTPS CardKit fixture. Main produced 1,784 characters with two copies of the tail, twice; with this change the exact 1,730-character answer with one tail was produced twice, and again after merging current main. Non-streaming, single-block and repeated-paragraph controls were unchanged. Card fanout and reordering behavior is not changed or claimed fixed here. Details: openclaw#192482 (comment) and openclaw#192482 (comment).

Co-authored-by: Ayaan Zaidi <[email protected]>

Source: 6a4638c

Release adaptation: Full source change cherry-picked (-x no-commit), preserving preview consumed-prefix order and block-only repeated paragraphs. Baseline double-counted cumulative preview plus blocks; outbound-media followup unrelated. Formatting passed. Focused vitest bounded at 20s ended without test verdict during setup; shared dependency/compiler limitations remain. No schema change.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit f9ea7d1b9065b82e51db7bced54b700194cfd166)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

[Bug]: Feishu streaming card shows the last block twice when preview and block streaming are both on

1 participant