Skip to content

fix(git): cache unsupported capabilities per host - #8109

Merged
nwparker merged 8 commits into
mainfrom
nwparker/131-crashes
Jul 11, 2026
Merged

nwparker merged 8 commits into
mainfrom
nwparker/131-crashes

Conversation

@nwparker

@nwparker nwparker commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add a shared Git capability cache with 30-minute negative caching and concurrent-probe coalescing
  • isolate capability results by native host, WSL distro, SSH provider, and relay connection
  • stop retrying unsupported worktree list -z, rev-parse path-format, for-each-ref exclude, merge-tree merge-base, and merge-tree write-tree behavior
  • preserve baseline-compatible fallbacks across local, WSL, runtime SSH, IPC SSH, and relay paths
  • document a Git 2.25 core-workflow baseline and the capability/fallback policy

Investigation context

This came from investigating two Slack crash bundles. Both bundles were from Orca 1.4.131, not the newly released 1.4.132:

  • the Windows renderer OOM followed host-wide memory exhaustion; Git reported fatal: not enough memory for initialization two seconds earlier while the renderer heap remained stable
  • the Linux renderer was externally SIGKILLed twice, 119.936 seconds apart, with a stable 18/22 MB heap; no Orca path kills the renderer

Neither crash points to a new Orca release regression. The same diagnostics did reveal a separate reproducible compatibility problem: Git before 2.36 rejected worktree list -z 1,436 times, consuming 2.96 MB of a 4 MiB diagnostic bundle. The broader command audit also found recurring probes for path-format and for-each-ref exclude, plus Git before 2.38 lacking merge-tree write-tree entirely.

Why not simple-git

simple-git still shells out to the Git installed on the execution host and forwards custom/raw arguments. It cannot make a newer flag work on an older native, WSL, or SSH Git binary, nor choose Orca's semantic fallback. A migration would also have to preserve Orca's routing, cancellation, tracing, redaction, process cleanup, and output bounds, so it would move rather than remove this compatibility layer.

Performance and safety

A known unsupported capability now costs at most one failed probe per execution host during the 30-minute retry window. The retry allows an in-place Git upgrade to self-heal. Concurrent first probes share one result. Each cache holds only the five registered capability states, and SSH state is weakly keyed by provider lifetime.

Git before 2.38 cannot produce Orca's real-merge conflict summary. That optional summary now degrades quietly, while branch cleanup remains conservative and never force-deletes without proof.

Validation

  • 478 focused Git/worktree tests passed after rebasing on current main
  • 182 focused capability, cleanup, conflict-summary, and relay tests passed after the broader audit follow-up
  • runtime SSH compatibility regression passed
  • full Node, CLI, and web typecheck passed
  • targeted oxlint passed
  • max-lines ratchet and diff checks passed
  • full lint still reaches the existing ja.json localization interpolation mismatch; no locale files changed here

Follow-up

The strongest additional guard would be a small real-binary CI matrix for Git 2.25, a pre-2.36 release, and current Git. The unit contracts remain necessary for localized errors, concurrency, and native/WSL/SSH isolation.

Crash-triage summary

Description

During investigation of Linux crash report 2dc6f755-ccc7-408f-b394-80623df7f32f, the renderer SIGKILL itself could not be reproduced or attributed to Orca, but the diagnostic bundle exposed a separate deterministic Git compatibility defect: the host Git rejected worktree list --porcelain -z 1,436 times. This PR adds a Git 2.25-compatible line-block fallback and remembers unsupported capabilities per native, WSL, SSH, or relay execution host so recurring scans do not repeat known-invalid commands.

