Skip to content

fix(agent-core): handle cross-device ripgrep install - #178

Closed
lurenjia534 wants to merge 1 commit into
MoonshotAI:mainfrom
lurenjia534:main
Closed

fix(agent-core): handle cross-device ripgrep install#178
lurenjia534 wants to merge 1 commit into
MoonshotAI:mainfrom
lurenjia534:main

Conversation

@lurenjia534

Copy link
Copy Markdown
Contributor

Related Issue

Resolve #111

Problem

When ripgrep is not available on PATH, Kimi Code downloads and extracts a managed rg binary before installing it into the user cache directory. On systems where the temporary directory and the Kimi Code cache directory are on different filesystems, the final rename() from the extracted file under /tmp to <KIMI_CODE_HOME>/bin/rg fails with EXDEV.

This makes the automatic ripgrep bootstrap fail even though the download, checksum verification, and extraction have already succeeded.

What changed

The install step now keeps the existing fast path and still tries to rename() the extracted binary directly first.

If that direct rename fails specifically with EXDEV, it falls back to copying the extracted binary into a staging directory next to the final destination, applies executable permissions there, and then renames the staged file into place on the same filesystem.

Other rename failures are still surfaced unchanged, so permission errors, missing files, and other unexpected install problems are not hidden by the fallback.

Tests were added for both the EXDEV fallback path and the non-EXDEV error path.

Validation

  • Reproduced the original EXDEV failure locally on Arch Linux by clearing PATH, forcing the real CDN bootstrap path, and installing into a temporary shareDir on a different device from /tmp. The pre-fix flow downloaded, verified, and extracted ripgrep successfully, then failed on the final cross-device rename().
  • Re-ran the same real CDN bootstrap scenario after the fix with /tmp and the target shareDir still on different devices; ensureRgPath() returned share-bin-downloaded and installed rg successfully.
  • pnpm exec vitest run test/tools/rg-locator.test.ts
  • pnpm run typecheck in packages/agent-core
  • pnpm exec oxlint --type-aware packages/agent-core/src/tools/support/rg-locator.ts packages/agent-core/test/tools/rg-locator.test.ts
  • Manual CDN end-to-end verification with PATH cleared and /tmp on a different device from the target shareDir

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.
  • 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 May 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6f1769e

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

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/agent-core Patch
@moonshot-ai/kimi-code 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

@lurenjia534

Copy link
Copy Markdown
Contributor Author

Closing this as a duplicate of #198, which addresses the same #111 ripgrep cross-device install failure from an upstream branch.

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.

Ubuntu环境下,grep工具在rg未安装的时候无法使用

1 participant