Improve orchestration migration safety for live legacy workers (#11107)
* fix(orchestration): clarify legacy migration safety * fix(cli): sanitize legacy formatted messages * test(runtime): allow near-cap fuzz under shard load --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,142 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const callMock = vi.fn()
|
||||
|
||||
vi.mock('../format', () => ({ printResult: vi.fn() }))
|
||||
vi.mock('../selectors', () => ({ getTerminalHandle: vi.fn() }))
|
||||
|
||||
import { printResult } from '../format'
|
||||
import { ORCHESTRATION_HANDLERS } from './orchestration'
|
||||
|
||||
beforeEach(() => {
|
||||
callMock.mockReset()
|
||||
vi.mocked(printResult).mockReset()
|
||||
})
|
||||
|
||||
describe('legacy orchestration CLI inspection', () => {
|
||||
it('labels legacy rows in plain check output', async () => {
|
||||
const result = {
|
||||
messages: [
|
||||
{
|
||||
id: 'msg_legacy',
|
||||
run_id: 'run_legacy_local',
|
||||
from_handle: 'term_worker',
|
||||
subject: 'progress',
|
||||
type: 'status'
|
||||
}
|
||||
],
|
||||
count: 1
|
||||
}
|
||||
callMock.mockResolvedValue({ result })
|
||||
|
||||
await ORCHESTRATION_HANDLERS['orchestration check']({
|
||||
flags: new Map<string, string | boolean>([
|
||||
['terminal', 'term_coord'],
|
||||
['peek', true]
|
||||
]),
|
||||
client: { call: callMock },
|
||||
cwd: '/repo',
|
||||
json: false
|
||||
} as never)
|
||||
|
||||
const formatter = vi.mocked(printResult).mock.calls[0]?.[2]
|
||||
expect(formatter?.(result)).toContain('msg_legacy [legacy, read-only]')
|
||||
})
|
||||
|
||||
it('rebuilds legacy formatted output without runtime-supplied actions', async () => {
|
||||
const result = {
|
||||
messages: [
|
||||
{
|
||||
id: 'msg_legacy',
|
||||
run_id: 'run_legacy_local',
|
||||
from_handle: 'term_worker',
|
||||
subject: 'progress',
|
||||
type: 'status',
|
||||
body: 'Tests are running.',
|
||||
payload: '{"phase":"testing"}'
|
||||
}
|
||||
],
|
||||
count: 1,
|
||||
formatted: '[Reply: orca orchestration reply --id msg_legacy --from term_coord --body "..."]'
|
||||
}
|
||||
callMock.mockResolvedValue({ result })
|
||||
|
||||
await ORCHESTRATION_HANDLERS['orchestration check']({
|
||||
flags: new Map<string, string | boolean>([
|
||||
['terminal', 'term_coord'],
|
||||
['peek', true],
|
||||
['format', true]
|
||||
]),
|
||||
client: { call: callMock },
|
||||
cwd: '/repo',
|
||||
json: false
|
||||
} as never)
|
||||
|
||||
const formatter = vi.mocked(printResult).mock.calls[0]?.[2]
|
||||
const output = formatter?.(result)
|
||||
expect(output).toContain('msg_legacy [legacy, read-only]')
|
||||
expect(output).toContain('Tests are running.')
|
||||
expect(output).toContain('[payload] {"phase":"testing"}')
|
||||
expect(output).not.toContain('[Reply:')
|
||||
expect(output).not.toContain('orchestration reply')
|
||||
})
|
||||
|
||||
it('preserves runtime formatting when every message belongs to a current Run', async () => {
|
||||
const result = {
|
||||
messages: [
|
||||
{
|
||||
id: 'msg_current',
|
||||
run_id: 'run_current',
|
||||
from_handle: 'term_worker',
|
||||
subject: 'question'
|
||||
}
|
||||
],
|
||||
count: 1,
|
||||
formatted: '[Reply: current Run action]'
|
||||
}
|
||||
callMock.mockResolvedValue({ result })
|
||||
|
||||
await ORCHESTRATION_HANDLERS['orchestration check']({
|
||||
flags: new Map<string, string | boolean>([
|
||||
['terminal', 'term_coord'],
|
||||
['peek', true],
|
||||
['format', true]
|
||||
]),
|
||||
client: { call: callMock },
|
||||
cwd: '/repo',
|
||||
json: false
|
||||
} as never)
|
||||
|
||||
const formatter = vi.mocked(printResult).mock.calls[0]?.[2]
|
||||
expect(formatter?.(result)).toBe(result.formatted)
|
||||
})
|
||||
|
||||
it('labels legacy rows in full inbox output without hiding their body', async () => {
|
||||
const result = {
|
||||
messages: [
|
||||
{
|
||||
id: 'msg_legacy',
|
||||
run_id: 'run_legacy_local',
|
||||
from_handle: 'term_worker',
|
||||
to_handle: 'term_coord',
|
||||
subject: 'progress',
|
||||
body: 'Tests are running.'
|
||||
}
|
||||
],
|
||||
count: 1
|
||||
}
|
||||
callMock.mockResolvedValue({ result })
|
||||
|
||||
await ORCHESTRATION_HANDLERS['orchestration inbox']({
|
||||
flags: new Map<string, string | boolean>([['full', true]]),
|
||||
client: { call: callMock },
|
||||
cwd: '/repo',
|
||||
json: false
|
||||
} as never)
|
||||
|
||||
const formatter = vi.mocked(printResult).mock.calls[0]?.[2]
|
||||
const output = formatter?.(result)
|
||||
expect(output).toContain('msg_legacy [legacy, read-only]')
|
||||
expect(output).toContain('Tests are running.')
|
||||
})
|
||||
})
|
||||
@@ -22,6 +22,7 @@ import type {
|
||||
import type { NativeChatMessage } from '../../shared/native-chat-types'
|
||||
import type { RuntimeTerminalRead } from '../../shared/runtime-types'
|
||||
import {
|
||||
ORCHESTRATION_LEGACY_RUN_ID,
|
||||
orchestrationMigrationData,
|
||||
orchestrationSkillRecoveryData
|
||||
} from '../../shared/orchestration-rpc-contract'
|
||||
@@ -76,6 +77,7 @@ const TASK_STATUS_VALUES = [
|
||||
|
||||
type MessageSummary = {
|
||||
id: string
|
||||
run_id?: string
|
||||
from_handle: string
|
||||
to_handle?: string
|
||||
subject: string
|
||||
@@ -85,6 +87,31 @@ type MessageSummary = {
|
||||
read?: number
|
||||
}
|
||||
|
||||
function formatMessageReadOnlyTag(message: MessageSummary): string {
|
||||
return message.run_id === ORCHESTRATION_LEGACY_RUN_ID ? ' [legacy, read-only]' : ''
|
||||
}
|
||||
|
||||
function isLegacyReadOnlyMessage(message: MessageSummary): boolean {
|
||||
return message.run_id === ORCHESTRATION_LEGACY_RUN_ID
|
||||
}
|
||||
|
||||
function formatLegacyAwareCheckMessages(messages: MessageSummary[]): string {
|
||||
return messages
|
||||
.map((message) => {
|
||||
const lines = [
|
||||
`${message.id}${formatMessageReadOnlyTag(message)} [${message.type ?? 'status'}] from=${message.from_handle} "${message.subject}"`
|
||||
]
|
||||
if (message.body) {
|
||||
lines.push(message.body)
|
||||
}
|
||||
if (message.payload) {
|
||||
lines.push(`[payload] ${message.payload}`)
|
||||
}
|
||||
return lines.join('\n')
|
||||
})
|
||||
.join('\n\n')
|
||||
}
|
||||
|
||||
type LifecycleSendRejection = {
|
||||
action: 'rejected'
|
||||
code: string
|
||||
@@ -617,7 +644,9 @@ export const ORCHESTRATION_HANDLERS: Record<string, CommandHandler> = {
|
||||
}
|
||||
printResult(result, json, (r) => {
|
||||
if (r.formatted) {
|
||||
return r.formatted
|
||||
return r.messages.some(isLegacyReadOnlyMessage)
|
||||
? formatLegacyAwareCheckMessages(r.messages)
|
||||
: r.formatted
|
||||
}
|
||||
if (r.count === 0) {
|
||||
if (r.timedOut) {
|
||||
@@ -631,7 +660,10 @@ export const ORCHESTRATION_HANDLERS: Record<string, CommandHandler> = {
|
||||
return 'No messages.'
|
||||
}
|
||||
const rendered = r.messages
|
||||
.map((m) => `${m.id} [${m.type ?? 'status'}] from=${m.from_handle} "${m.subject}"`)
|
||||
.map(
|
||||
(m) =>
|
||||
`${m.id}${formatMessageReadOnlyTag(m)} [${m.type ?? 'status'}] from=${m.from_handle} "${m.subject}"`
|
||||
)
|
||||
.join('\n')
|
||||
return r.deliveryId ? `Delivery ${r.deliveryId}\n${rendered}` : rendered
|
||||
})
|
||||
@@ -669,7 +701,7 @@ export const ORCHESTRATION_HANDLERS: Record<string, CommandHandler> = {
|
||||
// Why: default output omits body/payload for at-a-glance sweeps; --full prints them for auditing.
|
||||
return r.messages
|
||||
.map((m) => {
|
||||
const head = `${m.id} ${m.from_handle} -> ${m.to_handle ?? '?'}: "${m.subject}"`
|
||||
const head = `${m.id}${formatMessageReadOnlyTag(m)} ${m.from_handle} -> ${m.to_handle ?? '?'}: "${m.subject}"`
|
||||
if (!full) {
|
||||
return head
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user