mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
fix(orchestration): a worktree a paired client starts on a remote server is that client's (#38034)
A remote worker-start created its worktree without the caller's identity, so the server stamped itself as the creator and the client that asked hid it under "Hide other-client workspaces". Stamp the authenticated paired device, as worktree.create does.
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
type FederationEffect
|
||||
} from './federation-effects'
|
||||
import type { FederationAttachStartInput } from './federation-start-schema'
|
||||
import type { Worktree } from '../../../../../../shared/worktree/types'
|
||||
|
||||
const TERMINAL_ONLY_MESSAGE = 'A federated worker starts a terminal agent only.'
|
||||
|
||||
@@ -26,6 +27,8 @@ export async function launchFederatedWorkerAgent(args: {
|
||||
launchPreferences: AgentLaunchPreferences | undefined
|
||||
/** The workspace to start in; absent creates the new top-level worktree the params describe. */
|
||||
worktree?: { id: string }
|
||||
/** The paired client that asked, so its own sidebar counts the new worktree as its own. */
|
||||
creatorProvenance?: Worktree['creatorProvenance']
|
||||
setupSource: string
|
||||
effects: FederationEffect[]
|
||||
/** The created worktree's setup receipt, as soon as it exists, so a later failure reports it. */
|
||||
@@ -97,6 +100,7 @@ export async function launchFederatedWorkerAgent(args: {
|
||||
startupSuppressUpdatePrompt: true,
|
||||
...(args.launchPreferences ? { startupLaunchPreferences: args.launchPreferences } : {}),
|
||||
activate: false,
|
||||
...(args.creatorProvenance ? { creatorProvenance: args.creatorProvenance } : {}),
|
||||
lineage: { noParent: true }
|
||||
})
|
||||
created = result.worktree
|
||||
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { OrcaRuntimeService } from '../../../../orca-runtime'
|
||||
import { OrchestrationDb } from '../../../../orchestration/db'
|
||||
import { ORCHESTRATION_METHODS } from '../../orchestration'
|
||||
import { isWorkspaceOwnedBySomeoneElse } from '../../../../../../shared/workspace-creator-visibility'
|
||||
import { configureFederationWorkerRuntime } from './federation-runtime.test-support'
|
||||
|
||||
const HANDLE = 'term_windows_worker'
|
||||
|
||||
// A worktree a paired client starts here through orchestration is that client's, as with worktree.create.
|
||||
describe('federated worker-start creator provenance', () => {
|
||||
const databases: OrchestrationDb[] = []
|
||||
|
||||
afterEach(() => {
|
||||
for (const db of databases.splice(0)) {
|
||||
db.close()
|
||||
}
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
function createWorkerHost(): OrcaRuntimeService {
|
||||
const db = new OrchestrationDb(':memory:')
|
||||
databases.push(db)
|
||||
const runtime = new OrcaRuntimeService()
|
||||
runtime.setOrchestrationDb(db)
|
||||
configureFederationWorkerRuntime(runtime)
|
||||
vi.spyOn(runtime, 'waitForFreshWorkerComposer').mockResolvedValue({
|
||||
handle: HANDLE,
|
||||
condition: 'tui-idle',
|
||||
satisfied: true,
|
||||
status: 'running',
|
||||
exitCode: null
|
||||
})
|
||||
return runtime
|
||||
}
|
||||
|
||||
async function attach(
|
||||
runtime: OrcaRuntimeService,
|
||||
caller: { pairedDeviceId?: string; clientKind?: 'mobile' | 'runtime' }
|
||||
): Promise<unknown> {
|
||||
const method = ORCHESTRATION_METHODS.find(
|
||||
(candidate) => candidate.name === 'orchestration.federationAttachStart'
|
||||
)
|
||||
if (!method) {
|
||||
throw new Error('federationAttachStart method is not registered')
|
||||
}
|
||||
return await method.handler(
|
||||
method.params!.parse({
|
||||
runId: 'run-home',
|
||||
dispatchId: 'ctx_remote',
|
||||
taskId: 'task_remote',
|
||||
taskSpec: 'remote worker',
|
||||
protocolVersion: 3,
|
||||
worktree: 'new-top-level',
|
||||
repo: 'windows-repo',
|
||||
name: 'remote-worker',
|
||||
agent: 'claude'
|
||||
}),
|
||||
{
|
||||
runtime,
|
||||
...caller,
|
||||
orchestrationMutation: {
|
||||
callerFingerprint: 'home_peer',
|
||||
requestId: 'request_remote',
|
||||
method: 'orchestration.federationAttachStart',
|
||||
payloadHash: 'remote_payload'
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
it('stamps the paired client that asked, so its sidebar keeps the worktree as its own', async () => {
|
||||
const runtime = createWorkerHost()
|
||||
|
||||
await expect(
|
||||
attach(runtime, { pairedDeviceId: 'device-home', clientKind: 'runtime' })
|
||||
).resolves.toMatchObject({ state: 'ready' })
|
||||
|
||||
const request = vi.mocked(runtime.createManagedWorktree).mock.calls[0]?.[0]
|
||||
expect(request?.creatorProvenance).toEqual({ kind: 'paired-device', deviceId: 'device-home' })
|
||||
expect(
|
||||
isWorkspaceOwnedBySomeoneElse(
|
||||
{ creatorProvenance: request?.creatorProvenance, runtimeOwnerEnvironmentId: 'env-server' },
|
||||
new Map([['env-server', 'device-home']])
|
||||
)
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('stamps the host when no paired device asked', async () => {
|
||||
const runtime = createWorkerHost()
|
||||
|
||||
await expect(attach(runtime, {})).resolves.toMatchObject({ state: 'ready' })
|
||||
|
||||
expect(vi.mocked(runtime.createManagedWorktree).mock.calls[0]?.[0]?.creatorProvenance).toEqual({
|
||||
kind: 'host'
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
} from '../../../../../../shared/orchestration-timing-budgets'
|
||||
import { assertWorkerStartTaskSpecWithinPromptBudget } from '../worker/worker-start-prompt-budget'
|
||||
import { prepareFederatedAttachmentAuthority } from './federation-attachment-authority'
|
||||
import { resolveRpcWorkspaceCreatorProvenance } from '../../../workspace-creator-context'
|
||||
|
||||
export const ORCHESTRATION_FEDERATION_ATTACH_METHODS = [
|
||||
defineMethod({
|
||||
@@ -32,7 +33,8 @@ export const ORCHESTRATION_FEDERATION_ATTACH_METHODS = [
|
||||
requires: ['accounts'],
|
||||
permission: 'workspace',
|
||||
params: FederationAttachStartParams,
|
||||
handler: async (params, { runtime, orchestrationMutation }) => {
|
||||
handler: async (params, context) => {
|
||||
const { runtime, orchestrationMutation } = context
|
||||
if (!orchestrationMutation) {
|
||||
throw new OrchestrationError(
|
||||
'invalid_argument',
|
||||
@@ -102,7 +104,9 @@ export const ORCHESTRATION_FEDERATION_ATTACH_METHODS = [
|
||||
params,
|
||||
agent,
|
||||
launchPreferences: launch.preferences,
|
||||
...(existing ? { worktree: existing } : {}),
|
||||
...(existing
|
||||
? { worktree: existing }
|
||||
: { creatorProvenance: resolveRpcWorkspaceCreatorProvenance(context) }),
|
||||
setupSource,
|
||||
effects,
|
||||
onSetup: (created) => {
|
||||
|
||||
Reference in New Issue
Block a user