Skip to content

fix(hooks): stop orphaned managed markers from consuming user TOML - #20148

Merged
nwparker merged 1 commit into
mainfrom
fix/orphan-hook-marker
Sep 12, 2026
Merged

nwparker merged 1 commit into
mainfrom
fix/orphan-hook-marker

Conversation

@nwparker

@nwparker nwparker commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​553 $\color{#cf222e}{\Huge{\mathbf{−}}}$​20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​533
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​359 $\color{#cf222e}{\Huge{\mathbf{−}}}$​62 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​297

Fixes #18861

ELI5

Orca adds its own section to the bottom of some agent config files, and wraps that section in two comment lines that say "Orca's stuff starts here" and "Orca's stuff ends here". If the "ends here" line went missing — someone tidied the file, or a config tool rewrote it — Orca assumed everything from "starts here" to the end of the file was its own, and deleted all of it the next time it installed or uninstalled. Anything you had added below, like an API key or another tool's settings, silently disappeared. On top of that, if the marker comments went missing entirely, "uninstall" quietly found nothing to remove and left Orca's hooks running on your machine after you'd turned them off.

Now Orca only deletes two kinds of thing: what sits between a matched pair of markers, and lines it can positively recognise as text it wrote itself. If it can't prove a line is its own, it leaves it alone. So your settings survive, and uninstall actually removes the hooks even when the markers are long gone.

Why no screenshots

There is no UI for this. Managed hook install/remove is deliberately never exposed to the renderer (src/main/ipc/agent-hooks.ts: "install/remove are intentionally not exposed to the renderer" — Orca auto-installs at startup), so the only human-facing surfaces are the orca agent hooks status CLI output and the config file itself. Both are captured below as literal text. A screenshot here would be theatre.

The bug (data loss, two separate paths)

Orca appends marker-delimited blocks to user-owned TOML config files. The end marker is the only proof of where Orca's bytes stop. Both managed-TOML-block implementations treated a missing end marker as "Orca owns everything through EOF" — so a single hand-edit that dropped the end marker turned the next uninstall or reinstall into a silent delete of every table the user had appended below.

Path 1 — Kimi ~/.kimi-code/config.toml (src/main/kimi/kimi-hook-config-toml.ts). The block regex ended in (?:BLOCK_END[^\n]*|$); the $ alternative swallowed the rest of the file.

Path 2 — Codex legacy profile ~/.codex/orca-agent-status.config.toml (src/main/codex/codex-hook-legacy-cleanup.ts). Same shape, spelled differently:

const end = endMarker === -1 ? content.length : endMarker + LEGACY_ORCA_PROFILE_BLOCK_END.length

This second one runs from cleanupLegacyManagedHookRepresentations() on every Codex hook cleanup, against a file that also holds the user's [projects.*] trust entries. It is not a footnote — it is an independent way to lose user config.

I re-swept src/main/ for a third instance: there are exactly two paired start/end marker conventions in the codebase (kimi-hook-config-toml.ts, codex-hook-legacy-cleanup.ts), both fixed here. The other === -1 ? content.length hits in config-toml-hook-trust-blocks.ts, config-toml-hook-trust-read.ts and config-toml-project-trust.ts are not affected: those bound a block by the next TOML table header, which is the actual TOML grammar for a table's extent, not a marker convention that can go missing. The .orca-managed-* / @orca-managed-pi-extension markers are whole-file ownership flags with no extent to get wrong.

The policy

New shared module src/main/agent-hooks/managed-toml-ownership.ts. Two independent things make a byte Orca's, and separating them is the whole fix:

Marker extent — where a block starts and stops.

  1. A block opens at a line whose trimmed text starts with the start marker.
  2. Terminated block: everything between the markers is Orca's. The end marker is proof of extent, regardless of content.
  3. Orphaned block: owns only its own stray marker line. Never any content, for any caller, no exceptions. Without the end marker there is no evidence of extent, so there is nothing to infer from.
  4. A second start marker always closes a preceding orphan.
  5. Splicing is offset-based on the raw text, so CRLF round-trips verbatim.

Recognition — content Orca can prove it wrote.

  1. A provider may supply a recognizer. Every table it positively identifies is Orca's wherever it sits in the file, inside a block or not.
  2. A provider with no recognizer owns nothing beyond rules 1–5 (fail closed).
  3. Both sets of regions are merged and spliced in a single pass, so overlaps and nesting cannot double-remove.

Kimi's recognizer: a [[hooks]] table whose command is accepted by createManagedCommandMatcher('kimi-hook.sh'). That command path is the only reason the table fires, and it is there because Orca put it there — so the table is Orca's, extra keys and all. A table invoking anything else is the user's and is never touched. One shape guard remains: if a line in the table is not a simple key = value pair (a multi-line array or string, say) the table's extent is not knowable by line scanning, so recognition fails closed rather than splicing the wrong bytes.

Ownership is deliberately the same test for remove, install and status. An asymmetry here is not a safety margin — it is a bug: if status cannot see a table that install does not remove, install appends a second table for the same event and the hook double-fires.

Codex's legacy block gets no recognizer on purpose. That body's shape is not derivable from current source (it was written by a version that no longer exists), so there is nothing to positively recognize and rule 7 applies.

Recovery therefore never has to guess. Orphan handling does not try to infer where Orca's bytes end — it deletes the stray marker and lets recognition reclaim the actual content, wherever a hand-edit or a rewriter left it.

Evidence on real files

Driven through the real code paths — kimiHookService.install() / .remove() and cleanupLegacyManagedHookRepresentations() — against real files on disk, not test doubles. Pre-fix results come from running the parent commit's functions on byte-identical input.

Kimi: end marker hand-deleted, user tables appended below

BEFORE (3308 bytes; end marker absent; managed [[hooks]] bodies elided for length):

default_model = "kimi-k2.6"

[providers."mine"]
type = "openai"
base_url = "https://example.com/v1"
api_key = "sk-SECRET-DO-NOT-LOSE"

# >>> orca-managed-kimi-hooks (managed by Orca; do not edit) >>>
[[hooks]]
event = "UserPromptSubmit"
command = "<managed kimi-hook.sh launcher>"
timeout = 10
... 6 more managed tables ...
                              <-- end marker was here, deleted by hand

[providers."work"]
type = "anthropic"
api_key = "sk-USER-APPENDED-AFTER-THE-ORPHAN"

[[hooks]]
event = "Stop"
command = "node /home/u/my-own-hook.mjs"
timeout = 30

PRE-FIX remove() → 134 bytes. Everything from the stray marker to EOF is gone:

default_model = "kimi-k2.6"

[providers."mine"]
type = "openai"
base_url = "https://example.com/v1"
api_key = "sk-SECRET-DO-NOT-LOSE"
sk-USER-APPENDED-AFTER-THE-ORPHAN survived? 0
user's own [[hooks]] survived?            0
[providers."work"] survived?              0

install() on the same input loses the same bytes (3177 bytes out, 0 occurrences of either user string).

FIXED remove() → 299 bytes:

default_model = "kimi-k2.6"

[providers."mine"]
type = "openai"
base_url = "https://example.com/v1"
api_key = "sk-SECRET-DO-NOT-LOSE"

[providers."work"]
type = "anthropic"
api_key = "sk-USER-APPENDED-AFTER-THE-ORPHAN"

[[hooks]]
event = "Stop"
command = "node /home/u/my-own-hook.mjs"
timeout = 30
$ diff <before user-owned tail> <after user-owned tail>
IDENTICAL (164 bytes preserved verbatim)
stray start marker gone?          0 occurrences
managed kimi-hook.sh tables gone? 0 occurrences

FIXED install() on the same orphan keeps both user tables, emits exactly 1 start marker and 1 end marker, and a second install() is byte-identical — the recovery converges in one step.

Kimi: the other cases

Case Result
Intact block, remove() restored to exactly the 134-byte pre-install user config (diff clean)
Duplicate start markers (orphan + a full block) both reclaimed; 0 markers and 0 managed commands left, [user.kept] intact
Genuinely managed orphan table + [hand.written] below managed table reclaimed (540 → 62 bytes), [hand.written] kept
Managed table stranded below user text reclaimed (916 → 20 bytes); 0 live hooks left, [user.table] kept
User's own [[hooks]] table outside any marker untouched (diff clean)
Managed table with a user-added matcher key untouched (diff clean)

Kimi: CRLF

Install onto a CRLF config, delete the end marker, append CRLF user tables, run the real remove():

$ od -c ~/.kimi-code/config.toml
0000000  d e f a u l t _ m o d e l   =
0000020  " k i m i - k 2 . 6 "  \r  \n  \r  \n   [
...
0000220  E - O R P H A N "  \r  \n
$ file ~/.kimi-code/config.toml
ASCII text, with CRLF line terminators
bare LF count: 0

For contrast, the pre-fix builder had no EOL detection at all and wrote LF into a CRLF file: with CRLF, LF line terminators, bare LF count: 32.

Codex legacy profile

BEFORE (200 bytes, end marker hand-deleted):

model = "o3"
model_provider = "openai"

# BEGIN ORCA AGENT STATUS HOOKS
[[hooks]]
event = "Stop"
command = "/home/u/.orca/agent-hooks/codex-hook.sh"

[projects."/home/u/work"]
trust_level = "trusted"

PRE-FIX → 39 bytes. The user's trust grant is gone:

model = "o3"
model_provider = "openai"

FIXED → 200 bytes, diff against the input is empty: fail closed, file untouched byte-for-byte.

Intact-block removal still works (230 → 90 bytes; managed block gone, trust_level kept), and the splice seam now rejoins with the file's own terminator, so a CRLF profile comes back with CRLF line terminators / bare LF count: 0 instead of the previous mixed endings.

The CLI surface

orca agent hooks status on a config whose markers were dropped by a TOML rewriter (7 managed hook tables, 0 markers):

main   $ orca agent hooks status
       kimi: not_installed          <- wrong; 7 hooks are live and unreachable

this   $ orca agent hooks status
       kimi: installed

And on a config where only some managed tables survive, this PR reports the truth instead of silence:

$ orca agent hooks status
kimi: partial
  detail: Managed hook missing for events: UserPromptSubmit, PostToolUse, PostToolUseFailure, PermissionRequest, StopFailure

Known behaviour changes

Called out so they are not a surprise in review:

  • Uninstall now removes an Orca-shaped hook table sitting outside the markers. A [[hooks]] table with exactly event/command/timeout, a known Kimi event and a command pointing at agent-hooks/kimi-hook.sh is Orca's wherever it sits. On main such a table survived remove(); now it does not. That is the point of the change, but a user who deliberately copied Orca's table into their own section will find it gone after uninstall.
  • Status can now say installed for a config containing no Orca markers. Correct — the hooks really are live — but it may look odd to someone reading their config for the marker comments.
  • Orca's managed hook table cannot be customised by adding keys to it. Adding matcher = "Bash" to a table that invokes kimi-hook.sh no longer protects it: uninstall removes it and reinstall replaces it with the canonical block. This matches what the markers already say ("managed by Orca; do not edit") and what happens to a customised table inside an intact block today. The alternative was worse — an earlier revision of this PR exempted such tables, which left the hook running after uninstall and double-fired Stop after the next startup install.
  • Removing a block that starts at byte 0 can leave one leading blank line. Cosmetic; valid TOML.

Bonus: uninstall now works on a marker-less config

Recognition fixes a second, more reachable problem that predates #18861. Markers are TOML comments, so anything that round-trips the file through a TOML serializer — kimi config set, a dotfile manager, any config editor — drops both markers while keeping the hook tables. Pre-fix, remove() then found nothing and left all 7 managed hooks live, permanently, with no way for Orca to ever find them again:

config after a TOML-aware rewrite: 0 start markers, 0 end markers, 7 managed [[hooks]] tables

PRE-FIX  remove() -> 7 managed hooks still live after "uninstall"
FIXED    remove() -> 0 managed hooks live; user config preserved verbatim

Unlike the interleaved-orphan case, this one needs no hand-editing at all.

The one remaining fail-closed trade

An orphaned legacy Codex block is never removed. Rule 7 means the block stays in orca-agent-status.config.toml forever. That is acceptable because the stale profile is inert — the runtime CODEX_HOME supersedes it, and it defines no live hook — so leaving it costs nothing next to destroying the [projects.*] trust entries sitting below it. The failure mode is "a stale comment block remains", not "a hook keeps running".

There is deliberately no equivalent trade on the Kimi side. An earlier revision of this PR bounded orphan recovery at the first unrecognized line and accepted that managed tables stranded below user text would survive remove(). That was wrong: those tables still execute. Verified against a real config — after remove() a TOML reader still saw event=PreToolUse managed=true, ~/.orca/agent-hooks/kimi-hook.sh was still present and executable, and that script spools agent events to disk and POSTs them to Orca's hook server. getStatus() meanwhile reported not_installed, and a subsequent install() produced two PreToolUse tables and double-fired the event. Fail-closed on user bytes is right; fail-silent on Orca's own leftovers is a different thing and does not inherit the same justification. Recognition-based ownership removes the trade entirely:

After remove() on a stranded managed table Earlier revision Now
Managed [[hooks]] a TOML reader sees 1 (PreToolUse, live) 0
getStatus() not_installed (wrong) not_installed (true)
install() afterwards PreToolUse ×2, double-fires ×1, converges, byte-identical on a second run

Relationship to open community PRs

#19033 — @cat-xierluo, "fix(kimi): bound orphaned managed-block recovery to installer-shaped tables". Same root cause, and their bounded-recovery mechanism is exactly the rule this PR started with: stop orphan recovery at the first line that is not installer-shaped. They are credited as co-author. Their patch is careful in ways I had to rediscover — CRLF-aware line boundaries, and a boundary check so a user table that reuses the installer field order but carries extra keys is left whole rather than truncated to its installer-shaped prefix.

This PR then goes further in three places, all found by pushing on that shared design:

  1. A second instance. src/main/codex/codex-hook-legacy-cleanup.ts had the same "no end marker means delete to EOF" shape against a file that also holds the user's [projects.*] trust entries. fix(kimi): bound orphaned managed-block recovery to installer-shaped tables #19033 fixes Kimi only.
  2. Bounded recovery leaves a live hook. Stopping at the first unrecognized line means a managed table stranded below user text survives uninstall and keeps firing, invisible to status — and the next startup install then double-fires that event. That is why ownership here is by recognition wherever the table sits, not by position, and why remove, install and status share one test.
  3. Marker matching must be exact. fix(kimi): bound orphaned managed-block recovery to installer-shaped tables #19033's regex embeds escapeRegex(BLOCK_START) without a line anchor, so — like this PR before review — a user quoting the marker in a comment of their own opens a region. CodeRabbit caught it here; both markers are now compared against the whole trimmed line.

#18813 — @Djiit, "feat(vibe): add managed hook transport, live status, and session resume". Not a fix for #18861, but it is not unrelated: it adds src/main/vibe/hook-config-toml.ts containing a verbatim copy of the pre-fix regex, `\n*${escapeRegex(BLOCK_START)}[\s\S]*?(?:${escapeRegex(BLOCK_END)}[^\n]*|$)`, so merging it as-is reintroduces this data-loss bug for Vibe. @cat-xierluo flagged this lockstep risk on #19033 and they were right. Vibe is not on main, so this PR cannot fix it; #18813 should adopt managed-toml-ownership.ts instead of cloning the regex. Commented there.

Verification

  • pnpm test src/main/kimi src/main/codex src/main/agent-hooks/managed-toml-ownership.test.ts src/main/agent-hooks/installer-utils.test.ts src/main/agent-hooks/remote-hook-service-installers.test.ts src/main/agent-hooks/managed-hook-detection-commands.test.ts — 8 files, 141 passed / 3 skipped
  • pnpm tc — clean
  • oxlint — clean; oxfmt --check — clean
  • pnpm run check:code-quality:changed — 0 new findings across 7 changed files

SSH: installRemote shares the same recognizer, so a remote Kimi config orphaned or rewritten the same way recovers identically. No mobile-facing surface touched.

Orca's own writeConfigToml is temp+rename atomic, so Orca cannot itself truncate a config into the orphaned state — it takes an external edit or an external writer. The marker-less case above needs neither.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: be2bd576-25cb-42fb-8163-a2303ebffde8

📥 Commits

Reviewing files that changed from the base of the PR and between 42437ddb7bc71ba05d9100af79664b204c1d936f and 47391f9.

📒 Files selected for processing (4)
  • src/main/codex/codex-hook-legacy-cleanup.ts
  • src/main/codex/codex-hook-legacy-profile-block.test.ts
  • src/main/kimi/kimi-hook-config-toml.test.ts
  • src/main/kimi/kimi-hook-config-toml.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/codex/codex-hook-legacy-cleanup.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The change adds shared TOML ownership utilities for marker blocks and recognized tables. Codex cleanup now fails closed on unterminated blocks and preserves EOL style. Kimi hook management uses validated ownership matching across status, installation, remote installation, removal, and event reading. Tests cover orphaned markers, user configuration preservation, duplicate blocks, idempotency, and CRLF handling.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 47391

Managed TOML cleanup now preserves unrecognized user configuration while removing validated managed content, including malformed-marker and CRLF cases. No merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Issue #18861 requires the orphaned TOML fix in both Kimi and Vibe, plus a user-TOML preservation regression test in both suites. The PR implements shared ownership logic and updates Kimi with the requ… Update the Vibe TOML implementation and add the required orphaned-block user-TOML preservation regression test in the Vibe test suite. Ensure orphan recovery does not claim user TOML through end-of-file.
Out of Scope Changes check ⚠️ Warning Issue #18861 scopes this fix to Kimi and Vibe TOML hook handling. The PR also changes Codex legacy profile cleanup and adds Codex-specific tests. The linked issue provides no Codex coding requirement.… Remove the Codex cleanup implementation and tests from this PR, or provide a directly linked coding requirement that includes Codex legacy profile cleanup.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: preventing orphaned managed markers from consuming user TOML.
Description check ✅ Passed The description is detailed and directly covers the problem, solution, linked issue, behavior changes, testing, cross-platform considerations, and lack of UI impact. It uses some headings that differ …
Full details: Linked Issues check

Explanation

Issue #18861 requires the orphaned TOML fix in both Kimi and Vibe, plus a user-TOML preservation regression test in both suites. The PR implements shared ownership logic and updates Kimi with the required tests. The change summary contains no Vibe implementation or Vibe test change, and the reviewed head has no readable Vibe path at the expected locations. Vibe compliance is not established and the required two-provider change is incomplete.

Full details: Out of Scope Changes check

Explanation

Issue #18861 scopes this fix to Kimi and Vibe TOML hook handling. The PR also changes Codex legacy profile cleanup and adds Codex-specific tests. The linked issue provides no Codex coding requirement. These changes are not necessary to implement the Kimi and Vibe requirements.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 07706188-7d5b-4fb9-bb49-7a7284791650

📥 Commits

Reviewing files that changed from the base of the PR and between 7294915 and 9d4bdd33eefec6b7e6e085642542bdabd3e8c7c7.

📒 Files selected for processing (8)
  • config/tsconfig.cli.json
  • src/main/agent-hooks/managed-toml-block-ownership.test.ts
  • src/main/agent-hooks/managed-toml-block-ownership.ts
  • src/main/codex/codex-hook-legacy-cleanup.ts
  • src/main/codex/codex-hook-legacy-profile-block.test.ts
  • src/main/kimi/hook-service.ts
  • src/main/kimi/kimi-hook-config-toml.test.ts
  • src/main/kimi/kimi-hook-config-toml.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Comment thread src/main/kimi/kimi-hook-config-toml.ts Resolved
@nwparker
nwparker force-pushed the fix/orphan-hook-marker branch from 9d4bdd3 to 3f6ae50 Compare September 11, 2026 19:48

@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 — a data-loss fix for Orca's marker-delimited TOML hook config blocks, applied to both the Kimi config block and the legacy Codex profile cleanup path.

  • managed-toml-block-ownership.ts — new shared, offset-based scanner that bounds an orphaned (end-marker-deleted) block to content a per-policy recognizer positively identifies, and fails closed when no recognizer is supplied; splices CRLF back verbatim.
  • Kimi config block — applyManagedKimiHooks / removeManagedKimiHooks / readManagedKimiHookEvents now route through the new module with a conservative [[hooks]] recognizer (exact event/command/timeout shape, known event, numeric timeout, command still pointing at kimi-hook.sh).
  • Legacy Codex profile block — stripLegacyManagedProfileBlock fails closed on an orphan instead of deleting to EOF, and rejoins with the file's own terminator.
  • Tests — thorough coverage of orphan recovery, user-tail preservation, CRLF round-trips, duplicate/stray markers, and fail-closed behavior.

The core guarantee holds up under tracing: an orphaned block's ownership is bounded at the first line the recognizer rejects, so user tables appended below a hand-deleted end marker are preserved on both remove() and install(). The two documented fail-closed trades (Kimi tables stranded below user text survive and stay invisible to getStatus(); orphaned legacy Codex blocks are left in place) are the correct direction — "stale text remains" instead of "user keys and trust grants are gone."

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

@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 (delta since the prior review at 9d4bdd3) — the fix was redesigned from "bound an orphan at the first unrecognized line" to a cleaner two-signal model, and the stranded-table trade was eliminated.

  • Module renamed to managed-toml-ownership.ts and the policy split: marker extent (terminated block owns everything between markers; an orphan owns only its stray marker line) is now independent of recognition.
  • Recognition decoupled from markers — findRecognizedManagedTables identifies Orca-emitted tables anywhere in the file, and stripManagedTomlRegions merges the two region sets in one sorted splice so nesting/overlap can't double-remove.
  • Stranded-table trade removed — managed [[hooks]] tables left below user text are now reclaimed on remove()/install() instead of silently firing, and readManagedKimiHookEvents (now derived purely from recognition) reports them as live so getStatus() can't claim not_installed.
  • Recognizer tightened — the key run now terminates on a # line (the end marker included), so the last managed table adjacent to BLOCK_END is still recognized; otherwise unchanged (exact event/command/timeout, known event, numeric timeout, managed command path).

I re-traced the ownership logic end-to-end: the merge splice is correct for disjoint, overlapping, and nested regions; readManagedKimiHookEvents matches getStatus() to the tables actually still firing; and the file-wide recognition can't over-remove user content because a table only qualifies when its command still references agent-hooks/kimi-hook.sh. The orphan fail-closed guarantee for the legacy Codex block is preserved.

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 3b1ee35a-fdb0-417e-8468-24c221f8b7d9

📥 Commits

Reviewing files that changed from the base of the PR and between 9d4bdd33eefec6b7e6e085642542bdabd3e8c7c7 and 3f6ae50.

📒 Files selected for processing (6)
  • config/tsconfig.cli.json
  • src/main/agent-hooks/managed-toml-ownership.test.ts
  • src/main/agent-hooks/managed-toml-ownership.ts
  • src/main/codex/codex-hook-legacy-cleanup.ts
  • src/main/kimi/kimi-hook-config-toml.test.ts
  • src/main/kimi/kimi-hook-config-toml.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@nwparker
nwparker force-pushed the fix/orphan-hook-marker branch 2 times, most recently from e7ed867 to c8ec67c Compare September 12, 2026 02:24

@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 critical issues — one edge case in the relaxed recognizer worth a look.

Reviewed changes — delta since the prior pullfrog review at 3f6ae50: the Kimi hook-table recognizer was relaxed to key only on the managed command path.

  • Relaxed recognizer — matchManagedHookTable no longer requires exactly event/command/timeout, a known KIMI_HOOK_EVENTS event, or a numeric timeout; a [[hooks]] table is Orca-owned whenever its command resolves to the managed script, so extra keys (e.g. matcher) no longer shield a customised hook from uninstall.
  • Status derived from recognition — readManagedKimiHookEvents now reads events from the same recognizer rather than re-parsing the marker block, keeping stranded tables visible to getStatus().
  • Tests — exact-assertion coverage added for extra-key ownership, customised tables sitting outside any marker, multi-line-value fail-closed, and user hooks that don't invoke the managed script. Re-ran the three focused suites locally: 42 passed.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Comment thread src/main/kimi/kimi-hook-config-toml.ts Resolved

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: ef0efa02-ea62-4009-9e05-aad2cb2cf304

📥 Commits

Reviewing files that changed from the base of the PR and between 3f6ae50 and c8ec67c.

📒 Files selected for processing (2)
  • src/main/kimi/kimi-hook-config-toml.test.ts
  • src/main/kimi/kimi-hook-config-toml.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Comment thread src/main/kimi/kimi-hook-config-toml.ts Resolved
@nwparker
nwparker force-pushed the fix/orphan-hook-marker branch from c8ec67c to 42437dd Compare September 12, 2026 03:37
A managed block missing its end marker was treated as Orca-owned through EOF,
so uninstall/reinstall deleted appended user tables. The same shape existed a
second time in the Codex legacy profile cleanup.

Ownership is now two separate claims: a marker pair proves extent, and a
provider that can recognize its own emitted tables owns them wherever they
sit. An orphaned marker owns only its own line. Recognition uses the same
test for remove, install and status, so a table Orca cannot see is never one
it leaves running.

Co-authored-by: maoking <[email protected]>

Fixes #18861

@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 — delta since the prior pullfrog review at c8ec67c: two review-driven hardening fixes plus the recognizer/status alignment raised in the prior thread.

  • Exact marker matching — findManagedTomlBlocks now requires the whole trimmed line to equal a marker, so a user comment quoting a marker can no longer open or close a region and consume the file between two quoted lines.
  • Gap-inside-table guard — matchManagedHookTable fails closed when a key line follows a blank line or comment before the next [ header, so recognition cannot splice a table's installer-shaped prefix and strand the trailing keys (e.g. timeout) without their [[hooks]] header.
  • Status/remove agreement — readTomlString/readEventName now parse basic and literal TOML strings and ignore inline comments, falling back to the raw literal for an unparseable event; a table remove() strips can no longer leave getStatus() at not_installed.
  • Legacy Codex cleanup — stripLegacyManagedProfileBlock scans all block regions and strips the first terminated one, so a stray start marker above a complete block no longer hides it.

I traced the recognizer end-to-end against the new tests: exact matching still accepts the indented/trailing-whitespace marker forms and no longer fires on prefixed or altered markers; keysFollowGap only fails when genuine keys follow a gap before a header (consecutive [[hooks]] tables and a trailing end marker still recognize), and the event fallback keeps an unparseable literal out of not_installed. Ran the three focused suites locally — 50 passed.

Pullfrog  | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 438e0f4 into main Sep 12, 2026
33 checks passed
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.

Managed hook marker regex: orphaned end-marker deletes user TOML (Kimi + Vibe)

1 participant