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
@@ -13,20 +13,11 @@ import {
const digest = `sha256:${'a'.repeat(64)}`
const binding: RemoteWorkspaceProjectBinding = {
hostId: 'host-1',
hostRevision: 2,
hostKeyGeneration: 3,
remoteUsername: 'builder',
remoteRootPath: '/srv/project',
workspaceIdentity: 'identity-1',
agentInstallationId: 'installation-1',
agentBinaryDigest: digest,
agentVersion: '0.11.0',
agentArchitecture: 'x64',
agentProtocolMajor: 1
remoteRootPath: '/srv/project'
}
const handle: RemoteWorkspaceHandle = {
workspaceId: 'workspace-1',
workspaceIdentity: binding.workspaceIdentity,
workspaceIdentity: 'identity-1',
canonicalDisplayPath: binding.remoteRootPath,
access: 'read-only',
git: 'available',
@@ -47,25 +38,20 @@ function createLease(
return {
binding: {
hostId: binding.hostId,
hostRevision: binding.hostRevision,
hostKeyGeneration: binding.hostKeyGeneration,
remoteUsername: binding.remoteUsername,
agentInstallationId: binding.agentInstallationId,
agentBinaryDigest: binding.agentBinaryDigest,
agentVersion: binding.agentVersion,
agentArchitecture: binding.agentArchitecture,
agentProtocolMajor: binding.agentProtocolMajor,
hostRevision: 2,
hostKeyGeneration: 3,
remoteUsername: 'builder',
agentInstallationId: 'installation-1',
agentBinaryDigest: digest,
agentVersion: '0.11.0',
agentArchitecture: 'x64',
agentProtocolMajor: 1,
capabilityGeneration: 6
},
validateWorkspace: vi.fn(async () => ({
handle,
validatedAt: '2026-08-21T00:00:00.000Z'
})),
openWorkspace: vi.fn(async () => handle),
resumeWorkspace: vi.fn(async () => ({
resumed: true,
handle
})),
closeWorkspace: vi.fn(async (request) => ({
...request,
closed: true as const
@@ -278,64 +264,59 @@ describe('RemoteWorkspaceAccess', () => {
expect(getGitDiff).not.toHaveBeenCalled()
})
it('resumes a previous handle and opens a replacement when resume fails', async () => {
const lease = createLease({
resumableHandle: handle,
resumeWorkspace: vi.fn(async () => ({
resumed: false,
handle
}))
})
it('validates the configured path instead of resuming persisted state', async () => {
const lease = createLease()
const { access } = createAccess(lease)
await access.getIdentity()
expect(lease.resumeWorkspace).toHaveBeenCalledWith(
expect(lease.validateWorkspace).toHaveBeenCalledWith(
{
workspaceId: 'workspace-1',
generation: 5,
workspaceIdentity: 'identity-1'
remoteRootPath: binding.remoteRootPath,
requestedAccess: 'read-only',
requiredCapabilities: [
'list',
'stat',
'read-text',
'search'
]
},
undefined
)
expect(lease.openWorkspace).toHaveBeenCalledWith(
{
workspaceIdentity: 'identity-1',
requestedAccess: 'read-only'
},
undefined
)
expect(lease.validateWorkspace).not.toHaveBeenCalled()
})
it('rejects immutable transport and workspace binding mismatches', async () => {
for (const changedBinding of [
{ hostKeyGeneration: 99 },
{ agentBinaryDigest: `sha256:${'b'.repeat(64)}` },
{ agentVersion: '0.11.1' },
{ agentArchitecture: 'arm64' as const }
]) {
const release = vi.fn()
const lease = createLease({
binding: {
...createLease().binding,
...changedBinding
},
release
})
const { access } = createAccess(lease)
it('uses live Agent identity but rejects a different Host or path', async () => {
const currentAgent = createLease({
binding: {
...createLease().binding,
hostRevision: 99,
agentBinaryDigest: `sha256:${'b'.repeat(64)}`,
agentVersion: '0.11.1',
agentArchitecture: 'arm64'
}
})
await expect(
createAccess(currentAgent).access.getIdentity()
).resolves.toMatchObject({
kind: 'remote',
canonicalDisplayPath: binding.remoteRootPath
})
await expect(access.getIdentity()).rejects.toThrow(
'绑定已失效'
)
expect(release).toHaveBeenCalledOnce()
}
const otherHost = createLease({
binding: {
...createLease().binding,
hostId: 'host-2'
}
})
await expect(
createAccess(otherHost).access.getIdentity()
).rejects.toThrow('绑定已失效')
const identityMismatch = createLease({
validateWorkspace: vi.fn(async () => ({
handle: {
...handle,
workspaceIdentity: 'identity-2'
canonicalDisplayPath: '/srv/other'
},
validatedAt: '2026-08-21T00:00:00.000Z'
}))
+17 -80
View File
@@ -10,12 +10,8 @@ import {
remoteWorkspaceHandleSchema,
remoteWorkspaceListRequestSchema,
remoteWorkspaceListResultSchema,
remoteWorkspaceOpenRequestSchema,
remoteWorkspaceOpenResultSchema,
remoteWorkspaceReadTextRequestSchema,
remoteWorkspaceReadTextResultSchema,
remoteWorkspaceResumeRequestSchema,
remoteWorkspaceResumeResultSchema,
remoteWorkspaceSearchRequestSchema,
remoteWorkspaceSearchResultSchema,
remoteWorkspaceStatRequestSchema,
@@ -31,12 +27,8 @@ import {
type RemoteWorkspaceHandle,
type RemoteWorkspaceListRequest,
type RemoteWorkspaceListResult,
type RemoteWorkspaceOpenRequest,
type RemoteWorkspaceOpenResult,
type RemoteWorkspaceReadTextRequest,
type RemoteWorkspaceReadTextResult,
type RemoteWorkspaceResumeRequest,
type RemoteWorkspaceResumeResult,
type RemoteWorkspaceSearchRequest,
type RemoteWorkspaceSearchResult,
type RemoteWorkspaceStatRequest,
@@ -67,16 +59,7 @@ const DEFAULT_READ_BYTES = 256 * 1024
const DEFAULT_SEARCH_RESULTS = 100
export type RemoteWorkspaceProjectBinding = {
hostId: string
hostRevision: number
hostKeyGeneration: number
remoteUsername: string
remoteRootPath: string
workspaceIdentity: string
agentInstallationId: string
agentBinaryDigest: string
agentVersion: string
agentArchitecture: 'x64' | 'arm64'
agentProtocolMajor: number
}
export type RemoteWorkspaceTransportBinding = {
@@ -98,19 +81,10 @@ export type RemoteWorkspaceTransportBinding = {
*/
export interface RemoteWorkspaceTransportLease {
readonly binding: RemoteWorkspaceTransportBinding
readonly resumableHandle?: RemoteWorkspaceHandle
validateWorkspace(
request: RemoteWorkspaceValidateRequest,
signal?: AbortSignal
): Promise<RemoteWorkspaceValidateResult>
openWorkspace(
request: RemoteWorkspaceOpenRequest,
signal?: AbortSignal
): Promise<RemoteWorkspaceOpenResult>
resumeWorkspace(
request: RemoteWorkspaceResumeRequest,
signal?: AbortSignal
): Promise<RemoteWorkspaceResumeResult>
closeWorkspace(
request: RemoteWorkspaceCloseRequest
): Promise<RemoteWorkspaceCloseResult>
@@ -182,15 +156,7 @@ function assertTransportBinding(
if (
!Number.isSafeInteger(actual.capabilityGeneration) ||
actual.capabilityGeneration < 1 ||
actual.hostId !== expected.hostId ||
actual.hostRevision !== expected.hostRevision ||
actual.hostKeyGeneration !== expected.hostKeyGeneration ||
actual.remoteUsername !== expected.remoteUsername ||
actual.agentInstallationId !== expected.agentInstallationId ||
actual.agentBinaryDigest !== expected.agentBinaryDigest ||
actual.agentVersion !== expected.agentVersion ||
actual.agentArchitecture !== expected.agentArchitecture ||
actual.agentProtocolMajor !== expected.agentProtocolMajor
actual.hostId !== expected.hostId
) {
throw new Error('远程工作区连接绑定已失效')
}
@@ -202,7 +168,7 @@ function assertHandleBinding(
): RemoteWorkspaceHandle {
const handle = remoteWorkspaceHandleSchema.parse(handleInput)
if (
handle.workspaceIdentity !== expected.workspaceIdentity ||
handle.canonicalDisplayPath !== expected.remoteRootPath ||
handle.access !== 'read-only'
) {
throw new Error('远程工作区身份绑定不匹配')
@@ -328,51 +294,22 @@ export class RemoteWorkspaceAccess implements WorkspaceAccess {
try {
assertTransportBinding(this.binding, lease.binding)
signal?.throwIfAborted()
let handle: RemoteWorkspaceHandle
if (lease.resumableHandle) {
const previous = assertHandleBinding(
this.binding,
lease.resumableHandle
const validation = remoteWorkspaceValidateResultSchema.parse(
await lease.validateWorkspace(
remoteWorkspaceValidateRequestSchema.parse({
remoteRootPath: this.binding.remoteRootPath,
requestedAccess: 'read-only',
requiredCapabilities: [
...REMOTE_WORKSPACE_READ_CAPABILITIES
]
}),
signal
)
const resumed = remoteWorkspaceResumeResultSchema.parse(
await lease.resumeWorkspace(
remoteWorkspaceResumeRequestSchema.parse({
workspaceId: previous.workspaceId,
generation: previous.generation,
workspaceIdentity: this.binding.workspaceIdentity
}),
signal
)
)
handle = resumed.resumed
? assertHandleBinding(this.binding, resumed.handle)
: assertHandleBinding(
this.binding,
remoteWorkspaceOpenResultSchema.parse(
await lease.openWorkspace(
remoteWorkspaceOpenRequestSchema.parse({
workspaceIdentity: this.binding.workspaceIdentity,
requestedAccess: 'read-only'
}),
signal
)
)
)
} else {
const validation = remoteWorkspaceValidateResultSchema.parse(
await lease.validateWorkspace(
remoteWorkspaceValidateRequestSchema.parse({
remoteRootPath: this.binding.remoteRootPath,
requestedAccess: 'read-only',
requiredCapabilities: [
...REMOTE_WORKSPACE_READ_CAPABILITIES
]
}),
signal
)
)
handle = assertHandleBinding(this.binding, validation.handle)
}
)
const handle = assertHandleBinding(
this.binding,
validation.handle
)
assertTransportBinding(this.binding, lease.binding)
retained = true
return {