Skip to content

fix(agent-hooks): stop test runs and secondary profiles deleting the user's agent hooks (STA-5679) - #16980

Merged
brennanb2025 merged 4 commits into
mainfrom
brennan/sta-5679-bug-cursor-loading-status-not-shown-in-left-sidebar-v14190
Aug 28, 2026
Merged

brennanb2025 merged 4 commits into
mainfrom
brennan/sta-5679-bug-cursor-loading-status-not-shown-in-left-sidebar-v14190

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​111 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​107
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​58 $\color{#cf222e}{\Huge{\mathbf{−}}}$​31 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​27

Two ways Orca deletes the user's own agent hooks. Both empty the user-global files ~/.claude/settings.json and ~/.cursor/hooks.json, and both are silent — the hook POSTs keep returning 204 afterwards.

1. A green test run deletes the developer's real hooks (the one that bites)

src/cli/runtime-client-deferral.test.ts:113 feeds ['agent','hooks','off'] to the real main(). It mocks only ./runtime/environments and ./runtime-client, so the production handler runs end to end — agent-hooks.ts:197 writes its state file, then :202 calls applyAgentStatusHooksEnabled(false) → removeManagedAgentHooks() → the developer's own ~/.claude and ~/.cursor.

Measured with a sandboxed HOME:

BEFORE -> claude:5 cursor:2
$ vitest run src/cli/runtime-client-deferral.test.ts
   Tests  23 passed (23)
AFTER  -> claude:0 cursor:0      # after this PR: 5 / 2

The repo already knew. The byte-for-byte equivalence twin refuses these exact tokens:

"MUTATING — writes outside ORCA_USER_DATA_PATH (agent hooks off parks the real ~/.claude hooks)"
— config/scripts/cli-runtime-client-deferral-equivalence.mjs

The vitest twin never got that guard. Live since #10919 (2026-07-27).

Stubbed rather than dropped: agent hooks off is the only row in that table that reads ctx.client, so it carries the null-vs-undefined coverage the other four cannot. All 23 tests still pass.

2. Startup removal is per-profile but user-global

src/main/index.ts removed the hooks whenever this profile had the off switch set. The decision reads one profile's settings; the files are shared by every instance — so a secondary profile with the switch off deletes the primary's hooks. shouldInstallManagedHooks() returns true unconditionally, so dev builds and test rigs do this to the real config too.

Honoring the off switch only needs the install skipped; removal stays on the explicit Settings toggle, which is the user-initiated path that should own it.

Verified end to end in Electron with a sandboxed HOME and a profile whose own agentStatusHooksEnabled is false:

build seeded after launch
without this fix claude 5 / cursor 4 0 / 0
with this fix claude 5 / cursor 4 5 / 4

Only the hooks key is affected either way — other settings survive.

Why this shows up as "Cursor status missing"

Cursor is the only agent with no title-derived status fallback: its native title is deliberately parsed as status-less (agent-title-status.ts:175-177), never reaches the tracker (terminal-output-side-effects.ts:167-180), and STA-2472 floors the row at 'idle' (worktree-title-derived-agent-rows.ts:152-154). So a hook wipe makes Cursor go completely silent while Claude and Codex still paint status from their own titles. Codex is unaffected regardless — its hooks live in an Orca-owned runtime home.

Tests

Three in managed-agent-hook-controls.test.ts, verified failing-first: restoring the pre-fix behavior fails with expected 'remove' to be 'skip'. A third test asserts removers still fire on the explicit toggle, anchoring the first against being a vacuous constant.

Scope

Deliberately not included: the Settings toggle still removes user-globally by design — a user with two profiles who flips it in one loses hooks in both. That is a product decision, not a bug, and is left alone here.

…ed hooks (STA-5679)

Startup reconciliation removed the managed agent hooks whenever THIS profile had
the agent-status-hooks off switch set. The hook files it removes are user-global
(~/.claude/settings.json, ~/.cursor/hooks.json), so a second Orca profile with the
switch off deleted the hooks every other running instance depends on.

Cursor is the only agent with no title-derived status fallback: its native title is
deliberately parsed as status-less, so a hookless Cursor pane is floored at 'idle'
rather than showing a spinner. A global hook wipe therefore surfaces as "Cursor
loading status missing from the sidebar" while Claude and Codex still paint status
from their own titles, which is why this reads as a Cursor-only bug. Codex is
unaffected either way because its hooks live in an Orca-owned runtime home.

Honoring the off switch only requires skipping the install; removal stays on the
explicit Settings toggle, which is the user-initiated path that should own it.

Regression from #2778, which restored the destructive startup branch.
@coderabbitai

coderabbitai Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e06d4185-5201-4920-a792-d66f5e92ddd1

📥 Commits

Reviewing files that changed from the base of the PR and between c9b38d4 and 0819373.

📒 Files selected for processing (3)
  • src/main/agent-hooks/managed-agent-hook-controls.test.ts
  • src/main/agent-hooks/managed-agent-hook-controls.ts
  • src/main/index.ts

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


📝 Walkthrough

Walkthrough

The change adds startup action resolution and per-agent startup installation checks. Startup reconciliation installs managed hooks only when global settings enable them and the agent is not disabled. Disabled settings now skip reconciliation instead of removing user-global managed hook files. Explicit Settings toggles still remove managed hooks. Tests cover startup states, disabled agents, and the explicit removal path.

Merge Risk: ⚪ Minimal · up to 08193

The change prevents test runs and disabled profiles from deleting shared agent hooks while preserving explicit user-requested removal. No actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the two deletion paths, the implementation scope, and verification results. However, it does not follow the repository template and omits or leaves incomplete several required… Restructure the description using the repository template. Add the required section headings and content, provide the linked issue in the Fixes #... field, add visual proof or write N/A with a reason, document manual and automated testi…
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main fix: preventing test runs and secondary profiles from deleting user-global agent hooks.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the two deletion paths, the implementation scope, and verification results. However, it does not follow the repository template and omits or leaves incomplete several required sections, including ELI5, What Changed, Why, Linked Issue with an issue number, Visual Proof or N/A, testing checkboxes and platform details, Review, Agent skill upstream boundary, Notes, and Checklist.

Resolution

Restructure the description using the repository template. Add the required section headings and content, provide the linked issue in the Fixes #... field, add visual proof or write N/A with a reason, document manual and automated testing with platforms, and complete the applicable review, boundary, notes, and checklist sections.

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

🧹 Nitpick comments (1)
src/main/agent-hooks/managed-agent-hook-controls.ts (1)

46-50: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reduce the repeated startup rationale to concise comments.

  • src/main/agent-hooks/managed-agent-hook-controls.ts#L46-L50: replace this with one policy comment.
  • src/main/agent-hooks/managed-agent-hook-controls.test.ts#L284-L285: remove or reduce this test explanation to one line.
  • src/main/agent-hooks/managed-agent-hook-controls.test.ts#L296-L297: remove or reduce this test explanation to one line.
  • src/main/index.ts#L3100-L3102: remove the duplicate rationale or use one short policy comment.

As per coding guidelines, **/*.{ts,tsx,js,jsx} requires concise comments, one line if possible.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e3e106d8-205e-4bfb-837f-077fcff8e6ef

📥 Commits

Reviewing files that changed from the base of the PR and between 6c58038 and 4ff07da.

📒 Files selected for processing (3)
  • src/main/agent-hooks/managed-agent-hook-controls.test.ts
  • src/main/agent-hooks/managed-agent-hook-controls.ts
  • src/main/index.ts

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

… agent hooks

runtime-client-deferral.test.ts runs the REAL `main()` and feeds it
`agent hooks off`. It mocks only ./runtime/environments and ./runtime-client, so
the production handler ran end to end: updateEnabledOnDisk() wrote its state file
and applyAgentStatusHooksEnabled(false) called removeManagedAgentHooks() against
the developer's OWN ~/.claude/settings.json and ~/.cursor/hooks.json.

A green test run therefore deleted every Orca-managed hook on the machine. Agent
status then stopped reporting until the next Orca restart reinstalled them —
silently, because the hook POSTs still return 204 and Cursor has no title-derived
status fallback at all.

The byte-for-byte equivalence twin already refuses these exact tokens, commented
"MUTATING — writes outside ORCA_USER_DATA_PATH (`agent hooks off` parks the real
~/.claude hooks)". The vitest twin never got that guard.

Stub the hook-controls module rather than dropping the row: `agent hooks off` is
the only case in the table that reads ctx.client, so it carries the
null-vs-undefined coverage the other four cannot. All 23 tests still pass, and a
sandboxed HOME now keeps its hooks (5 -> 5) where it previously lost them (5 -> 0).
@brennanb2025 brennanb2025 changed the title fix(agent-hooks): stop startup from deleting another instance's managed hooks (STA-5679) fix(agent-hooks): stop test runs and secondary profiles deleting the user's agent hooks (STA-5679) Aug 28, 2026
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: PASS / CLEAN

Completed the requested review loop with same-model, xhigh-reasoning subagents, including $readiness-checklist passes at the start and end plus a precedent review using $ref-oss.

The loop found and pushed two meaningful, in-scope improvements:

  • c9b38d4aca — ratchets the CLI deferral test so the mutating hook handler is mocked and positively asserted, and isolates each case with temporary user data.
  • 0819373c49 — closes the remaining startup ownership gap: automatic startup reconciliation is install-only for both managed providers and Codex real-home hooks, while explicit Settings, CLI, and runtime actions retain removal behavior.

Post-fix adversarial review and the final readiness pass found no remaining P0/P1/P2 correctness, lifecycle, regression, cross-platform, security, or performance issues. The implementation is aligned with established managed-integration precedent: automatic startup may reconcile/install shared user-global integration state, but profile-local startup preferences must not destructively remove it; destructive cleanup remains tied to explicit user action.

Verification completed:

  • Sandboxed hook suites: 74/74 passed.
  • Sandboxed explicit-action coverage: 56 selected tests passed.
  • Direct oxlint, type-aware oxlint, React Doctor, and git diff --check: passed.
  • Node 24 changed-code-quality check: passed.
  • GitHub CI: typecheck, static analysis, packaging, managed-hooks Node 18, all 8 test shards, and native smoke checks are green.

Residual note: no Electron/mobile UI validation was run because this PR changes non-visual main-process startup and test safety paths; the rendered UI is unchanged. The branch is clean, pushed, and the PR currently reports a clean merge state.

@brennanb2025
brennanb2025 merged commit 2c86d2a into main Aug 28, 2026
31 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 30, 2026
…user's agent hooks (STA-5679) (stablyai#16980)

* fix(agent-hooks): stop startup from deleting another instance's managed hooks (STA-5679)

Startup reconciliation removed the managed agent hooks whenever THIS profile had
the agent-status-hooks off switch set. The hook files it removes are user-global
(~/.claude/settings.json, ~/.cursor/hooks.json), so a second Orca profile with the
switch off deleted the hooks every other running instance depends on.

Cursor is the only agent with no title-derived status fallback: its native title is
deliberately parsed as status-less, so a hookless Cursor pane is floored at 'idle'
rather than showing a spinner. A global hook wipe therefore surfaces as "Cursor
loading status missing from the sidebar" while Claude and Codex still paint status
from their own titles, which is why this reads as a Cursor-only bug. Codex is
unaffected either way because its hooks live in an Orca-owned runtime home.

Honoring the off switch only requires skipping the install; removal stays on the
explicit Settings toggle, which is the user-initiated path that should own it.

Regression from stablyai#2778, which restored the destructive startup branch.

* fix(cli-tests): stop the deferral suite deleting the developer's real agent hooks

runtime-client-deferral.test.ts runs the REAL `main()` and feeds it
`agent hooks off`. It mocks only ./runtime/environments and ./runtime-client, so
the production handler ran end to end: updateEnabledOnDisk() wrote its state file
and applyAgentStatusHooksEnabled(false) called removeManagedAgentHooks() against
the developer's OWN ~/.claude/settings.json and ~/.cursor/hooks.json.

A green test run therefore deleted every Orca-managed hook on the machine. Agent
status then stopped reporting until the next Orca restart reinstalled them —
silently, because the hook POSTs still return 204 and Cursor has no title-derived
status fallback at all.

The byte-for-byte equivalence twin already refuses these exact tokens, commented
"MUTATING — writes outside ORCA_USER_DATA_PATH (`agent hooks off` parks the real
~/.claude hooks)". The vitest twin never got that guard.

Stub the hook-controls module rather than dropping the row: `agent hooks off` is
the only case in the table that reads ctx.client, so it carries the
null-vs-undefined coverage the other four cannot. All 23 tests still pass, and a
sandboxed HOME now keeps its hooks (5 -> 5) where it previously lost them (5 -> 0).

* fix(cli-tests): ratchet agent hook deferral safety

* fix(agent-hooks): keep startup reconciliation install-only

(cherry picked from commit 2c86d2a)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…user's agent hooks (STA-5679) (stablyai#16980)

* fix(agent-hooks): stop startup from deleting another instance's managed hooks (STA-5679)

Startup reconciliation removed the managed agent hooks whenever THIS profile had
the agent-status-hooks off switch set. The hook files it removes are user-global
(~/.claude/settings.json, ~/.cursor/hooks.json), so a second Orca profile with the
switch off deleted the hooks every other running instance depends on.

Cursor is the only agent with no title-derived status fallback: its native title is
deliberately parsed as status-less, so a hookless Cursor pane is floored at 'idle'
rather than showing a spinner. A global hook wipe therefore surfaces as "Cursor
loading status missing from the sidebar" while Claude and Codex still paint status
from their own titles, which is why this reads as a Cursor-only bug. Codex is
unaffected either way because its hooks live in an Orca-owned runtime home.

Honoring the off switch only requires skipping the install; removal stays on the
explicit Settings toggle, which is the user-initiated path that should own it.

Regression from stablyai#2778, which restored the destructive startup branch.

* fix(cli-tests): stop the deferral suite deleting the developer's real agent hooks

runtime-client-deferral.test.ts runs the REAL `main()` and feeds it
`agent hooks off`. It mocks only ./runtime/environments and ./runtime-client, so
the production handler ran end to end: updateEnabledOnDisk() wrote its state file
and applyAgentStatusHooksEnabled(false) called removeManagedAgentHooks() against
the developer's OWN ~/.claude/settings.json and ~/.cursor/hooks.json.

A green test run therefore deleted every Orca-managed hook on the machine. Agent
status then stopped reporting until the next Orca restart reinstalled them —
silently, because the hook POSTs still return 204 and Cursor has no title-derived
status fallback at all.

The byte-for-byte equivalence twin already refuses these exact tokens, commented
"MUTATING — writes outside ORCA_USER_DATA_PATH (`agent hooks off` parks the real
~/.claude hooks)". The vitest twin never got that guard.

Stub the hook-controls module rather than dropping the row: `agent hooks off` is
the only case in the table that reads ctx.client, so it carries the
null-vs-undefined coverage the other four cannot. All 23 tests still pass, and a
sandboxed HOME now keeps its hooks (5 -> 5) where it previously lost them (5 -> 0).

* fix(cli-tests): ratchet agent hook deferral safety

* fix(agent-hooks): keep startup reconciliation install-only
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