Skip to content

fix(wework): reclassify final text as commentary - #2423

Merged
qdaxb merged 4 commits into
mainfrom
fix/wework-final-commentary-reclassification
Aug 4, 2026
Merged

qdaxb merged 4 commits into
mainfrom
fix/wework-final-commentary-reclassification

Conversation

@qdaxb

@qdaxb qdaxb commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

What

  • emit a replacement hint when Codex completes a streamed final_answer item as commentary
  • atomically replace the matching assistant text item with one process block in Wework
  • clear reclassified text from the executor final outcome
  • add Rust, frontend, and real Tauri desktop regressions plus bilingual E2E documentation

Why

Some DeepSeek responses provisionally start as final_answer but complete as commentary. Wework previously appended the completed process block without removing the already streamed assistant text, so the same text appeared twice.

Impact

Only same-item phase reversals are migrated. Normal final answers and ordinary process blocks keep their existing behavior.

Root cause

The executor forwarded the completed commentary as a new response.block.created event, but the event contract did not identify the assistant text item that had to be replaced. The frontend therefore retained both representations.

Checks

  • cargo fmt --manifest-path executor/Cargo.toml --check
  • cargo test --manifest-path executor/Cargo.toml reclassif
  • pnpm --dir packages/chat-core build
  • pnpm --dir packages/chat-core test (128 tests)
  • pnpm --dir wework typecheck
  • pnpm --dir wework test (269 files, 2692 tests)
  • pnpm --dir wework e2e:desktop:streaming-text
  • isolated pnpm --dir wework ai:verify start session
  • pre-push ESLint, TypeScript, unit tests, cargo fmt, cargo test, and cargo clippy

Summary by CodeRabbit

  • Bug Fixes

    • Prevented streamed assistant text from appearing twice when reclassified as process content.
    • Existing text now moves atomically into the process section, leaving the final-answer area empty.
    • Improved handling of streamed message phase changes and replacement events.
  • Tests

    • Added regression coverage for phase reclassification, duplicate prevention, and screenshot validation.
  • Documentation

    • Updated English and Chinese E2E automation guidance with the new validation scenarios.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4a285ed6-829c-4b0f-9fe3-25b928e1fe75

📥 Commits

Reviewing files that changed from the base of the PR and between db5d6af and 190cf63.

📒 Files selected for processing (5)
  • executor/src/agents/codex/run_state.rs
  • executor/src/agents/codex/tests.rs
  • wework/e2e/desktop/scenarios/streaming-text.scenario.mjs
  • wework/src/features/workbench/runtimePaneMessages.ts
  • wework/src/types/api.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • wework/src/features/workbench/runtimePaneMessages.ts
  • wework/src/types/api.ts
  • executor/src/agents/codex/tests.rs
  • executor/src/agents/codex/run_state.rs
  • wework/e2e/desktop/scenarios/streaming-text.scenario.mjs

📝 Walkthrough

Walkthrough

The change adds atomic migration of streamed assistant text into completed process blocks. Replacement identifiers flow from Codex events through the workbench. Unit, runtime, desktop E2E, and documentation coverage validate the phase change.

Changes

Streamed text reclassification

