Repository navigation
fix(kimi): don't crash if config.toml is deleted mid-write - #23293
Conversation
writeConfigToml checked existsSync(configPath) then called statSync(configPath) to preserve the file's mode, with no error handling in between. If the file was deleted in that window (e.g. a concurrent uninstall), statSync threw ENOENT and the exception escaped install()/getStatus() uncaught. Now a missing-file stat during that race is treated the same as a missing file at the check: fall back to the default 0o600 mode and continue the write. Any other stat error still throws, preserving the existing mode-read-failure behavior.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughWhen Priority: ⬇️ Low Merge Risk: 🔵 Low · up to The changed error-handling path is exercised, but the regression test does not verify the deleted-file outcome or default permissions. The remaining risk is limited to test coverage. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/kimi/hook-service-config-delete-race.test.ts (1)
16-17: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDelete the fixture before simulating the race.
The mocked
statSyncthrowsENOENT, but the config file remains. The laterexistsSync(configPath)check therefore still sees the file and exercises the backup path. Unlink the file before throwing, then assert that installation recreates it with mode0o600.Suggested test fix
if (typeof target === 'string' && target === deleteRace.path) { + actual.unlinkSync(target) throw Object.assign(new Error('ENOENT: no such file or directory, stat'), { code: 'ENOENT' }) } ... const config = fs.readFileSync(configPath(), 'utf-8') + expect(fs.statSync(configPath()).mode & 0o777).toBe(0o600) for (const event of KIMI_HOOK_EVENTS) {
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 8db41468-eb31-4f9d-9351-e214f9907b17
📒 Files selected for processing (2)
src/main/kimi/hook-service-config-delete-race.test.tssrc/main/kimi/hook-service.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — one minor reuse suggestion inline.
Reviewed changes
- Guarded the mode-preservation
statSync—writeConfigTomlnow try/catches the permission read and only swallows the error when the file is gone, falling back to the existing0o600default instead of lettingENOENTescapeinstall()/getStatus(). - Delete-race regression test —
hook-service-config-delete-race.test.tsmocksnode:fs'sstatSyncto throwENOENTfor the config path and assertsinstall()writes a complete config. Sinceinstall()is synchronous, the test genuinely fails against the unfixed code.
The fix is correct and well scoped: it closes exactly the window #22422 opened while preserving the deliberate abort-on-unreadable behavior covered by hook-service-mode-read-failure.test.ts (hook-service.ts:157 rethrows anything that is not ENOENT). No security, cross-platform, SSH, or mobile exposure — this is a local POSIX/Windows filesystem read with no ACL-specific branch.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Reuse the repo's canonical absence check instead of a hand-rolled ENOENT comparison, per review feedback on #23293. isDefinitiveAbsence also covers ENOTDIR (an ancestor directory replaced by a file), which the inline check missed but is equally "the config is definitively not there."
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (delta since prior pullfrog review)
- Adopted the canonical absence predicate —
writeConfigTomlnow gates its rethrow onisDefinitiveAbsence(error)instead of an inlinecode !== 'ENOENT', so theENOENT/ENOTDIRallowlist lives insrc/shared/definitive-filesystem-absence.tsrather than being re-derived here. - Broadened the regression test — the delete-race test is parameterised over
it.each(['ENOENT', 'ENOTDIR']), and the mockedstatSyncnow throws whichever code the case supplies; theENOTDIRarm would fail against the original inline check.
The prior reuse suggestion is fully addressed, and the widened predicate has no new blast radius: an ENOTDIR at the mode stat means a path component of config.toml is not a directory, so the subsequent temp write in the same dir fails on its own with a real error rather than being masked. ENOTDIR is also a legitimate "nothing to preserve" case. Tests pass locally (hook-service-config-delete-race.test.ts + hook-service-mode-read-failure.test.ts, 3 tests).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Orca writes a small hook config file for the Kimi CLI agent. Right before writing it, Orca peeks at the file's current permissions so it can keep them unchanged. If something deletes that file in the split second between "does it exist?" and "read its permissions," Orca was crashing instead of just writing a fresh file.
What Changed
writeConfigTomlinsrc/main/kimi/hook-service.tschecksexistsSync(configPath)and then callsstatSync(configPath)to read the file's current permission bits so the rewrite preserves them. Nothing handled the case where the file disappears in between those two calls (e.g. a concurrent uninstall, or the user deleting~/.kimi-code/config.tomlby hand) —statSyncthrowsENOENT, and that throw was outside anytry, so it escaped uncaught out ofinstall()/getStatus().Before: config file deleted mid-write → uncaught exception.
After: config file deleted mid-write → falls back to the same default
0o600mode used for a brand-new file, and the write proceeds normally. Any other stat failure (e.g. an unreadable file) still throws, same as before — this fix only recognizes the file's-already-gone case.Why
The minimal fix is to catch the
statSyncerror at the exact point it can now fail, and only swallow it when the failure means "the file is gone" (ENOENT). This keeps the existing deliberate behavior for other stat failures — there's already a test (hook-service-mode-read-failure.test.ts) documenting that Orca intentionally aborts rather than risk silently dropping permissions when it truly cannot determine the current mode. Widening the catch to swallow all errors would have broken that safety property; narrowing it to just the race condition preserves it while closing the crash.Linked Issue
Found during a production release scan (introduced by #22422, "Preserve Kimi config permissions"); no separate tracking issue was filed.
Visual Proof
N/A — backend-only fix, no UI change.
Testing
Added
src/main/kimi/hook-service-config-delete-race.test.ts, which mocksnode:fs'sstatSyncto throwENOENTfor the config path (simulating the delete race) and assertsinstall()no longer throws and still writes a working config.Before the fix: test fails with
AssertionError: expected [Function] to not throw an error but 'Error: ENOENT: no such file or directory, stat' was thrown.After the fix: test passes.
Ran the full Kimi hook-service suite (new test +
hook-service.test.ts+hook-service-mode-read-failure.test.ts): 3 files, 7 tests, all passing. Also ranpnpm tc:node(clean) andpnpm run check:code-quality:changed(clean, 0 new findings).This is a filesystem race, not platform-specific, so no separate OS verification was needed. Confirmed there's no separate Windows ACL-preserving code path in this function —
chmodSync/statSyncmode bits are applied the same way on every platform here, so the fix behaves identically on Windows.AI Disclosure
Written by an Anthropic Claude agent (Claude Code) as part of an automated production-release scan follow-up. Reviewed and verified by the human author before opening.
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)