fix: make managed SSH sessions fast and resilient
GoodBuddy Agents / Validate Agent source (push) Canceled after 0s
GoodBuddy Agents / Build Linux arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build Linux x64 Agent (push) Canceled after 0s
Cross-platform packages / Validate source (push) Canceled after 0s
Cross-platform packages / Authorize desktop packaging (push) Canceled after 0s
Cross-platform packages / linux arm64 (push) Canceled after 0s
Cross-platform packages / macos arm64 (push) Canceled after 0s
Cross-platform packages / windows arm64 (push) Canceled after 0s
Cross-platform packages / linux x64 (push) Canceled after 0s
Cross-platform packages / macos x64 (push) Canceled after 0s
Cross-platform packages / windows x64 (push) Canceled after 0s
Cross-platform packages / Publish GitHub and OSS release (push) Canceled after 0s

Managed SSH project selection repeatedly activated the remote Host and could
leave idle ACP bindings rejected as stale-controller after a controller
generation change. Host environment updates also coupled project state to
component installation evidence and presented a crowded control surface.

Project selection is now local-only, one Host connection serves compatible
project and conversation callers, idle bindings are safely replaced only
after proven controller takeover, and active prompts keep exact resume/replay.
Remote environment setup now uses explicit signed compound package
preparation with bounded transfer, rollback, recovery, and clearer settings.

Managed Hosts must be updated to separately distributed Agent 0.11.6 before
the daemon-side controller recovery fix takes effect. Desktop packages do not
embed the Agent or remote Runtime, and existing project data is preserved.