Layer / File(s) Summary
Codex reclassification state and runtime events
executor/src/agents/codex/run_state.rs, executor/src/runtime_work/events.rs, executor/src/agents/codex/tests.rs
Codex clears matching final-message state when streamed final_answer text completes as commentary. Runtime events emit replacesItemId for the resulting process block. Tests cover state clearing, replacement metadata, and duplicate prevention.
Replacement event contract
wework/src/types/api.ts, wework/src/stream/responseApiStream.ts, wework/src/stream/responseApiStream.test.ts
Block-created payloads now carry the optional replacesItemId value. Stream tests verify the identifier and block content.
Workbench atomic replacement
packages/chat-core/src/workbench-message-reducer.ts, wework/src/features/workbench/runtimePaneMessages.ts, wework/src/features/workbench/runtimeConversationTurns.ts, wework/src/features/workbench/runtimePaneMessages.test.ts, wework/src/features/workbench/runtimeConversationTurns.test.ts
Workbench actions forward replacement identity. Matching assistant text is replaced by the process block while preserving identity and content. Unmatched items use the existing upsert path.
Phase-flip desktop validation and documentation
wework/e2e/desktop/scenarios/streaming-text.scenario.mjs, docs/en/wework/developer-guide/wework-e2e-automation.md, docs/zh/wework/developer-guide/wework-e2e-automation.md
The E2E mock emits streamed final_answer text that completes as commentary. Assertions verify process-only rendering, no duplicate final content, and screenshot capture. Both guides document the checks.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Codex
  participant RuntimeEvents
  participant ResponseStream
  participant Workbench
  participant DesktopE2E
  Codex->>RuntimeEvents: complete streamed text as commentary
  RuntimeEvents->>ResponseStream: emit block with replacesItemId
  ResponseStream->>Workbench: dispatch block_created
  Workbench->>Workbench: replace matching assistant text with process block
  DesktopE2E->>Workbench: verify process-only text and no duplicate final content
Loading

Possibly related PRs

  • wecode-ai/Wegent#2395: Both changes handle Codex phase reclassification across runtime events and workbench message processing.
  • wecode-ai/Wegent#2334: Both changes modify Codex streamed assistant-output handling and item-ID-based phase semantics.
  • wecode-ai/Wegent#2278: Both changes modify Codex phase handling and the streaming-text desktop E2E scenario.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary change: reclassifying streamed final text as commentary.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/wework-final-commentary-reclassification

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@executor/src/agents/codex/run_state.rs`:
- Line 228: Update the final-message clearing flow around
clear_reclassified_final_message and final_message_ids_match so it returns
unless the current item_id is Some and equals self.final_message_id; do not
treat two missing IDs as a match. Add a regression case covering identifier-less
final and commentary items, while preserving migration only for same-item phase
reversals.

In `@wework/e2e/desktop/scenarios/streaming-text.scenario.mjs`:
- Around line 829-851: Wait for the streaming turn’s completed state, including
response.completed handling, after waiting for PHASE_FLIP_TEXT and before
asserting assistant content count or taking the snapshot. Keep the assertions
and subsequent new-chat transition unchanged, using the existing
completion-state selector or wait mechanism exposed by the scenario.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c402ffa1-b2de-4b94-ba86-0d2d2e3da0b4

📥 Commits

Reviewing files that changed from the base of the PR and between 4cb37ba and db5d6af.

📒 Files selected for processing (14)
  • docs/en/wework/developer-guide/wework-e2e-automation.md
  • docs/zh/wework/developer-guide/wework-e2e-automation.md
  • executor/src/agents/codex/run_state.rs
  • executor/src/agents/codex/tests.rs
  • executor/src/runtime_work/events.rs
  • packages/chat-core/src/workbench-message-reducer.ts
  • wework/e2e/desktop/scenarios/streaming-text.scenario.mjs
  • wework/src/features/workbench/runtimeConversationTurns.test.ts
  • wework/src/features/workbench/runtimeConversationTurns.ts
  • wework/src/features/workbench/runtimePaneMessages.test.ts
  • wework/src/features/workbench/runtimePaneMessages.ts
  • wework/src/stream/responseApiStream.test.ts
  • wework/src/stream/responseApiStream.ts
  • wework/src/types/api.ts

Comment thread executor/src/agents/codex/run_state.rs Resolved
@qdaxb
qdaxb added this pull request to the merge queue Aug 4, 2026
Merged via the queue into main with commit 20eb31e Aug 4, 2026
48 checks passed
@qdaxb
qdaxb deleted the fix/wework-final-commentary-reclassification branch August 4, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant