Skip to content

fix(hooks): run worktree setup only when its content matches the approved script - #37977

Merged
nwparker merged 4 commits into
mainfrom
nwparker/setup-trust-created-worktree
Nov 6, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/setup-trust-created-worktree

Conversation

@nwparker

@nwparker nwparker commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When you create a workspace, Orca asks you to trust the repo's orca.yaml setup commands. It showed you the commands from your main checkout, but ran the ones in the new workspace's branch. Usually they're the same. When they're not, Orca now holds off running them, tells you, and shows you the commands that are actually in that branch.

Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​379 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​378
Prod 24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​294 $\color{#cf222e}{\Huge{\mathbf{−}}}$​89 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​205

What Changed

  • hashOrcaHookTrustContent (main) uses the same trimmed SHA-256 as the renderer prompt. A parity test hashes one orca.yaml fixture on both sides: CRLF and BOM primary checkouts, trailing whitespace, tabs, YAML merge keys, quoted/folded tab commands, the plain-HTTP JS digest, and the hash a runtime host reports to remote/mobile clients. It also pins the digest, so changing the trust-content format (which would invalidate saved automation approvals) has to be deliberate.
  • Creates carry an optional approvedSetupHash (local IPC, worktree.create RPC, web client). The composer and direct work-item launch send it; repo-wide trust and the local-only policy don't.
  • After git worktree add, both host paths (desktop/WSL and runtime/SSH orcad) hash the created worktree's setup + default-tab commands via checkCreatedWorktreeSetupTrust. On a mismatch they skip setup and command tabs and return setupTrustMismatch with the content.
  • Renderer: on a mismatch, a "Setup didn't run" toast plus the existing trust prompt with the worktree's content (approval recorded once per hash).

Stack: this PR → #37978 (run setup after approval) → #37979 (automations). This PR is safe on its own: mismatches skip setup instead of running unapproved content.

Why

The commands that run should be the ones that were approved.

Linked Issue

N/A (maintainer). Earlier remote-only attempt: #15087.

Visual Proof

N/A for the common case (content matches: unchanged). Mismatch shows an existing toast + the existing trust dialog.

Testing

  • Host: matching hash runs; different hash skips and returns content; no hash (older client) behaves as today, on both host paths.
  • Renderer: hash sent; mismatch re-prompts.
  • pnpm tc, oxlint, changed-code quality gate.

Risk

Level: Low. Only creates where the base branch's orca.yaml setup or default-tab commands really differ from the primary checkout's change: the workspace is still created and setup waits for approval. False mismatches are ruled out by the parity tests: both sides parse with the same parseOrcaYaml, which normalizes CRLF/BOM, then build the content with getSetupTrustContent and hash it with trimmed SHA-256. Nothing changes when there's no hash: older clients, CLI, mobile, orchestration workers, session fork, stored decisions from before this change, repo-wide trust, and the local-only policy all keep today's behaviour. Mixed versions are unchanged too: a new client talking to an old host has the field stripped by the zod schema, and an old client sends none. Folder workspaces aren't affected. On its own this PR shows the prompt, but approving only takes effect once #37978 lands. Plain revert.

AI Disclosure

Written with Claude Code.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9676e927-7e4f-4d92-b563-d3d82fd5b2ab
Commits

Reviewing files that changed from the base of the PR and between d3a94e2 and 7b617ae.

Files selected for processing: 29

  • config/tsconfig.node.json
  • src/main/ipc/worktree-remote.ts
  • src/main/runtime/repositories/runtime-repository-hooks-commands.ts
  • src/main/runtime/rpc/methods/workspaces/worktree-create-args.ts
  • src/main/runtime/workspaces/creation/runtime-local-worktree-setup-trust.test.ts
  • src/main/runtime/workspaces/creation/runtime-local-worktree-setup.ts
  • src/main/runtime/workspaces/creation/runtime-managed-worktree-create-types.ts
  • src/main/runtime/workspaces/creation/workspace-creation.ts
  • src/main/workspace-hooks/created-worktree-setup-trust-parity.test.ts
  • src/main/workspace-hooks/created-worktree-setup-trust.ts
  • src/renderer/src/components/terminal-pane/launch-parity-window-tab.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/ensure-hooks-confirmed.test.ts
  • src/renderer/src/lib/ensure-hooks-confirmed.ts
  • src/renderer/src/lib/vm-recipe-trust-content.ts
  • src/renderer/src/lib/workspace-setup-trust.ts
  • src/renderer/src/lib/workspace/creation/pending-worktree-creation.ts
  • src/renderer/src/lib/workspace/creation/work-item/direct-work-item-setup.ts
  • src/renderer/src/lib/workspace/creation/work-item/launch-work-item-direct-test-fixture.ts
  • src/renderer/src/lib/workspace/creation/work-item/launch-work-item-direct.ts
  • src/renderer/src/lib/workspace/creation/worktree-creation-flow-execute.ts
  • src/renderer/src/lib/workspace/creation/worktree-creation-hook-preparation.ts
  • src/renderer/src/store/slices/worktrees-remote-runtime-create.test.ts
  • src/renderer/src/store/slices/worktrees/create/create-worktree.ts
  • src/renderer/src/store/slices/worktrees/create/created-worktree-setup-trust.ts
  • src/renderer/src/store/slices/worktrees/create/worktree-create-payload.ts
  • src/renderer/src/web/preload-api/web-worktrees-api.ts
  • src/shared/rpc-contract/worktree-create-params.ts
  • src/shared/worktree/create-types.ts
Walkthrough

Worktree creation now carries a hash of setup content approved by the client. Runtime code compares that hash with setup content in the created branch. If the content differs, setup and default-tab commands are skipped, and the result reports the mismatch. The renderer then warns about the skipped setup and asks for confirmation of the branch’s script content. The change also updates setup receipts and adds tests for matching, mismatching, and absent approval hashes.

Merge Risk: Low · previous review d3a94

A narrowly timed change to orca.yaml could cause setup to run a command that was not approved. Use the same parsed hooks for the check and execution before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 31.58% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed

Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: worktree setup runs only when the content matches the approved script.
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.
Description check Passed The description is mostly complete. It explains the change, testing, and risk. It lacks before-and-after visual proof for the mismatch behavior, test platforms and steps, an alternatives comparison, a…
Full details: Description check

Explanation

The description is mostly complete. It explains the change, testing, and risk. It lacks before-and-after visual proof for the mismatch behavior, test platforms and steps, an alternatives comparison, and the review checklist.

Full details: Docstring Coverage

Explanation

Docstring coverage is 31.58% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 19 functions across 27 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 576acf72-a4ef-4da7-8e87-a0018e7bdf44
Commits

Reviewing files that changed from the base of the PR and between f22231d and d3a94e2.

Files selected for processing: 28
  • src/main/ipc/worktree-remote.ts
  • src/main/ipc/worktrees-setup-launch-sparse-checkout.test.ts
  • src/main/runtime/rpc/methods/worktree-create-args.ts
  • src/main/runtime/runtime-local-worktree-setup-trust.test.ts
  • src/main/runtime/runtime-local-worktree-setup.ts
  • src/main/runtime/runtime-managed-worktree-create-types.ts
  • src/main/runtime/runtime-repository-hooks-commands.ts
  • src/main/runtime/workspaces/workspace-creation.ts
  • src/main/workspace-hooks/created-worktree-setup-trust.ts
  • src/renderer/src/components/terminal-pane/launch-parity-window-tab.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/direct-work-item-setup.ts
  • src/renderer/src/lib/ensure-hooks-confirmed.test.ts
  • src/renderer/src/lib/ensure-hooks-confirmed.ts
  • src/renderer/src/lib/launch-work-item-direct-test-fixture.ts
  • src/renderer/src/lib/launch-work-item-direct.ts
  • src/renderer/src/lib/pending-worktree-creation.ts
  • src/renderer/src/lib/vm-recipe-trust-content.ts
  • src/renderer/src/lib/workspace-setup-trust.ts
  • src/renderer/src/lib/worktree-creation-flow-execute.ts
  • src/renderer/src/lib/worktree-creation-hook-preparation.ts
  • src/renderer/src/store/slices/worktrees-remote-runtime-create.test.ts
  • src/renderer/src/store/slices/worktrees/create/create-worktree.ts
  • src/renderer/src/store/slices/worktrees/create/created-worktree-setup-trust.ts
  • src/renderer/src/store/slices/worktrees/create/worktree-create-payload.ts
  • src/renderer/src/web/preload-api/web-worktrees-api.ts
  • src/shared/rpc-contract/worktree-create-params.ts
  • src/shared/worktree/create-types.ts

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

Comment on lines +51 to +56
const setupTrustMismatch = checkCreatedWorktreeSetupTrust(
repo,
yamlHooks,
effectiveDecision,
request.approvedSetupHash
)

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.

Minor · Security & Privacy · Quick win

Supported by static analysis

Script executed:

sed -n '1,150p' src/main/runtime/runtime-local-worktree-setup.ts
sed -n '1,180p' src/main/workspace-hooks/effective-hook-config.ts

Repository: stablyai/orca

Length of output: 8543


Script executed:

rg -n -F -e 'export function getEffectiveHooks(' -e 'export function loadHooks(' -e 'export function checkCreatedWorktreeSetupTrust' src/main/workspace-hooks || test "$?" -eq 1
rg -n -A25 -B2 -F 'export function getEffectiveHooks(' src/main/workspace-hooks/hooks.ts || test "$?" -eq 1
rg -n -A25 -B2 -F 'export function loadHooks(' src/main/workspace-hooks/hooks.ts || test "$?" -eq 1
cat -n src/main/workspace-hooks/created-worktree-setup-trust.ts | sed -n '1,160p'
rg -n -C12 -F 'getEffectiveHooksFromConfig(repo, createdYamlHooks)' src/main/ipc/worktree-remote.ts || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 5683


Execute the hooks parsed for the trust check.

prepareRuntimeLocalWorktreeSetup reads orca.yaml twice. loadHooks(worktreePath) feeds the trust check, while getEffectiveHooks(repo, worktreePath) reads the file again to build hooks. hooks.scripts.setup selects the command that runs. If another writer changes orca.yaml between these reads, the approved content and the executed setup script can differ. The window is small, but the approval gate then does not cover the command that runs.

getEffectiveHooks is getEffectiveHooksFromConfig(repo, loadHooks(hooksRoot)). Passing the already-loaded yamlHooks produces the same effective hooks from one parse. The IPC path in src/main/ipc/worktree-remote.ts already uses this pattern.

♻️ Proposed change (line 49, outside the changed range)
-import { getEffectiveHooks, loadHooks, runHook } from '../workspace-hooks/hooks'
+import { loadHooks, runHook } from '../workspace-hooks/hooks'
 import {
   getDefaultTabsLaunch,
+  getEffectiveHooksFromConfig,
   shouldRunSetupForCreate
 } from '../workspace-hooks/effective-hook-config'
-  const hooks = getEffectiveHooks(repo, worktreePath)
+  const hooks = getEffectiveHooksFromConfig(repo, yamlHooks)

…oved script

Clients may send approvedSetupHash with a create. After git worktree add the
host hashes the created branch's shared setup and default-tab commands with
the prompt's function; on a difference it skips them and returns
setupTrustMismatch with the branch content. Creates without a hash (older
clients, CLI, mobile, orchestration) and older hosts behave as before.
…ranch

The composer and direct work-item creates send the hash of the setup content
the user approved (empty content included; none under repo-wide trust or
local-only policy). When the host reports different branch content, show a
setup-skipped toast and the existing trust prompt with that content.
… fixture

Covers CRLF and BOM primary checkouts, the plain-HTTP digest, the hash a
runtime host reports to remote and mobile clients, run-both and local-only
policies, creates without a hash, and pins the digest so a format change is
deliberate.
@nwparker
nwparker force-pushed the nwparker/setup-trust-created-worktree branch from 17b02ff to 7b617ae Compare November 6, 2026 22:41
@nwparker
nwparker merged commit 71ebf75 into main Nov 6, 2026
52 checks passed
@nwparker
nwparker deleted the nwparker/setup-trust-created-worktree branch November 6, 2026 23:03
brennanb2025 added a commit that referenced this pull request Nov 13, 2026
…#41823)

* fix(hooks): approve setup from the ref a new workspace checks out

The setup trust check before a create read orca.yaml from the project's
own checkout, while the host (since #37977) checks the created worktree.
A checkout behind origin/main made every create skip setup and open the
"branch has different setup commands" dialog right after creation.

The check now reads orca.yaml at the ref the create checks out (the
resolved base, or the local branch for explicit reuse), refreshing it
only when create would, under one deadline. Any failure falls back to
the previous checkout read, and older hosts ignore the new parameter.

* fix(hooks): stop optional setup reads at the deadline and cover automation recovery, VM and web paths

* fix(hooks): refuse late WSL git retries and approve an automation's saved base on recovery

* docs(hooks): move the skipped-setup recovery comment back to its function

* fix(automations): re-approve setup when an automation's base branch changes
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