Reduce Orca idle CPU (#5402)

* Reduce Orca idle CPU

Co-authored-by: Orca <help@stably.ai>

* Restore low-cost working spinner

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Jinwoo Hong
2026-06-15 12:56:22 -07:00
committed by GitHub
co-authored by Orca
parent 4880b56998
commit 5bf24368c0
10 changed files with 709 additions and 78 deletions
-2
View File
@@ -49,7 +49,6 @@ import { registerCodexAccountHandlers } from './codex-accounts'
import { registerAgentHookHandlers } from './agent-hooks'
import { registerAgentTrustHandlers } from './agent-trust'
import { registerClaudeAccountHandlers } from './claude-accounts'
import { warmSystemFontFamilies } from '../system-fonts'
import { registerUpdaterHandlers } from '../window/attach-main-window-services'
import { registerClipboardHandlers } from '../window/clipboard-ipc-handlers'
import type { ClaudeUsageStore } from '../claude-usage/store'
@@ -163,5 +162,4 @@ export function registerCoreHandlers(
registerClipboardHandlers()
registerUpdaterHandlers(store)
registerSpeechHandlers(store)
warmSystemFontFamilies()
}
+8 -5
View File
@@ -195,7 +195,7 @@ describe('RateLimitService', () => {
}
})
it('can defer the startup fetch until the attached window becomes active', async () => {
it('does not turn the initial window activation into a hidden startup quota fetch', async () => {
vi.mocked(fetchClaudeRateLimits).mockResolvedValue(okProvider('claude', 12))
vi.mocked(fetchCodexRateLimits).mockResolvedValue(okProvider('codex', 24))
const service = new RateLimitService()
@@ -205,14 +205,17 @@ describe('RateLimitService', () => {
service.start({ fetchImmediately: false })
await Promise.resolve()
window.emit('show')
window.emit('focus')
window.emit('restore')
await Promise.resolve()
expect(fetchClaudeRateLimits).not.toHaveBeenCalled()
expect(fetchCodexRateLimits).not.toHaveBeenCalled()
window.emit('show')
await service.refresh()
await vi.waitFor(() => {
expect(fetchClaudeRateLimits).toHaveBeenCalledTimes(1)
})
expect(fetchClaudeRateLimits).toHaveBeenCalledTimes(1)
expect(fetchCodexRateLimits).toHaveBeenCalledTimes(1)
service.stop()
+7
View File
@@ -80,6 +80,7 @@ export class RateLimitService {
private codexOnlyFetchQueued = false
private claudeOnlyFetchQueued = false
private fetchIdleResolvers: (() => void)[] = []
private hasCompletedFetch = false
private codexFetchGeneration = 0
private claudeFetchGeneration = 0
private opencodeFetchGeneration = 0
@@ -556,6 +557,9 @@ export class RateLimitService {
if (!this.shouldBackgroundPoll()) {
return
}
if (!this.hasCompletedFetch) {
return
}
if (Date.now() - this.lastFetchAt < MIN_REFETCH_MS) {
return
}
@@ -592,6 +596,7 @@ export class RateLimitService {
}
}
} finally {
this.hasCompletedFetch = true
this.isFetching = false
this.resolveFetchIdleWaiters()
}
@@ -627,6 +632,7 @@ export class RateLimitService {
}
}
} finally {
this.hasCompletedFetch = true
this.isFetching = false
this.resolveFetchIdleWaiters()
}
@@ -662,6 +668,7 @@ export class RateLimitService {
}
}
} finally {
this.hasCompletedFetch = true
this.isFetching = false
this.resolveFetchIdleWaiters()
}
@@ -53,6 +53,7 @@ describe('CmdJPaletteFeatureTipVisual', () => {
expect(html).toContain('auth-redirect')
expect(html).not.toContain('payments-api')
expect(html).not.toContain('animate-spin')
expect(html).not.toContain('animate-cmd-j-tip-caret')
expect(html).not.toContain('animate-cmd-j-tip-result-in')
})
@@ -83,6 +84,31 @@ describe('CmdJPaletteFeatureTipVisual', () => {
expect(clearTimeoutSpy).toHaveBeenCalled()
})
it('settles after the one-shot demo instead of looping idle timers', async () => {
vi.useFakeTimers()
const { container, root } = await renderVisual()
await act(async () => {
vi.runAllTimers()
})
expect(container.textContent).toContain('auth')
expect(container.textContent).toContain('auth-redirect')
expect(container.textContent).not.toContain('payments-api')
expect(vi.getTimerCount()).toBe(0)
await act(async () => {
root.unmount()
})
})
it('does not render infinite animation classes in the default preview', () => {
const html = renderToStaticMarkup(<CmdJPaletteFeatureTipVisual />)
expect(html).not.toContain('animate-spin')
expect(html).not.toContain('animate-cmd-j-tip-caret')
})
it('falls back to default per-key chips when the live binding is unassigned', () => {
shortcutKeysMock.mockReturnValue([])
formatShortcutKeysMock.mockReturnValue(['Ctrl', 'Shift', 'J'])
@@ -34,13 +34,7 @@ function filterDemoWorktrees(query: string): typeof DEMO_WORKTREES {
// Why: cycle phases are sequenced so the keypress visibly precedes the palette
// opening (cause → effect), matching what the user will see when they actually
// press the shortcut.
type CyclePhase = 'idle' | 'pressed' | 'open' | 'typing' | 'closing'
type ClosingFrame = {
query: string
worktrees: ReturnType<typeof filterDemoWorktrees>
showCreate: boolean
}
type CyclePhase = 'idle' | 'pressed' | 'open' | 'typing'
const KEYPRESS_AT_MS = 450
const PALETTE_OPEN_AT_MS = 850
@@ -50,12 +44,6 @@ const HOLD_BEFORE_TYPING_MS = 700
// Per-character typing interval. Kept tight and constant so the cursor advances
// at an even cadence instead of feeling staggered.
const TYPE_INTERVAL_MS = 120
// Pause on the final, filtered state before the cycle resets, so the
// user has time to actually read the matched worktrees + create option.
const HOLD_AFTER_RESULTS_MS = 3200
// Matches the palette container's `duration-300` fade plus a small buffer so we
// never swap list content while the closing fade is still running.
const PALETTE_FADE_OUT_MS = 350
export function CmdJPaletteFeatureTipVisual(): JSX.Element {
const reducedMotion = usePrefersReducedMotion()
@@ -69,7 +57,6 @@ export function CmdJPaletteFeatureTipVisual(): JSX.Element {
const [phase, setPhase] = useState<CyclePhase>('idle')
const [typedLength, setTypedLength] = useState(0)
const [closingFrame, setClosingFrame] = useState<ClosingFrame | null>(null)
// Why: for reduced-motion users, jump straight to the fully-populated end
// state so they see what the feature does without any animation.
@@ -78,23 +65,16 @@ export function CmdJPaletteFeatureTipVisual(): JSX.Element {
const currentQuery = TYPED_QUERY.slice(0, effectiveTypedLength)
const visibleWorktrees = filterDemoWorktrees(currentQuery)
const showCreateAction = currentQuery.trim().length > 0
// Why: snapshot the final filtered frame during `closing` so loop reset never
// re-renders the empty-query worktree list while the palette is still visible.
const renderQuery = phase === 'closing' && closingFrame ? closingFrame.query : currentQuery
const renderWorktrees =
phase === 'closing' && closingFrame ? closingFrame.worktrees : visibleWorktrees
const renderShowCreate =
phase === 'closing' && closingFrame ? closingFrame.showCreate : showCreateAction
const renderQuery = currentQuery
const renderWorktrees = visibleWorktrees
const renderShowCreate = showCreateAction
// Why: mirror WorktreeJumpPalette — recent worktrees render as soon as the
// palette opens; typing only filters them down. Keep the list mounted through
// `closing` so the final filtered frame fades out with the palette.
const showWorktreeList =
reducedMotion || phase === 'open' || phase === 'typing' || phase === 'closing'
// Why: keep the palette hidden during `pressed` — an empty search shell between
// cycles read as the pre-search list flashing back before the fade finished.
const paletteMounted =
reducedMotion || phase === 'open' || phase === 'typing' || phase === 'closing'
const paletteOpaque = reducedMotion || (paletteMounted && phase !== 'closing')
// palette opens; typing only filters them down.
const showWorktreeList = reducedMotion || phase === 'open' || phase === 'typing'
// Why: keep the palette hidden during `pressed` so the keypress visibly
// precedes the palette opening.
const paletteMounted = reducedMotion || phase === 'open' || phase === 'typing'
const paletteOpaque = reducedMotion || paletteMounted
const resultEnterClass =
showWorktreeList && !reducedMotion && phase === 'open' ? 'animate-cmd-j-tip-result-in' : ''
@@ -118,45 +98,27 @@ export function CmdJPaletteFeatureTipVisual(): JSX.Element {
i += 1
setTypedLength(i)
if (i >= TYPED_QUERY.length) {
later(() => closeAndRestart(), HOLD_AFTER_RESULTS_MS)
return
}
timeouts.push(window.setTimeout(typeNext, TYPE_INTERVAL_MS))
}
if (i >= TYPED_QUERY.length) {
later(() => closeAndRestart(), HOLD_AFTER_RESULTS_MS)
return
}
later(typeNext, TYPE_INTERVAL_MS)
}
const scheduleCycle = (): void => {
later(() => setPhase('pressed'), KEYPRESS_AT_MS)
later(() => setPhase('open'), PALETTE_OPEN_AT_MS)
later(() => {
setPhase('typing')
startTyping(0)
}, PALETTE_OPEN_AT_MS + HOLD_BEFORE_TYPING_MS)
}
const closeAndRestart = (): void => {
setClosingFrame({
query: TYPED_QUERY,
worktrees: filterDemoWorktrees(TYPED_QUERY),
showCreate: true
})
setPhase('closing')
later(() => {
setPhase('idle')
setClosingFrame(null)
setTypedLength(0)
scheduleCycle()
}, PALETTE_FADE_OUT_MS)
}
// Why: this tip may remain open while Orca is idle. Play the demo once,
// then settle on the final useful state instead of looping timers forever.
later(() => setPhase('pressed'), KEYPRESS_AT_MS)
later(() => setPhase('open'), PALETTE_OPEN_AT_MS)
later(() => {
setPhase('typing')
startTyping(0)
}, PALETTE_OPEN_AT_MS + HOLD_BEFORE_TYPING_MS)
setPhase('idle')
setTypedLength(0)
scheduleCycle()
return () => {
cancelled = true
@@ -210,7 +172,9 @@ export function CmdJPaletteFeatureTipVisual(): JSX.Element {
<span className="block truncate">
{renderQuery}
{!reducedMotion && (phase === 'open' || phase === 'typing') ? (
<span className="ml-px inline-block h-[14px] w-px -translate-y-px align-middle bg-foreground/75 animate-cmd-j-tip-caret" />
// Why: this tip can sit open while Orca is idle; keep the
// caret static so the preview does not wake the compositor.
<span className="ml-px inline-block h-[14px] w-px -translate-y-px align-middle bg-foreground/75" />
) : null}
</span>
</div>
@@ -227,14 +191,9 @@ export function CmdJPaletteFeatureTipVisual(): JSX.Element {
{result.status === 'done' ? (
<span className="size-2.5 rounded-full bg-emerald-500" aria-hidden="true" />
) : (
// Why: yellow border spinner mirrors StatusIndicator's
// 'working' affordance, so users connect the icon to the
// same running-workspace state they see in the sidebar.
<span
className={`block size-2.5 rounded-full border-[1.5px] border-yellow-500 ${
reducedMotion ? 'border-t-yellow-500' : 'animate-spin border-t-transparent'
}`}
/>
// Why: this tip can stay mounted while Orca is idle; mirror
// the sidebar's static working ring instead of spinning.
<span className="block size-2.5 rounded-full border-[1.5px] border-yellow-500 bg-yellow-500/15" />
)}
</span>
<div className="min-w-0 flex-1">
@@ -17,12 +17,13 @@ function renderDotClassNames(status: Status): string[] {
}
describe('StatusIndicator', () => {
it('renders working as a yellow spinner', () => {
it('renders working as a stepped yellow spinner', () => {
const classNames = renderDotClassNames('working')
expect(classNames).toContain('border-yellow-500')
expect(classNames).toContain('border-t-transparent')
expect(classNames).toContain('animate-spin')
expect(classNames).toContain('[animation:spin_1s_steps(12,end)_infinite]')
expect(classNames).not.toContain('animate-spin')
})
it('renders permission as an amber attention dot', () => {
@@ -33,7 +33,9 @@ const StatusIndicator = React.memo(function StatusIndicator({
title={resolvedTitle}
{...rest}
>
<span className="block size-2 rounded-full border-2 border-yellow-500 border-t-transparent animate-spin" />
{/* Why: a stepped spin preserves the worker-is-running affordance while
avoiding a full-refresh-rate compositor loop for long agent runs. */}
<span className="block size-2 rounded-full border-2 border-yellow-500 border-t-transparent [animation:spin_1s_steps(12,end)_infinite]" />
</span>
)
}
@@ -52,8 +54,7 @@ const StatusIndicator = React.memo(function StatusIndicator({
: status === 'done' || status === 'active'
? // Green dot for both hook-reported 'done' and the heuristic
// 'active' (terminal open, quiet). Working uses a yellow
// spinner so working vs done differ by motion; 'inactive'
// stays grey.
// ring above; 'inactive' stays grey.
'bg-emerald-500'
: 'bg-neutral-500/40'
)}