Clear, undeniable fix evidence

  • Field evidence: the bundle contains 1,436 unknown switch z failures, consuming 2.96 MB of its 4 MiB diagnostic cap while renderer heap remained stable at 18/22 MB.
  • The compatibility contract runs the preferred -z command only on Git 2.36+, recognizes the narrow unsupported error below that boundary, and proves plain worktree list --porcelain remains available.
  • Current-main focused verification passed 11 capability/cache/host-isolation tests; the real installed Git contract and the CI workflow matrix pin also passed (3 tests). PR CI covers real Git 2.25.5, 2.38.1, and 2.49.1.
  • The tests cover the first fallback, later cached calls, concurrent first probes, native/WSL isolation, and relay connection isolation.

This evidence proves the Git compatibility/fanout fix. It does not claim the fix caused or prevents the externally reported renderer SIGKILL.

ELI5

Orca asked every Git installation a newer-version question. Older Git answered “I don’t understand,” but Orca kept asking on every refresh. Orca now asks once, falls back to the older wording, remembers that answer for the specific machine or remote host, and periodically retries so an upgraded Git can self-heal.

Trade-offs

  • Unsupported capability results are cached for 30 minutes per execution host. An in-place Git upgrade can therefore use the fallback until the retry window expires; the bounded retry is intentional so scans do not return to failure spam.
  • Git before 2.38 cannot provide the optional real-merge conflict summary. Orca now omits that summary and keeps branch cleanup conservative instead of treating missing support as a hard failure.
  • The cache tracks only the five registered capability states and uses weak provider lifetime keys for SSH, bounding memory while preserving native/WSL/SSH/relay isolation.

Old Git worktree, ref-search, and merge-tree fallbacks retried unsupported flags on recurring operations, flooding subprocess traces. Centralize capability probing per native, WSL, and SSH execution host, coalesce concurrent probes, and retry periodically for in-place Git upgrades.
@coderabbitai

coderabbitai Bot commented Jul 10, 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

Run ID: 0102f8c6-d082-43dc-9a65-7adeb3889858

📥 Commits

Reviewing files that changed from the base of the PR and between 05946b3 and c03ffbd.

📒 Files selected for processing (9)
  • src/main/git/remove-worktree.test.ts
  • src/main/git/worktree.test.ts
  • src/main/git/worktree.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/relay/git-handler-utils.ts
  • src/relay/git-handler-worktree-list.ts
  • src/relay/git-handler-worktree-ops.test.ts
  • src/relay/git-handler-worktree-remove.ts
🚧 Files skipped from review as they are similar to previous changes (9)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/git/worktree.test.ts
  • src/relay/git-handler-worktree-list.ts
  • src/relay/git-handler-utils.ts
  • src/main/git/remove-worktree.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/relay/git-handler-worktree-ops.test.ts
  • src/relay/git-handler-worktree-remove.ts
  • src/main/git/worktree.ts

📝 Walkthrough

Walkthrough

Adds a host-scoped GitCapabilityCache with retry scheduling, concurrent probe coalescing, and test reset support. Local, SSH, relay, worktree, ref-search, conflict-summary, and branch-cleanup Git operations now use cached preferred-command and fallback execution. Unsupported Git behavior is detected through focused predicates, including merge-tree option handling. Documentation defines the compatibility policy, capability matrix, host isolation rules, and required test coverage.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is missing required template sections, including Screenshots, the Testing checklist, AI Review Report, Security Audit, and Notes. Add the missing sections from the repository template and fill in the testing checklist, AI review report, security audit, screenshots/no visual change, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 2.50% which is insufficient. The required threshold is 80.00%. 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 directly summarizes the main change: caching unsupported Git capabilities per host.
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.
✨ Finishing Touches
📝 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/relay/git-handler-worktree-remove.ts (1)

88-106: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Import readRelayWorktreeList from git-handler-worktree-ops.ts instead of duplicating it.

This local readRelayWorktreeList is identical to the exported version in src/relay/git-handler-worktree-ops.ts (lines 121–138). git-handler-local-base-ref-refresh.ts already imports and uses the canonical version. Maintaining two copies risks silent divergence if one is updated and the other is not.

♻️ Proposed refactor

