Skip to content

refactor: main process workspace switch state machine with phase logging (phase 4)#24

Merged
lyx-tec merged 1 commit into
mainfrom
refactor/workspace-switch-phase4
Jul 17, 2026
Merged

refactor: main process workspace switch state machine with phase logging (phase 4)#24
lyx-tec merged 1 commit into
mainfrom
refactor/workspace-switch-phase4

Conversation

@lyx-tec

@lyx-tec lyx-tec commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

Phase 4 of workspace-switch refactor: main 进程 workspace switch 状态机。

Changes

核心改动: processActionQueue 重构

before: workspace switch 的 switchworkspace case 是 20 行内联代码,混杂在 action queue 的 80 行函数中:

  • positionTabOffScreen(-15000) 隐藏旧 workspace views
  • 无阶段日志,切换失败时无法定位
  • this.activeTabView 在 detach 后未清理

after: 提取命名方法 + 阶段日志 + 精确时点拆分

方法 职责
detachForWorkspaceSwitch() 后端调用 → detach activeTabView + old views → clear loadedTabViews
setTabViewIntoWindow(..., isWorkspaceSwitch) 复用现有方法,传参控制日志输出点

阶段日志

switchworkspace:start              windowId target=wsId
switchworkspace:backend-ready      windowId workspace=wsId
  or: backend-failed               windowId reason
switchworkspace:previous-views-detached windowId count=N, kept-alive-in-cache
switchworkspace:view-attached      windowId tab=tabId
switchworkspace:reinit-sent        windowId
  or: init-sent                    windowId
switchworkspace:ready              windowId
  or: failed                       windowId

view-attachedreinit-sent/init-sent 分别在 addChildViewwebContents.send("wave-init", ...) 的确切时点打印,而非批处理后。

Bug 修复

# 问题 修复
1 失败路径误打 ready 显式 success 标志 → ready/failed 互斥
2 coalesce 时 ready 漏打 entry?.op 在 coalesce 后指向新 action,自然跳过
3 detach 后 activeTabView 仍指向旧 view this.activeTabView = null
4 error return 卡死 coalesced action returncontinuefinally 执行 shift() 后 while 继续处理)
5 workspaceId 来自入参而非后端 this.workspaceId = newWs.oid

未变更

  • _queueActionInternal coalescing 逻辑([0] 执行中、[1] 覆盖)完全保留
  • finalizePositioningpositionTabOffScreen 保留(同 workspace 内 tab 切换仍需隐藏非 active tab)
  • removeChildView 后旧 workspace 的 WaveTabView 实例保留在全局 wcvCache,由 cache eviction 按需销毁

设计文档

补充 docs/design/workspace-switch-refactor-plan.md,覆盖四阶段完整方案描述。

Review 闭环

所有 8 项 Review 意见已修复:
https://github.com/anomalyco/opencode/issues

TypeCheck

零新增错误。仅 frontend/preview/ 下 3 个文件的 17 个已有错误(与本 PR 无关)。

- extract detachForWorkspaceSwitch with named phase logging
  (start → backend-ready/backend-failed → previous-views-detached
   → view-attached → reinit-sent/init-sent → ready/failed)
- replace positionTabOffScreen(-15000) with removeChildView
  during workspace switch (keep views alive in wcvCache)
- clear activeTabView after detach to prevent stale state
- fix processActionQueue error returns causing coalesce deadlock
  (return → continue for all non-terminal errors)
- add isWorkspaceSwitch param to setTabViewIntoWindow for
  precise log placement at addChildView / send wave-init points
- action queue coalescing semantics preserved unchanged
@lyx-tec
lyx-tec merged commit 2fbd073 into main Jul 17, 2026
4 of 6 checks passed
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