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:
OrcaWin
2026-07-28 00:36:25 -07:00
committed by GitHub
co-authored by OrcaWin
parent df9f55990b
commit 77d4c64f7a
13 changed files with 302 additions and 25 deletions
@@ -49,6 +49,54 @@ describe('orchestration migration behavior', () => {
expect(db.getTask(task.id)?.status).toBe('ready')
})
it('formats legacy terminal inspection as read-only without consuming mail', async () => {
const { db, runtime } = createRuntime()
const message = db.insertMessage({
from: 'term_worker',
to: 'term_coord',
subject: 'still working',
body: 'Tests are running.'
})
const check = ORCHESTRATION_METHODS.find((method) => method.name === 'orchestration.check')!
const inspected = (await check.handler(
check.params!.parse({ terminal: 'term_coord', peek: true, format: true }),
{ runtime }
)) as { count: number; formatted: string }
expect(inspected.count).toBe(1)
expect(inspected.formatted).toContain('[LEGACY READ-ONLY]')
expect(inspected.formatted).toContain('Tests are running.')
expect(inspected.formatted).not.toContain('[Reply:')
expect(db.getMessageById(message.id)?.read).toBe(0)
})
it('rejects replies to legacy mail without marking or inserting rows', async () => {
const { db, runtime } = createRuntime()
const message = db.insertMessage({
from: 'term_worker',
to: 'term_coord',
subject: 'legacy question'
})
const reply = ORCHESTRATION_METHODS.find((method) => method.name === 'orchestration.reply')!
await expect(
reply.handler(
reply.params!.parse({
id: message.id,
body: 'replacement started',
from: 'term_coord'
}),
{ runtime }
)
).rejects.toMatchObject({
code: 'legacy_read_only',
data: { effectsApplied: false }
})
expect(db.getMessageById(message.id)?.read).toBe(0)
expect(db.getInbox(100)).toHaveLength(1)
})
it('rejects a pre-contract worker_done before message or lifecycle mutation', async () => {
const { db, runtime } = createRuntime()
const run = db.createRun({
@@ -1529,17 +1529,25 @@ describe('orchestration RPC methods', () => {
describe('orchestration.reply', () => {
it('replies to a message', async () => {
setup()
const original = db.insertMessage({ from: 'a', to: 'b', subject: 'question' })
const original = db.insertMessage({
from: 'a',
to: 'b',
subject: 'question',
runId: activeRunId
})
const result = (await call('orchestration.reply', {
id: original.id,
body: 'answer',
from: 'b'
})) as { message: { to_handle: string; subject: string; thread_id: string } }
})) as {
message: { to_handle: string; subject: string; thread_id: string; run_id: string }
}
expect(result.message.to_handle).toBe('a')
expect(result.message.subject).toBe('Re: question')
expect(result.message.thread_id).toBe(original.id)
expect(result.message.run_id).toBe(activeRunId)
})
it('throws on nonexistent message', async () => {
+13 -2
View File
@@ -9,7 +9,10 @@ import { formatMessageBanner } from '../../orchestration/formatter'
import { isGroupAddress, resolveGroupAddress } from '../../orchestration/groups'
import { reconcileLifecycleMessage } from '../../orchestration/lifecycle-reconciliation'
import { abbreviateOrchestrationTasks } from '../../../../shared/orchestration-task-summary'
import { orchestrationSkillRecoveryData } from '../../../../shared/orchestration-rpc-contract'
import {
ORCHESTRATION_LEGACY_RUN_ID,
orchestrationSkillRecoveryData
} from '../../../../shared/orchestration-rpc-contract'
import { clampOrchestrationAskTimeoutMs } from '../../../../shared/orchestration-ask-timeout'
import { ORCHESTRATION_GATE_METHODS } from './orchestration-gates'
import { ORCHESTRATION_RUN_METHODS } from './orchestration-runs'
@@ -899,6 +902,13 @@ export const ORCHESTRATION_METHODS: RpcMethod[] = [
if (!original) {
throw new Error(`Message not found: ${params.id}`)
}
if (original.run_id === ORCHESTRATION_LEGACY_RUN_ID) {
throw new OrchestrationError(
'legacy_read_only',
'Legacy orchestration messages are inspect-only; no reply was applied.',
{ effectsApplied: false }
)
}
const question = db.getQuestion(params.id)
if (question) {
@@ -943,7 +953,8 @@ export const ORCHESTRATION_METHODS: RpcMethod[] = [
to: original.from_handle,
subject: `Re: ${original.subject}`,
body: params.body,
threadId: original.thread_id ?? original.id
threadId: original.thread_id ?? original.id,
runId: original.run_id
})
runtime.notifyMessageArrived(original.from_handle, reply.type)