fix(ui-reference): retry a rejected mention stat and record presence trade-offs

A stat that rejects left its Session and path marked as outstanding, so the
mention stayed original text until reload. The flag now clears on rejection
and the rejection stays unhandled, so the Remote assembly fault is reported.

The README states why presence does not read the `file` resource through
`useResource`, that a symbolic link counts as present, and that a picked
candidate is confirmed only for the same Session and page load. The module
comment states that outstanding stats are unbounded. `openReference` and
`presenceFor` reuse `mentionPath` and `MentionSessionId`, and the Web scenario
drops a fixture write the scaffold already performs on refresh.
This commit is contained in:
LegGasai committed 2026-11-17 14:15:01 +08:00
1 parent 014d02b96c
commit 6db6ff9be0
7 files changed
+44 -20

No files matched your search

+1 -2
View File
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url'
import { chromium, type Browser, type Page } from 'playwright'
import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
import {
captureStableAria, compareOrRefreshGolden, fixtureUserPrompts, launchWebScaffold, readPersistedEvents, recordFixture,
captureStableAria, compareOrRefreshGolden, fixtureUserPrompts, launchWebScaffold, readPersistedEvents,
watchConsole, webSnapshotMode, type WebScaffold,
} from './scaffold.ts'
import { connectFreshWorkspace, newEnglishPage, saveFailureShot, writeComposerDraft } from './support.ts'
@@ -60,7 +60,6 @@ describe.skipIf(MODE === 'record')('web e2e: mention path presence', () => {
const persisted = (await readPersistedEvents(scaffold, sessionId))
.find(event => event.type === 'user/message' && event.data.source.kind === 'user')
expect(persisted).toMatchObject({ data: { content: [{ type: 'text', text: PROMPT }] } })
if (MODE === 'refresh') await recordFixture(scaffold, sessionId, FIXTURE)
expect(fixtureUserPrompts(await readFile(FIXTURE, 'utf8'))).toEqual([PROMPT])
for (const reload of [false, true]) {
@@ -21,8 +21,8 @@
en: 0b41c33743e5b422
zh: 551896094c03f57e
/deepseek-ai-dsh-client-ui-reference/use-this-package/sent-file-and-folder-mentions:
en: 6f276d2ef3135c8e
zh: f4aaadb82a828af9
en: 87c27115eae5a660
zh: a9a20431928072ec
/deepseek-ai-dsh-client-ui-reference/use-this-package/failure-behavior:
en: 386bbd9dc0a2c322
zh: 3014a367157532b7
@@ -33,8 +33,8 @@
en: 6c77da1e946f72e1
zh: b7b8e1e1d4f5a102
/deepseek-ai-dsh-client-ui-reference/understand-the-implementation/serialization:
en: 9138c6d815be54db
zh: 5c3075c07e35c783
en: 1126dd5a1189cde8
zh: 87866765edd7e343
/deepseek-ai-dsh-client-ui-reference/further-exploration:
en: 157b1bcf84b5c11b
zh: 6b7e4f3326b19036
+2 -2
View File
@@ -35,7 +35,7 @@ A session pick inserts an atomic inline reference whose hidden `ref` and clipboa
### Sent file and folder mentions
In sent messages, queued rows, and local echoes, an `@path` or `@"path"` token renders as a file or folder reference only after the Session's filesystem confirms the path exists. Until then, and for a path that does not exist, such as a hand-typed `@notes`, the original text stays verbatim; email addresses never match. A picked candidate counts as confirmed, so its echo shows the reference immediately. Each Session and path is checked once per page load.
In sent messages, queued rows, and local echoes, an `@path` or `@"path"` token renders as a file or folder reference only after the Session's filesystem confirms the path exists. Until then, and for a path that does not exist, such as a hand-typed `@notes`, the original text stays verbatim; email addresses never match. A candidate picked and sent in the same Session during one page load counts as confirmed, so its echo shows the reference immediately.
### Failure behavior
@@ -65,7 +65,7 @@ Candidate requests require an existing retained Client Session and share one tem
File picks preserve the natural text defined by the shared `@path` grammar as the hidden serialized and clipboard form. Session picks use the canonical `@[label](dsh-session:…)` mention; serialization never reconstructs identity from the visible title.
The plugin also registers file and folder matchers with [UserText](../ui-conversation/README.md#sent-user-text) and owns their `conversation.user.text.node` renderers. Each query returns the next complete candidate reference at an original-text offset without file discovery; the shared evaluator resolves overlaps by source position. Both node renderers subscribe to a Session-bound `pathPresence` keyed Hook backed by `workspaceFiles/stat`: a stat result or a `workspace-file/not-regular-file` failure confirms the path, `workspace-file/not-found` rejects it, and any other failure leaves it unconfirmed for the next subscriber to retry. The plugin owns these answers, keeps one per Session and path, and aborts outstanding stats on disposal; a settling pick records its path as confirmed. Interactive file nodes also receive a Session-bound `openFile` injection; navigation failures keep the reference visible and offer a local retry/close dialog. Folder nodes remain labels.
The plugin also registers file and folder matchers with [UserText](../ui-conversation/README.md#sent-user-text) and owns their `conversation.user.text.node` renderers. Each query returns the next complete candidate reference at an original-text offset without file discovery; the shared evaluator resolves overlaps by source position. Both node renderers subscribe to a Session-bound `pathPresence` keyed Hook backed by `workspaceFiles/stat`: a stat result or a `workspace-file/not-regular-file` failure (a directory, a symbolic link whatever it points to, or another non-regular entry) confirms the path, `workspace-file/not-found` rejects it, and any other failure leaves it unconfirmed for the next subscriber to retry. The plugin owns these answers, keeps one per Session and path, and aborts outstanding stats on disposal; a settling pick records its path as confirmed. Presence does not read the [`file` resource](../../api/workspace-files/README.md) through `useResource`: that provider keeps one Host change subscription open per Session and path while a reader is mounted, and a mention needs a single answer. Interactive file nodes also receive a Session-bound `openFile` injection; navigation failures keep the reference visible and offer a local retry/close dialog. Folder nodes remain labels.
</details>
+2 -2
View File
@@ -35,7 +35,7 @@ Web 用户需要从同一个 `@` 补全菜单提及文件、文件夹或会话
### 已发送的文件与目录引用
在已发送消息、排队行和本地回显中,`@path` 或 `@"path"` token 只有在 Session 的文件系统确认该路径存在后才渲染为文件或目录引用。确认之前,以及路径不存在时(例如手写的 `@notes`),原文保持不变;邮箱地址永远不会匹配。从候选中选择的路径视为已确认,因此其回显会立即显示引用。每个 Session 与路径在一次页面加载中只检查一次。
在已发送消息、排队行和本地回显中,`@path` 或 `@"path"` token 只有在 Session 的文件系统确认该路径存在后才渲染为文件或目录引用。确认之前,以及路径不存在时(例如手写的 `@notes`),原文保持不变;邮箱地址永远不会匹配。在同一 Session、同一次页面加载内从候选中选择并发送的路径视为已确认,因此其回显会立即显示引用。
### 失败行为
@@ -65,7 +65,7 @@ Web 用户需要从同一个 `@` 补全菜单提及文件、文件夹或会话
文件选择把共享 `@path` 语法所定义的自然文本保留为隐藏的序列化与剪贴板形式。会话选择使用规范的 `@[label](dsh-session:…)` mention;序列化永远不会根据可见标题重建身份。
插件还向 [UserText](../ui-conversation/README.zh.md#sent-user-text) 注册文件和目录匹配器,并拥有它们的 `conversation.user.text.node` renderer。每次查询返回原文偏移之后的下一个完整候选引用,不执行文件发现;共享计算器按原文位置裁定重叠。两个节点 renderer 都订阅绑定 Session 的 `pathPresence` 键控 Hook,其背后是 `workspaceFiles/stat`:stat 成功或 `workspace-file/not-regular-file` 失败即确认路径存在,`workspace-file/not-found` 判定不存在,其他失败则保持未确认,由下一个订阅者重试。插件持有这些结果,每个 Session 与路径保留一份,并在卸载时中止未完成的 stat;选定 pick 会把其路径记为已确认。可交互的文件节点还通过 Injection 接收绑定 Session 的 `openFile`;导航失败时保留引用,提供局部重试/关闭对话框。目录节点仍为标签。
插件还向 [UserText](../ui-conversation/README.zh.md#sent-user-text) 注册文件和目录匹配器,并拥有它们的 `conversation.user.text.node` renderer。每次查询返回原文偏移之后的下一个完整候选引用,不执行文件发现;共享计算器按原文位置裁定重叠。两个节点 renderer 都订阅绑定 Session 的 `pathPresence` 键控 Hook,其背后是 `workspaceFiles/stat`:stat 成功或 `workspace-file/not-regular-file` 失败(目录、无论指向何处的符号链接或其他非普通条目)即确认路径存在,`workspace-file/not-found` 判定不存在,其他失败则保持未确认,由下一个订阅者重试。插件持有这些结果,每个 Session 与路径保留一份,并在卸载时中止未完成的 stat;选定 pick 会把其路径记为已确认。存在性不通过 `useResource` 读取 [`file` 资源](../../api/workspace-files/README.zh.md):该 provider 在有读取方挂载期间为每个 Session 与路径保持一个 Host 变更订阅,而一次提及只需要一个结果。可交互的文件节点还通过 Injection 接收绑定 Session 的 `openFile`;导航失败时保留引用,提供局部重试/关闭对话框。目录节点仍为标签。
</details>
@@ -31,7 +31,7 @@ import type { UserTextNodeProps } from '@deepseek-ai/dsh-client-ui-conversation/
import {
FileReference, FolderReference, type FileReferenceInjected, type PathPresenceInjected,
} from './FileReference.tsx'
import { createPathPresence } from './path-presence.ts'
import { createPathPresence, type MentionSessionId } from './path-presence.ts'
import { fileReferenceRule, folderReferenceRule, mentionPath } from './user-text-rules.ts'
export type {} from './user-text-rules.ts'
import type {
@@ -66,7 +66,7 @@ export function apply(ctx: ClientContext): void {
const sessions = ctx.get('sessions') as ISessions
const presence = createPathPresence((sessionId, path, signal) => ctx.remote.workspaceFiles.stat(sessionId, path, signal))
ctx.effect(() => () => { presence.dispose() }, 'ui-reference: mention path stats')
const presenceFor = (sessionId: UserTextNodeProps<'file'>['sessionId']): PathPresenceInjected => ({
const presenceFor = (sessionId: MentionSessionId): PathPresenceInjected => ({
keyedHooks: { pathPresence: path => presence.source(sessionId, path) },
})
ctx.uiConversation.userText.register(fileReferenceRule)
@@ -182,7 +182,7 @@ export function apply(ctx: ClientContext): void {
},
openReference(session, { ref, appearance }) {
if (appearance !== 'file') return false
const path = ref.startsWith('@"') ? ref.slice(2, -1) : ref.slice(1)
const path = mentionPath(ref)
const cwd = sessions.list.getSnapshot().byId[session.sessionId]?.cwd
ctx.sidebarRight.openResource(fileAddressFor(session.sessionId, cwd, path))
return true
@@ -5,7 +5,9 @@
* is live. Only a definitive Host answer is retained; any other failure leaves
* the pair unconfirmed, and the next subscriber asks again. Retained answers
* are not refreshed when the path is created or removed later. Entries live as
* long as the plugin, one per distinct mention the client has rendered.
* long as the plugin, one per distinct mention the client has rendered. Each
* unconfirmed pair starts its own Host request when first subscribed; nothing
* bounds how many are outstanding at once.
*/
import type { UserTextNodeProps } from '@deepseek-ai/dsh-client-ui-conversation/client'
import type { WorkspaceFileStat } from '@deepseek-ai/dsh-api-remotes/client'
@@ -58,8 +60,9 @@ interface Entry {
}
/**
* Classify one stat. A directory or other non-regular entry still exists;
* failures that do not describe the path leave it unconfirmed.
* Classify one stat. A directory, a symbolic link whatever it points to, or
* another non-regular entry still exists; failures that do not describe the
* path leave it unconfirmed.
* @param result - Host stat result.
* @returns the definitive presence, or undefined.
*/
@@ -92,15 +95,15 @@ export function createPathPresence(stat: PathStat): PathPresenceSources {
const probe = (entry: Entry, sessionId: MentionSessionId, path: string) => {
if (entry.probing || entry.presence !== undefined || lifetime.signal.aborted) return
entry.probing = true
// Cancellation and carrier faults resolve as failures; only a Remote
// assembly fault rejects, and it surfaces as an unhandled rejection.
// Cancellation and carrier faults resolve as failures. Only a Remote
// assembly fault rejects: it stays an unhandled rejection so the fault is
// reported, and the pair stays unconfirmed for the next subscriber.
void stat(sessionId, path, lifetime.signal).then((result) => {
entry.probing = false
const presence = presenceOf(result)
// A confirmation recorded while this stat was outstanding is newer.
if (presence === undefined || entry.presence !== undefined || lifetime.signal.aborted) return
publish(entry, presence)
})
}).finally(() => { entry.probing = false })
}
const entryFor = (sessionId: MentionSessionId, path: string): Entry => {
@@ -95,6 +95,28 @@ describe('createPathPresence', () => {
expect(stat).toHaveBeenCalledTimes(2)
})
it('reports a rejected stat as an unhandled rejection and asks again for the next subscriber', async () => {
const fault = new Error('client api: workspaceFiles/stat has no active Connection')
const stat = vi.fn<PathStat>()
.mockRejectedValueOnce(fault)
.mockResolvedValueOnce({ ok: true, value: STAT })
const rejections: unknown[] = []
const onUnhandled = (reason: unknown): void => { rejections.push(reason) }
process.on('unhandledRejection', onUnhandled)
try {
const presence = createPathPresence(stat)
const source = presence.source(sid('a'), 'LICENSE')
source.subscribe(vi.fn())
await vi.waitFor(() => { expect(rejections).toEqual([fault]) })
expect(source.getSnapshot()).toBeUndefined()
source.subscribe(vi.fn())
expect(stat).toHaveBeenCalledTimes(2)
await vi.waitFor(() => { expect(source.getSnapshot()).toBe('present') })
} finally {
process.off('unhandledRejection', onUnhandled)
}
})
it('aborts outstanding stats on disposal, drops their answers, and starts no further stats', async () => {
const { stat, calls } = deferredStat()
const presence = createPathPresence(stat)