Remove the local readRelayWorktreeList and import the canonical version from git-handler-worktree-ops.ts:

-async function readRelayWorktreeList(
-  git: GitExec,
-  repoPath: string,
-  capabilities: GitCapabilityCache
-): Promise<RelayWorktreeInfo[]> {
-  return capabilities.runWithFallback(
-    'worktree-list-z',
-    async () => {
-      const { stdout } = await git(['worktree', 'list', '--porcelain', '-z'], repoPath)
-      return normalizeRelayWorktrees(parseWorktreeList(stdout, { nulDelimited: true }))
-    },
-    async () => {
-      // Why: `-z` preserves newlines; fallback keeps Git <2.36 compatible.
-      const { stdout } = await git(['worktree', 'list', '--porcelain'], repoPath)
-      return normalizeRelayWorktrees(parseWorktreeList(stdout))
-    },
-    isUnsupportedWorktreeListZError
-  )
-}

Add readRelayWorktreeList to the existing import from ./git-handler-worktree-ops (or create one if it does not exist):

+import { readRelayWorktreeList } from './git-handler-worktree-ops'

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f70f0b4b-3824-4e6a-b0de-34a164c50a3c

📥 Commits

Reviewing files that changed from the base of the PR and between c5669cc and 6f37ef1.

📒 Files selected for processing (25)
  • docs/reference/git-compatibility.md
  • src/main/git/git-capability-state.ts
  • src/main/git/remove-worktree.test.ts
  • src/main/git/repo-search-ref-compat.test.ts
  • src/main/git/repo.ts
  • src/main/git/worktree-git-capabilities.test.ts
  • src/main/git/worktree.test.ts
  • src/main/git/worktree.ts
  • src/main/github/conflict-summary.test.ts
  • src/main/github/conflict-summary.ts
  • src/main/ipc/repos-remote.test.ts
  • src/main/ipc/repos.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/relay/git-handler-branch-cleanup.ts
  • src/relay/git-handler-local-base-ref-refresh.ts
  • src/relay/git-handler-worktree-git-capabilities.test.ts
  • src/relay/git-handler-worktree-ops.ts
  • src/relay/git-handler-worktree-remove.ts
  • src/relay/git-handler.ts
  • src/shared/git-branch-cleanup.test.ts
  • src/shared/git-branch-cleanup.ts
  • src/shared/git-capability-cache.test.ts
  • src/shared/git-capability-cache.ts
  • src/shared/git-merge-tree-capability.ts

Comment on lines +21062 to +21077
const repeatedResult = await runtime.searchRepoRefs('id:remote-repo', '', 1)

expect(result).toEqual({
refs: ['origin/main'],
refDetails: [{ refName: 'origin/main', localBranchName: 'main' }],
truncated: true
})
expect(repeatedResult).toEqual(result)
const forEachRefCalls = provider.exec.mock.calls.filter(
(call) => (call[0] as string[])[0] === 'for-each-ref'
)
expect(forEachRefCalls).toHaveLength(2)
expect(forEachRefCalls).toHaveLength(3)
expect(forEachRefCalls[0][0]).toContain('--exclude=refs/remotes/**/HEAD')
expect(forEachRefCalls[1][0]).not.toContain('--exclude=refs/remotes/**/HEAD')
expect(forEachRefCalls[1][0]).toContain('--count=108')
expect(forEachRefCalls[2][0]).not.toContain('--exclude=refs/remotes/**/HEAD')

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check whether orca-runtime.test.ts resets git capability state in its test setup.
rg -n 'clearGitCapabilityStateForTests|beforeEach' src/main/runtime/orca-runtime.test.ts | head -30

Repository: stablyai/orca

Length of output: 264


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find the helper definition and any capability-reset calls in the test file.
rg -n 'resetRuntimeTestMocks|clearGitCapabilityStateForTests|gitCapability|capabilityState' src/main/runtime/orca-runtime.test.ts

