Repository navigation
fix(kimi): preserve config permissions during hook writes - #22422
Conversation
Adapted from the investigation and proposal by @Pr1p. Co-authored-by: Pr1p <[email protected]>
…23-kimi-config-mode
|
Warning Review limit reachedNext included review available in 22 minutes. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
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.
✅ No new issues found.
Reviewed changes
- Preserve the config mode across the atomic write —
writeConfigToml()now reads the existingconfig.tomlmode (statSync(...).mode & 0o777), creates the temp file owner-only (mode: 0o600), restores the prior mode withchmodSyncbefore the rename, and defaults a new config to0o600. AstatSyncfailure now aborts the write instead of replacing the file. - Mode-preservation tests —
hook-service.test.tsasserts install/remove keep an existing0o640mode (config and.bak) under umask0o077and that a new config lands at0o600under umask0o022; a newhook-service-mode-read-failure.test.tsmocksstatSyncto fail and assertsinstall()throws with the original config byte-identical.
The fix mirrors the existing remote writer (writeTextFileRemoteAtomic) and the repo's other & 0o777 mode-preservation patterns. I ran the two test files (6 passing), oxlint, and check:code-quality:changed — all clean. The tests genuinely fail without the fix, since the temp file would take the umask default. The fail-closed throw is safe: runInstaller in managed-agent-hook-controls.ts:114 converts it to a structured error status.
ℹ️ Other writeHooksJson callers still reset an existing mode
This is deliberately out of scope for this PR (which correctly covers Kimi only), but it is the remainder #20597 says to keep in lockstep: writeHooksJson only preserves a mode when the caller passes preserveMode: true, and most managed-hook installers do not. No action needed here; flagging so the parallel writers are not forgotten.
Technical details
# Scope: other managed-hook config writers still lose an existing mode
## Affected sites
- `src/main/agent-hooks/installer-utils.ts:352` — `writeHooksJson` passes `mode: existingMode`, which is `undefined` unless `preserveMode: true`; the temp file then takes the umask default and `renameSync` (line 359) makes that the config's mode.
- Callers that omit `preserveMode`: `src/main/claude/hook-service.ts:161,275`, `src/main/cursor/hook-service.ts:199,290`, `src/main/droid/hook-service.ts:249,326`, `src/main/gemini/hook-service.ts:202,306`, `src/main/grok/hook-service.ts:192,245`, `src/main/copilot/hook-service.ts:153,196`, `src/main/antigravity/hook-service.ts:168,228`, `src/main/command-code/hook-service.ts:159,229`, `src/main/codex/codex-hook-definition.ts:37`, `src/main/devin/hook-service.ts:166,240`, `src/main/muse/hook-service.ts:207,216,296`.
- Only `src/main/codex/codex-hook-legacy-cleanup.ts:138` and `src/main/codex/codex-real-home-hook-install.ts:184,281` pass `preserveMode: true`.
## Required outcome
- None for this PR. Tracked by #20597; noted so the intentionally-parallel writers can be brought into lockstep.
## Open questions for the human
- Is a follow-up planned to pass `preserveMode: true` from the remaining callers, or to make mode preservation the default inside `writeHooksJson`?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Installing or removing Orca’s Kimi hooks should not make a private config readable by more users.
What Changed
Read the current POSIX mode before replacing the config; create the temporary file owner-only, then restore the prior mode before the atomic rename. New configs default to 0600, and an unreadable existing mode fails without replacing the file.
Why
This keeps the existing atomic writer and backup behavior while preserving permissions, instead of adding another config-writing mechanism.
Linked Issue
Related to #20597; this covers the Kimi writer only. Adapted from @Pr1p’s #20623.
Visual Proof
N/A — on-disk file permissions only; no UI change.
Testing
Kimi service tests pass on macOS, including mode preservation under an explicit umask, owner-only creation and mode-read failure. Node typecheck and changed-code quality pass. Windows ACL behavior, live SSH/Kimi and other config writers were not exercised.
All checks run with
ORCA_BACKGROUND_LAUNCH=1. Full lint, desktop build and the full test suite remain CI coverage.Review
Current head
f55b93bf9199: GitHub checks pass and the complete Pullfrog review has no actionable findings. CodeRabbit remains rate-limited.Independently reviewed the final diff after advancing to main
996f9cc3068c, including cleanup, persistence, failure behavior, cross-platform paths and execution-host boundaries.Agent skill upstream boundary
Notes
The existing concurrent delete/replace race around stat and rename remains; this change does not add locking. The earlier casting-gate finding on #20623 is absent here: the mock uses checked annotations without those casts.
Checklist