Files
mnote/bugs/07-ai/done/7-55-page-ai-current-page-target-stale-workspace-v1.md
T

33 lines
1.8 KiB
Markdown
Raw Normal View History

2026-06-01 09:29:12 +08:00
# 7-55 Page AI 当前页目标继承 stale workspacePath
## 状态
- 状态:done
- Owner07-ai / Page AI target runtime
- 发现时间:2026-06-01
- 修复时间:2026-06-01
## 现象
`task504-page-ai-history-agent-filter-smoke.js` 在模拟 stale `OpenEditorsSnapshot` 后,用户偏好已将 `active_editor` contextRef 关闭,只发送当前页上下文;但 `sendPageAiMessage()` 仍强制把 `scopedContext.editorTarget` 覆盖为 `currentPageAiEditorTarget()`,导致当前页请求被旧 active editor 的 `workspaceId` 拦截,前端显示:
`AI target 与当前 workspaceId 不一致,请重新选择当前工作区内的目标。`
## 根因
- `pageAiScopedPageContext()` 已按 contextRefs 计算 scoped target,但发送链路又覆盖为 `currentPageAiEditorTarget()`
- `currentPageAiPageEditorTarget()` 从 page editor snapshot 读取 `workspacePath` 时,没有把当前 `workspaceId/sourceKind/rootUri/relativePath/documentId` 写回,stale snapshot 会把旧 workspace 信息带进当前页目标。
## 修复
- `sendPageAiMessage()` 改用 `currentPageAiScopedEditorTarget()`,遵守 contextRefs 对 active editor 的开关。
- `currentPageAiPageEditorTarget()` 在复用 page editor snapshot 时显式覆盖当前 workspace path 字段,避免 stale snapshot 污染当前页 target。
## 验证
- `node --check rust/crates/mnote-web/browser/sidebar-page-ai-target-runtime.js`
- `node --check rust/crates/mnote-web/browser/sidebar-page-ai-runtime.js`
- `MNOTE_UI_BASE_URL=http://127.0.0.1:3301 MNOTE_WEB_SMOKE_BASE_URL=http://127.0.0.1:3301 node scripts/task504-page-ai-history-agent-filter-smoke.js`
验证结果:`task504` 通过,`capturedRuns[0].contextRefs` 只包含 `current_page``runTargetSnapshot.editorTarget.workspaceId` 为当前 `local-ws:mnote-e2e:task504`,未继续使用 stale workspaceId。