Skip to content

fix(worktrees): when the host can't fetch a remote base, create from the local branch and say so - #26009

Merged
brennanb2025 merged 8 commits into
mainfrom
brennanb2025/runtime-create-local-base-fallback
Oct 7, 2026
Merged

brennanb2025 merged 8 commits into
mainfrom
brennanb2025/runtime-create-local-base-fallback

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​235 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​235
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​148 $\color{#cf222e}{\Huge{\mathbf{−}}}$​79 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69

ELI5

You ask the host (from the phone, the CLI, a paired desktop or the web client) for a workspace on origin/main in a repo that has no refs/remotes/origin/main yet, while you're offline. Today that fails with "Check your network", even though local main is right there. Now Orca still tries the network first. Only when that fails does it create from local main, and it reports that in the result. Online, the base is the same as before. Unattended runs (automations, orchestration) on a repo the host creates in locally still fail loudly offline, as today.

What Changed

The problem.

  • Orca has two code paths that create a git worktree:
    • the desktop window's own path;
    • the host's path, used by the phone, the CLI (orca worktree create), agent.launch, the worktree.create RPC (which a paired desktop and the web client also use), automation runs (scheduled or Run now), orchestration workers and federation.
  • When the requested base is a remote ref like origin/X and the repo has no tracking ref refs/remotes/origin/X yet, the host's path fetches it.
    • That happens with a remote that was added but never fetched, a single-branch or narrowed clone, a pruned branch, or a branch that only exists locally.
    • Offline, or when the remote doesn't have the branch, that fetch fails and the create throws Could not refresh base ref "origin/X" from "origin". Check your network and try again. It does so even when local X is there to build from.
  • With the tracking ref present, offline creates already worked, because the refresh failure is tolerated. This PR doesn't change that case.

For users:

  • A person asked for it (the worktree.create RPC used by the phone, the CLI, a paired desktop and the web client, and agent.launch): offline, or when the remote lacks the branch, a create from origin/X with only a local X now succeeds from local X instead of failing. The workspace's base is X, and the result carries baseFallback (requestedRef: origin/X, localRef: X).
    • Who sees the notice: a paired desktop and the web client. Both already show the existing "Workspace created from a local base" dialog for that field. CLI --json output includes it.
    • Who doesn't yet (follow-up): the phone, the CLI's text output and agent.launch. They drop the field.
  • Nobody is watching (automation runs, scheduled or Run now; orchestration workers; federation): unchanged for repos the host creates in locally. Offline they still fail with "Check your network", so the run's failure shows the problem instead of an agent quietly working on a possibly stale local branch.
    • An automation run that a desktop or web client sends to a host carries its automation identity, so it is treated as unattended too.
    • Not covered, and unchanged from main: SSH repos and desktop-local automation runs already fall back offline, through the desktop's create rule.
  • Online: the base is unchanged for everyone. The host still fetches origin/X first and builds on it.
  • No local X: the error is the same as before.
  • A local ref literally named the requested origin/X (for example a local branch team/feature while team is also a remote): unchanged. The create uses it without fetching and reports nothing.

The change:

  • New runtime-local-worktree-create-base.ts decides the base once, before naming:
    • tracking ref present: use it, and keep the existing refresh after naming;
    • a local ref of the exact requested name: use it without fetching, as before;
    • otherwise fetch. If the fetch fails, the caller allowed the fallback, and local X exists, use X and report it. Otherwise throw the existing error.
  • The fallback is gated by a host-side create option, allowLocalBaseFallback. It isn't a wire field and it defaults to off.
    • buildManagedWorktreeCreateArgs sets it for the worktree.create RPC and agent.launch unless the request carries automation provenance.
    • The host's own automation runs, orchestration workers and federation don't set it.
  • runtime-local-worktree-create.ts runs that decision before branch-name resolution. Naming, the add and the persisted baseRef all use the same decided base.
  • runtime-local-git-worktree-create.ts takes the decided base instead of re-resolving it.
  • baseFallback is its own typed field on the create result. orca-runtime-create-managed-worktree.ts copies it onto the managed create result.

Why

  • A missing tracking ref shouldn't make an offline create fail when the local branch is right there.
  • Fetching first keeps online creates as fresh as before. The phone, CLI, agent.launch, automations and orchestration never fetch the base ahead of time. Skipping the fetch whenever a local branch exists would therefore build on a possibly stale branch every time.

Differences from the desktop create:

  • Intended: a local ref of the exact requested name stays silent.
    • The desktop create reports it and shows "Workspace created from a local base … may not include the latest remote changes", even online.
    • That copy is wrong for a plain local branch (for example a repo's saved base team/feature), and main's host shows nothing there.
    • Fixing the desktop's copy for that case is a separate follow-up.
  • Intended: unattended host creates don't fall back. The desktop create falls back for every caller, including desktop-local automations; that's unchanged here.
  • Intended (deliberate difference in mechanism, same online outcome): the host fetches first.
    • The desktop's create doesn't fetch in this case (worktree-remote.ts:2321-2337).
    • The desktop composer, though, fetches the base when you pick it (worktree-create-base-prefetch.ts), whenever the named ref isn't local. So online, desktop users already end up on the fetched base.
    • A paired desktop and the web client call the same prefetch on the host (worktree.prefetchCreateBase). The other host callers listed above don't prefetch, so the create itself has to fetch.
  • Temporary: copies of the rule.
    • The base-fallback rule now exists on the desktop local create, the desktop SSH create and this host path.
    • They aren't the same rule. The two desktop copies fall back without fetching; the host fetches first.
    • The desktop-local copy goes away when desktop new-workspace launches move onto this path (planned, no PR yet).
    • A shared decision function for the SSH copy and this one is a follow-up. It needs a fetch-policy input, or the SSH route needs the same prefetch.
  • Unchanged (intended): SSH repos. Host creates in SSH repos already go through the desktop SSH create, which falls back for every caller, with no fetch. This PR leaves that as is.

Known edges (follow-ups, not fixed here):

  • Failed fetches aren't remembered. Only successful fetches are cached, for 30 seconds, the same as today.
    • A base fetched ahead of time is reused only if the create starts within those 30 seconds.
    • Offline, a paired-desktop or web create already retries the fetch its prefetch failed. That will also apply to the desktop once it moves onto this path.
  • A hung fetch can outlast the CLI.
    • A fetch can hang until the 60-second git timeout on a network that silently drops packets: a dead VPN, a captive portal or a black-holed route. Credential prompts can't cause it, because network git runs with prompts disabled (git-process-env.ts:50-80).
    • Any wait to start git comes on top of the 60 seconds (git-exec-file.ts:71-94).
    • For an attended create, such a hang now ends in a fallback create, where main threw.
    • orca worktree create waits 60 seconds and sends no request id for deduplication. So the CLI can report a timeout while the host goes on to create the workspace, and a retry makes a second one (-2).
    • On main, a slow fetch that succeeded near 60 seconds already did this. The follow-up is a longer CLI timeout or a request id for worktree.create.

Linked Issue

None.

Visual Proof

Electron QA screenshots from the dev app on an M4 MacBook Air, at e8d477e (the same production code as the current head).

Offline CLI create from origin/main: it created from local main and returned baseFallback.

Offline CLI create from origin/main falls back to local main

Online create: it fetched origin/main and returned no fallback.

Online create fetches origin/main with no fallback

Not captured: the base-fallback dialog on a paired desktop or the web client. No paired environment was available. That dialog is existing UI, driven by the existing baseFallback field.

Testing

  • runtime-local-worktree-create.test.ts (base origin/main with no tracking ref, only local main):

    • Fetch works: it fetches, creates from origin/main, reports no baseFallback, and baseRef is refs/remotes/origin/main. Naming runs only after the fetch has settled and sees origin/main.
    • Fetch works but the tracking ref is still missing: the same "not found after fetching" error as before.
    • Fetch fails, fallback allowed: it creates from main, baseFallback is {origin/main, main}, and the persisted baseRef is main. Naming sees main.
    • Fetch fails, fallback not allowed (the default): the same "Check your network" error, even though local main exists.
    • Fetch fails, no local main: the same "Check your network" error; nothing is named or created.
    • A local ref of the exact requested name: no fetch, no baseFallback.
  • worktree-create-args.test.ts: a person's request gets allowLocalBaseFallback; one carrying automation provenance doesn't. worktree.test.ts pins that the RPC handler passes it.

  • orca-runtime-tests/local-worktree-creation.spec.ts: the full managed create offline with only local main.

    • Without the option it throws the network error.
    • With it, it adds from main, carries baseFallback, and persists baseRef: main.
  • Re-broken and watched fail:

    • naming before the decision;
    • skipping the fetch when local main exists;
    • dropping the fallback;
    • dropping the post-fetch check;
    • persisting the requested base;
    • falling back with no local branch;
    • reporting the exact-name ref;
    • ignoring the option;
    • never setting it, or also setting it for automation runs;
    • dropping baseFallback from the create result or the managed result.
  • Scripted CLI QA on an M4 MacBook Air, this PR vs main: the offline, online, no-local-main and tracking-ref-present rows all behaved as expected. An unattended offline create (an orchestration worker) fails with the same network error on both and creates nothing, while a person's offline create on this PR still falls back.

  • tc:node passes. The test files around the host's create, the worktree.create RPC and agent.launch pass. oxlint and oxfmt are clean on the changed files.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Author: @BrennanKB5.

  • Performance: the online path makes the same git calls as before, and nothing that ran concurrently is now serialized.
    • Only when the tracking ref is missing does the fetch move ahead of branch-name resolution. Both steps were already serial.
    • When the tracking ref exists, the refresh still runs after naming.
  • Naming after the fetch: with the tracking ref missing and the fetch working, naming now runs after the fetch. A leftover local branch at origin/X's tip can then be reused instead of getting a -2 suffix.
  • WSL: every probe still uses the repo's WSL options.
  • Wire: baseFallback is an existing optional field of the create result. Older clients ignore it.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…acking ref, and say so, on the host's create

The host's create (agent.launch, worktree.create, the phone and the CLI) asked for a remote base like
origin/main with no tracking ref yet fetched it, and threw offline, even when the local branch existed;
it also never reported a base it fell back to. Like the desktop create, it now uses the local branch
without fetching and returns baseFallback, which the desktop window already turns into a notice.
…l branch only when the fetch fails

The host's create skipped the fetch whenever a local branch matched a
remote base with no tracking ref, so online phone/CLI/agent.launch creates
silently built on a possibly stale local branch, every time. Fetch first,
as main does; only when that fetch fails use the local branch the remote
names and report it with baseFallback. With no local branch the existing
error is unchanged.

Decide the base before naming so branch reuse and conflict checks, the add
and the persisted baseRef all see the base actually used, and return
baseFallback as its own field of the create result instead of riding on the
git add result.
@brennanb2025 brennanb2025 changed the title fix(worktrees): create from the usable local base when there is no tracking ref, on the host's create fix(worktrees): when the host can't fetch a remote base, create from the local branch and say so Oct 7, 2026
…name, as the desktop create does

The tracking ref is still missing there; only the fetch is skipped, as before.
…etch settles

Also pins the existing not-found-after-fetching error, now owned by the base decision.
… asked for; keep the exact-name ref silent

Scheduled automations, orchestration workers and federation keep main's
"Check your network" error offline: nobody is watching to be told the
workspace was built on a possibly stale local branch. The fallback is a
host-side create option (allowLocalBaseFallback, default off, not on the
wire) that the worktree.create RPC and agent.launch set unless the request
carries automation provenance.

A local ref of the exact requested name goes back to silent, as on main's
host: reporting it showed "may not include the latest remote changes"
online for plain local branches.
Resolves the conflict with #26006 in runtime-local-worktree-create.test.ts by keeping both
describe blocks. runtime-local-worktree-create.ts auto-merged: the setup check stays before
any base resolution, and the local-base decision stays after the !baseBranch check.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review summary (head 81f4193)

The problem. The host's workspace create (used by the phone, the CLI, agent.launch, and the worktree.create RPC that a paired desktop and the web client also use) fails offline when you ask for origin/X in a repo with no refs/remotes/origin/X, even if local X exists. The error is "Could not refresh base ref "origin/X" from "origin". Check your network and try again." The desktop window's own create uses local X instead and tells you. Before desktop new-workspace launches can move onto the host's create, the host needs to match.

What changes for users.

  • A person asked for the create (phone, CLI, paired desktop, web client, agent.launch): offline, a create from origin/X with only local X now succeeds from local X. The result carries baseFallback {requestedRef: origin/X, localRef: X}. A paired desktop and the web client show the existing "Workspace created from a local base" dialog; CLI --json includes the field.
  • Online: unchanged for everyone. The host still fetches origin/X first and builds on it.
  • Nobody is watching (automation runs, scheduled or Run now; orchestration workers; federation), in repos the host creates in locally: unchanged. Offline they still fail loudly. SSH repos and desktop-local automations already fell back on main and still do.
  • A local branch literally named like origin/X: unchanged and silent, as on main's host.

What review changed (the PR as first opened copied the desktop rule as-is):

  1. Fetch first, fall back only when the fetch fails. The first version skipped the fetch whenever local X existed, even online. Phone, CLI and agent.launch creates would then have built silently on a possibly stale local branch, every time, where main fetched. The desktop avoids this because its composer fetches the base before you click Create. Desktop outcomes are unchanged.
  2. Fallback only for creates a person started. Unattended callers keep main's loud error rather than starting an agent on a stale branch with nobody watching. This is a host-side option, allowLocalBaseFallback: off by default, not on the wire, and off whenever the request carries automation provenance.
  3. The base is decided before naming the branch, as on desktop. Branch reuse and conflict checks, the add, and the saved baseRef all see the same base.
  4. The named-local-ref case stays silent. Reporting it would have shown paired-desktop and web users a dialog saying the workspace "may not include the latest remote changes", online, on every create from such a branch. That wording is wrong for a plain local branch.
  5. baseFallback is now a typed field of the create result, no longer added untyped onto the git add's result.
  6. Merged current main (fix(worktrees): decide setup before git worktree add on the host's create #26006, setup decided before the add): its setup check runs before this PR's base decision, so a repo that needs a setup answer refuses before any fetch.
  7. Tests at each seam and at the real entry points (worktree.create, agent.launch, the full managed create). Each was re-broken and watched to fail. The PR body was corrected; the first version said "no UI change".

Deferred (follow-ups, not in this PR):

  • The phone, the CLI's text output and agent.launch don't show baseFallback yet. CLI QA confirmed that an offline CLI create in text mode prints a normal success, with only baseRef: main among the fields.
  • A fetch that hangs until git's 60s timeout (a network that silently drops packets) now ends in a fallback create. The CLI's own 60s timeout can fire first, so the CLI reports a timeout while the host creates the workspace, and a retry makes a -2. Main has the same race for slow fetches that succeed. Follow-up: a longer CLI timeout or a request id for worktree.create.
  • Failed fetches aren't cached. Offline, a create retries a fetch its prefetch already failed. That's the same as today for paired desktop and web; noted for the desktop move.
  • The base-fallback rule now exists in three places: desktop local, desktop SSH, and the host. They differ (the desktop copies don't fetch). The desktop-local copy goes away with the desktop move; a shared decision function is a follow-up.
  • The desktop's own dialog for a named-local-ref base has wrong wording (pre-existing).
  • The args builder defaults the option on for the requests it builds. A future unattended caller that reuses the builder would inherit it. There is none today.

Verified:

  • Three review rounds plus an architecture challenge, then a readiness checklist (network, crash/retry, security, performance, correctness, compatibility incl. mobile, cross-platform, organization): no P0, P1 or P2 issues open.
  • Typecheck (tc:node) and the named vitest files around the host's create, worktree.create and agent.launch pass (run by the fixer on the pushing worktree).
  • Scripted CLI QA on an M4 MacBook Air, this PR vs main (rows 1-4 at e8d477e, the same production code as the head apart from the main merges):
    • offline, no tracking ref, local main: PR creates from local main with baseFallback; main errors;
    • online: identical (fetches, builds on the newer commit);
    • offline without local main: same error on both;
    • tracking ref present: identical;
    • unattended offline create (an orchestration worker): fails with the same network error on both, creating no workspace and starting no agent. In the same run a person's offline create on this PR still falls back. (Run at b444d7d, which has the same PR code as the head.)
  • Electron QA on the M4 MacBook Air dev app: the offline CLI create appears with the fallback, and the online create fetches. Screenshots, captured by the QA agent at e8d477e, are in the PR body.
  • CI: green on 81f4193, including lint, typecheck, tests, packaging on macOS and Windows, and wire compatibility.

Not verified:

  • The paired-desktop/web dialog itself: no paired environment was available. It's existing UI fed by an existing field.
  • The desktop composer's own offline create: unchanged code, but its row was blocked by a native picker under automation.
  • Mobile UI QA: not run. No mobile code changed; the phone uses the same worktree.create RPC the CLI rows exercised, and ignores the new field.
  • SSH and Windows/WSL live runs: not run. SSH repos don't take this path; on WSL the new probe uses the same git options as the existing ones.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 7, 2026 07:01
@coderabbitai

coderabbitai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 53f55646-7726-43ad-9982-48af4b5e7171
📥 Commits

Reviewing files that changed from the base of the PR and between 988f87e and 81f4193.

📒 Files selected for processing (11)
  • src/main/runtime/orca-runtime-create-managed-worktree.ts
  • src/main/runtime/orca-runtime-tests/local-worktree-creation.spec.ts
  • src/main/runtime/rpc/methods/agent-launch.test.ts
  • src/main/runtime/rpc/methods/worktree-create-args.test.ts
  • src/main/runtime/rpc/methods/worktree-create-args.ts
  • src/main/runtime/rpc/methods/worktree.test.ts
  • src/main/runtime/runtime-local-git-worktree-create.ts
  • src/main/runtime/runtime-local-worktree-create-base.ts
  • src/main/runtime/runtime-local-worktree-create.test.ts
  • src/main/runtime/runtime-local-worktree-create.ts
  • src/main/runtime/runtime-managed-worktree-create-types.ts

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


📝 Walkthrough

Walkthrough

Managed worktree requests without automation provenance now allow local-base fallback. Runtime creation resolves the requested base before branch selection and worktree creation. If a remote refresh fails, the resolver uses the corresponding local branch only when fallback is allowed and that branch exists. The runtime result reports fallback details when present. Tests cover request policy, refresh behavior, fallback selection, and failure cases.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 81f41

The fallback behavior is ready for normal merge checks; some interfaces do not yet display the fallback notice.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 4 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: host worktree creation can fall back to a local branch when fetching the remote base fails, and it reports that fallback.
Description check ✅ Passed The description is detailed and covers the user impact, implementation, rationale, visual proof, testing, and known limitations. The Linked Issue section says “None,” although the template requires an…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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

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

@brennanb2025
brennanb2025 merged commit e5ade4b into main Oct 7, 2026
56 checks passed
brennanb2025 added a commit that referenced this pull request Oct 7, 2026
Rebuild the base-fetch overlap on #26009's base decision: the base is
still decided before naming, and its deferred refresh (the existing
tracking ref, or `fetch origin` for a plain base not local yet) now starts
right after that decision and is awaited before the add, so naming's
first-name PR lookup overlaps it. A remote base with no tracking ref still
fetches before naming, since the base (and any local fallback) depends on
that fetch.
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