# Show the setup block around the beforeEach.
sed -n '680,740p' src/main/runtime/orca-runtime.test.ts

Repository: stablyai/orca

Length of output: 2438


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '523,718p' src/main/runtime/orca-runtime.test.ts

printf '\n---\n'

rg -n 'clearGitCapabilityStateForTests|resetGitCapabilityState|GitCapabilityState' src/main/runtime src/main

Repository: stablyai/orca

Length of output: 10150


Reset git capability state in the shared test setup. resetRuntimeTestMocks() doesn’t clear git-capability-state, so this test can inherit cached --exclude support and skip the initial probe. Add clearGitCapabilityStateForTests() to that shared hook.

@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/relay/git-handler-worktree-ops.test.ts (1)

3-12: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider extracting the removeWorktreeWithCapabilityCache helper to a shared test fixture.

This 6-line wrapper is duplicated identically in git-handler-worktree-paths.test.ts:7-12 and git-handler-branch-cleanup.test.ts:8-13. If removeWorktreeOp's signature changes again, all three files require the same update. Extracting to a shared file (e.g. relay-worktree-test-fixture.ts) would reduce maintenance overhead.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 45ac4770-1780-4eca-bf5f-c413c59b14ae

📥 Commits

Reviewing files that changed from the base of the PR and between 6f37ef1 and 0c978a4.

📒 Files selected for processing (21)
  • .github/workflows/pr.yml
  • AGENTS.md
  • config/scripts/git-binary-compatibility-workflow.test.mjs
  • docs/reference/git-compatibility.md
  • src/main/git/git-capability-state.test.ts
  • src/main/git/repo.ts
  • src/main/git/worktree.ts
  • src/main/github/conflict-summary.test.ts
  • src/main/github/conflict-summary.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/relay/git-handler-branch-cleanup.test.ts
  • src/relay/git-handler-local-base-ref-refresh.ts
  • src/relay/git-handler-utils.ts
  • src/relay/git-handler-worktree-git-capabilities.test.ts
  • src/relay/git-handler-worktree-list.ts
  • src/relay/git-handler-worktree-ops.test.ts
  • src/relay/git-handler-worktree-ops.ts
  • src/relay/git-handler-worktree-paths.test.ts
  • src/relay/git-handler-worktree-remove.ts
  • src/relay/git-handler.ts
✅ Files skipped from review due to trivial changes (1)
  • docs/reference/git-compatibility.md
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/github/conflict-summary.test.ts
  • src/main/git/repo.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/git/worktree.ts
  • src/relay/git-handler.ts
  • src/main/github/conflict-summary.ts

nwparker added 3 commits July 10, 2026 17:44
# Conflicts:
#	src/renderer/src/store/slices/store-cascades.test.ts
# Conflicts:
#	src/relay/git-handler-worktree-remove.ts
@nwparker

Copy link
Copy Markdown
Contributor Author

Verified against current main across native, WSL, SSH, and relay ownership paths. Review also caught and fixed supported-capability probe serialization, preserving parallel ref searches after the first successful probe. Local full suite, typecheck, lint, relay build, and Electron boot passed; CI is green with Git 2.25.5, 2.38.1, and 2.49.1 compatibility coverage, the full test suite, unpacked build, and packaged CLI smoke. Docker SSH e2e was unavailable locally, so relay integration tests and CI provide that transport coverage.

@nwparker
nwparker merged commit 533992b into main Jul 11, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(git): cache unsupported capabilities per host

Old Git worktree, ref-search, and merge-tree fallbacks retried unsupported flags on recurring operations, flooding subprocess traces. Centralize capability probing per native, WSL, and SSH execution host, coalesce concurrent probes, and retry periodically for in-place Git upgrades.

* fix(git): recognize real old-Git merge-tree rejection

* test(git): enforce real binary compatibility matrix

* fix(ci): preserve Git compatibility test ownership

* fix(git): retain supported capability state
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