Skip to content

fix(wework): restore history after rapid conversation switching - #2333

Merged
qdaxb merged 6 commits into
mainfrom
fix/wework-conversation-history-switch
Jul 30, 2026
Merged

qdaxb merged 6 commits into
mainfrom
fix/wework-conversation-history-switch

Conversation

@qdaxb

@qdaxb qdaxb commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • restore a conversation transcript when the loaded task key matches but the pane is displaying another task
  • add a regression test for switching A → pending B → A before B finishes loading
  • extend the real desktop short-conversation E2E with a running second conversation and rapid switching
  • document the transcript identity rule in Chinese and English

Root cause

loadedRuntimeTranscriptKeyRef tracked only the last successfully loaded task. During a rapid switch, task B could replace the displayed messages while its transcript was still pending. Switching back to task A then returned early because A was still the last loaded key, even though the pane was displaying B.

The pane now skips transcript restoration only when both the loaded key and the displayed transcript identity match the target task.

Verification

  • pnpm --filter wework exec vitest run src/components/layout/useWorkbenchPaneSession.test.ts src/features/workbench/WorkbenchProvider.test.tsx — 142 passed
  • focused race regression after rebasing onto latest origin/main — passed
  • Prettier and ESLint for all changed Wework files — passed
  • real Tauri short-conversation E2E — passed
    • evidence: wework/test-results/desktop-e2e/2026-07-30T08-06-18-113Z-11406
  • pre-push ESLint, TypeScript, and unit-test suite — passed

Summary by CodeRabbit

  • Bug Fixes

    • Improved conversation switching so cached history restores reliably when returning before another transcript finishes loading.
    • Prevented delayed transcript responses from overwriting the currently displayed conversation.
    • Ensured transcript restoration only skips reload when the displayed conversation matches the loaded transcript identity, keeping historical turns visible.
  • Tests

    • Added component race-condition coverage for rapid runtime pane switching and transcript restoration.
    • Extended desktop E2E flows to verify prompt/completion restoration and that background conversation transcripts do not leak into the restored view.

Additional CI fix

  • classify pull request changes from the merge base in lint, test, platform E2E, and Wework E2E workflows
  • prevent files added to main after a branch diverges from incorrectly enabling backend, CLI, frontend, or platform E2E jobs
  • add a workflow-level regression assertion for three-dot diff usage

Additional verification

@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Runtime transcript restoration now requires both transcript key and displayed identity matches. Component and desktop coverage exercise rapid switching and late-response isolation. CI path classification now uses merge-base diff ranges, with validation ensuring all relevant workflows use the updated syntax.

Changes

Transcript restoration and desktop flow validation

Layer / File(s) Summary
Identity-aware transcript loading
wework/src/components/layout/useWorkbenchPaneSession.ts, docs/en/..., docs/zh/...
Transcript reloads are skipped only when the loaded key and displayed identity both match the target; corresponding restoration contracts are documented.
Component race validation
wework/src/features/workbench/WorkbenchProvider.test.tsx
A runtime switching test verifies cached history restoration and isolation from a late transcript response.
Desktop switching and flow validation
wework/src/e2e/automation.ts, wework/e2e/desktop/task-flow.e2e.mjs
Adds macrotask-ordered clicking and validates historical message restoration, task isolation, and task-row reuse during concurrent conversations.

CI changed-path classification

Layer / File(s) Summary
Merge-base workflow classification
.github/workflows/{lint,test,e2e-tests,wework-e2e}.yml
Changed-path detection uses three-dot merge-base ranges for downstream job classification.
Classification syntax validation
.github/scripts/test-classify-ci-changes.sh
The classifier test verifies all four workflows contain the required merge-base diff command.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: micro66, ficohu

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing transcript history restoration during rapid conversation switching in Wework.
✨ Finishing Touches
📝 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-conversation-history-switch

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.

@qdaxb
qdaxb marked this pull request as ready for review July 30, 2026 08:28
@qdaxb
qdaxb enabled auto-merge July 30, 2026 08:29
@qdaxb
qdaxb force-pushed the fix/wework-conversation-history-switch branch from d43c5c9 to 5a1030f Compare July 30, 2026 10:00

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

🤖 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 `@wework/e2e/desktop/task-flow.e2e.mjs`:
- Around line 1597-1618: Move or repeat the active-pane snapshot assertions
after releaseConcurrentMemoryResponses() and the running-task settlement in the
rapid-switch flow. Verify the active A conversation still contains both expected
user and assistant history messages and excludes
CONVERSATION_SWITCH_RACE_PROMPT, using the existing snapshot and assertion
helpers around restoredAfterRace.
🪄 Autofix (Beta)

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: 68b54652-ef18-48bf-b408-fb985c05452a

