Repository navigation
fix(app-core): return session media URLs synchronously for unknown sessions - #5336
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 7126e55 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
7Sageer
approved these changes
Nov 24, 2026
Merged
7723qqq
pushed a commit
to 7723qqq/kimi-code
that referenced
this pull request
Nov 25, 2026
Route file download and session media URL calls through a sessionSync route that answers from the current owner without a session load (MoonshotAI#5336). Add thoughtsTokenCount to the Google GenAI output usage with thinking and zero-thinking fixtures (MoonshotAI#5334), update the desktop composer e2e specs for the label-only slash menu (MoonshotAI#5274), and document the Bash session/workspace env vars (MoonshotAI#5053).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Screenshots / Recordings
在
kimi web开发环境里(和桌面端是同一套渲染层,无 SSH 主机),先打开页面,再通过 REST 从外部新建一个带图片的会话,然后在侧栏点开它。看对话区域:修复前整段崩溃,修复后图片正常显示。修复后,在同一个会话里从输入框再上传一张图发送(用户日志里实际的触发方式),也正常显示:
Requirement or Bug
用户在桌面端打开带图片或视频的会话(包括刚发出一条带图的消息时),整个对话区域变成「出错了 / 重试」,DevTools 里持续报
n.url?.startsWith is not a function和i.value?.url.startsWith is not a function。点重试无效,只有重启 App 才可能恢复。kimi web用的是同一套渲染层,同样受影响。这个 PR 之后,会话里的图片和视频在任何会话上都能正常渲染。Bug Reproduction Steps
kimi web或 Remote Control 里新建的会话,或者不在侧栏某项目前 5 个、后来因为有活动才被顶上来的会话。startsWith报错,重试后仍然出错。Root Cause
HostRouter把getSessionMediaUrl和getFileDownloadUrl标成'session'路由,但这两个方法在KimiWebApi里声明为同步返回string,所有调用方也都同步使用返回值。sequenceDiagram participant View as MediaThumb / MediaTool participant Router as HostRouter participant Local as 本机 API View->>Router: getSessionMediaUrl(sessionId, fileId) alt sessionHost 已记录该会话 Router->>Local: getSessionMediaUrl(...) Local-->>View: "…/media/f_xxx"(string) else sessionHost 未记录 Router->>Router: dispatchUnknownSession(async) Router-->>View: Promise View->>View: url.startsWith(...) → TypeError,整段对话渲染失败 end本机会话的归属只在会话列表接口(首屏每个项目只取前 5 个)和本窗口的
createSession/forkSession里记录。本机的sessionCreated等事件不会记录归属。而且没有远程主机时,dispatchUnknownSession本身也不会补记,所以这类会话每次调用都会拿到 Promise。另外,算出来的 tool media 按会话缓存,点「重试」也恢复不了。这次是根本修复:让同步方法在任何情况下都同步返回字符串,不再依赖归属是否已知。问题来自 #5079 的桌面迁移。
Code Changes
新增一种路由
sessionSync,用于按会话路由、但必须同步返回的 URL 方法:dispatch(method, route, args) if route is 'session' or 'localSession' owner known → call owner host owner unknown → async lookup, then call (returns Promise) + if route is 'sessionSync' + if owner unknown → start background lookup (errors ignored) + call owner host if known, otherwise this machine (always returns string)归属未知时回落到本机 URL:
fileId时由AuthMedia通过异步的getSessionMediaBlob加载,灯箱下载也优先走这条路径。这条路径会先查到会话归属,所以远程会话的显示不受影响。hostRouting.test.ts原有一条测试断言getSessionMediaUrl对未知会话resolves出 URL。它断言的是返回 Promise,和types.ts里声明的string返回类型矛盾,正是这个 bug。这里改成断言同步返回字符串,并在拿到归属后改用远程主机。Behavior Changes and Affected Users
getSessionMediaUrl返回值getFileDownloadUrl返回值filesstore 按string | null使用<audio src>可能指向本机地址,播放失败受影响人群:桌面端和
kimi web用户,只要打开的会话还没经过会话列表接口加载,且会话里有图片或视频(用户消息里的附件、工具截图、浏览器工具结果),就会受影响。其他按会话路由的 API('session'/'localSession')完全没动。测试覆盖与验证
packages/app-core/test/hostRouting.test.ts›returns session URLs synchronously and uses the owning host once it is known:覆盖第 1、2 行(同步返回本机 URL)和远程归属记下后改用远程主机。修复前这条测试失败(expected Promise{…} to be 'local-media-url'),修复后通过。pnpm exec vitest run --reporter=agent packages/app-core/test/hostRouting.test.ts packages/app-core/test/conversation.test.ts packages/app-core/test/browserToolMedia.test.ts:73 个测试全部通过。pnpm --filter kimi-code-app run typecheck:通过。pnpm lint:通过。pnpm dev:server+pnpm dev:web,隔离的KIMI_CODE_HOME,本地假模型,无 SSH 主机):先打开 Web 页面,再通过 REST 从外部新建会话,并发一条带图片的提示,然后在页面侧栏点开这个会话。props.url?.startsWith is not a function,点重试仍然报错。刷新页面后可以恢复。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.