Skip to content

fix: handle duplicate workspace source folders and fs roots - #4513

Merged
liruifengv merged 1 commit into
mainfrom
fix/multi-root-workspace-followup
Oct 29, 2026
Merged

liruifengv merged 1 commit into
mainfrom
fix/multi-root-workspace-followup

Conversation

@liruifengv

@liruifengv liruifengv commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Multi-root workspaces can reject duplicate source folders with an opaque validation error, and workspace file operations can drop additional source directories.

Bug Reproduction Steps

  1. Create a workspace with primary directory A and additional directory B, then add B again using a trailing slash. The server returns the generic 40001 error with additional_dirs.N: duplicate path instead of a useful error code and the actual directory.
  2. Open a registered multi-root workspace without an active session and call workspace FS list/search/suggest with the workspace ID and additional directory B. The temporary FS scope only includes A, so operations on B fail or can cause B to be registered as a separate implicit workspace.

Root Cause

Duplicate directory validation reused the generic validation envelope, which exposed only a field index and an English diagnostic string. The workspace FS resolver also built its temporary scope from ws.root alone, discarding additionalDirs and making it impossible for clients to address a registered multi-root workspace safely by ID.

This is a fundamental fix: duplicate directories now have a dedicated error code and resolved path, and workspace FS resolution preserves the complete registered directory set.

Code Changes

  • Add WORKSPACE_DUPLICATE_DIR = 40006 for additional directories that duplicate the primary directory or another additional directory.
  • Return Duplicate source folder: <resolved absolute path> in msg, with structured details: [{ path, directory }]. Other validation errors keep their existing 40001 contract.
  • Register the new error and its details schema on workspace create and update routes.
  • Preserve ws.additionalDirs when acquiring workspace FS scopes for list, search, suggest, and workspace-form searches.
  • Update the English and Chinese API reference with the new code and response shape.
  • Add REST coverage for duplicate creation and update, normalized paths, additional-directory FS access, and isolation between workspaces that share an additional directory.

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
Duplicate workspace source folders Generic 40001 with additional_dirs.N: duplicate path 40006 with a resolved absolute path and structured { path, directory } details Desktop, Web, CLI, and API consumers creating or editing multi-root workspaces Other validation codes and non-duplicate behavior are unchanged
Workspace FS with additional directories Only the primary root was included in the temporary FS scope The complete registered directory set is included Clients browsing, searching, and suggesting files in multi-root workspaces No alternate behavior is required
Unregistered absolute workspace refs Absolute paths could be registered or touched through createOrTouch Unchanged for genuinely unregistered paths; registered IDs use their own directory set Single-directory drafts and implicit CLI/TUI channels Existing implicit registration remains available
Workspace API documentation Duplicate directories were documented as 40001 40006 and its msg / details contract are documented in English and Chinese API consumers No compatibility branch was added

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (no tracking issue was provided).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill; no changeset was requested for this PR.
  • Updated the English and Chinese API documentation for the new error contract.

CI Note

test (3) was retried once and hit the same 5-second timeout in packages/session-import/test/images.test.ts:267 (concurrent processes wait for another writer to finish publishing a complete file). This is unrelated to the changed code and passes locally with pnpm --filter @moonshot-ai/session-import exec vitest run test/images.test.ts -t "concurrent processes wait". All other core checks passed, and no unrelated test changes were made.

Copilot AI balanced review requested due to automatic review settings October 29, 2026 07:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-29T07:53:50.819286Z 31fc803 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@changeset-bot

changeset-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 31fc803

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@pkg-pr-new

pkg-pr-new Bot commented Oct 29, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@31fc803
npx https://pkg.pr.new/@moonshot-ai/kimi-code@31fc803

commit: 31fc803

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ 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".

Comment thread packages/kap-server/src/routes/fs.ts Resolved
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex

@liruifengv
liruifengv merged commit 67045e5 into main Oct 29, 2026
40 of 42 checks passed
@liruifengv
liruifengv deleted the fix/multi-root-workspace-followup branch October 29, 2026 08:36
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
…t land yet

Both need multi-root workspace registration (MoonshotAI#4336): the REST create and
update schemas carry only `root` and `name`, so there is no
`additional_dirs` field to pass through or to de-duplicate. MoonshotAI#4511's fs
half is already in place — resolveWorkspaceFs forwards
ws.additionalDirs — so it stays in_progress with that note rather than
being closed or signed off.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
Port of upstream MoonshotAI/kimi-code 67045e5 (MoonshotAI#4513), on top of the
source-folder surface added in 0390f64.

A repeated `additional_dirs` entry, or one naming the root itself, used to
be dropped silently, so a caller could not tell a typo from an accepted
folder. Both the create and the update route now answer `40006` with
`Duplicate source folder: <path>` and `details: [{ path:
"additional_dirs.N", directory }]`.

`PATCH /workspaces/{id}` also accepts `additional_dirs` now, so the
folder list can be replaced without re-registering the workspace.

Verified: kap-server typecheck clean, the workspaces suite is 25 pass / 1
fail where that failure (legacy split-bucket session counts) fails
identically before this work, the locale and hardcoded-prose gates pass,
and check:no-comments is green.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
…MoonshotAI#4513

MoonshotAI#4336 is in_progress: d07cc07 adds managed creation with retry-safe
ids and 0390f64 puts source folders on the REST and wire surfaces.
MoonshotAI#4513 lands on top of that in 718a3ae and is closed against a route
probe.

MoonshotAI#4511 keeps its fs-side forwarding, but its route-level cross-folder
search test is still missing, so it stays in_progress with a manual
probe rather than borrowing the workspace-creation case as evidence.
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.

3 participants