diff --git a/src/main/skills/bundled-skill-install/bundled-skill-other-build.test.ts b/src/main/skills/bundled-skill-install/bundled-skill-other-build.test.ts index 53ec7fd01aa..625a0159d90 100644 --- a/src/main/skills/bundled-skill-install/bundled-skill-other-build.test.ts +++ b/src/main/skills/bundled-skill-install/bundled-skill-other-build.test.ts @@ -57,6 +57,18 @@ const hasMarker = (home: SkillHome, text: string) => ) describe("another Orca build's copy on the same host", () => { + it('links a newly selected agent to a recognized shared copy', async () => { + const home = await makeSkillHome() + await writeCopy(home.shared, NEWER_TEXT) + await autoUpdateAs(home, NEWER_SOURCE) + + const input = { ...serviceInput(home, { agents: ['cursor'] }), sources: [NEW_SOURCE] } + await previewAndInstall(input) + + expect((await lstat(home.cursor)).isSymbolicLink()).toBe(true) + expect(await readFile(join(home.cursor, 'SKILL.md'), 'utf8')).toBe(NEWER_TEXT) + }) + it('is not reported out of date or downgraded by an older build, until the user edits it', async () => { const home = await makeSkillHome() await writeCopy(home.shared, OLD_TEXT) diff --git a/src/main/skills/bundled-skill-install/bundled-skill-plan-execution.ts b/src/main/skills/bundled-skill-install/bundled-skill-plan-execution.ts index c9ca946c1a8..770e70d8a9a 100644 --- a/src/main/skills/bundled-skill-install/bundled-skill-plan-execution.ts +++ b/src/main/skills/bundled-skill-install/bundled-skill-plan-execution.ts @@ -120,7 +120,12 @@ async function applyContent(run: SkillRun, op: BundledSkillOp): Promise vi.fn()) +const toastWarning = vi.hoisted(() => vi.fn()) +vi.mock('sonner', () => ({ toast: { warning: toastWarning } })) +vi.mock('@/store/index', () => ({ + useAppStore: { getState: () => ({ runtimeEnvironments: [] }) } +})) vi.mock('@/runtime/skills/bundled/runtime-bundled-skills-client', () => ({ autoUpdateBundledSkillsOnTarget: autoUpdate })) @@ -13,6 +18,7 @@ vi.mock('@/hooks/skills/discovery/installed-agent-skill-discovery', () => ({ const { _resetSkillFreshnessAutoUpdate, autoUpdateUnmodifiedSkills } = await import('./skill-freshness-auto-update') const { getSkillUpdateRun } = await import('./skill-update-run-store') +const { RuntimeRpcCallError } = await import('@/runtime/rpc/calls/runtime-rpc-result') const DIGEST = 'a'.repeat(64) @@ -42,6 +48,7 @@ const currentPlan: BundledSkillPlan = { afterEach(() => { _resetSkillFreshnessAutoUpdate() autoUpdate.mockReset() + toastWarning.mockReset() }) describe('startup scan of an already-current host', () => { @@ -52,7 +59,9 @@ describe('startup scan of an already-current host', () => { autoUpdate.mockResolvedValue({ scope: 'global', skills: [] }) expect(autoUpdateUnmodifiedSkills(target, currentPlan).size).toBe(0) - await vi.waitFor(() => expect(autoUpdate).toHaveBeenCalledWith(target, ['orca-cli'])) + await vi.waitFor(() => + expect(autoUpdate).toHaveBeenCalledWith(target, ['orca-cli'], expect.anything()) + ) autoUpdateUnmodifiedSkills(target, currentPlan) expect(autoUpdate).toHaveBeenCalledTimes(1) }) @@ -87,4 +96,43 @@ describe('startup scan of an already-current host', () => { expect(autoUpdate).toHaveBeenCalledTimes(2) }) }) + + it.each<[string, (options: { onSent?: () => void }) => Promise, boolean]>([ + [ + 'warns when the reply to a sent marking call is lost', + async (options) => { + options.onSent?.() + throw new Error('timed out') + }, + true + ], + [ + 'stays quiet when the marking call is refused before sending', + async () => { + throw new Error('server unreachable') + }, + false + ], + [ + 'stays quiet when the host answers the marking call with an error', + async (options) => { + options.onSent?.() + throw new RuntimeRpcCallError({ + id: '1', + ok: false, + error: { code: 'internal', message: 'boom' }, + _meta: { runtimeId: 'r' } + }) + }, + false + ] + ])('%s', async (_, reject, warns) => { + const target: BundledSkillTarget = { kind: 'environment', environmentId: 'server-1' } + autoUpdate.mockImplementationOnce((_target, _names, options) => reject(options)) + + autoUpdateUnmodifiedSkills(target, currentPlan) + await vi.waitFor(() => expect(getSkillUpdateRun('runtime:server-1').state).toBe('idle')) + await new Promise((resolve) => setTimeout(resolve, 0)) + expect(toastWarning).toHaveBeenCalledTimes(warns ? 1 : 0) + }) }) diff --git a/src/renderer/src/components/skills/freshness/skill-freshness-auto-update.ts b/src/renderer/src/components/skills/freshness/skill-freshness-auto-update.ts index ff40a15e1f4..c1d605d6ed0 100644 --- a/src/renderer/src/components/skills/freshness/skill-freshness-auto-update.ts +++ b/src/renderer/src/components/skills/freshness/skill-freshness-auto-update.ts @@ -15,6 +15,10 @@ import { } from '@/lib/skills/runtime/bundled-skill-target' import { translate } from '@/i18n/i18n' import { autoUpdateBundledSkillsOnTarget } from '@/runtime/skills/bundled/runtime-bundled-skills-client' +import { + RuntimeConnectionChangedBeforeSendError, + RuntimeRpcCallError +} from '@/runtime/rpc/calls/runtime-rpc-result' import { useAppStore } from '@/store/index' import { getSkillUpdateRun, runAutomaticSkillUpdate } from './skill-update-run-store' @@ -123,6 +127,18 @@ function reportUncertainOutcome(target: BundledSkillTarget, plan: BundledSkillPl ) } +/** + * A rejection after the request left for the host, other than the host's own error reply, may + * hide a committed update. Refused before sending, or answered with an error, nothing was written. + */ +function mayHaveWritten(sent: boolean, error: unknown): boolean { + return ( + sent && + !(error instanceof RuntimeRpcCallError) && + !(error instanceof RuntimeConnectionChangedBeforeSendError) + ) +} + /** * Lets the next plan refresh ask again when the host did not run the recording: the call failed, * another update held the target, or the host reported the skill busy or changed. A host that @@ -188,12 +204,17 @@ export function autoUpdateUnmodifiedSkills( for (const { mark } of marking) { markedCopies.add(mark) } - // Marking-only names are not owned: the host records them and changes nothing on disk. + // Marking-only names are not owned; the host re-plans and may still update a copy that became released. const names = [...started, ...marking.map(({ name }) => name)] if (names.length > 0) { + let sent = false // The host re-plans under its locks and re-checks each location right before writing. void runAutomaticSkillUpdate(target, names, () => - autoUpdateBundledSkillsOnTarget(target, names) + autoUpdateBundledSkillsOnTarget(target, names, { + onSent: () => { + sent = true + } + }) ) .then( (ran) => { @@ -201,10 +222,12 @@ export function autoUpdateUnmodifiedSkills( reportPreservedEdits(ran?.value ?? null) }, // Settling the keys below means the same state is never retried; the nudge takes over. - // A marking-only call writes no skill, so its failure has nothing to report. - () => { + (error: unknown) => { releaseUnrecordedMarks(marking, null) - return started.length > 0 ? reportUncertainOutcome(target, plan) : undefined + // A marking-only call can write only if it reached the host and its reply was lost. + if (started.length > 0 || mayHaveWritten(sent, error)) { + reportUncertainOutcome(target, plan) + } } ) .catch(() => undefined) @@ -214,9 +237,7 @@ export function autoUpdateUnmodifiedSkills( for (const key of keys) { settled.set(key, 'settled') } - if (started.length > 0) { - notifyInstalledAgentSkillsChanged() - } + notifyInstalledAgentSkillsChanged() }) } return owned diff --git a/src/renderer/src/runtime/skills/bundled/runtime-bundled-skills-client.ts b/src/renderer/src/runtime/skills/bundled/runtime-bundled-skills-client.ts index a290a3446d0..e218f5b8427 100644 --- a/src/renderer/src/runtime/skills/bundled/runtime-bundled-skills-client.ts +++ b/src/renderer/src/runtime/skills/bundled/runtime-bundled-skills-client.ts @@ -94,10 +94,14 @@ export async function executeBundledSkillsOnTarget( ) } -/** Silently updates hash-verified copies of `names`; null when the host predates it, so the caller asks instead. */ +/** + * Silently updates hash-verified copies of `names`; null when the host predates it, so the caller asks instead. + * `onSent` fires once the request leaves for a paired host, so a later lost reply may follow a write. + */ export async function autoUpdateBundledSkillsOnTarget( target: BundledSkillTarget, - names: string[] + names: string[], + options: { onSent?: () => void } = {} ): Promise { if (target.kind === 'ssh') { return null @@ -118,6 +122,9 @@ export async function autoUpdateBundledSkillsOnTarget( { kind: 'environment', environmentId: target.environmentId }, 'skills.autoUpdateBundledOrca', { names }, - { timeoutMs: BUNDLED_SKILL_EXECUTE_TIMEOUT_MS } + { + timeoutMs: BUNDLED_SKILL_EXECUTE_TIMEOUT_MS, + ...(options.onSent ? { beforeSend: options.onSent } : {}) + } ) }