Repository navigation
fix: route session status and git data through bound environments - #4698
Conversation
🦋 Changeset detectedLatest commit: 8f79e9c 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 SummaryThis 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: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c1b5d8f75a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const environmentId = summary.environmentId ?? LOCAL_ENVIRONMENT_ID; | ||
| const cwd = environmentId === LOCAL_ENVIRONMENT_ID ? (workspaceCwd ?? undefined) : summary.environmentCwd; |
There was a problem hiding this comment.
Rebuild old session summaries before routing git
On an existing install with a session-index generation built before these fields were added, stored summaries lack environmentId; the unchanged schema version and freshness checks let that generation continue serving them. This fallback then treats a remote session as local and probes the host path, so /api/v2/sessions?include=git can silently return missing or incorrect git details until the summary is reprojected or rewritten. Invalidate or migrate older summaries before relying on these fields.
AGENTS.md reference: AGENTS.md:L110-L112
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
已在 8f79e9c 修复:同时提升 session 索引 schema 版本(2 → 3)和扫描缓存版本(1 → 2)。只提升前者不够,重建时仍会从扫描缓存复用缺少环境字段的旧 summary。新增测试模拟升级前遗留的索引与扫描缓存,验证重建后能恢复 environmentId / environmentCwd;只提升其中任一版本时该测试都会失败。
| status = await this.core.accessor.get(IGitService).status(target.cwd); | ||
| } else { | ||
| const environments = this.core.accessor.get(IEnvironmentService); | ||
| const lease = environments.acquire({ environmentId: target.environmentId }, ['fs']); |
There was a problem hiding this comment.
Connect pending environments before reading remote git
When a listed remote session is cold and its declared environment has not connected in this server process, DeclaredRemoteEnvironment has no fs capability yet. This acquire() therefore throws, and the catch silently returns null git details instead of opening the connection; unlike session creation, this path never uses acquireWhenReady. Acquire the environment when ready so include=git can work for cold sessions.
Useful? React with 👍 / 👎.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Derive the displayed session directory from one TUI helper, and stop the v2 session list from caching environment-unavailable git misses. Remote lookups now time out after a short budget and share one in-flight request per environment and cwd.
Bump the session index schema and scan cache versions so summaries projected before environmentId and environmentCwd were recorded are re-read from session metadata instead of routing remote sessions as local.
2c24f42 to
8f79e9c
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8f79e9c7f5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (value !== undefined) this.cache.set(key, { value, fetchedAt }); | ||
| return value; | ||
| }) | ||
| .finally(() => this.inflight.delete(key)); |
There was a problem hiding this comment.
Bound stalled remote git lookups
When a remote process.spawn() never settles—as modeled by the new stalled-process test—GitService.runCommand() never reaches its own command timer, so this promise never settles and the .finally() cannot remove it from inflight. Every later include=git request for the same environment and cwd therefore reuses the poisoned promise and silently returns null after three seconds, even after that environment reconnects or is replaced because the key contains no generation. Give the underlying lookup a finite lifetime or invalidate it when the environment generation changes while retaining bounded deduplication.
AGENTS.md reference: AGENTS.md:L130-L132
Useful? React with 👍 / 👎.
Requirement or Bug
Follow-up to #4649。远程会话的欢迎面板和 footer 已经能读取实际绑定环境,但
/status、Markdown 导出元数据和 kap-server 的 v2 sessionsinclude=git仍读取本地启动目录,导致同一 session 在不同表面显示不一致。本 PR 把这三处剩余路径也接到绑定环境。Bug Reproduction Steps
kimi --environment dev-box --environment-cwd /home/example/project启动远程会话,本地启动目录与远程目录不同。/status或/export-md /tmp/session.md,可见 Directory / frontmatter 仍显示本地启动目录。POST /api/v2/sessions?include=git,其git.branch/pull_request来自本地 cwd,无法表示远程仓库。Root Cause
这三处仍沿用“本地工作区即 session 工作目录”的假设:TUI 直接传
appState.workDir,v2GitDomainResolver则只用 cwd 调 App 级IGitService。此外,SessionSummary在索引和镜像过程中丢弃了environmentId/environmentCwd,所以即使要按环境路由,冷会话也没有足够信息。本 PR 保留原有本地路径作为旧会话的兼容回退,并为远程会话补齐绑定元数据和按环境执行的查询路径,是根本修复。
Code Changes
核心思路是让“展示用工作目录”和“git 查询目标”都由 session 绑定决定,同时不改变本地 workspace 的归属和导出文件保存位置。
远程
GitService复用环境自己的 fs/process。缺少环境信息的旧会话继续按local处理;远程绑定缺少 cwd 或环境不可用时返回nullgit 域,不回落到本地仓库。workspace.cwd仍用于本地 workspace 分组,Markdown 文件仍默认保存在本地启动目录。阅读顺序:
packages/kap-server/src/routes/v2/sessions.ts:按环境解析、查询和缓存 git 域。packages/agent-core-v2/src/app/sessionIndex/sessionIndexSource.ts:环境字段在冷读取、镜像和相等比较中的保留。apps/kimi-code/src/tui/commands/info.ts与session.ts:/status和导出元数据的目录选择。可略读:三个 summary 写入点的字段透传、回归测试、中英文文档和 changeset。
Screenshots / Recordings
新增测试直接渲染
/status并读取实际导出的 Markdown,关键输出如下(省略其余面板内容):/statusDirectory /tmp/proj-aDirectory /remote/project/export-mdfrontmatterwork_dir: /tmp/proj-awork_dir: /remote/projectBehavior Changes and Affected Users
/statusDirectory/export-md的work_dirinclude=git受影响模块与测试覆盖:
/status的实际渲染和远程导出 frontmatter;原有本地/status用例保留。environmentId/environmentCwd;metadata、fork、archive 和 mirror 测试通过。验证记录与未覆盖范围
agent-core-v2、kap-server、apps/kimi-code类型检查通过。v2Sessions.test.ts:49 个测试全部通过。git diff --check通过。gen-docs所需的docs/scripts/sync-changelog.mjs在当前 release 不存在,因此未生成 changelog;相关指南与 API 参考已手工双语同步。FakeEnvironment驱动真实 git 进程的集成测试覆盖。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.