📥 Commits

Reviewing files that changed from the base of the PR and between d43c5c9 and 5a1030f.

📒 Files selected for processing (6)
  • docs/en/wework/developer-guide/wework-chat-state-sources.md
  • docs/zh/wework/developer-guide/wework-chat-state-sources.md
  • wework/e2e/desktop/task-flow.e2e.mjs
  • wework/src/components/layout/useWorkbenchPaneSession.ts
  • wework/src/e2e/automation.ts
  • wework/src/features/workbench/WorkbenchProvider.test.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • docs/zh/wework/developer-guide/wework-chat-state-sources.md
  • docs/en/wework/developer-guide/wework-chat-state-sources.md

Comment thread wework/e2e/desktop/task-flow.e2e.mjs Resolved
@qdaxb
qdaxb added this pull request to the merge queue Jul 30, 2026
@qdaxb
qdaxb removed this pull request from the merge queue due to a manual request Jul 30, 2026
@qdaxb
qdaxb force-pushed the fix/wework-conversation-history-switch branch from 5a1030f to e406de4 Compare July 30, 2026 10:24

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

🧹 Nitpick comments (1)
wework/e2e/desktop/task-flow.e2e.mjs (1)

1562-1566: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Repeated task-row snapshot boilerplate.

taskRowsBeforeRace duplicates the same "snapshot body → filter runtime-local-task-row- ids" pattern already used for taskRowsBeforeConversation (line 1442) and elsewhere in this file (taskRowsBeforeInitialTask, projectRowsBeforeComposerCreate). Extracting a small helper (e.g. captureExistingTaskRowIds(control)) would remove this recurring duplication.

As per coding guidelines: "Before adding code, search for and reuse existing components, services, utilities, and patterns; extract shared logic instead of duplicating it."

♻️ Suggested helper
+async function captureExistingTaskRowIds(control) {
+  return new Set(
+    JSON.parse(await control.command('snapshot', 'body')).testIds.filter(testId =>
+      testId.startsWith('runtime-local-task-row-')
+    )
+  )
+}
-  const taskRowsBeforeRace = new Set(
-    JSON.parse(await control.command('snapshot', 'body')).testIds.filter(testId =>
-      testId.startsWith('runtime-local-task-row-')
-    )
-  )
+  const taskRowsBeforeRace = await captureExistingTaskRowIds(control)
🤖 Prompt for 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.

In `@wework/e2e/desktop/task-flow.e2e.mjs` around lines 1562 - 1566, Extract the
repeated snapshot-and-filter logic into a shared helper such as
captureExistingTaskRowIds(control), then replace taskRowsBeforeRace and the
equivalent task-row collection sites including taskRowsBeforeConversation and
taskRowsBeforeInitialTask with calls to that helper. Preserve the existing
snapshot command and runtime-local-task-row- ID filtering behavior.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In `@wework/e2e/desktop/task-flow.e2e.mjs`:
- Around line 1562-1566: Extract the repeated snapshot-and-filter logic into a
shared helper such as captureExistingTaskRowIds(control), then replace
taskRowsBeforeRace and the equivalent task-row collection sites including
taskRowsBeforeConversation and taskRowsBeforeInitialTask with calls to that
helper. Preserve the existing snapshot command and runtime-local-task-row- ID
filtering behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 186a9547-7bdf-4686-8200-92da388a9a44

📥 Commits

Reviewing files that changed from the base of the PR and between 5a1030f and 38d2727.

📒 Files selected for processing (11)
  • .github/scripts/test-classify-ci-changes.sh
  • .github/workflows/e2e-tests.yml
  • .github/workflows/lint.yml
  • .github/workflows/test.yml
  • .github/workflows/wework-e2e.yml
  • docs/en/wework/developer-guide/wework-chat-state-sources.md
  • docs/zh/wework/developer-guide/wework-chat-state-sources.md
  • wework/e2e/desktop/task-flow.e2e.mjs
  • wework/src/components/layout/useWorkbenchPaneSession.ts
  • wework/src/e2e/automation.ts
  • wework/src/features/workbench/WorkbenchProvider.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/en/wework/developer-guide/wework-chat-state-sources.md

@qdaxb
qdaxb added this pull request to the merge queue Jul 30, 2026
Merged via the queue into main with commit 03b737d Jul 30, 2026
38 checks passed
@qdaxb
qdaxb deleted the fix/wework-conversation-history-switch branch July 30, 2026 10:56
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