diff --git a/docs/reference/spec-v01-postgres.md b/docs/reference/spec-v01-postgres.md index e789aae..4acc536 100644 --- a/docs/reference/spec-v01-postgres.md +++ b/docs/reference/spec-v01-postgres.md @@ -83,7 +83,7 @@ Secret 名称和 key 可以在实现时按 Kubernetes 命名限制微调,但 | --- | --- | --- | | Postgres durable store 规格 | 已定义 | 本文为 v0.1 存储权威。 | | StatefulSet/Service/PVC | 已实现/已通过主闭环 | `agentrun-v01-postgres` StatefulSet、Service 和 PVC 已由 GitOps runtime 提供,作为 `agentrun-v01` durable store。 | -| migration ledger | 已实现/已通过主闭环 | `agentrun-mgr` 启动 Postgres adapter 时幂等创建 `agentrun_schema_migrations` 并记录 migration id/checksum;当前最新 migration 为 `004_v01_queue_q1`,用于新增 Q1 Queue task 与 read cursor 持久化;readiness 必须显示 migration ready。 | +| migration ledger | 已实现/已通过主闭环 | `agentrun-mgr` 启动 Postgres adapter 时幂等创建 `agentrun_schema_migrations` 并记录 migration id/checksum;当前最新 migration 为 `005_v01_minimax_m3_backend_profile`,用于在不改写既有 migration checksum 的前提下新增 `minimax-m3` backend profile;readiness 必须显示 migration ready。 | | manager Postgres adapter | 已实现/已通过主闭环 | `agentrun-mgr` 通过 `DATABASE_URL` 启用 Postgres adapter,持久化 runs、commands、events、runners、runner_jobs、sessions、backends、leases、Queue task 和 read cursor;缺少 `DATABASE_URL` 时 live runtime fail fast,memory 只允许显式 self-test/dev。 | | health/readiness store 状态 | 已实现 | health/readiness 返回 adapter、reachable、migrationReady、migrationId、failureKind 和 redacted Secret 状态,不输出 DSN 明文。 | | file/sqlite durable store | 不采用 | 只可用于临时本地测试,不作为 v0.1 runtime truth。 | diff --git a/src/common/backend-profiles.ts b/src/common/backend-profiles.ts index 25b7f46..26e0e0b 100644 --- a/src/common/backend-profiles.ts +++ b/src/common/backend-profiles.ts @@ -102,8 +102,15 @@ export function backendCapabilities(): JsonRecord[] { return backendProfileSpecs.map(backendCapability); } -export function backendCapabilitiesSqlValues(): string { - return backendProfileSpecs.map((spec) => { +export function backendCapabilitiesSqlValues(profiles?: readonly BackendProfile[]): string { + const specs = profiles + ? profiles.map((profile) => { + const spec = backendProfileSpec(profile); + if (!spec) throw new Error(`unknown backend profile for SQL seed: ${profile}`); + return spec; + }) + : backendProfileSpecs; + return specs.map((spec) => { const capabilities = JSON.stringify({ backendKind: spec.backendKind, protocol: spec.protocol, diff --git a/src/mgr/postgres-store.ts b/src/mgr/postgres-store.ts index 057d877..e4ac6b6 100644 --- a/src/mgr/postgres-store.ts +++ b/src/mgr/postgres-store.ts @@ -119,7 +119,17 @@ ON CONFLICT (profile) DO UPDATE SET const backendProfilesMigrationSql = ` INSERT INTO agentrun_backends (profile, capabilities, capacity, health, updated_at) -VALUES ${backendCapabilitiesSqlValues()} +VALUES ${backendCapabilitiesSqlValues(["codex", "deepseek"])} +ON CONFLICT (profile) DO UPDATE SET + capabilities = EXCLUDED.capabilities, + capacity = EXCLUDED.capacity, + health = EXCLUDED.health, + updated_at = EXCLUDED.updated_at; +`; + +const minimaxM3BackendProfileMigrationSql = ` +INSERT INTO agentrun_backends (profile, capabilities, capacity, health, updated_at) +VALUES ${backendCapabilitiesSqlValues(["minimax-m3"])} ON CONFLICT (profile) DO UPDATE SET capabilities = EXCLUDED.capabilities, capacity = EXCLUDED.capacity, @@ -239,6 +249,11 @@ const postgresMigrations: MigrationDefinition[] = [ checksum: checksumSql(queueQ1MigrationSql), sql: queueQ1MigrationSql, }, + { + id: "005_v01_minimax_m3_backend_profile", + checksum: checksumSql(minimaxM3BackendProfileMigrationSql), + sql: minimaxM3BackendProfileMigrationSql, + }, ]; export function postgresMigrationContract(): JsonRecord { diff --git a/src/selftest/cases/00-redaction-postgres.ts b/src/selftest/cases/00-redaction-postgres.ts index 6402fd0..8f2e136 100644 --- a/src/selftest/cases/00-redaction-postgres.ts +++ b/src/selftest/cases/00-redaction-postgres.ts @@ -13,7 +13,8 @@ const selfTest: SelfTestCase = async () => { (error) => error instanceof AgentRunError && error.failureKind === "infra-failed" && error.message.includes("DATABASE_URL is required"), ); const postgresContract = postgresMigrationContract(); - assert.equal(postgresContract.latestMigrationId, "004_v01_queue_q1"); + assert.equal(postgresContract.latestMigrationId, "005_v01_minimax_m3_backend_profile"); + assert.equal((postgresContract.checksums as Record)["002_v01_backend_profiles"], "928b5c490cc4539cb64ecef34784557601b2724fa2870570f16a53576804e49c"); assert.ok(Array.isArray(postgresContract.requiredTables)); assert.ok(postgresContract.requiredTables.includes("agentrun_schema_migrations")); assert.ok(postgresContract.requiredTables.includes("agentrun_runs"));