Skip to content

fix(worktree): prevent stale-base worktree creation and dispatch#1390

Closed
Jinwoo-H wants to merge 1 commit intomainfrom
Jinwoo-H/orca-improvements-worktree-base
Closed

fix(worktree): prevent stale-base worktree creation and dispatch#1390
Jinwoo-H wants to merge 1 commit intomainfrom
Jinwoo-H/orca-improvements-worktree-base

Conversation

@Jinwoo-H
Copy link
Copy Markdown
Contributor

@Jinwoo-H Jinwoo-H commented May 4, 2026

Summary

  • Fixes ORCHESTRATOR_FEEDBACK.md item 16
  • UI create path switches from fire-and-forget fetch (introduced in PR 776) to concurrent-fetch-with-gate: fire async, await before addWorktree. Preserves the ~300ms warm-case perf win while guaranteeing fresh base in the cold case
  • Two-phase spinner via createWorktree:progress IPC events ('fetching' → 'creating') so 1-5s waits are legible
  • Shared in-flight Map + 30s timestamp cache on OrcaRuntimeService — renderer creates and dispatch drift probes share one cache
  • .finally() eviction + success-only timestamp write prevents DNS hiccups from wedging future creates
  • Coordinator dispatchTask pre-flight refusal: probe rev-list --left-right --count vs tracking remote; silently skip dispatch (no circuit-breaker burn) when behind > DISPATCH_STALE_THRESHOLD (20) unless task spec text contains allow-stale-base: true
  • Preamble --- BASE DRIFT --- section only when baseDrift.behind > 0 (loud-but-rare)
  • Explicitly deferred: default-base-ref rewrite, create-time warn toast, DB column for allow_stale_base (stored in task spec text v1)
  • Design doc at DESIGN_DOC_STALE_BASE_FIX.md (local-only)

Test plan

  • pnpm typecheck clean
  • 35 new unit tests pass (coordinator stale-base guard + parseAllowStaleBaseFromSpec + preamble drift section + fetch-remote-cache eviction/serialization/freshness)
  • Manual smoke: UI worktree create on a repo with a new origin ref — verify new tip is used, not stale ref
  • Manual smoke: orchestration dispatch to a worktree 25+ commits behind origin — verify refusal with clear error

Addresses feedback #16 per DESIGN_DOC_STALE_BASE_FIX.md §0. Four v1
components coordinated by a single shared fetch cache on the runtime:

1. Concurrent-fetch-with-gate in UI create path: `createLocalWorktree`
   fires `git fetch` BEFORE the suffix loop / PR probe / path
   resolution, then awaits right before `addWorktree` so the new branch
   always spawns from a fresh remote tip. Renderer sees a two-phase
   spinner via the new `createWorktree:progress` IPC event. The cache
   is a `Map<repoPath::remote, Promise<void>>` + 30s success-only
   timestamp on `OrcaRuntimeService` (§7.1 — shared with dispatch).
2. Dispatch pre-flight drift guard in `Coordinator.dispatchTask`:
   probes `rev-list --left-right --count` against the target worktree
   and silently returns (preserves `ready`, no circuit-breaker burn)
   when `behind > 20` unless the task spec carries
   `allow-stale-base: true`. Parsing strips the flag so it never leaks
   into the worker's `--- TASK ---` block.
3. Preamble drift section: populated only when dispatch detected drift.
   Workers see `--- BASE DRIFT ---` with the N-most-recent subjects
   they don't have, so they can pull them in before running.
4. §3.3 Lifecycle: `.finally()` evicts Map entries on BOTH success and
   rejection; timestamp is written ONLY on success. Prevents a single
   DNS hiccup from wedging every future create on the repo until
   restart, and keeps the freshness window honest.

Defers the DB `allow_stale_base` column (§0.2) and the create-time
warn toast; both can layer in later without migration.

Tests: 35 new/updated unit tests covering drift preamble, dispatch
refusal, spec-text flag parsing, fetch Map eviction after rejection,
freshness-window short-circuit, and concurrent-caller serialization.

Co-authored-by: Orca <help@stably.ai>
@Jinwoo-H
Copy link
Copy Markdown
Contributor Author

Jinwoo-H commented May 4, 2026

Superseded by #1403, which bundles this PR with the other three orchestration improvement PRs and resolves the merge conflicts they shared. Branch preserved for diff comparison — not deleting.

@Jinwoo-H Jinwoo-H closed this May 4, 2026
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