fix(orchestration): fence process-bound control messages

This commit is contained in:
Jinwoo-H
2026-08-16 23:29:39 -04:00
parent a4d4c15a0f
commit eae88f921b
2 changed files with 45 additions and 2 deletions
@@ -250,6 +250,45 @@ describe('orchestration RPC methods', () => {
expect(accepted.lifecycle.action).toBe('completed')
})
it.each(['escalation', 'decision_gate'] as const)(
'fences a replacement process from a %s mutation',
async (type) => {
setup()
const task = db.createTask({ spec: `process-bound ${type}` })
const dispatch = db.createDispatchContext(
task.id,
'term_worker',
'tab_worker:leaf_worker',
undefined,
'runtime_test:term_worker:1'
)
vi.mocked(runtime.getTerminalPaneKey).mockImplementation((handle) =>
handle === 'term_worker' ? 'tab_worker:leaf_worker' : coordinatorPaneKey
)
vi.mocked(runtime.getTerminalProcessIncarnation).mockReturnValue(
'runtime_test:term_worker:2'
)
const rejected = (await call('orchestration.send', {
from: 'term_worker',
subject: `${type} after replacement`,
type,
payload: JSON.stringify({
taskId: task.id,
...(type === 'decision_gate' ? { question: 'Proceed?' } : {})
})
})) as { lifecycle: { action: string; code: string } }
expect(rejected.lifecycle).toMatchObject({
action: 'rejected',
code: 'sender_not_assignee'
})
expect(db.getTask(task.id)?.status).toBe('dispatched')
expect(db.getDispatchContextById(dispatch.id)?.status).toBe('dispatched')
expect(db.listGates({ taskId: task.id })).toHaveLength(0)
}
)
it('rejects an identity-less lifecycle send resolved through the coordinator handle', async () => {
setup()
const task = db.createTask({ spec: 'work' })
@@ -639,9 +639,13 @@ export const ORCHESTRATION_METHODS: RpcMethod[] = [
const dispatch = routing.dispatchId
? db.getDispatchContextById(routing.dispatchId)
: undefined
const lifecycleMessage = msg.type === 'worker_done' || msg.type === 'heartbeat'
const dispatchMutationMessage =
msg.type === 'worker_done' ||
msg.type === 'heartbeat' ||
msg.type === 'escalation' ||
msg.type === 'decision_gate'
if (
lifecycleMessage &&
dispatchMutationMessage &&
dispatch &&
(dispatch.capability_hash || dispatch.process_incarnation)
) {