Skip to content

fix(chat): minis:// 链接跨项目解析失败——回退扫描项目树 - #393

Merged
tall-1997 merged 2 commits into
mainfrom
fix/chatlink-cross-project-fallback
Nov 18, 2026
Merged

tall-1997 merged 2 commits into
mainfrom
fix/chatlink-cross-project-fallback

Conversation

@tall-1997

Copy link
Copy Markdown
Owner

现象

模型把油猴脚本写到 /var/minis/attachments/uploads/susu.wiki_______-3.4.txt,回复里给 minis://attachments/uploads/... 链接;点击无任何反应(无预览、无报错、无跳转)。截图证据:368.jpg。

根因(实测定位,非推断)

文件真实位置(宿主侧):files/minis-workspaces/216f98ef-a053-4736-a535-742a0eeb6e93/attachments/uploads/susu.wiki_______-3.4.txt —— 由会话 9bf3399f("安装并部署",folder=216f98ef)的 agent 写入其项目视图。

解析链:ChatLinkResolver.resolve → PRootKernel.resolveSessionHostPath(sessionId, "/var/minis/attachments/...") → SessionWorkspace.hostDir(filesDir, sessionId, "attachments"):

  • folderIdFor(session) != null 且是 SHARED_SUBDIRS → 映射到 minis-workspaces/<该会话的folder>/attachments
  • 否则 → 映射到 minis-sessions/<该会话id>/attachments

失败条件:渲染该链接的会话绑定的 project 与写入会话不同(实测库中:62cdb0f1→963c0b3f、cd5cd202→default-workspace、f4612b54→default-workspace,均非 216f98ef),此时 /var/minis/attachments 被映射到另一个不存在该文件的宿主目录。firstOrNull{exists} 落空后,回退分支把主候选路径原样返回(注释明确:为了诊断可读),exists()==false → resolve() 走到 ChatLinkAction.Web("minis://...") → WebView 加载 minis:// 永远失败(ERR_UNKNOWN_URL_SCHEME),表现为"点了没反应"。

即:minis:// 链接的可点性取决于"点击会话"的项目绑定,而写入方无从得知。跨项目/跨会话分享一个模型产物链接时必死。

修复([T-chatlink-cross-project-fallback])

resolveSandboxFile 的 minis 分支在会话视图 miss 后、放弃前,增加跨项目回退扫描 sweepProjectTrees:

  • 在 files/minis-workspaces/<folder>/<shared-subdir>/<rest> 下做精确相对路径匹配;
  • 仅允许 SessionWorkspace.SHARED_SUBDIRS(attachments/offloads/workspace/browser)作为首段,memory/任意根一律拒绝;
  • 只读,永不进入 minis-sessions/<其他会话> 私有树(单测钉死该边界);
  • context 为空时 no-op,行为与旧版完全一致(渐进增强,无回归面)。

测试

  • 新增 ChatLinkResolverSweepTest(Robolectric,7 用例):跨项目命中、私有树拒扫、非共享首段拒绝、无项目目录干净 miss、仅精确匹配(拒模糊)、null-context no-op、目录布局校验。
  • 扫描逻辑先在 Python 中对模拟 filesDir 树回放 6 个分支,全部通过。
  • 本地沙箱无 Android 工具链,编译 + 单测交由 CI。

…n view

Root cause of the field report (screenshot 368.jpg, session 9bf3399f /
project 216f98ef): the agent wrote susu.wiki_______-3.4.txt into ITS OWN
/var/minis/attachments/uploads/ and emitted
minis://attachments/uploads/susu.wiki_______-3.4.txt. Session layout maps
/var/minis/<shared-subdir> through SessionWorkspace.hostDir — per-PROJECT
(minis-workspaces/<folderId>) when the tapping session is filed, private
(minis-sessions/<sid>) when not. The chat that rendered the link binds a
different host dir, so the session-scoped lookup resolved to a host path
that does not exist there; firstOrNull{exists} missed, the fallback handed
back the same non-existent primary path, exists()==false, and resolve()
fell through to ChatLinkAction.Web — a web preview of a minis:// URL is
always a dead tap (no error, no toast, no navigation). Confirmed on-device:
the file lives in files/minis-workspaces/216f98ef/attachments/uploads/,
while the tapping sessions map to 963c0b3f / default-workspace.

Fix: [T-chatlink-cross-project-fallback] — before giving up, sweep every
project tree for the same shared-subdir relative path. Read-only, exact
relative match, scoped to SessionWorkspace.SHARED_SUBDIRS, never crosses
into minis-sessions/<other> (unit test pins the private-tree rejection).

ChatLinkResolverSweepTest covers: cross-project hit, private-tree refusal,
non-shared first-segment refusal, no-projects-dir clean miss, exact-match
only, null-context no-op. Sweep logic additionally replayed in Python
against a simulated filesDir tree (6/6 branches OK).
@tall-1997
tall-1997 merged commit 0475fb0 into main Nov 18, 2026
1 check passed
@tall-1997
tall-1997 deleted the fix/chatlink-cross-project-fallback branch November 18, 2026 08:24
tall-1997 added a commit that referenced this pull request Nov 18, 2026
* fix(chat): autolink bare minis:// and http(s):// URLs in streaming markdown

Field evidence (screenshot 368.jpg, session 1bd04f03 "油猴脚本更新添加
网站支持", model glm-5.3): the assistant emitted the file link as

    **minis://attachments/uploads/susu.wiki_______-3.4.txt**

— a bare URL wrapped in bold markers, NOT the [label](url) form. The DB
parts_json is unambiguous. parseInline has branches for code, bold,
[link](url), italic — but NO autolink branch: the bold branch consumed the
run, painted bold dark text with no "url" annotation, and the tap died
before ChatLinkResolver ever ran. Nothing was blue because nothing was a
link; that is also why older chats looked fine — those models emitted
proper markdown links, and the previous PR (#393) fixed resolution for
links that DO render, which this one never reached.

- parseInline gains a bare-URL autolink branch (GFM-style): schemes
  minis://, https://, http://. Matched after code/bold so those keep their
  own semantics; bold recursion re-enters the parser, so **<url>** now
  renders a bold link — the exact field case.
- bareUrlEnd(): whitespace ends the run; ')' ends it only when parens are
  balanced (Wikipedia-style /Go_(programming_language) survives); CJK
  full-width punctuation terminates, while CJK ideographs continue inside
  the URL (relay filenames are commonly Chinese); ASCII sentence
  punctuation is trimmed off the tail.
- Annotated spans use the same "url" tag the markdown-link branch writes,
  so the tap handler, ChatLinkResolver.resolve, and PR #393's
  cross-project sweep all fire unchanged.

Tests: BareUrlAutolinkTest (12 cases) pins the field case, CJK-period and
ASCII-period trimming, paren balance, md-link and inline-code immutability,
CJK filenames, multi-URL lines, non-URL schemes staying plain. The full
matrix was replayed in Python against the parser mirror first (11/11 OK).

* test(chat): use getStringAnnotations for string-tag spans

* test(chat): getStringAnnotations(start,end) with .item — match compose API

* fix(chat): autolink bare URLs inside emphasis too — appendRecursive has its own branch list

**minis://…** is the field case: the bold branch routes its body through
appendRecursive, which never re-entered parseInline's new autolink branch.
Mirror the same scheme/bareUrlEnd handling here so the bold-wrapped URL
renders as a bold link with the same url annotation.
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