mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 19:07:41 +00:00
fix(orchestration): name the reused terminal's agent on unbound reuse starts
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
import { FederationAttachStartParams } from '../../../../shared/rpc-contract/orchestration/orchestration-federation-start-params'
|
||||
import { failFederatedAttachmentWithReceipt } from './federation-start-receipt'
|
||||
import { prepareFederationWorkerLaunchOnHost } from '../../rpc/methods/orchestration/worker/start/launch/worker-opencode-model-preflight'
|
||||
import { reusedWorkerLaunchReceipt } from '../../rpc/methods/orchestration/worker/start/launch/worker-launch-preferences'
|
||||
import {
|
||||
isWorkerStartTimeoutWithinTimerLimit,
|
||||
resolveWorkerStartReadinessTimeoutMs
|
||||
@@ -158,6 +159,11 @@ export const ORCHESTRATION_FEDERATION_ATTACH_METHODS = [
|
||||
`Terminal ${terminalHandle} is not running a recognized agent.`
|
||||
)
|
||||
}
|
||||
launch.receipt = reusedWorkerLaunchReceipt(runtime, launch.receipt, {
|
||||
address: terminalHandle,
|
||||
terminalHandle,
|
||||
orcaSessionId: null
|
||||
})
|
||||
effects.push({
|
||||
kind: 'terminal',
|
||||
role: 'agent',
|
||||
|
||||
@@ -252,12 +252,16 @@ function observedTaskName(
|
||||
return task?.display_name || task?.task_title || null
|
||||
}
|
||||
|
||||
export function liveSenderAgent(observation: SenderObservation): AgentType | null {
|
||||
return observation.chat?.agent || observation.terminal?.agent || null
|
||||
}
|
||||
|
||||
/** Current live kind wins; exact durable dispatch knowledge survives loss of live observations. */
|
||||
export function orchestrationSenderAgent(
|
||||
sources: Pick<SenderNamingSources, 'db' | 'dispatchLaunch'>,
|
||||
observation: SenderObservation
|
||||
): AgentType | null {
|
||||
const live = observation.chat?.agent || observation.terminal?.agent
|
||||
const live = liveSenderAgent(observation)
|
||||
if (live) {
|
||||
return live
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import { structuredAgentSessionIdFromTabId } from '../../../../../shared/agent-s
|
||||
import type { TerminalTab } from '../../../../../shared/workspace-layout/terminal-tab-types'
|
||||
import type { OrchestrationDb } from '../../db/orchestration-db'
|
||||
import {
|
||||
liveSenderAgent,
|
||||
observeOrchestrationSender,
|
||||
orchestrationSenderName,
|
||||
structuredChatNaming,
|
||||
captureMirroredTabs,
|
||||
@@ -93,6 +95,11 @@ export class RuntimeOrchestrationSenderNames {
|
||||
)
|
||||
}
|
||||
|
||||
/** The agent a chat or terminal party is running now, as its sender card would show it. */
|
||||
liveAgentOf(party: AgentMessageSender['party']): AgentType | null {
|
||||
return liveSenderAgent(observeOrchestrationSender(party, this.namingSources()))
|
||||
}
|
||||
|
||||
/** Name and agent share one current chat or terminal observation. */
|
||||
snapshotOf(party: AgentMessageSender['party'], reportedDispatchId?: string) {
|
||||
return observeSenderSnapshot(party, this.namingSources(), reportedDispatchId)
|
||||
|
||||
+25
@@ -26,4 +26,29 @@ describe('a worker-start that fails', () => {
|
||||
)
|
||||
expect(mail[0]?.body).not.toContain('still open')
|
||||
})
|
||||
|
||||
it('names the agent already running in a reused terminal when the start never binds', async () => {
|
||||
h.setup()
|
||||
vi.spyOn(h.runtime.orchestrationSenderNames, 'liveAgentOf').mockImplementation((party) =>
|
||||
party.terminalHandle === 'term_reused' ? 'claude' : null
|
||||
)
|
||||
vi.spyOn(h.runtime, 'waitForTerminal').mockResolvedValue({
|
||||
handle: 'term_reused',
|
||||
condition: 'tui-idle',
|
||||
satisfied: false,
|
||||
status: 'running',
|
||||
exitCode: null
|
||||
})
|
||||
const task = h.db.createTask({ spec: 'follow up on the PR', runId: h.activeRunId })
|
||||
const receipt = await h.call('orchestration.workerStart', {
|
||||
task: task.id,
|
||||
from: 'term_coord',
|
||||
terminal: 'term_reused'
|
||||
})
|
||||
expect(receipt).toMatchObject({ state: 'failed', failedStage: 'agent_readiness' })
|
||||
|
||||
const [lost] = h.db.getUnreadRunMailbox(h.activeRunId, 100, ['escalation'])
|
||||
expect(lost?.from_handle).toMatch(/^dispatch:/)
|
||||
expect(h.runtime.orchestrationSenderNames.sender(lost!.from_handle).agent).toBe('claude')
|
||||
})
|
||||
})
|
||||
|
||||
+22
@@ -2,6 +2,9 @@ import type { AgentLaunchPreferences } from '../../../../../../../../shared/agen
|
||||
import { checkAgentLaunchModelPreferences } from '../../../../../../../../shared/agent-launch/choices/agent-launch-model-preferences'
|
||||
import { ORCHESTRATION_WORKER_LAUNCH_PREFERENCES_RUNTIME_CAPABILITY } from '../../../../../../../../shared/orchestration/orchestration-runtime-capabilities'
|
||||
import type { TuiAgent } from '../../../../../../../../shared/agent-launch/catalog/tui-agent'
|
||||
import { isTuiAgent } from '../../../../../../../../shared/agent-launch/catalog/tui-agent-config'
|
||||
import type { OrcaRuntimeService } from '../../../../../../orca-runtime'
|
||||
import type { AgentMessageSender } from '../../../../../../../../shared/agent-session/agent-session-message-source'
|
||||
import { OrchestrationError } from '../../../../../../orchestration/orchestration-error'
|
||||
|
||||
export type OrchestrationWorkerLaunchSelection = {
|
||||
@@ -28,6 +31,25 @@ export function createWorkerLaunchReceipt(args: {
|
||||
return { requested: selection, effective: { ...selection } }
|
||||
}
|
||||
|
||||
/** A reuse start launches nothing; the agent already running there is its effective agent, so
|
||||
* mail from a start that never binds still names it. */
|
||||
export function reusedWorkerLaunchReceipt(
|
||||
runtime: Pick<OrcaRuntimeService, 'orchestrationSenderNames'>,
|
||||
receipt: OrchestrationWorkerLaunchReceipt,
|
||||
party: AgentMessageSender['party']
|
||||
): OrchestrationWorkerLaunchReceipt {
|
||||
if (receipt.effective?.agent) {
|
||||
return receipt
|
||||
}
|
||||
const running = runtime.orchestrationSenderNames.liveAgentOf(party)
|
||||
return isTuiAgent(running)
|
||||
? {
|
||||
...receipt,
|
||||
effective: { ...(receipt.effective ?? receipt.requested), agent: running }
|
||||
}
|
||||
: receipt
|
||||
}
|
||||
|
||||
export function createPendingWorkerLaunchReceipt(args: {
|
||||
agent: TuiAgent | null
|
||||
model?: string
|
||||
|
||||
@@ -34,6 +34,7 @@ import { recordCreatedWorkerTerminalCustody } from './placement/created-worker-t
|
||||
import { releaseRetriedWorkerTerminal } from '../release/retried-worker-terminal-release'
|
||||
import { requireWorkerAuthority, type WorkerEffect } from './placement/worker-placement-topology'
|
||||
import { prepareLocalWorkerStart } from './launch/worker-start-validation'
|
||||
import { reusedWorkerLaunchReceipt } from './launch/worker-launch-preferences'
|
||||
import { deliverAndSettleWorkerStartReadiness } from './readiness/worker-start-readiness-settlement'
|
||||
import type { WorkerStartMutation } from './worker-start-mutation'
|
||||
import { prepareWorkerStartCard } from '../../../../../orchestration/workers/launch/worker-start-card'
|
||||
@@ -135,6 +136,7 @@ export async function startLocalWorker(args: {
|
||||
coordinator,
|
||||
resolvedWorktreeId: resolvedWorktree?.id
|
||||
})
|
||||
launch.receipt = reusedWorkerLaunchReceipt(runtime, launch.receipt, terminal)
|
||||
}
|
||||
const hostMode = resolveWorkerStartModeOnHost(runtime, args.mode, resolvedWorktree?.id, agent)
|
||||
let mode = chatWorkerMode(await hostMode, chat)
|
||||
|
||||
Reference in New Issue
Block a user