From 0550fc058781366b2f0451e4bddd3950ece4d877 Mon Sep 17 00:00:00 2001 From: hided62 Date: Tue, 4 Aug 2026 15:08:33 +0000 Subject: [PATCH] fix(gateway): migrate fresh profile before reset state read --- .../src/orchestrator/gatewayOrchestrator.ts | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/app/gateway-api/src/orchestrator/gatewayOrchestrator.ts b/app/gateway-api/src/orchestrator/gatewayOrchestrator.ts index fc0d9db..e7ffe19 100644 --- a/app/gateway-api/src/orchestrator/gatewayOrchestrator.ts +++ b/app/gateway-api/src/orchestrator/gatewayOrchestrator.ts @@ -1353,23 +1353,9 @@ export class GatewayOrchestrator implements GatewayOrchestratorHandle { return { status: 'FAILED', detail: 'selected workspace build failed' }; } await this.assertProfileSeedCli(workspace.root); - const seedInfo = await this.resolveResetSeedInfo( - profile, - { - scenarioId, - tickSeconds: tickOverride, - }, - profileDatabaseUrl - ); - const profileMeta = normalizeMeta(profile.meta); - const nextSeasonIdx = readMetaNumber(profileMeta, 'nextSeasonIdx'); - const baseSeason = readMetaNumber(normalizeMeta(seedInfo.meta), 'season'); - const season = nextSeasonIdx ?? baseSeason ?? 1; - await updateClaimedProfile({ status: 'STOPPED' }, () => - this.repository.updateStatus(profile.profileName, 'STOPPED') - ); - await this.stopProfile(profile, assertLease); - await assertLease?.(); + // A newly provisioned profile schema has no world_state row (or table) yet. + // Apply the selected release's migrations before reading optional prior-season + // metadata; existing profiles still expose the same season/tick values afterward. const migrationResult = await this.runProfileMigration(workspace.root, profileDatabaseUrl); await assertLease?.(); if (!migrationResult.ok) { @@ -1388,6 +1374,23 @@ export class GatewayOrchestrator implements GatewayOrchestratorHandle { ); return { status: 'FAILED', detail: 'profile database migration failed' }; } + const seedInfo = await this.resolveResetSeedInfo( + profile, + { + scenarioId, + tickSeconds: tickOverride, + }, + profileDatabaseUrl + ); + const profileMeta = normalizeMeta(profile.meta); + const nextSeasonIdx = readMetaNumber(profileMeta, 'nextSeasonIdx'); + const baseSeason = readMetaNumber(normalizeMeta(seedInfo.meta), 'season'); + const season = nextSeasonIdx ?? baseSeason ?? 1; + await updateClaimedProfile({ status: 'STOPPED' }, () => + this.repository.updateStatus(profile.profileName, 'STOPPED') + ); + await this.stopProfile(profile, assertLease); + await assertLease?.(); const serverId = buildServerId(profile.profileName, seedTime, installOptions?.installOperationId); const seedResult = await this.runSelectedProfileSeed({ workspaceRoot: workspace.root,