Skip to content

fix(kimi): preserve config permissions during hook writes - #22422

Merged
nwparker merged 2 commits into
mainfrom
nwparker/external-20623-kimi-config-mode
Sep 26, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/external-20623-kimi-config-mode

Conversation

@nwparker

@nwparker nwparker commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​127 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​125
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​7 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6

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

  • Automated tests added/updated
  • Full app manually tested in this publication pass

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

  • Not applicable; no upstream skill content copied.

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

  • Small, focused change with before/after behavior and rationale
  • Visual proof or a precise N/A reason
  • Reviewed correctness, security, performance, cross-platform and remote impact
  • Full CI checks complete

nwparker and others added 2 commits September 22, 2026 22:38
Adapted from the investigation and proposal by @Pr1p.

Co-authored-by: Pr1p <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 22 minutes.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 10dfddf9-531a-407d-9be0-30bec77e75dd

📥 Commits

Reviewing files that changed from the base of the PR and between 0b16a31 and f55b93b.

📒 Files selected for processing (3)
  • src/main/kimi/hook-service-mode-read-failure.test.ts
  • src/main/kimi/hook-service.test.ts
  • src/main/kimi/hook-service.ts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Preserve the config mode across the atomic write — writeConfigToml() now reads the existing config.toml mode (statSync(...).mode & 0o777), creates the temp file owner-only (mode: 0o600), restores the prior mode with chmodSync before the rename, and defaults a new config to 0o600. A statSync failure now aborts the write instead of replacing the file.
  • Mode-preservation tests — hook-service.test.ts asserts install/remove keep an existing 0o640 mode (config and .bak) under umask 0o077 and that a new config lands at 0o600 under umask 0o022; a new hook-service-mode-read-failure.test.ts mocks statSync to fail and asserts install() 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`?

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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.

1 participant