Skip to content

fix(web): surface cwd errors in mention search and validate new-session cwd#1005

Open
tomsen-ai wants to merge 1 commit into
MoonshotAI:mainfrom
tomsen-ai:fix/web-cwd-mention-error
Open

fix(web): surface cwd errors in mention search and validate new-session cwd#1005
tomsen-ai wants to merge 1 commit into
MoonshotAI:mainfrom
tomsen-ai:fix/web-cwd-mention-error

Conversation

@tomsen-ai

@tomsen-ai tomsen-ai commented Jun 23, 2026

Copy link
Copy Markdown

Related Issue

Closes #1007

Problem

  1. @-mention shows "no match" when search fails. When the active session's working directory no longer exists, typing @<query> in the composer triggers fs:search. The backend returns an ENOENT error, but workspaceState.searchFiles swallowed the exception and returned an empty array. The UI then rendered the generic "无匹配" (no match) state, hiding the real problem.

  2. New sessions can be created in deleted directories. The new-session dialog validated the cwd, but the one-click "+" button in the sidebar and the onboarding composer both create sessions via createSessionInWorkspace / startSessionAndSendPrompt, which never checked whether the directory still exists.

What changed

  • apps/kimi-web/src/composables/client/useWorkspaceState.ts

    • searchFiles now propagates backend errors instead of returning [] on failure, so Composer.vue can distinguish "no matches" from "search failed".
    • Added validateCwdForCreate(cwd) and called it before createSession, createSessionInWorkspace, and startSessionAndSendPrompt.
    • Empty @ queries short-circuit to [] to avoid exposing the backend's "query too small" validation error.
  • apps/kimi-web/src/api/daemon/client.ts

    • browseFs now propagates errors. The folder picker already consumes workspaceState.browseFs, which retains its defensive wrapper, so the picker behavior is unchanged.
  • apps/kimi-web/src/components/Composer.vue / MentionMenu.vue / NewSessionDialog.vue

    • Added mentionError state and error UI for the mention menu.
    • New-session dialog validates cwd via browseFs and disables creation while the directory is invalid.
  • .changeset/cwd-mention-error.md

    • Added a patch changeset for @moonshot-ai/kimi-web.

Verification

  • pnpm -C apps/kimi-web exec vue-tsc --noEmit passes.
  • Manually verified in the browser:
    • In a session whose cwd was deleted, @package now shows the backend ENOENT message instead of "no match".
    • In the same deleted workspace, clicking "+" and sending a message no longer creates a new session; an error toast is shown.
    • Normal workspaces still list files and create sessions correctly.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works. (Verified manually; no new test files added.)
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 562096c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-web Patch

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

@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.

Reviewed commit: 2a03bd92c4

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

*/
async function validateCwdForCreate(cwd: string): Promise<void> {
const api = getKimiWebApi();
await api.browseFs(cwd);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid making create depend on fs:browse

When the web app is paired with a daemon that still lacks the PRESUMED /fs:browse route, api.browseFs(cwd) throws and every create path using this helper returns through pushOperationFailure before reaching api.createSession. The surrounding workspace create code still explicitly falls back for older daemons without /workspaces, so this breaks the legacy cwd-only session creation path for that compatibility case; treat unsupported browse validation as non-blocking or rely on the daemon create path to reject bad cwd.

Useful? React with 👍 / 👎.

Comment on lines +54 to +57
await getKimiWebApi().browseFs(cwd);
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
cwdError.value = msg.includes('ENOENT') ? t('newSession.cwdNotFound') : msg;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Ignore stale cwd validation results

If a validation request for an older cwd is still in flight when the user edits to a different path, this callback still applies the old result when it resolves. A delayed failure for a previous missing directory can therefore leave the current valid cwd disabled with a stale error; track a validation token/current cwd before writing cwdError.

Useful? React with 👍 / 👎.

@itxaiohanglover itxaiohanglover 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.

Good fix — propagating errors instead of silently swallowing them is the right pattern. The changeset is well-written.

One question: the browseFs method now throws on error, but the workspace-state layer still has a defensive wrapper. Is there a risk that callers who previously relied on the empty-result fallback (instead of catching the throw) will break? If so, maybe worth adding a note in the changeset about the behavior change.

Overall solid work though.

…on cwd

- Composer @-mention now shows the backend error message instead of 'no match' when fs:search fails (e.g., deleted workspace directory).

- NewSessionDialog validates the working directory via browseFs before allowing creation, preventing sessions from being created in deleted directories.
@tomsen-ai tomsen-ai force-pushed the fix/web-cwd-mention-error branch from 2a03bd9 to 562096c Compare June 23, 2026 07:41
@tomsen-ai

Copy link
Copy Markdown
Author

Thanks for the review!

Good catch on the browseFs behavior change. The only existing caller that consumed api.browseFs directly was NewSessionDialog, and it already expects errors for validation. The folder picker goes through workspaceState.browseFs, which still has its defensive wrapper, so it should be unaffected.

I've updated the changeset to mention that browseFs now propagates errors and that the defensive wrapper remains at the workspace-state layer.

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.

web: @-mention hides backend errors and new sessions can be created in deleted directories

2 participants