Skip to content

fix(cli): include working tree in WorktreeFamily.list for submodules#9499

Open
truffle-dev wants to merge 1 commit intoKilo-Org:mainfrom
truffle-dev:fix/tui-submodule-session-worktree-family
Open

fix(cli): include working tree in WorktreeFamily.list for submodules#9499
truffle-dev wants to merge 1 commit intoKilo-Org:mainfrom
truffle-dev:fix/tui-submodule-session-worktree-family

Conversation

@truffle-dev
Copy link
Copy Markdown

Closes #9267.

What

Inside a git submodule, git worktree list --porcelain reports the
submodule's gitdir (<repo>/.git/modules/<sub>) instead of the working
tree, so WorktreeFamily.list() returns a path that no session's
directory ever falls under. The experimental /session endpoint then
filters every session out, leaving the in-TUI session list (/sessions,
ctrl-x l) empty. The kilo session list CLI is unaffected
because it filters by project_id only and never consults the family.

Fix

Append Instance.worktree to the parsed dirs in
packages/opencode/src/kilocode/worktree-family.ts. Normal repos and
linked worktrees already include it (the git worktree list output
contains the current worktree), so the trailing [...new Set(...)]
dedups them away. The fallback path that runs when git worktree list
fails was already prefixing Instance.worktree, so this just extends
the same guarantee to the success path.

What git worktree list does inside a submodule

$ git -C parent/sub rev-parse --show-toplevel
/tmp/parent/sub
$ git -C parent/sub rev-parse --git-common-dir
/tmp/parent/.git/modules/sub
$ git -C parent/sub worktree list --porcelain
worktree /tmp/parent/.git/modules/sub
HEAD ...
branch refs/heads/main

The reported worktree is the gitdir, not core.worktree
(../../../sub). Sessions store directory as Instance.directory
which is the actual submodule path, so the family filter rejects them.

Regression test

packages/opencode/test/kilocode/worktree-family-submodule.test.ts
sets up a real parent repo with a file-protocol submodule and asserts
that WorktreeFamily.list() from inside the submodule contains the
working tree. Stash-bisected to confirm the test fails on main:

without fix:
  Expected to contain: "/tmp/opencode-test-.../sub"
  Received: [ "/tmp/opencode-test-.../.git/modules/sub" ]
  1 fail

with fix:
  1 pass

bun test test/kilocode/session-list.test.ts and
bun test test/kilocode/worktree-family-submodule.test.ts both pass.

Scope

Only the worktree-family success path is touched. The fallback path
already includes Instance.worktree. Project-identity discovery in
Project.fromDirectory (which currently sets project.worktree to
<repo>/.git/modules for submodules) is left alone — it doesn't
affect the symptoms reported here.

Inside a git submodule `git worktree list --porcelain` reports the
gitdir (`<repo>/.git/modules/<sub>`) rather than the actual working
tree, so the worktree-family filter for the experimental session
listing endpoint dropped every session whose directory was the real
submodule path. The CLI `kilo session list` was unaffected because
it filters on `project_id` only.

Append `Instance.worktree` to the parsed dirs so the working tree is
always in scope. Normal repos and linked worktrees already include it,
so the [...new Set(...)] dedup keeps those cases unchanged.

Closes Kilo-Org#9267
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Apr 25, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • .changeset/tui-submodule-session-list.md
  • packages/opencode/src/kilocode/worktree-family.ts
  • packages/opencode/test/kilocode/worktree-family-submodule.test.ts

Reviewed by gpt-5.4-20260305 · 188,020 tokens

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.

TUI session list empty when working inside a git submodule

1 participant