Repository navigation
Conversation
There was a problem hiding this comment.
ℹ️ No critical issues — one minor test-quality suggestion inline.
Reviewed changes
- Preserve
config.tomlmode across the atomic rewrite —writeConfigToml()now pins0o600for a newly created config and, when overwriting, reads the existingstatSync(...).mode & 0o777; it writes the temp file withmode: 0o600and thenchmodSync(tmpPath, mode)so the rename can't widen the config (e.g.0600→0644under a permissive umask). - POSIX regression coverage —
hook-service.test.tsadds tests that an existing0640survives install + remove under umask077, and that a fresh config is0600. - Test isolation hardening —
USERPROFILEis now redirected to the temp dir alongsideHOME, so Windows can't write the managed script into the real user profile.
The core fix is correct: the explicit chmodSync is what defeats umask masking (passing mode to writeFileSync alone would still be masked). I verified the .bak copy keeps the source mode, so the backup doesn't reintroduce the exposure.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
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: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to Configuration updates preserve existing permissions, create new files with owner-only permissions, and leave existing files unchanged when mode inspection fails. No merge-blocking issue remains. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (1)
src/main/kimi/hook-service.ts (1)
142-161: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winAbort when
statSynccannot read the existing config mode
KimiHookService.install()andremove()callwriteConfigToml. IfstatSync(configPath)fails after the content changes,moderemains0o600. If the path exists again at the later check,copyFileSyncandrenameSyncreplace it with mode0o600. A delete-and-recreate race can produce this path. This violates the existing-file mode-preservation contract and can remove access granted by the prior mode. Handle the metadata read separately and abort whenstatSyncfails. Use0o600only when the config is known to be absent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: d339c147-ecd8-4414-aeef-7c32c4e5ec3d
📒 Files selected for processing (2)
src/main/kimi/hook-service.test.tssrc/main/kimi/hook-service.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review (78fa0f8 → c4fc209): a single test-determinism commit.
- Pinned the umask in the new-config mode regression — the
creates a new config with an owner-only modetest now wrapsinstall()inprocess.umask(0o022)and restores the previous umask infinally. Under unfixed code the temp write becomes0o666 & ~0o022 = 0o644, so the assertion fails regardless of the runner's ambient umask; with the fix it stays0o600. This addresses the prior inline note and the regression now has real teeth.
The core fix from 78fa0f8 is unchanged and remains correct: the explicit chmodSync(tmpPath, mode) is what defeats umask masking after the atomic rename swaps the inode.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Important
The new mode-read-failure test trips the required changed-code quality gate: its casting scan flags three as casts, so the static_analysis job the verify aggregate requires will stay red until they are suppressed or removed.
Reviewed changes
Reviewed the delta since the prior pullfrog review (c4fc209 → 94defbc).
- Abort on an unreadable config mode —
writeConfigToml()movedmode = statSync(configPath).mode & 0o777outside the readtry/catch, so a metadata failure now throws instead of silently rewriting an existing config with a guessed0o600. The registry callers (runInstaller,removeManagedAgentHooks) catch and convert to an error status, so the new throw is a safe failure mode. - Added a mode-read-failure regression —
hook-service-mode-read-failure.test.tsmocksnode:fs.statSyncto throw for the config path and assertsinstall()rejects and the config text is untouched. It fails against the pre-94defbccode that swallowed the stat error, so it has real regression value.
The functional change is correct; the only blocker is the gate failure below.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| import { tmpdir } from 'node:os' | ||
| import { join } from 'node:path' | ||
|
|
||
| const modeReadFailure = vi.hoisted(() => ({ path: null as string | null })) |
There was a problem hiding this comment.
This new file fails the required changed-code quality gate: the casting scan (assertionStyle: never from config/oxlint-code-quality-casting.json) reports three typescript/consistent-type-assertions errors on the added as casts (reported at lines 6, 10 and 14). pnpm run check:code-quality:changed is enforced by the static_analysis job that verify requires, so the PR stays red until they are suppressed or removed. The author's local oxlint run used the root config, where an as cast is legal, which is why it looked clean.
Technical details
# Casting gate fails on the new mode-read-failure test
## Affected sites
- `src/main/kimi/hook-service-mode-read-failure.test.ts:6` — `path: null as string | null`.
- `src/main/kimi/hook-service-mode-read-failure.test.ts:10` and `:14` — the `statSync` mock: `(…) => unknown` and `) as typeof actual.statSync`.
## Required outcome
- `pnpm run check:code-quality:changed` reports 0 casting findings without weakening the test.
## Suggested approach
- Add `// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: <why>` directly above each cast. Verified locally that this suppresses the rule, and the gate's `isCastingDirectiveUnusedWarning` exempts the root-scan "unused directive" warning the directive would otherwise raise.
- Or remove the casts: `vi.hoisted((): { path: string | null } => ({ path: null }))`, and type the mock function with an annotation instead of `as typeof actual.statSync`.|
Closing as superseded by merged #22422, which carries the reviewed fix and regression coverage. Thank you for the original contribution. |

ELI5
Updating Kimi hook settings replaces its TOML config through a temporary file. The settings stayed intact, but the replacement file could lose its private permissions. This keeps existing permissions and makes a newly created config owner-only. If Orca cannot read an existing config's permissions, it leaves that config untouched instead of guessing.
What Changed
0600.0640file under a restrictive umask and for creating a new0600file.USERPROFILEalongsideHOMEin the hook-service tests so Windows never writes a managed script to the real user profile.Why
Kimi's config may contain an
api_key. Atomic rename swaps in the temporary inode, so its mode becomes the config mode unless explicitly restored. This prevents an existing private config from becoming more broadly readable while retaining user-selected permissions. Aborting on an unreadable mode avoids a race or metadata failure silently narrowing an existing file's access.Linked Issue
Fixes #20597
Visual Proof
N/A — this only changes local TOML file permissions; there is no rendered UI or interaction change.
Testing
node ... vitest ... src/main/kimi/hook-service.test.ts src/main/kimi/hook-service-mode-read-failure.test.ts src/main/kimi/kimi-hook-config-toml.test.ts— 33 passed, 2 POSIX-only permission tests skipped on Windows and will run on Linux CI.oxlint src/main/kimi/hook-service.ts src/main/kimi/hook-service.test.ts src/main/kimi/hook-service-mode-read-failure.test.tsAI Disclosure
Used OpenAI Codex (GPT-5) for implementation and test authoring. I reviewed the change and ran the focused validation above.
Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)