mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
fix(skills): include Codex session's P2 fixes; warn only when a marker call may have written
Includes two P2 review fixes from a Codex session in this worktree: - A newly selected agent links to a recognized other-build shared copy instead of being left as shared-not-current, and execution re-checks that shared copy so the dependent link is skipped if it changed after planning. - Installed-skill views refresh after every silent-update call, since a marking-only call re-plans on the host and can still update a copy. A rejected marking-only call now shows the uncertain-outcome warning only when the request reached a paired host and its reply was lost. A refusal before sending, or the host's own error reply, cannot hide a write: the mark is released for retry without a warning. Calls that started real updates keep warning on any rejection. Restores the docstrings removed in that session.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -120,7 +120,12 @@ async function applyContent(run: SkillRun, op: BundledSkillOp): Promise<string |
|
||||
}
|
||||
switch (op.kind) {
|
||||
case 'keep':
|
||||
return undefined
|
||||
case 'leave':
|
||||
// Agent links may depend on another build's shared copy; skip them if it changed since planning.
|
||||
if (op.reason === 'other-build') {
|
||||
await requireUnchanged(run, op.path, op.observed)
|
||||
}
|
||||
return undefined
|
||||
case 'write':
|
||||
case 'copy':
|
||||
|
||||
@@ -162,11 +162,8 @@ async function planTarget(
|
||||
if (!shared) {
|
||||
return files('write')
|
||||
}
|
||||
if (!shared.current && former.installed) {
|
||||
return files('write')
|
||||
}
|
||||
if (!shared.current) {
|
||||
return leave('shared-not-current', false)
|
||||
if (!shared.current && !(shared.otherBuild && filesystem.supportsLinks)) {
|
||||
return former.installed ? files('write') : leave('shared-not-current', false)
|
||||
}
|
||||
return filesystem.supportsLinks ? linkToShared('link', shared) : files('copy')
|
||||
case 'edited':
|
||||
|
||||
@@ -3,6 +3,11 @@ import type { BundledSkillPlan } from '../../../../../shared/bundled-skill-plan'
|
||||
import type { BundledSkillTarget } from '@/lib/skills/runtime/bundled-skill-target'
|
||||
|
||||
const autoUpdate = vi.hoisted(() => 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<never>, 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)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<BundledSkillInstallResult | null> {
|
||||
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 } : {})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user