Release note: 托管 SSH 项目切换不再重复连接,同一 Host 可顺畅承载多个项目和对话;同时修复重连后的 stale-controller,并优化远程环境安装、更新与状态布局。
This commit is contained in:
mesalogo
2026-08-29 10:58:19 +08:00
parent eb947213c8
commit 459cc21e3d
117 changed files with 19876 additions and 9664 deletions
@@ -5,11 +5,6 @@ import {
} from '../../shared/agent-protocol'
import type { RemoteWorkspaceHandle } from '../../shared/remote-agent-contracts'
import type { RemoteWorkspaceProjectBinding } from '../workspace/remote-workspace-access'
import { verifyAgentInstallationId } from '../ssh/ssh-agent-command'
import type {
AgentInstallationIdentity,
AgentInstallationManager
} from './agent-installation-manager'
import type { AgentProtocolClient } from './agent-protocol-client'
import {
ManagedRemoteWorkspaceAccessFactory,
@@ -19,35 +14,26 @@ import type {
RemoteAgentConnection,
RemoteAgentConnectionManager
} from './remote-agent-connection-manager'
import type { AgentInstallationIdentity } from './agent-installation-manager'
import { verifyAgentInstallationId } from '../ssh/ssh-agent-command'
const digest = `sha256:${'a'.repeat(64)}`
const binding: RemoteWorkspaceProjectBinding = {
hostId: '00000000-0000-4000-8000-000000000201',
hostRevision: 2,
hostKeyGeneration: 3,
remoteUsername: 'builder',
remoteRootPath: '/srv/project',
workspaceIdentity: 'workspace-identity',
agentInstallationId: 'installation-test',
agentBinaryDigest: digest,
agentVersion: '0.11.0',
agentArchitecture: 'x64',
agentProtocolMajor: AGENT_PROTOCOL_VERSION.major
remoteRootPath: '/srv/project'
}
const installation: AgentInstallationIdentity = {
installationId: verifyAgentInstallationId(
binding.agentInstallationId
),
binaryDigest: binding.agentBinaryDigest,
agentVersion: binding.agentVersion,
protocol: { ...AGENT_PROTOCOL_VERSION },
installationId: verifyAgentInstallationId('installation-test'),
binaryDigest: digest,
agentVersion: '0.11.0',
protocol: AGENT_PROTOCOL_VERSION,
platform: 'linux',
architecture: binding.agentArchitecture,
architecture: 'x64',
supervisor: 'detached-on-demand'
}
const handle: RemoteWorkspaceHandle = {
workspaceId: 'workspace-1',
workspaceIdentity: binding.workspaceIdentity,
workspaceIdentity: 'workspace-identity',
canonicalDisplayPath: binding.remoteRootPath,
access: 'read-only',
git: 'available',
@@ -63,21 +49,38 @@ const handle: RemoteWorkspaceHandle = {
}
describe('ManagedRemoteWorkspaceAccessFactory', () => {
it('verifies installation before network work and owns the connection lease', async () => {
it('opens with the Host current Agent and owns the connection lease', async () => {
const test = createHarness()
const access = test.factory.create(binding)
await expect(access.getIdentity()).resolves.toEqual({
kind: 'remote',
id: `${binding.hostId}:${binding.workspaceIdentity}`,
id: `${binding.hostId}:${handle.workspaceIdentity}`,
canonicalDisplayPath: binding.remoteRootPath,
access: 'read-only'
})
expect(test.events.slice(0, 2)).toEqual([
'agent:ensure',
'installation:activate',
'connection:acquire'
])
expect(test.activateInstalled).toHaveBeenCalledWith(
binding.hostId,
{}
)
expect(test.acquire).toHaveBeenCalledWith(
binding.hostId,
expect.objectContaining({
installationId: installation.installationId,
binaryDigest: installation.binaryDigest,
agentVersion: installation.agentVersion,
architecture: installation.architecture,
protocol: expect.objectContaining({
major: installation.protocol.major
})
}),
undefined
)
expect(test.protocolMethods).toContain('workspace/validate')
expect(test.protocolMethods).not.toContain('workspace/open')
expect(test.protocolMethods).not.toContain('workspace/resume')
@@ -92,49 +95,6 @@ describe('ManagedRemoteWorkspaceAccessFactory', () => {
).toHaveLength(1)
})
it.each([
[
'installation id',
{
...installation,
installationId:
verifyAgentInstallationId('installation-other')
}
],
[
'binary digest',
{
...installation,
binaryDigest: `sha256:${'b'.repeat(64)}`
}
],
['version', { ...installation, agentVersion: '0.11.1' }],
['architecture', { ...installation, architecture: 'arm64' as const }],
[
'protocol major',
{
...installation,
protocol: {
...installation.protocol,
major: installation.protocol.major + 1
}
}
]
])(
'rejects an installed Agent with a different persisted %s',
async (_field, changedInstallation) => {
const test = createHarness({
ensureInstalled: async () => changedInstallation
})
const access = test.factory.create(binding)
await expect(access.getIdentity()).rejects.toThrow(
'does not match the persisted project binding'
)
expect(test.acquire).not.toHaveBeenCalled()
}
)
it('propagates connection acquisition failures', async () => {
const test = createHarness({
acquireError: new Error('network unavailable')
@@ -150,25 +110,18 @@ describe('ManagedRemoteWorkspaceAccessFactory', () => {
type HarnessOptions = {
acquireError?: Error
ensureInstalled?: () => Promise<AgentInstallationIdentity>
}
function createHarness(options: HarnessOptions = {}): {
factory: ManagedRemoteWorkspaceAccessFactory
events: string[]
protocolMethods: string[]
ensureInstalled: ReturnType<typeof vi.fn>
acquire: ReturnType<typeof vi.fn>
activateInstalled: ReturnType<typeof vi.fn>
connectionRelease: ReturnType<typeof vi.fn>
} {
const events: string[] = []
const protocolMethods: string[] = []
const ensureInstalled = vi.fn(async () => {
events.push('agent:ensure')
return options.ensureInstalled
? await options.ensureInstalled()
: installation
})
const client = {
request: vi.fn(async (method: string) => {
protocolMethods.push(method)
@@ -198,23 +151,23 @@ function createHarness(options: HarnessOptions = {}): {
identity: {
cacheKey: 'connection-cache',
hostId: binding.hostId,
hostRevision: binding.hostRevision,
hostKeyGeneration: binding.hostKeyGeneration,
remoteUsername: binding.remoteUsername,
installationId: binding.agentInstallationId,
binaryDigest: binding.agentBinaryDigest,
protocolMajor: binding.agentProtocolMajor,
protocolMinor: installation.protocol.minor
hostRevision: 2,
hostKeyGeneration: 3,
remoteUsername: 'builder',
installationId: installation.installationId,
binaryDigest: installation.binaryDigest,
protocolMajor: installation.protocol.major,
protocolMinor: AGENT_PROTOCOL_VERSION.minor
},
status: {
state: 'ready',
installationId: binding.agentInstallationId,
binaryDigest: binding.agentBinaryDigest,
installationId: installation.installationId,
binaryDigest: installation.binaryDigest,
daemonBootId: 'boot-1',
agentVersion: binding.agentVersion,
protocol: { ...installation.protocol },
agentVersion: installation.agentVersion,
protocol: { ...AGENT_PROTOCOL_VERSION },
platform: 'linux',
architecture: binding.agentArchitecture,
architecture: installation.architecture,
supervisor: 'detached-on-demand',
remoteUserIdentity: 'uid:1000',
draining: false
@@ -235,20 +188,24 @@ function createHarness(options: HarnessOptions = {}): {
}
return connection
})
const activateInstalled = vi.fn(async () => {
events.push('installation:activate')
return installation
})
const factoryOptions = {
installationManager: {
ensureInstalled
} as unknown as Pick<AgentInstallationManager, 'ensureInstalled'>,
connectionManager: {
acquire
} as unknown as Pick<RemoteAgentConnectionManager, 'acquire'>
} as unknown as Pick<RemoteAgentConnectionManager, 'acquire'>,
installationManager: {
activateInstalled
}
} satisfies ManagedRemoteWorkspaceAccessFactoryOptions
return {
factory: new ManagedRemoteWorkspaceAccessFactory(factoryOptions),
events,
protocolMethods,
ensureInstalled,
acquire,
activateInstalled,
connectionRelease
}
}