fix: make Host updates simple and fast
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
GoodBuddy Agent Release / Authorize Agent release (push) Canceled after 0s
Cross-platform packages / Validate source (push) Canceled after 0s
GoodBuddy Agent Release / Build Linux arm64 compound package (push) Canceled after 0s
GoodBuddy Agent Release / Build Linux x64 compound package (push) Canceled after 0s
GoodBuddy Agent Release / Sign cumulative Agent catalog (push) Canceled after 0s
GoodBuddy Agent Release / Publish Agent to GitHub and OSS (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

Host repair could fail while adopting the published OpenCode Runtime, then
repeat package and payload verification and carry durable metadata snapshots
for recovery. Host preparation now verifies each acquired compound archive
once, adopts signed Agent and Runtime metadata without rereading payload trees,
and retries failed work by cleaning staging and preparing fresh.

The desktop and Agent versions are advanced to 0.11.9 with the approved
bilingual release notes. Remote Projects remain a disabled-by-default technical
preview, Agent packages remain separate Linux x64/arm64 releases, and this
release has no LoongArch preview.

Release note: 修复 Host 更新采用失败,移除重复远端包体校验,并将中断恢复简化为清理暂存后重新准备。
This commit is contained in:
mesalogo
2026-08-29 22:31:39 +08:00
parent a99b90cc02
commit 85e14ca626
35 changed files with 1062 additions and 1951 deletions
@@ -6,42 +6,18 @@ import {
writeJsonFileAtomically
} from '../settings-file-utils'
const MAXIMUM_RECORD_BYTES = 8 * 1024 * 1024
const MAXIMUM_RECORD_BYTES = 4 * 1024
const OPERATION_ID_PATTERN =
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u
const SHA256_PATTERN = /^[a-f0-9]{64}$/u
type PendingRemoteEnvironmentOperationBase = {
export type PendingRemoteEnvironmentOperation = {
version: 1
hostId: string
targetIdentity: string
operationId: string
size: number
sha256: string
urls: readonly string[]
}
export type PersistedRemoteEnvironmentMetadataSnapshot = {
path:
| '.goodbuddy/agent/release-keys.json'
| '.goodbuddy/agent/registry.json'
| '.goodbuddy/runtimes/release-keys.json'
| '.goodbuddy/runtimes/remote-runtime-lock.json'
| '.goodbuddy/runtimes/registry.json'
contentsBase64?: string
uid: number
}
export type PendingRemoteEnvironmentOperation =
PendingRemoteEnvironmentOperationBase &
(
| { version: 1 }
| {
version: 2
metadataSnapshots:
readonly PersistedRemoteEnvironmentMetadataSnapshot[]
}
)
export class RemoteEnvironmentOperationStore {
readonly #directory: string
@@ -116,27 +92,12 @@ function parsePendingOperation(
throw new Error('远程环境恢复记录无效')
}
const record = value as Record<string, unknown>
const version = record.version
const expectedKeys = version === 2
? [
'hostId',
'metadataSnapshots',
'operationId',
'sha256',
'size',
'targetIdentity',
'urls',
'version'
]
: [
'hostId',
'operationId',
'sha256',
'size',
'targetIdentity',
'urls',
'version'
]
const expectedKeys = [
'hostId',
'operationId',
'targetIdentity',
'version'
]
if (
Object.keys(value).sort().join('\0') !==
expectedKeys.sort().join('\0')
@@ -144,128 +105,19 @@ function parsePendingOperation(
throw new Error('远程环境恢复记录无效')
}
if (
(version !== 1 && version !== 2) ||
record.version !== 1 ||
record.hostId !== expectedHostId ||
typeof record.targetIdentity !== 'string' ||
!SHA256_PATTERN.test(record.targetIdentity) ||
typeof record.operationId !== 'string' ||
!OPERATION_ID_PATTERN.test(record.operationId) ||
!Number.isSafeInteger(record.size) ||
Number(record.size) <= 0 ||
typeof record.sha256 !== 'string' ||
!SHA256_PATTERN.test(record.sha256) ||
!Array.isArray(record.urls) ||
record.urls.length > 4 ||
record.urls.some(
(url) =>
typeof url !== 'string' ||
Buffer.byteLength(url, 'utf8') > 4_096
)
!OPERATION_ID_PATTERN.test(record.operationId)
) {
throw new Error('远程环境恢复记录无效')
}
const base: PendingRemoteEnvironmentOperationBase = {
hostId: expectedHostId,
targetIdentity: record.targetIdentity,
operationId: record.operationId,
size: Number(record.size),
sha256: record.sha256,
urls: [...record.urls] as string[]
}
if (version === 1) {
return { version: 1, ...base }
}
return {
version: 2,
...base,
metadataSnapshots: parseMetadataSnapshots(
record.metadataSnapshots
)
version: 1,
hostId: expectedHostId,
targetIdentity: record.targetIdentity,
operationId: record.operationId
}
}
const metadataPaths =
new Set<PersistedRemoteEnvironmentMetadataSnapshot['path']>([
'.goodbuddy/agent/release-keys.json',
'.goodbuddy/agent/registry.json',
'.goodbuddy/runtimes/release-keys.json',
'.goodbuddy/runtimes/remote-runtime-lock.json',
'.goodbuddy/runtimes/registry.json'
])
function parseMetadataSnapshots(
value: unknown
): readonly PersistedRemoteEnvironmentMetadataSnapshot[] {
if (!Array.isArray(value) || value.length !== metadataPaths.size) {
throw new Error('远程环境恢复记录无效')
}
const paths = new Set<string>()
let totalBytes = 0
const snapshots = value.map((item) => {
if (
typeof item !== 'object' ||
item === null ||
!(
Object.keys(item).sort().join('\0') ===
['path', 'uid'].sort().join('\0') ||
Object.keys(item).sort().join('\0') ===
['contentsBase64', 'path', 'uid'].sort().join('\0')
)
) {
throw new Error('远程环境恢复记录无效')
}
const snapshot = item as Record<string, unknown>
if (
typeof snapshot.path !== 'string' ||
!metadataPaths.has(
snapshot.path as PersistedRemoteEnvironmentMetadataSnapshot['path']
) ||
paths.has(snapshot.path) ||
!Number.isSafeInteger(snapshot.uid) ||
Number(snapshot.uid) < 0
) {
throw new Error('远程环境恢复记录无效')
}
paths.add(snapshot.path)
if (snapshot.contentsBase64 === undefined) {
return {
path:
snapshot.path as PersistedRemoteEnvironmentMetadataSnapshot['path'],
uid: Number(snapshot.uid)
}
}
if (
typeof snapshot.contentsBase64 !== 'string' ||
!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u
.test(snapshot.contentsBase64)
) {
throw new Error('远程环境恢复记录无效')
}
const contents = Buffer.from(
snapshot.contentsBase64,
'base64'
)
if (
contents.toString('base64') !==
snapshot.contentsBase64 ||
contents.byteLength > 1024 * 1024
) {
throw new Error('远程环境恢复记录无效')
}
totalBytes += contents.byteLength
return {
path:
snapshot.path as PersistedRemoteEnvironmentMetadataSnapshot['path'],
contentsBase64: snapshot.contentsBase64,
uid: Number(snapshot.uid)
}
})
if (
paths.size !== metadataPaths.size ||
[...metadataPaths].some((path) => !paths.has(path)) ||
totalBytes > 5 * 1024 * 1024
) {
throw new Error('远程环境恢复记录无效')
}
return snapshots
}