You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(hooks): run worktree setup only when its content matches the approved script - #37977
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.
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.
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: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
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 checks: 4 passed
Check name
Status
Explanation
Title check
The title clearly and concisely describes the main change: worktree setup runs only when the content matches the approved script.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
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'
…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.
…#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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
When you create a workspace, Orca asks you to trust the repo's
orca.yamlsetup 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.What Changed
hashOrcaHookTrustContent(main) uses the same trimmed SHA-256 as the renderer prompt. A parity test hashes oneorca.yamlfixture 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.approvedSetupHash(local IPC,worktree.createRPC, web client). The composer and direct work-item launch send it; repo-wide trust and the local-only policy don't.git worktree add, both host paths (desktop/WSL and runtime/SSH orcad) hash the created worktree's setup + default-tab commands viacheckCreatedWorktreeSetupTrust. On a mismatch they skip setup and command tabs and returnsetupTrustMismatchwith the content.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
pnpm tc, oxlint, changed-code quality gate.Risk
Level: Low. Only creates where the base branch's
orca.yamlsetup 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 sameparseOrcaYaml, which normalizes CRLF/BOM, then build the content withgetSetupTrustContentand 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.