Skip to content

[Bug] git分支往本地版本开发后分支内容无法直接点开 #1747

Closed

Description

@lesoncn

What happened? / 问题描述

git分支版本后以特定worktree分支开发,提供的文档、图片点击都显示没有匹配xxxx的文件,它没有按照分支的路径去读取,而是依然按照主干路径读取。使用的是deepseek v4.1 flash模型。我在查看它的思考过程,它是知道worktree的,但是给出的文件路径却没有。

Steps to reproduce / 复现步骤

  1. 初始化git
  2. 新建worktree分支
  3. 在worktree开发,提供文档
  4. 点击文档无法打开。

Expected behavior / 预期行为

能按照实际worktree路径打开文件

Actual behavior / 实际行为

能按照实际worktree路径打开文件

App version / 应用版本

0.20.1

Operating system / 操作系统

Linux

Extra environment / 其他环境信息

PI-Desktop 0.20.1 · linux x64 · protocol 11 · host 0.20.1

Logs / 日志

Screenshots / 截图

No response

Activity

  1. muzimu217 commented on Oct 18, 2026

    @muzimu217
    Contributor

    Read the reference-resolution chain on main (f1daa54a2); the pieces exist but one of them cannot recognize a worktree path, which matches what you describe.

    What the code does today:

    • File reads (fsList/fsRead) resolve their root through requireWorkspaceRoot(sessionId) (apps/desktop/electron/main/ipc/workspace-ipc.ts:771-789), which does branch on the session's worktree — so the file browser and tool reads already see the worktree.
    • Chat reference clicks go through fsResolveRef (:996-1021), which builds roots with projectRootsFor(workspaceRoot) → workspaceRootsFor(path) (apps/desktop/electron/main/workspace-roots.ts:59-72). That helper matches the path against the project group records by exact comparable path; a worktree path is not one of the group's roots (the group stores the main checkout), so it returns {} and the code falls back to a single root — which is fine.
    • The failure is in what the reference names: resolveChatFileRef treats an absolute ref as exact-absolute and requires it to sit inside one of those roots (packages/host-runtime/src/chat-ref-resolve.ts:386-413), and isChatRefOutsideRoots rejects it before that (:234-248). When the model writes an absolute path into the main checkout — which is where the parent repo lives and what many prompts/tools default to — the reference is outside the only root (the worktree) and resolves to null. Relative refs do work, because step 3 joins them against the worktree root first (:444-460).

    So the likely bug is not the click handler but the path the model is handed/emits: the session's workspaceRoot (worktree) is passed to the runtime (packages/agent-runtime/src/sidecar.ts:127), yet a path from the parent checkout still reaches the transcript. Worth checking where file references are generated for a worktree session — if any producer still uses projectPath instead of workspaceRoot, that is the one line to fix. A secondary hardening: when a session has a worktree, also accept its parent checkout as a containment root (read-only) so a stray absolute ref opens instead of failing.

    I'm on macOS and cannot drive a worktree session here, so this is static analysis of the chain rather than a reproduction — the last step (which producer writes the parent path) needs a session trace from a Linux worktree run.

  2. added a commit that references this issue on Oct 21, 2026
    1b1032c
  3. added a commit that references this issue on Oct 25, 2026
    7a95fd0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions