Skip to content

fix(wework): restore background task plans - #2281

Merged
qdaxb merged 7 commits into
mainfrom
fix/wework-plan-restoration
Jul 28, 2026
Merged

qdaxb merged 7 commits into
mainfrom
fix/wework-plan-restoration

Conversation

@qdaxb

@qdaxb qdaxb commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • keep the cached runtime conversation authoritative while the server transcript has not settled the same latest turnId
  • switch back to the server transcript once it contains a completed assistant message for that turn
  • add focused unit coverage and a real desktop E2E scenario for switching away during plan generation and returning after completion

Root cause

When a task finished in the background, returning to it could load a transcript that only covered an older turn. Because the lifecycle already reported the task as stopped, that stale transcript replaced the newer cached stream state and removed the generated plan from the pane.

The reconciliation now uses turn identity as the boundary between the two sources. It does not merge messages or compare content size.

User impact

Plans generated while another task is open remain visible when users return to the completed task.

Validation

  • pnpm exec vitest run src/components/layout/useWorkbenchPaneSession.test.ts
  • pnpm exec eslint src/components/layout/useWorkbenchPaneSession.ts src/components/layout/useWorkbenchPaneSession.test.ts e2e/desktop/task-flow.e2e.mjs
  • pnpm typecheck
  • pnpm e2e:desktop -- --task-plan-only
  • Wework pre-push ESLint, TypeScript, and unit-test suite

Summary by CodeRabbit

  • Bug Fixes
    • Improved background task plan restoration when reopening a pane.
    • Refined chat transcript reconciliation to use latest turn identity instead of recency heuristics, preventing stale transcript content from overriding newer results.
    • Correctly restores only completed tool activity while avoiding showing pending/streaming items as active.
  • Tests
    • Added end-to-end coverage for background task plan restoration.
    • Expanded unit tests for transcript settlement and turn-identity–based reconciliation scenarios.

@coderabbitai

coderabbitai Bot commented Jul 28, 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: 51df660b-480d-44d0-8e74-8a4c0de8b987

📥 Commits

Reviewing files that changed from the base of the PR and between dc2fcf5 and 4a07ccf.

📒 Files selected for processing (1)
  • wework/src/components/layout/useWorkbenchPaneSession.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • wework/src/components/layout/useWorkbenchPaneSession.test.ts

📝 Walkthrough

Walkthrough

Changes

Turn reconciliation and restoration

Layer / File(s) Summary
Identity-based transcript reconciliation
wework/src/components/layout/useWorkbenchPaneSession.ts, docs/en/..., docs/zh/...
Cached and transcript messages are reconciled using normalized turnId/subtaskId identity, with transcript settlement determining when authority switches.
Reconciliation behavior coverage
wework/src/components/layout/useWorkbenchPaneSession.test.ts
Tests cover stale transcript turns, missing cached identity, completed cached plans, identity normalization, and matching-turn settlement.
Background task-plan restoration flow
wework/e2e/desktop/task-flow.e2e.mjs
The E2E harness streams a synchronized task_plan response and verifies restored plan content and runtime task identity.

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

Sequence Diagram(s)

sequenceDiagram
  participant Workbench
  participant useWorkbenchPaneSession
  participant Transcript
  Workbench->>useWorkbenchPaneSession: reconcile cached and transcript messages
  useWorkbenchPaneSession->>Transcript: check matching settled turn identity
  Transcript-->>useWorkbenchPaneSession: settlement status
  useWorkbenchPaneSession-->>Workbench: selected conversation messages
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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 main change: restoring background task plans in Wework.
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.
✨ 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-plan-restoration

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.

…ration

# Conflicts:
#	wework/e2e/desktop/task-flow.e2e.mjs
#	wework/src/components/layout/useWorkbenchPaneSession.test.ts
#	wework/src/components/layout/useWorkbenchPaneSession.ts
@qdaxb
qdaxb marked this pull request as ready for review July 28, 2026 16:37

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

🤖 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 597-604: Update verifyBackgroundTaskPlanRestoration to begin with
a snapshot and assert the expected initial UI state using visible text or stable
elements before clicking add-context-button or set-plan-mode-button. Preserve
the existing plan-mode verification flow after this precondition check.

In `@wework/src/components/layout/useWorkbenchPaneSession.ts`:
- Around line 2899-2902: The latestRuntimeTurnIdentity function must inspect
only the newest message, rather than reverse-searching for an older message with
an identity. Return that latest message’s runtimeMessageTurnIdentity when it has
a turnId or subtaskId, otherwise return null so the documented transcript
fallback applies; add coverage for an identified older turn followed by an
identity-less latest response.
- Around line 2905-2910: Update runtimeMessageTurnIdentity to normalize each
non-null turnId and subtaskId with String(value) before constructing the set,
preserving only the subtaskId field and adding no subtask_id alias. Add coverage
verifying numeric and string identities match equivalently.
🪄 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: 149ecd88-0db0-4ee6-9f89-14d085954f0f

📥 Commits

Reviewing files that changed from the base of the PR and between 9714c4e and 57d91ab.

📒 Files selected for processing (5)
  • 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.test.ts
  • wework/src/components/layout/useWorkbenchPaneSession.ts

Comment thread wework/e2e/desktop/task-flow.e2e.mjs Resolved

@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/src/components/layout/useWorkbenchPaneSession.test.ts`:
- Around line 110-117: Update the identity fixtures in the test “does not borrow
an older cached turn identity for an identity-less latest response” to use
subtaskId instead of turnId for both cached and transcript messages. Treat
subtaskId as the sole canonical transcript identity field and preserve the
test’s identity-less latest-response scenario.
🪄 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: c796986e-14f9-4f0b-aa83-b72ede4ec919

📥 Commits

Reviewing files that changed from the base of the PR and between 57d91ab and dc2fcf5.

📒 Files selected for processing (3)
  • wework/e2e/desktop/task-flow.e2e.mjs
  • wework/src/components/layout/useWorkbenchPaneSession.test.ts
  • wework/src/components/layout/useWorkbenchPaneSession.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • wework/src/components/layout/useWorkbenchPaneSession.ts
  • wework/e2e/desktop/task-flow.e2e.mjs

@qdaxb
qdaxb merged commit abf557a into main Jul 28, 2026
31 of 33 checks passed
@qdaxb
qdaxb deleted the fix/wework-plan-restoration branch July 28, 2026 18:10
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