Files
orca/src/main/git/fork-sync.ts
T
Jinwoo Hong c745051d7d refactor(main): share one caller-signal + timeout composition (#28393)
Behavior-preserving refactor. Eleven sites built the same
`signal ? AbortSignal.any([signal, AbortSignal.timeout(ms)]) : AbortSignal.timeout(ms)`
inline or behind a local wrapper (Codex `createCodexBackendRequestSignal`,
`probeDeadline`, `boundedSignal`). They now call one
`abortSignalWithTimeout(signal, timeoutMs)` in
src/main/lib/abort-signal-with-timeout.ts:

- usage requests: Claude OAuth, Cursor, Grok, OpenCode Go API key, ZCode,
  Codex backend usage + reset-credit read
- local worktree path presence, fork sync, retarget divergence budget,
  upstream-ref watch resolution

The Codex reset-credit redeem, which never had a caller signal, uses plain
AbortSignal.timeout. Transports, request options, timeout values, error
mapping, and Retry-After handling are unchanged.
2026-10-13 16:14:17 -04:00

34 lines
1.2 KiB
TypeScript

import { normalizeGitErrorMessage } from '../../shared/git-remote-error'
import {
syncForkDefaultBranch,
type GitForkSyncExpectedUpstream,
type GitForkSyncResult
} from '../../shared/git-fork-sync'
import type { GitRuntimeOptions } from './git-runtime-options'
import { gitOptionsForWorktree } from './git-runtime-options'
import { gitExecFileAsync } from './runner'
import { abortSignalWithTimeout } from '../lib/abort-signal-with-timeout'
export async function gitSyncForkDefaultBranch(
worktreePath: string,
expectedUpstream: GitForkSyncExpectedUpstream,
options: GitRuntimeOptions = {}
): Promise<GitForkSyncResult> {
// Compose the caller's cancel signal with the 60s timeout so neither is lost —
// the caller's signal was previously clobbered by the timeout controller.
const signal = abortSignalWithTimeout(options.signal, 60_000)
try {
return await syncForkDefaultBranch(
(args) =>
gitExecFileAsync(args, {
...gitOptionsForWorktree(worktreePath, options),
timeout: 60_000,
signal
}),
{ expectedUpstream }
)
} catch (error) {
throw new Error(normalizeGitErrorMessage(error, 'push'))
}
}