Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.
TypeScript adeagent-ideai-agentsautomationbotclaude-codecodexghosttygrok-bothermes-agentmobile-appmuseopenclawopencodeorchestrationpiruntimeterminalworktreesyc-backed
fix(wsl): user clicks on cwd-less gh may start the stopped default distro (#36230)
Neil58c50f294a3d
diff --git a/src/main/git/command-runner/default-wsl-cli-fallback.ts b/src/main/git/command-runner/default-wsl-cli-fallback.tsindex 2c4830b0c7d..fcf715db484 100644--- a/src/main/git/command-runner/default-wsl-cli-fallback.ts+++ b/src/main/git/command-runner/default-wsl-cli-fallback.ts@@ -1,6 +1,14 @@import { blockedWslDistroForExec } from '../../wsl/wsl-background-exec-gate'-import { WslDistroStoppedError, WslDistroUnverifiableError } from '../../wsl/wsl-unc-access-gate'-import { resolveDefaultWslCli, type ResolvedCommand } from './wsl-command-resolution'+import {+ runAsWslUserAct,+ WslDistroStoppedError,+ WslDistroUnverifiableError+} from '../../wsl/wsl-unc-access-gate'+import {+ defaultWslCliDistro,+ resolveDefaultWslCli,+ type ResolvedCommand+} from './wsl-command-resolution'/*** The default distro's gh/glab for a cwd-less call whose host CLI is missing. Background work must@@ -23,3 +31,11 @@ export async function resolveDefaultWslCliFallback(}return resolved}++/**+ * Runs a user's click (star, auth diagnosis, a project-board action) as a user act on the distro a+ * cwd-less gh/glab call would fall back to, so it may start that distro when it is stopped.+ */+export function runAsDefaultWslCliUserAct<T>(act: () => Promise<T>): Promise<T> {+ return runAsWslUserAct(process.platform === 'win32' ? defaultWslCliDistro() : null, act)+}diff --git a/src/main/git/command-runner/wsl-command-resolution.ts b/src/main/git/command-runner/wsl-command-resolution.tsindex d34b5317802..8b7ea8bf0ba 100644--- a/src/main/git/command-runner/wsl-command-resolution.ts+++ b/src/main/git/command-runner/wsl-command-resolution.ts@@ -60,11 +60,16 @@ export function setDefaultWslDistroOverride(distro: string | null): void {defaultWslDistroOverride = distro}+/** The distro a cwd-less gh/glab call falls back to when the host CLI is missing. */+export function defaultWslCliDistro(): string | null {+ return defaultWslDistroOverride ?? getDefaultWslDistro()+}+export function resolveDefaultWslCli(command: 'gh' | 'glab',args: string[]): ResolvedCommand | null {- const distro = defaultWslDistroOverride ?? getDefaultWslDistro()+ const distro = defaultWslCliDistro()return distro ? resolveCommand(command, args, undefined, distro) : null}diff --git a/src/main/git/default-wsl-cli-fallback-gate.test.ts b/src/main/git/default-wsl-cli-fallback-gate.test.tsindex 58a3a26d77f..8e41b958b56 100644--- a/src/main/git/default-wsl-cli-fallback-gate.test.ts+++ b/src/main/git/default-wsl-cli-fallback-gate.test.ts@@ -31,6 +31,7 @@ import { ghExecFileAsync, glabExecFileAsync, setDefaultWslDistroOverride } fromimport { _resetGhRateLimitBreaker } from './gh-rate-limit-breaker'import { runAsWslExecUserAct } from '../wsl/wsl-background-exec-gate'import { WslDistroStoppedError, WslDistroUnverifiableError } from '../wsl/wsl-unc-access-gate'+import { starOrca } from '../github/client/fetch/orca-star'const originalPlatform = process.platform@@ -108,3 +109,13 @@ describe.each(CLIS)('$cli default-distro fallback', ({ cli, run }) => {expect(spawnedWsl()).toBe(true)})})++describe('starring Orca, which is always a click', () => {+ it('may start the stopped default distro its gh lives in', async () => {+ readWslDistroRunningStateMock.mockResolvedValue('stopped')+ hostMissingThenWslAnswers('gh')++ await expect(starOrca()).resolves.toBe(true)+ expect(spawnedWsl()).toBe(true)+ })+})diff --git a/src/main/github/client/fetch/orca-star.ts b/src/main/github/client/fetch/orca-star.tsindex 398ad4bc858..168058f9edf 100644--- a/src/main/github/client/fetch/orca-star.ts+++ b/src/main/github/client/fetch/orca-star.ts@@ -1,4 +1,5 @@import { ghExecFileAsync, acquire, release } from '../../gh-utils'+import { runAsDefaultWslCliUserAct } from '../../../git/command-runner/default-wsl-cli-fallback'export const ORCA_REPO = 'stablyai/orca'// Bound optional star prompts more tightly than user work; failures can fall back to the browser.@@ -47,10 +48,13 @@ async function runOrcaStarredCheck(): Promise<boolean | null> {export async function starOrca(): Promise<boolean> {await acquire()try {- await ghExecFileAsync(['api', '-X', 'PUT', `user/starred/${ORCA_REPO}`], {- encoding: 'utf-8',- timeout: STAR_GH_TIMEOUT_MS- })+ // Starring is always a click, so it may start the stopped distro its gh lives in (E9).+ await runAsDefaultWslCliUserAct(() =>+ ghExecFileAsync(['api', '-X', 'PUT', `user/starred/${ORCA_REPO}`], {+ encoding: 'utf-8',+ timeout: STAR_GH_TIMEOUT_MS+ })+ )return true} catch {return falsediff --git a/src/main/ipc/github-click-wsl-user-act.test.ts b/src/main/ipc/github-click-wsl-user-act.test.tsnew file mode 100644index 00000000000..e0a820694b5--- /dev/null+++ b/src/main/ipc/github-click-wsl-user-act.test.ts@@ -0,0 +1,118 @@+// A click on a cwd-less gh action may start the stopped default distro its gh lives in (E9); the+// same reads from mount effects on a restored page must not.+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import type * as WslModule from '../wsl'++const { handlers, getDefaultWslDistroMock, ranAsUserAct } = vi.hoisted(() => ({+ handlers: new Map<string, (event: unknown, args?: unknown) => unknown>(),+ getDefaultWslDistroMock: vi.fn(),+ // Each stub answers whether it ran inside a user act for the default distro.+ ranAsUserAct: async (): Promise<boolean> =>+ (await import('../wsl/wsl-user-act-scope')).isWslUserActFor('Ubuntu')+}))++vi.mock('electron', () => ({+ ipcMain: {+ handle: (channel: string, handler: (event: unknown, args?: unknown) => unknown) =>+ handlers.set(channel, handler)+ }+}))++vi.mock('../wsl', async (importOriginal) => ({+ ...(await importOriginal<typeof WslModule>()),+ getDefaultWslDistro: getDefaultWslDistroMock+}))++vi.mock('../github/auth-diagnose', () => ({ diagnoseGhAuth: vi.fn(ranAsUserAct) }))++vi.mock('../github/project-view', () => ({+ addIssueCommentBySlug: vi.fn(ranAsUserAct),+ clearProjectItemFieldValue: vi.fn(ranAsUserAct),+ deleteIssueCommentBySlug: vi.fn(ranAsUserAct),+ getProjectViewTable: vi.fn(ranAsUserAct),+ getWorkItemDetailsBySlug: vi.fn(ranAsUserAct),+ listAccessibleProjects: vi.fn(ranAsUserAct),+ listAssignableUsersBySlug: vi.fn(ranAsUserAct),+ listIssueTypesBySlug: vi.fn(ranAsUserAct),+ listLabelsBySlug: vi.fn(ranAsUserAct),+ listProjectViews: vi.fn(ranAsUserAct),+ resolveProjectRef: vi.fn(ranAsUserAct),+ updateIssueBySlug: vi.fn(ranAsUserAct),+ updateIssueCommentBySlug: vi.fn(ranAsUserAct),+ updateIssueTypeBySlug: vi.fn(ranAsUserAct),+ updateProjectItemFieldValue: vi.fn(ranAsUserAct),+ updatePullRequestBySlug: vi.fn(ranAsUserAct)+}))++import { registerGitHubProjectViewHandlers } from './github-project-view-handlers'+import { registerGitHubAccountHandlers } from './github-account-handlers'+import type { Store } from '../persistence'+import type { WakeWslDistroArg } from '../../shared/github/project-request-types'++const originalPlatform = process.platform++beforeEach(() => {+ handlers.clear()+ getDefaultWslDistroMock.mockReset().mockReturnValue('Ubuntu')+ Object.defineProperty(process, 'platform', { configurable: true, value: 'win32' })+ registerGitHubProjectViewHandlers()+ registerGitHubAccountHandlers(unusedStore())+})++afterEach(() => {+ Object.defineProperty(process, 'platform', { configurable: true, value: originalPlatform })+})++function unusedStore(): Store {+ const store: Partial<Store> = {}+ // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the handlers invoked here never read the store.+ return store as Store+}++function invoke(channel: string, args: WakeWslDistroArg = {}): unknown {+ const handler = handlers.get(channel)+ if (!handler) {+ throw new Error(`no handler for ${channel}`)+ }+ return handler({}, args)+}++const CLICK_CHANNELS = [+ 'gh:listAccessibleProjects',+ 'gh:resolveProjectRef',+ 'gh:listProjectViews',+ 'gh:projectWorkItemDetailsBySlug',+ 'gh:updateProjectItemField',+ 'gh:clearProjectItemField',+ 'gh:updateIssueBySlug',+ 'gh:updatePullRequestBySlug',+ 'gh:addIssueCommentBySlug',+ 'gh:updateIssueCommentBySlug',+ 'gh:deleteIssueCommentBySlug',+ 'gh:updateIssueTypeBySlug'+]++describe('cwd-less gh calls run as a user act on the default distro only when a click says so', () => {+ it.each(CLICK_CHANNELS)('%s with wakeWslDistro', async (channel) => {+ await expect(invoke(channel, { wakeWslDistro: true })).resolves.toBe(true)+ })++ // E.g. useProjectViewTable lists a restored board's views from a mount effect, with no click.+ it.each(CLICK_CHANNELS)('%s without it stays gated', async (channel) => {+ await expect(invoke(channel)).resolves.toBe(false)+ })++ it.each([+ 'gh:getProjectViewTable',+ 'gh:listLabelsBySlug',+ 'gh:listAssignableUsersBySlug',+ 'gh:listIssueTypesBySlug'+ ])('%s never wakes, even when asked', async (channel) => {+ await expect(invoke(channel, { wakeWslDistro: true })).resolves.toBe(false)+ })++ // GhAuthErrorHelp diagnoses from a mount effect.+ it('the auth diagnosis never wakes', async () => {+ await expect(invoke('gh:diagnoseAuth', { wakeWslDistro: true })).resolves.toBe(false)+ })+})diff --git a/src/main/ipc/github-project-view-handlers.ts b/src/main/ipc/github-project-view-handlers.tsindex 0106bd80bc7..8ab06a743ad 100644--- a/src/main/ipc/github-project-view-handlers.ts+++ b/src/main/ipc/github-project-view-handlers.ts@@ -1,4 +1,5 @@import { ipcMain } from 'electron'+import { runAsDefaultWslCliUserAct } from '../git/command-runner/default-wsl-cli-fallback'import type {AddIssueCommentBySlugArgs,ClearProjectItemFieldArgs,@@ -15,7 +16,8 @@ import type {UpdateIssueCommentBySlugArgs,UpdateIssueTypeBySlugArgs,UpdateProjectItemFieldArgs,- UpdatePullRequestBySlugArgs+ UpdatePullRequestBySlugArgs,+ WakeWslDistroArg} from '../../shared/github/project-request-types'import {addIssueCommentBySlug,@@ -36,43 +38,50 @@ import {updatePullRequestBySlug} from '../github/project-view'+// Only a click (the renderer sets wakeWslDistro) may start the stopped distro gh lives in (E9); the+// same reads also run from mount effects on a restored page, which must stay gated.+function wakeOnClick<T>(args: WakeWslDistroArg | undefined, act: () => Promise<T>): Promise<T> {+ return args?.wakeWslDistro === true ? runAsDefaultWslCliUserAct(act) : act()+}+export function registerGitHubProjectViewHandlers(): void {ipcMain.handle('gh:listAccessibleProjects', (_event, args?: ListAccessibleProjectsArgs) =>- listAccessibleProjects(args)+ wakeOnClick(args, () => listAccessibleProjects(args)))ipcMain.handle('gh:resolveProjectRef', (_event, args: ResolveProjectRefArgs) =>- resolveProjectRef(args)+ wakeOnClick(args, () => resolveProjectRef(args)))ipcMain.handle('gh:listProjectViews', (_event, args: ListProjectViewsArgs) =>- listProjectViews(args)+ wakeOnClick(args, () => listProjectViews(args)))ipcMain.handle('gh:getProjectViewTable', (_event, args: GetProjectViewTableArgs) =>getProjectViewTable(args))ipcMain.handle('gh:projectWorkItemDetailsBySlug',- (_event, args: ProjectWorkItemDetailsBySlugArgs) => getWorkItemDetailsBySlug(args)+ (_event, args: ProjectWorkItemDetailsBySlugArgs) =>+ wakeOnClick(args, () => getWorkItemDetailsBySlug(args)))ipcMain.handle('gh:updateProjectItemField', (_event, args: UpdateProjectItemFieldArgs) =>- updateProjectItemFieldValue(args)+ wakeOnClick(args, () => updateProjectItemFieldValue(args)))ipcMain.handle('gh:clearProjectItemField', (_event, args: ClearProjectItemFieldArgs) =>- clearProjectItemFieldValue(args)+ wakeOnClick(args, () => clearProjectItemFieldValue(args)))ipcMain.handle('gh:updateIssueBySlug', (_event, args: UpdateIssueBySlugArgs) =>- updateIssueBySlug(args)+ wakeOnClick(args, () => updateIssueBySlug(args)))ipcMain.handle('gh:updatePullRequestBySlug', (_event, args: UpdatePullRequestBySlugArgs) =>- updatePullRequestBySlug(args)+ wakeOnClick(args, () => updatePullRequestBySlug(args)))ipcMain.handle('gh:addIssueCommentBySlug', (_event, args: AddIssueCommentBySlugArgs) =>- addIssueCommentBySlug(args)+ wakeOnClick(args, () => addIssueCommentBySlug(args)))ipcMain.handle('gh:updateIssueCommentBySlug', (_event, args: UpdateIssueCommentBySlugArgs) =>- updateIssueCommentBySlug(args)+ wakeOnClick(args, () => updateIssueCommentBySlug(args)))ipcMain.handle('gh:deleteIssueCommentBySlug', (_event, args: DeleteIssueCommentBySlugArgs) =>- deleteIssueCommentBySlug(args)+ wakeOnClick(args, () => deleteIssueCommentBySlug(args)))ipcMain.handle('gh:listLabelsBySlug', (_event, args: ListLabelsBySlugArgs) =>listLabelsBySlug(args)@@ -84,6 +93,6 @@ export function registerGitHubProjectViewHandlers(): void {listIssueTypesBySlug(args))ipcMain.handle('gh:updateIssueTypeBySlug', (_event, args: UpdateIssueTypeBySlugArgs) =>- updateIssueTypeBySlug(args)+ wakeOnClick(args, () => updateIssueTypeBySlug(args)))}diff --git a/src/renderer/src/components/github-project/ProjectPicker.tsx b/src/renderer/src/components/github-project/ProjectPicker.tsxindex a78fd5ad29b..771ba42b70b 100644--- a/src/renderer/src/components/github-project/ProjectPicker.tsx+++ b/src/renderer/src/components/github-project/ProjectPicker.tsx@@ -150,12 +150,16 @@ export default function ProjectPicker({setViewPickFor(selection)setViewLoading(true)try {- const result = await listProjectViewsForRuntime(sourceTarget, {- owner: choice.owner,- ownerType: choice.ownerType,- projectNumber: choice.number,- host: githubProjectHost(choice.host)- })+ const result = await listProjectViewsForRuntime(+ sourceTarget,+ {+ owner: choice.owner,+ ownerType: choice.ownerType,+ projectNumber: choice.number,+ host: githubProjectHost(choice.host)+ },+ { wake: true }+ )if (!mountedRef.current) {return}@@ -213,7 +217,9 @@ export default function ProjectPicker({setPasteError(null)setPasteBusy(true)try {- const result = await resolveProjectRefForRuntime(sourceTarget, input, parsed.host)+ const result = await resolveProjectRefForRuntime(sourceTarget, input, parsed.host, {+ wake: true+ })if (!mountedRef.current) {return}diff --git a/src/renderer/src/components/github-project/project-picker-runtime.ts b/src/renderer/src/components/github-project/project-picker-runtime.tsindex 94050a8d50c..87bb7877d1c 100644--- a/src/renderer/src/components/github-project/project-picker-runtime.ts+++ b/src/renderer/src/components/github-project/project-picker-runtime.ts@@ -18,16 +18,24 @@ export function getProjectPickerBrowseHost(activeProject: { host?: string } | nureturn githubProjectHost(activeProject?.host).toLowerCase()}+/** `wake`: a click, which may start the stopped WSL distro gh lives in (E9); mount effects omit it. */+type PickerCallOptions = { wake?: boolean }++function wakeArg(options: PickerCallOptions): { wakeWslDistro?: true } {+ return options.wake ? { wakeWslDistro: true } : {}+}+export async function listAccessibleProjectsForRuntime(target: RuntimeClientTarget,- host: string+ host: string,+ options: PickerCallOptions = {}): Promise<ListAccessibleProjectsResult> {const args = { host }return target.kind === 'environment'? callRuntimeRpc<ListAccessibleProjectsResult>(target, 'github.project.listAccessible', args, {timeoutMs: 60_000})- : window.api.gh.listAccessibleProjects(args)+ : window.api.gh.listAccessibleProjects({ ...args, ...wakeArg(options) })}export async function listProjectViewsForRuntime(@@ -37,19 +45,21 @@ export async function listProjectViewsForRuntime(ownerType: GitHubProjectOwnerTypeprojectNumber: numberhost?: string- }+ },+ options: PickerCallOptions = {}): Promise<ListProjectViewsResult> {return target.kind === 'environment'? callRuntimeRpc<ListProjectViewsResult>(target, 'github.project.listViews', args, {timeoutMs: 30_000})- : window.api.gh.listProjectViews(args)+ : window.api.gh.listProjectViews({ ...args, ...wakeArg(options) })}export async function resolveProjectRefForRuntime(target: RuntimeClientTarget,input: string,- host?: string+ host?: string,+ options: PickerCallOptions = {}): Promise<ResolveProjectRefResult> {return target.kind === 'environment'? callRuntimeRpc<ResolveProjectRefResult>(@@ -58,5 +68,5 @@ export async function resolveProjectRefForRuntime({ input, ...(host ? { host } : {}) },{ timeoutMs: 30_000 })- : window.api.gh.resolveProjectRef({ input, ...(host ? { host } : {}) })+ : window.api.gh.resolveProjectRef({ input, ...(host ? { host } : {}), ...wakeArg(options) })}diff --git a/src/renderer/src/components/github-project/project-view-mount-no-wake.test.tsx b/src/renderer/src/components/github-project/project-view-mount-no-wake.test.tsxnew file mode 100644index 00000000000..6a3d83c1e92--- /dev/null+++ b/src/renderer/src/components/github-project/project-view-mount-no-wake.test.tsx@@ -0,0 +1,62 @@+// @vitest-environment happy-dom+// A restored Projects page lists the board's views from a mount effect with no click: it must not+// ask to start the stopped WSL distro gh lives in (E9). Picker clicks do.+import { cleanup, renderHook, waitFor } from '@testing-library/react'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'++const { state, listProjectViewsMock } = vi.hoisted(() => ({+ state: {+ settings: {+ githubProjects: {+ activeProject: { owner: 'acme', ownerType: 'organization', number: 7 },+ lastViewByProject: {}+ }+ },+ projectViewCache: {},+ fetchProjectViewTable: async () => ({ ok: false, error: { type: 'unknown', message: '' } })+ },+ listProjectViewsMock: vi.fn()+}))++vi.mock('@/store', () => ({+ useAppStore: (select: (value: typeof state) => unknown) => select(state)+}))+vi.mock('@/lib/repo-slug-index', () => ({+ useRepoSlugIndex: () => ({ lookupSlugMatches: () => [], ready: true })+}))+vi.mock('@/i18n/i18n', () => ({ translate: (_key: string, fallback: string) => fallback }))+vi.mock('sonner', () => ({ toast: { error: vi.fn(), warning: vi.fn(), message: vi.fn() } }))++import { useProjectViewTable } from './useProjectViewTable'+import { listProjectViewsForRuntime } from './project-picker-runtime'++beforeEach(() => {+ listProjectViewsMock.mockReset().mockResolvedValue({ ok: true, views: [] })+ Object.defineProperty(window, 'api', {+ configurable: true,+ value: { gh: { listProjectViews: listProjectViewsMock } }+ })+})++afterEach(() => {+ cleanup()+})++describe('listing a board’s views', () => {+ it('from the mount effect never asks to wake the distro', async () => {+ renderHook(() => useProjectViewTable(new Set(), { kind: 'local' }))++ await waitFor(() => expect(listProjectViewsMock).toHaveBeenCalled())+ for (const [args] of listProjectViewsMock.mock.calls) {+ expect(args).not.toHaveProperty('wakeWslDistro')+ }+ })++ it('from a picker click asks to wake it', async () => {+ const args = { owner: 'acme', ownerType: 'organization', projectNumber: 7 } as const++ await listProjectViewsForRuntime({ kind: 'local' }, args, { wake: true })++ expect(listProjectViewsMock).toHaveBeenCalledWith({ ...args, wakeWslDistro: true })+ })+})diff --git a/src/renderer/src/components/github-project/slug-dialog/Comments.tsx b/src/renderer/src/components/github-project/slug-dialog/Comments.tsxindex 2ef14f08683..81c4e4bb010 100644--- a/src/renderer/src/components/github-project/slug-dialog/Comments.tsx+++ b/src/renderer/src/components/github-project/slug-dialog/Comments.tsx@@ -67,7 +67,7 @@ export function CommentsList({args,{ timeoutMs: 30_000 })- : await window.api.gh.deleteIssueCommentBySlug(args)+ : await window.api.gh.deleteIssueCommentBySlug({ ...args, wakeWslDistro: true })if (!res.ok) {toast.error(projectViewErrorMessage(res.error))return@@ -90,7 +90,7 @@ export function CommentsList({args,{ timeoutMs: 30_000 })- : await window.api.gh.updateIssueCommentBySlug(args)+ : await window.api.gh.updateIssueCommentBySlug({ ...args, wakeWslDistro: true })if (!res.ok) {toast.error(projectViewErrorMessage(res.error))return@@ -234,7 +234,7 @@ export function NewCommentForm({args,{ timeoutMs: 30_000 })- : await window.api.gh.addIssueCommentBySlug(args)+ : await window.api.gh.addIssueCommentBySlug({ ...args, wakeWslDistro: true })if (!res.ok) {toast.error(projectViewErrorMessage(res.error))returndiff --git a/src/renderer/src/components/github-project/slug-dialog/SlugDialogBody.tsx b/src/renderer/src/components/github-project/slug-dialog/SlugDialogBody.tsxindex 479435fd013..c9491cb8b9c 100644--- a/src/renderer/src/components/github-project/slug-dialog/SlugDialogBody.tsx+++ b/src/renderer/src/components/github-project/slug-dialog/SlugDialogBody.tsx@@ -65,7 +65,15 @@ export function SlugDialogBody({{ owner, repo, host, number, type },{ timeoutMs: 30_000 })- : window.api.gh.projectWorkItemDetailsBySlug({ owner, repo, host, number, type })+ : window.api.gh.projectWorkItemDetailsBySlug({+ owner,+ repo,+ host,+ number,+ type,+ // Opening an item is a click (E9).+ wakeWslDistro: true+ })request.then((res) => {if (rid !== requestIdRef.current) {diff --git a/src/renderer/src/components/github-project/useProjectPickerBrowse.ts b/src/renderer/src/components/github-project/useProjectPickerBrowse.tsindex cae40c0f6bd..22787ab8952 100644--- a/src/renderer/src/components/github-project/useProjectPickerBrowse.ts+++ b/src/renderer/src/components/github-project/useProjectPickerBrowse.ts@@ -54,7 +54,10 @@ export function useProjectPickerBrowse(setBrowseProjects([])setPartialFailures([])try {- const result = await listAccessibleProjectsForRuntime(settings, browseHost)+ const result = await listAccessibleProjectsForRuntime(settings, browseHost, {+ // Browsing follows the user opening the picker.+ wake: true+ })if (result.ok) {rememberProjectPickerBrowseCacheEntry(cacheKey, {projects: result.projects,diff --git a/src/renderer/src/components/github-project/useProjectViewTable.ts b/src/renderer/src/components/github-project/useProjectViewTable.tsindex 912150506ca..d780c7f9c11 100644--- a/src/renderer/src/components/github-project/useProjectViewTable.ts+++ b/src/renderer/src/components/github-project/useProjectViewTable.ts@@ -132,6 +132,7 @@ export function useProjectViewTable(return}let cancelled = false+ // No wake: this also runs on a restored page with no click, so a stopped distro stays stopped.void listProjectViewsForRuntime(sourceTarget, {owner: activeProject.owner,ownerType: activeProject.ownerType,diff --git a/src/renderer/src/components/github/code-host-rate-limit-stopped-wsl.test.tsx b/src/renderer/src/components/github/code-host-rate-limit-stopped-wsl.test.tsxnew file mode 100644index 00000000000..ff63e3e9202--- /dev/null+++ b/src/renderer/src/components/github/code-host-rate-limit-stopped-wsl.test.tsx@@ -0,0 +1,82 @@+// @vitest-environment happy-dom+// gh/glab living in a stopped WSL distro refuses the poll (E9); the card keeps its last numbers.+import { act, cleanup, renderHook } from '@testing-library/react'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'++vi.mock('@/i18n/i18n', () => ({ translate: (_key: string, fallback: string) => fallback }))++import { useGitHubRateLimitSnapshot } from './github-rate-limit-display'+import { useGitLabRateLimitSnapshot } from '../gitlab/gitlab-rate-limit-display'++const STOPPED = "WSL distro 'Ubuntu' is not running. Open a terminal in it to start it."+const UNVERIFIABLE = "WSL didn't answer whether 'Ubuntu' is running, so Orca left it alone."+const SNAPSHOT = { fetchedAt: 1 }++const rateLimit = vi.fn()++beforeEach(() => {+ rateLimit.mockReset()+ Object.defineProperty(window, 'api', {+ configurable: true,+ value: { gh: { rateLimit }, gl: { rateLimit } }+ })+})++afterEach(() => {+ cleanup()+})++describe.each([+ ['GitHub', useGitHubRateLimitSnapshot],+ ['GitLab', useGitLabRateLimitSnapshot]+] as const)('%s rate-limit card', (_provider, useSnapshot) => {+ function renderCard() {+ return renderHook(() => useSnapshot({ kind: 'local' }, { autoRefresh: false }))+ }++ it.each([STOPPED, UNVERIFIABLE])(+ 'keeps the last snapshot when refused with: %s',+ async (error) => {+ rateLimit.mockResolvedValueOnce({ ok: true, snapshot: SNAPSHOT })+ rateLimit.mockResolvedValueOnce({ ok: false, error })+ const { result } = renderCard()++ await act(() => result.current.refresh())+ await act(() => result.current.refresh())++ expect(result.current.snapshot).toEqual(SNAPSHOT)+ expect(result.current.hasError).toBe(false)+ }+ )++ it('keeps it when the refusal is thrown', async () => {+ rateLimit.mockResolvedValueOnce({ ok: true, snapshot: SNAPSHOT })+ rateLimit.mockRejectedValueOnce(new Error(STOPPED))+ const { result } = renderCard()++ await act(() => result.current.refresh())+ await act(() => result.current.refresh())++ expect(result.current.snapshot).toEqual(SNAPSHOT)+ expect(result.current.hasError).toBe(false)+ })++ it('reports the refusal when there is no snapshot yet to keep', async () => {+ rateLimit.mockResolvedValueOnce({ ok: false, error: STOPPED })+ const { result } = renderCard()++ await act(() => result.current.refresh())++ expect(result.current.snapshot).toBeNull()+ expect(result.current.hasError).toBe(true)+ })++ it('still reports any other failure', async () => {+ rateLimit.mockResolvedValueOnce({ ok: false, error: 'HTTP 401: Bad credentials' })+ const { result } = renderCard()++ await act(() => result.current.refresh())++ expect(result.current.hasError).toBe(true)+ })+})diff --git a/src/renderer/src/components/github/github-rate-limit-display.tsx b/src/renderer/src/components/github/github-rate-limit-display.tsxindex b877176560b..73ea6f62c7c 100644--- a/src/renderer/src/components/github/github-rate-limit-display.tsx+++ b/src/renderer/src/components/github/github-rate-limit-display.tsx@@ -4,6 +4,7 @@ import { cn } from '@/lib/utils'import { installWindowVisibilityInterval } from '@/lib/window-visibility-interval'import { callRuntimeRpc } from '@/runtime/runtime-rpc-client'import type { RuntimeClientTarget } from '../../../../shared/runtime-client-target'+import { isWslDistroNotRunningRefusal } from '../../../../shared/wsl-distro-not-running-refusal'import type {GetRateLimitResult,GitHubRateLimitSnapshot@@ -88,11 +89,15 @@ export function useGitHubRateLimitSnapshot(const [hasError, setHasError] = useState(false)const [isFetching, setIsFetching] = useState(false)const latestToken = useRef(0)+ const hasSnapshot = useRef(false)const autoRefresh = options?.autoRefresh ?? trueconst refresh = useCallback(async (force = false): Promise<void> => {const token = ++latestToken.current+ // A stopped WSL distro (where the CLI lives) is no failure: keep the last numbers if any.+ const keepsLastSnapshot = (error: unknown): boolean =>+ hasSnapshot.current && isWslDistroNotRunningRefusal(error)setIsFetching(true)try {const params = force ? { force: true } : undefined@@ -106,13 +111,14 @@ export function useGitHubRateLimitSnapshot(return}if (res?.ok) {+ hasSnapshot.current = truesetSnapshot(res.snapshot)setHasError(false)- } else {+ } else if (!keepsLastSnapshot(res?.error)) {setHasError(true)}- } catch {- if (token === latestToken.current) {+ } catch (error) {+ if (token === latestToken.current && !keepsLastSnapshot(error)) {setHasError(true)}} finally {diff --git a/src/renderer/src/components/github/github-work-item-edit-mutations.ts b/src/renderer/src/components/github/github-work-item-edit-mutations.tsindex e76ed6d93b8..e26af4e120f 100644--- a/src/renderer/src/components/github/github-work-item-edit-mutations.ts+++ b/src/renderer/src/components/github/github-work-item-edit-mutations.ts@@ -68,7 +68,7 @@ export async function runIssueUpdate(args: {timeoutMs: 30_000})- : await window.api.gh.updateIssueBySlug(updateArgs)+ : await window.api.gh.updateIssueBySlug({ ...updateArgs, wakeWslDistro: true })if (!res.ok) {throw new Error(res.error.message)}@@ -164,7 +164,7 @@ export async function runWorkItemBodyUpdate(args: {timeoutMs: 30_000})- : await window.api.gh.updatePullRequestBySlug(updateArgs)+ : await window.api.gh.updatePullRequestBySlug({ ...updateArgs, wakeWslDistro: true })if (!res.ok) {throw new Error(res.error.message)}@@ -225,7 +225,7 @@ export async function runPullRequestStateUpdate(args: {timeoutMs: 30_000})- : await window.api.gh.updatePullRequestBySlug(updateArgs)+ : await window.api.gh.updatePullRequestBySlug({ ...updateArgs, wakeWslDistro: true })if (!res.ok) {throw new Error(res.error.message)}diff --git a/src/renderer/src/components/github/github-work-item-issue-target.test.ts b/src/renderer/src/components/github/github-work-item-issue-target.test.tsindex 88056a25cbb..5722e856086 100644--- a/src/renderer/src/components/github/github-work-item-issue-target.test.ts+++ b/src/renderer/src/components/github/github-work-item-issue-target.test.ts@@ -83,7 +83,9 @@ describe('issue edits retain the displayed repository', () => {expect(window.api.gh.updateIssueBySlug).toHaveBeenCalledWith({...UPSTREAM,number: 12,- updates: { body: 'Project edit' }+ updates: { body: 'Project edit' },+ // An edit is a click: it may start a stopped WSL distro (E9).+ wakeWslDistro: true})expect(window.api.gh.updateIssue).not.toHaveBeenCalled()})@@ -108,7 +110,8 @@ describe('issue edits retain the displayed repository', () => {expect(window.api.gh.updateIssueBySlug).toHaveBeenCalledWith({...UPSTREAM,number: 12,- updates+ updates,+ wakeWslDistro: true})expect(window.api.gh.updateIssue).not.toHaveBeenCalled()})diff --git a/src/renderer/src/components/gitlab/gitlab-rate-limit-display.tsx b/src/renderer/src/components/gitlab/gitlab-rate-limit-display.tsxindex e227db86586..4d7a3e690b4 100644--- a/src/renderer/src/components/gitlab/gitlab-rate-limit-display.tsx+++ b/src/renderer/src/components/gitlab/gitlab-rate-limit-display.tsx@@ -5,6 +5,7 @@ import { cn } from '@/lib/utils'import { installWindowVisibilityInterval } from '@/lib/window-visibility-interval'import { callRuntimeRpc } from '@/runtime/runtime-rpc-client'import type { RuntimeClientTarget } from '../../../../shared/runtime-client-target'+import { isWslDistroNotRunningRefusal } from '../../../../shared/wsl-distro-not-running-refusal'import type {GetGitLabRateLimitResult,GitLabRateLimitSnapshot@@ -54,11 +55,15 @@ export function useGitLabRateLimitSnapshot(const [hasError, setHasError] = useState(false)const [isFetching, setIsFetching] = useState(false)const latestToken = useRef(0)+ const hasSnapshot = useRef(false)const autoRefresh = options?.autoRefresh ?? trueconst refresh = useCallback(async (force = false): Promise<void> => {const token = ++latestToken.current+ // A stopped WSL distro (where the CLI lives) is no failure: keep the last numbers if any.+ const keepsLastSnapshot = (error: unknown): boolean =>+ hasSnapshot.current && isWslDistroNotRunningRefusal(error)setIsFetching(true)try {const params = force ? { force: true } : undefined@@ -75,13 +80,14 @@ export function useGitLabRateLimitSnapshot(return}if (res?.ok) {+ hasSnapshot.current = truesetSnapshot(res.snapshot)setHasError(false)- } else {+ } else if (!keepsLastSnapshot(res?.error)) {setHasError(true)}- } catch {- if (token === latestToken.current) {+ } catch (error) {+ if (token === latestToken.current && !keepsLastSnapshot(error)) {setHasError(true)}} finally {diff --git a/src/renderer/src/components/right-sidebar/checks-panel/use-checks-panel-comment-mutations.tsx b/src/renderer/src/components/right-sidebar/checks-panel/use-checks-panel-comment-mutations.tsxindex 987d569cbbb..0d5ae2545ae 100644--- a/src/renderer/src/components/right-sidebar/checks-panel/use-checks-panel-comment-mutations.tsx+++ b/src/renderer/src/components/right-sidebar/checks-panel/use-checks-panel-comment-mutations.tsx@@ -99,7 +99,8 @@ export function useChecksPanelCommentMutations(model: ChecksPanelCommentMutationrepo: pr.prRepo.repo,host: githubProjectHost(pr.prRepo.host),commentId: comment.id,- body+ body,+ wakeWslDistro: true})if (!result.ok) {toast.error(result.error.message)@@ -134,7 +135,8 @@ export function useChecksPanelCommentMutations(model: ChecksPanelCommentMutationowner: pr.prRepo.owner,repo: pr.prRepo.repo,host: githubProjectHost(pr.prRepo.host),- commentId: comment.id+ commentId: comment.id,+ wakeWslDistro: true})if (!result.ok) {toast.error(result.error.message)diff --git a/src/renderer/src/components/task-page/github/AssigneesCell.tsx b/src/renderer/src/components/task-page/github/AssigneesCell.tsxindex b797f231b5c..b416f187c64 100644--- a/src/renderer/src/components/task-page/github/AssigneesCell.tsx+++ b/src/renderer/src/components/task-page/github/AssigneesCell.tsx@@ -109,7 +109,7 @@ export function GHAssigneesCell({>(target, 'github.project.updateIssueBySlug', args, {timeoutMs: 30_000})- : await window.api.gh.updateIssueBySlug(args)+ : await window.api.gh.updateIssueBySlug({ ...args, wakeWslDistro: true })if (!res.ok) {throw new Error(res.error.message)}diff --git a/src/renderer/src/components/task-page/github/StatusCell.tsx b/src/renderer/src/components/task-page/github/StatusCell.tsxindex 70e4bb28f4c..16ba9b324cd 100644--- a/src/renderer/src/components/task-page/github/StatusCell.tsx+++ b/src/renderer/src/components/task-page/github/StatusCell.tsx@@ -161,7 +161,8 @@ export function GHStatusCell({repo: parsedOwnerRepo.repo,host: githubProjectHost(parsedOwnerRepo.host),number: item.number,- updates+ updates,+ wakeWslDistro: true})}if (!repo) {diff --git a/src/renderer/src/store/github/project-field-mutations.ts b/src/renderer/src/store/github/project-field-mutations.tsindex d26207b176b..84ad49a2de6 100644--- a/src/renderer/src/store/github/project-field-mutations.ts+++ b/src/renderer/src/store/github/project-field-mutations.ts@@ -70,7 +70,7 @@ export function createProjectFieldActions({ ...args, value },{ timeoutMs: 30_000 })- : await window.api.gh.updateProjectItemField({ ...args, value })+ : await window.api.gh.updateProjectItemField({ ...args, value, wakeWslDistro: true }): target.kind === 'environment'? await callRuntimeRpc<GitHubProjectMutationResult>(target,@@ -78,7 +78,7 @@ export function createProjectFieldActions(args,{ timeoutMs: 30_000 })- : await window.api.gh.clearProjectItemField(args)+ : await window.api.gh.clearProjectItemField({ ...args, wakeWslDistro: true })} catch (error) {result = {ok: false,diff --git a/src/renderer/src/store/github/project-row-actions.ts b/src/renderer/src/store/github/project-row-actions.tsindex 8b67ed6861f..740ac4d4367 100644--- a/src/renderer/src/store/github/project-row-actions.ts+++ b/src/renderer/src/store/github/project-row-actions.ts@@ -119,7 +119,7 @@ export const createProjectRowActions = (args,{ timeoutMs: 30_000 })- : await window.api.gh.updatePullRequestBySlug(args)+ : await window.api.gh.updatePullRequestBySlug({ ...args, wakeWslDistro: true })if (!prRes.ok) {envelope = prRes}@@ -155,7 +155,7 @@ export const createProjectRowActions = (args,{ timeoutMs: 30_000 })- : await window.api.gh.updateIssueBySlug(args)+ : await window.api.gh.updateIssueBySlug({ ...args, wakeWslDistro: true })if (!issueRes.ok) {envelope = issueRes}@@ -240,7 +240,7 @@ export const createProjectRowActions = (args,{ timeoutMs: 30_000 })- : await window.api.gh.updateIssueTypeBySlug(args)+ : await window.api.gh.updateIssueTypeBySlug({ ...args, wakeWslDistro: true })if (!res.ok) {rollbackRowIfPresent(set, get, cacheKey, rowId, previousRow)}diff --git a/src/shared/github/project-request-types.ts b/src/shared/github/project-request-types.tsindex 740fa9fb8b8..709810e77f0 100644--- a/src/shared/github/project-request-types.ts+++ b/src/shared/github/project-request-types.ts@@ -2,6 +2,10 @@import type { GitHubProjectFieldMutationValue, GitHubProjectOwnerType } from './project-types'import type { GitHubIssueUpdate } from '../issue-mutation-types'+/** Set by a click: it may start the stopped WSL distro gh lives in (E9). Loads that also run+ * unprompted (mount effects, restore) leave it unset. Local IPC only. */+export type WakeWslDistroArg = { wakeWslDistro?: boolean }+export type GetProjectViewTableArgs = {owner: stringownerType: GitHubProjectOwnerType@@ -16,7 +20,7 @@ export type GetProjectViewTableArgs = {queryOverride?: string}-export type ProjectWorkItemDetailsBySlugArgs = {+export type ProjectWorkItemDetailsBySlugArgs = WakeWslDistroArg & {owner: stringrepo: stringhost?: string@@ -24,7 +28,7 @@ export type ProjectWorkItemDetailsBySlugArgs = {type: 'issue' | 'pr'}-export type UpdateProjectItemFieldArgs = {+export type UpdateProjectItemFieldArgs = WakeWslDistroArg & {projectId: stringhost?: stringitemId: string@@ -32,14 +36,14 @@ export type UpdateProjectItemFieldArgs = {value: GitHubProjectFieldMutationValue}-export type ClearProjectItemFieldArgs = {+export type ClearProjectItemFieldArgs = WakeWslDistroArg & {projectId: stringhost?: stringitemId: stringfieldId: string}-export type UpdateIssueBySlugArgs = {+export type UpdateIssueBySlugArgs = WakeWslDistroArg & {owner: stringrepo: stringhost?: string@@ -47,7 +51,7 @@ export type UpdateIssueBySlugArgs = {updates: GitHubIssueUpdate & { body?: string }}-export type UpdatePullRequestBySlugArgs = {+export type UpdatePullRequestBySlugArgs = WakeWslDistroArg & {owner: stringrepo: stringhost?: string@@ -55,7 +59,7 @@ export type UpdatePullRequestBySlugArgs = {updates: { title?: string; body?: string; state?: 'open' | 'closed' }}-export type AddIssueCommentBySlugArgs = {+export type AddIssueCommentBySlugArgs = WakeWslDistroArg & {owner: stringrepo: stringhost?: string@@ -63,7 +67,7 @@ export type AddIssueCommentBySlugArgs = {body: string}-export type UpdateIssueCommentBySlugArgs = {+export type UpdateIssueCommentBySlugArgs = WakeWslDistroArg & {owner: stringrepo: stringhost?: string@@ -71,7 +75,7 @@ export type UpdateIssueCommentBySlugArgs = {body: string}-export type DeleteIssueCommentBySlugArgs = {+export type DeleteIssueCommentBySlugArgs = WakeWslDistroArg & {owner: stringrepo: stringhost?: string@@ -97,7 +101,7 @@ export type ListIssueTypesBySlugArgs = {host?: string}-export type UpdateIssueTypeBySlugArgs = {+export type UpdateIssueTypeBySlugArgs = WakeWslDistroArg & {owner: stringrepo: stringhost?: string@@ -106,19 +110,19 @@ export type UpdateIssueTypeBySlugArgs = {issueTypeId: string | null}-export type ResolveProjectRefArgs = {+export type ResolveProjectRefArgs = WakeWslDistroArg & {input: stringhost?: string}-export type ListProjectViewsArgs = {+export type ListProjectViewsArgs = WakeWslDistroArg & {owner: stringownerType: GitHubProjectOwnerTypeprojectNumber: numberhost?: string}-export type ListAccessibleProjectsArgs = {+export type ListAccessibleProjectsArgs = WakeWslDistroArg & {/** GitHub host (e.g. GHES); absent means github.com. */host?: string}