Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Fix Proxmox backup posture identity
rcourtman20f9da541a6c
diff --git a/docs/release-control/v6/internal/status.json b/docs/release-control/v6/internal/status.jsonindex 9825fb3317..b6fb7b97b8 100644--- a/docs/release-control/v6/internal/status.json+++ b/docs/release-control/v6/internal/status.json@@ -9176,21 +9176,7 @@]}],- "work_claims": [- {- "id": "codex-release-gate-stable-patch-unattended-release-path",- "agent_id": "codex",- "summary": "Publish v6.1.1 emergency stable patch after backend release-gate repair",- "target_id": "v6-product-lane-expansion",- "claimed_at": "2026-07-23T13:06:46Z",- "heartbeat_at": "2026-07-23T13:06:46Z",- "expires_at": "2026-07-23T17:06:46Z",- "work_item": {- "kind": "release-gate",- "id": "stable-patch-unattended-release-path"- }- }- ],+ "work_claims": [],"open_decisions": [],"source_of_truth_file": "docs/release-control/v6/internal/SOURCE_OF_TRUTH.md","resolved_decisions": [diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 19372fca17..99c6d475d5 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -1358,6 +1358,11 @@ name, and type context from canonical `ReadState` instead of fromsnapshot-owned VM/container arrays, so storage backup polling, guest snapshotpolling, timeout sizing, PBS recovery candidate assembly, and Proxmox recoveryingest all follow unified runtime truth when a live resource registry exists.+That recovery identity adapter must carry the canonical unified-resource+`ResourceID` separately from the provider-native Proxmox `SourceID`. Recovery+mappers consume the canonical ID directly for subject linkage and retain the+source ID only for provider correlation and fallback derivation; a canonical+workload ID must never be passed through source-specific ID generation again.That same monitoring-owned workload boundary now includes canonical appworkloads projected through unified resources, not only VM/LXC-style guests.Consumers that need runtime workload truth must treat `ReadState.Workloads()`diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 71e1300836..d0c322cba2 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -2343,6 +2343,10 @@ backfill, purge, and retention, and re-evaluates requested resource batches atread time so freshness cannot age into a reassuring stale snapshot. Legacyrecovery rows receive additive provider scope and typed evidence duringmigration. Provider observations and recovery points share bounded retention.+When an upserted recovery point changes subject identity, posture refresh must+include both the previously persisted subject key and the new subject key so+obsolete materialized posture rows are removed rather than surviving an+identity correction.`GET /api/recovery/postures` is the bounded read boundary for one resource,resource-table batches, state-filtered attention lists, policy, evaluation@@ -2961,6 +2965,12 @@ like `lxc-*` or raw source IDs while newer points carry hashed canonicalresource IDs, and proxmox guest external keys must ignore display-name churn sorenaming a backup comment does not fork the protected inventory from recentevent history. That same store-owned continuity contract also applies when+Proxmox recovery mappers receive unified-resource workload identity: canonical+`ResourceID` is the stored `subject_resource_id`, while provider-native+`SourceID` remains external correlation metadata or a fallback input when no+canonical ID exists. Mappers must not hash an already canonical resource ID as+if it were a provider-native source ID. That same store-owned continuity+contract also applies whenProxmox PBS guest points temporarily lose unified-resource linkage or driftbetween historical PBS namespaces: if recovery history already proves onecanonical linked guest identity for the same friendly label, guest type, anddiff --git a/internal/monitoring/monitor_backups_readstate_test.go b/internal/monitoring/monitor_backups_readstate_test.goindex b56ad57c50..76eff56964 100644--- a/internal/monitoring/monitor_backups_readstate_test.go+++ b/internal/monitoring/monitor_backups_readstate_test.go@@ -855,6 +855,7 @@ func TestBuildPBSGuestCandidates_UsesCanonicalReadState(t *testing.T) {Instance: "pve1",NodeName: "nodeA",VMID: 100,+ SourceID: "pve1:nodeA:100",},},{@@ -866,6 +867,7 @@ func TestBuildPBSGuestCandidates_UsesCanonicalReadState(t *testing.T) {Instance: "pve1",NodeName: "nodeB",VMID: 200,+ SourceID: "pve1:nodeB:200",},},})@@ -879,7 +881,8 @@ func TestBuildPBSGuestCandidates_UsesCanonicalReadState(t *testing.T) {t.Fatalf("expected one candidate for %s, got %+v", key, entries)}if entries[0] != (proxmoxmapper.GuestCandidate{- SourceID: fmt.Sprintf("%s-store-%d", map[unifiedresources.ResourceType]string{unifiedresources.ResourceTypeVM: "vm", unifiedresources.ResourceTypeSystemContainer: "ct"}[resourceType], vmid),+ ResourceID: fmt.Sprintf("%s-store-%d", map[unifiedresources.ResourceType]string{unifiedresources.ResourceTypeVM: "vm", unifiedresources.ResourceTypeSystemContainer: "ct"}[resourceType], vmid),+ SourceID: fmt.Sprintf("pve1:%s:%d", node, vmid),ResourceType: resourceType,DisplayName: fmt.Sprintf("%s%d", map[unifiedresources.ResourceType]string{unifiedresources.ResourceTypeVM: "vm", unifiedresources.ResourceTypeSystemContainer: "ct"}[resourceType], vmid),InstanceName: "pve1",@@ -905,6 +908,7 @@ func TestBuildProxmoxGuestInfoIndex_UsesCanonicalReadState(t *testing.T) {Instance: "pve1",NodeName: "nodeA",VMID: 100,+ SourceID: "pve1:nodeA:100",},},{@@ -916,13 +920,14 @@ func TestBuildProxmoxGuestInfoIndex_UsesCanonicalReadState(t *testing.T) {Instance: "pve1",NodeName: "nodeB",VMID: 200,+ SourceID: "pve1:nodeB:200",},},})index := buildProxmoxGuestInfoIndex(readState)- assertInfo := func(key string, resourceType unifiedresources.ResourceType, name string) {+ assertInfo := func(key, resourceID, sourceID string, resourceType unifiedresources.ResourceType, name string) {t.Helper()info, ok := index[key]if !ok {@@ -931,11 +936,17 @@ func TestBuildProxmoxGuestInfoIndex_UsesCanonicalReadState(t *testing.T) {if info.ResourceType != resourceType {t.Errorf("expected type %v, got %v", resourceType, info.ResourceType)}+ if info.ResourceID != resourceID {+ t.Errorf("expected resource ID %q, got %q", resourceID, info.ResourceID)+ }+ if info.SourceID != sourceID {+ t.Errorf("expected source ID %q, got %q", sourceID, info.SourceID)+ }if info.Name != name {t.Errorf("expected name %q, got %q", name, info.Name)}}- assertInfo("pve1|nodeA|100", unifiedresources.ResourceTypeVM, "vm100")- assertInfo("pve1|nodeB|200", unifiedresources.ResourceTypeSystemContainer, "ct200")+ assertInfo("pve1|nodeA|100", "vm-store-100", "pve1:nodeA:100", unifiedresources.ResourceTypeVM, "vm100")+ assertInfo("pve1|nodeB|200", "ct-store-200", "pve1:nodeB:200", unifiedresources.ResourceTypeSystemContainer, "ct200")}diff --git a/internal/monitoring/recovery_ingest.go b/internal/monitoring/recovery_ingest.goindex 3a3cb06652..505a53cbde 100644--- a/internal/monitoring/recovery_ingest.go+++ b/internal/monitoring/recovery_ingest.go@@ -224,11 +224,13 @@ func buildProxmoxGuestInfoIndex(readState unifiedresources.ReadState) map[stringcontinue}key := proxmoxmapperKey(vm.Instance(), vm.Node(), vm.VMID())- sourceID := strings.TrimSpace(vm.ID())+ resourceID := strings.TrimSpace(vm.ID())+ sourceID := strings.TrimSpace(vm.SourceID())if sourceID == "" {sourceID = makeGuestID(vm.Instance(), vm.Node(), vm.VMID())}out[key] = proxmoxmapper.GuestInfo{+ ResourceID: resourceID,SourceID: sourceID,ResourceType: unifiedresources.ResourceTypeVM,Name: strings.TrimSpace(vm.Name()),@@ -240,11 +242,13 @@ func buildProxmoxGuestInfoIndex(readState unifiedresources.ReadState) map[stringcontinue}key := proxmoxmapperKey(ct.Instance(), ct.Node(), ct.VMID())- sourceID := strings.TrimSpace(ct.ID())+ resourceID := strings.TrimSpace(ct.ID())+ sourceID := strings.TrimSpace(ct.SourceID())if sourceID == "" {sourceID = makeGuestID(ct.Instance(), ct.Node(), ct.VMID())}out[key] = proxmoxmapper.GuestInfo{+ ResourceID: resourceID,SourceID: sourceID,ResourceType: unifiedresources.ResourceTypeSystemContainer,Name: strings.TrimSpace(ct.Name()),@@ -267,11 +271,13 @@ func buildPBSGuestCandidates(readState unifiedresources.ReadState) map[string][]continue}key := "vm:" + fmt.Sprintf("%d", vm.VMID())- sourceID := strings.TrimSpace(vm.ID())+ resourceID := strings.TrimSpace(vm.ID())+ sourceID := strings.TrimSpace(vm.SourceID())if sourceID == "" {sourceID = makeGuestID(vm.Instance(), vm.Node(), vm.VMID())}out[key] = append(out[key], proxmoxmapper.GuestCandidate{+ ResourceID: resourceID,SourceID: sourceID,ResourceType: unifiedresources.ResourceTypeVM,DisplayName: strings.TrimSpace(vm.Name()),@@ -286,11 +292,13 @@ func buildPBSGuestCandidates(readState unifiedresources.ReadState) map[string][]continue}key := "ct:" + fmt.Sprintf("%d", ct.VMID())- sourceID := strings.TrimSpace(ct.ID())+ resourceID := strings.TrimSpace(ct.ID())+ sourceID := strings.TrimSpace(ct.SourceID())if sourceID == "" {sourceID = makeGuestID(ct.Instance(), ct.Node(), ct.VMID())}out[key] = append(out[key], proxmoxmapper.GuestCandidate{+ ResourceID: resourceID,SourceID: sourceID,ResourceType: unifiedresources.ResourceTypeSystemContainer,DisplayName: strings.TrimSpace(ct.Name()),diff --git a/internal/recovery/mapper/proxmox/mapper.go b/internal/recovery/mapper/proxmox/mapper.goindex 26f67aa0e1..725888b0d0 100644--- a/internal/recovery/mapper/proxmox/mapper.go+++ b/internal/recovery/mapper/proxmox/mapper.go@@ -11,15 +11,17 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources")-// GuestInfo is best-effort metadata used to attach display identity and unified resource IDs.-// Keyed by guest source ID (see guestSourceID()).+// GuestInfo is best-effort metadata used to attach display, canonical, and provider identity.+// Callers key it by guestLookupKey().type GuestInfo struct {+ ResourceID stringSourceID stringResourceType unifiedresources.ResourceTypeName string}type GuestCandidate struct {+ ResourceID stringSourceID stringResourceType unifiedresources.ResourceTypeDisplayName string@@ -37,6 +39,16 @@ func guestLookupKey(instanceName, nodeName string, vmid int) string {return fmt.Sprintf("%s|%s|%d", strings.TrimSpace(instanceName), strings.TrimSpace(nodeName), vmid)}+func subjectResourceID(resourceType unifiedresources.ResourceType, resourceID, sourceID string) string {+ if resourceID = strings.TrimSpace(resourceID); resourceID != "" {+ return resourceID+ }+ if sourceID = strings.TrimSpace(sourceID); sourceID != "" {+ return unifiedresources.SourceSpecificID(resourceType, unifiedresources.SourceProxmox, sourceID)+ }+ return ""+}+func preferredPBSBackupSubjectName(comment, vmid string) string {return proxmoxidentity.PreferredPBSBackupSubjectName(comment, vmid)}@@ -166,7 +178,7 @@ func FromPVEGuestSnapshots(snapshots []models.GuestSnapshot, guestInfoByKey map[resourceType = resourceTypeFromGuestType(snap.Type)}if resourceType != "" {- subjectRID = unifiedresources.SourceSpecificID(resourceType, unifiedresources.SourceProxmox, sourceID)+ subjectRID = subjectResourceID(resourceType, info.ResourceID, sourceID)subjectRef = proxmoxSubjectRef(resourceType, info, instanceName, nodeName, vmid, sourceID)}}@@ -200,7 +212,7 @@ func FromPVEGuestSnapshots(snapshots []models.GuestSnapshot, guestInfoByKey map[return out}-func FromPVEStorageBackups(backups []models.StorageBackup, guestInfoBySourceID map[string]GuestInfo) []recovery.RecoveryPoint {+func FromPVEStorageBackups(backups []models.StorageBackup, guestInfoByKey map[string]GuestInfo) []recovery.RecoveryPoint {if len(backups) == 0 {return nil}@@ -220,7 +232,7 @@ func FromPVEStorageBackups(backups []models.StorageBackup, guestInfoBySourceID mif vmid > 0 && instanceName != "" && nodeName != "" {key := guestLookupKey(instanceName, nodeName, vmid)- info := guestInfoBySourceID[key]+ info := guestInfoByKey[key]sourceID := strings.TrimSpace(info.SourceID)if sourceID == "" {sourceID = guestSourceID(instanceName, nodeName, vmid)@@ -230,7 +242,7 @@ func FromPVEStorageBackups(backups []models.StorageBackup, guestInfoBySourceID mresourceType = resourceTypeFromGuestType(b.Type)}if resourceType != "" {- subjectRID = unifiedresources.SourceSpecificID(resourceType, unifiedresources.SourceProxmox, sourceID)+ subjectRID = subjectResourceID(resourceType, info.ResourceID, sourceID)subjectRef = proxmoxSubjectRef(resourceType, info, instanceName, nodeName, vmid, sourceID)}}@@ -287,7 +299,7 @@ func FromPVEStorageBackups(backups []models.StorageBackup, guestInfoBySourceID mreturn out}-func FromPVEBackupTasks(tasks []models.BackupTask, guestInfoBySourceID map[string]GuestInfo) []recovery.RecoveryPoint {+func FromPVEBackupTasks(tasks []models.BackupTask, guestInfoByKey map[string]GuestInfo) []recovery.RecoveryPoint {if len(tasks) == 0 {return nil}@@ -307,13 +319,13 @@ func FromPVEBackupTasks(tasks []models.BackupTask, guestInfoBySourceID map[strinif vmid > 0 && instanceName != "" && nodeName != "" {key := guestLookupKey(instanceName, nodeName, vmid)- info, ok := guestInfoBySourceID[key]+ info, ok := guestInfoByKey[key]sourceID := strings.TrimSpace(info.SourceID)if sourceID == "" {sourceID = guestSourceID(instanceName, nodeName, vmid)}if ok && info.ResourceType != "" {- subjectRID = unifiedresources.SourceSpecificID(info.ResourceType, unifiedresources.SourceProxmox, sourceID)+ subjectRID = subjectResourceID(info.ResourceType, info.ResourceID, sourceID)subjectRef = proxmoxSubjectRef(info.ResourceType, info, instanceName, nodeName, vmid, sourceID)} else {// At least show something in UIs even when type is unknown.@@ -384,7 +396,7 @@ func FromPBSBackups(backups []models.PBSBackup, candidatesByKey map[string][]Gue// Link to a unified resource when the candidate set is already singular or can be// disambiguated by PBS namespace / guest label without guessing across guest collisions.if c, ok := selectPBSGuestCandidate(b, candidates); ok {- subjectRID = unifiedresources.SourceSpecificID(c.ResourceType, unifiedresources.SourceProxmox, c.SourceID)+ subjectRID = subjectResourceID(c.ResourceType, c.ResourceID, c.SourceID)subjectRef = proxmoxSubjectRef(c.ResourceType, GuestInfo{Name: c.DisplayName, ResourceType: c.ResourceType, SourceID: c.SourceID}, c.InstanceName, c.NodeName, c.VMID, c.SourceID)} else {guestType := strings.ToLower(strings.TrimSpace(b.BackupType))diff --git a/internal/recovery/mapper/proxmox/mapper_test.go b/internal/recovery/mapper/proxmox/mapper_test.goindex 523a24ee54..28221700b1 100644--- a/internal/recovery/mapper/proxmox/mapper_test.go+++ b/internal/recovery/mapper/proxmox/mapper_test.go@@ -9,6 +9,49 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources")+func TestSubjectResourceIDPrefersCanonicalIdentityAndFallsBackToSourceIdentity(t *testing.T) {+ t.Parallel()++ resourceType := unifiedresources.ResourceTypeVM+ sourceID := "pve-main:pve-a:100"+ fallback := unifiedresources.SourceSpecificID(+ resourceType,+ unifiedresources.SourceProxmox,+ sourceID,+ )++ tests := []struct {+ name string+ resourceID string+ sourceID string+ want string+ }{+ {+ name: "canonical resource identity",+ resourceID: " vm-canonical ",+ sourceID: sourceID,+ want: "vm-canonical",+ },+ {+ name: "provider source fallback",+ sourceID: " " + sourceID + " ",+ want: fallback,+ },+ {+ name: "missing identity",+ want: "",+ },+ }++ for _, test := range tests {+ t.Run(test.name, func(t *testing.T) {+ if got := subjectResourceID(resourceType, test.resourceID, test.sourceID); got != test.want {+ t.Fatalf("subjectResourceID() = %q, want %q", got, test.want)+ }+ })+ }+}+func TestFromPVEGuestSnapshots_Empty(t *testing.T) {result := FromPVEGuestSnapshots(nil, nil)if result != nil {@@ -74,7 +117,8 @@ func TestFromPVEGuestSnapshots_WithGuestInfo(t *testing.T) {guestInfoByKey := map[string]GuestInfo{"pve-cluster|pve1|100": {- SourceID: "unified-resource-1",+ ResourceID: "vm-unified-resource-1",+ SourceID: "pve-cluster:pve1:100",ResourceType: unifiedresources.ResourceTypeVM,Name: "web-server",},@@ -87,8 +131,11 @@ func TestFromPVEGuestSnapshots_WithGuestInfo(t *testing.T) {}p := result[0]- if p.SubjectResourceID == "" {- t.Error("expected SubjectResourceID to be set when GuestInfo is provided")+ if got, want := p.SubjectResourceID, "vm-unified-resource-1"; got != want {+ t.Fatalf("SubjectResourceID = %q, want canonical resource ID %q", got, want)+ }+ if p.SubjectRef == nil || p.SubjectRef.ID != "pve-cluster:pve1:100" {+ t.Fatalf("SubjectRef = %#v, want provider-native source ID", p.SubjectRef)}}@@ -325,7 +372,8 @@ func TestFromPBSBackups_WithCandidates(t *testing.T) {candidatesByKey := map[string][]GuestCandidate{"vm:100": {{- SourceID: "unified-resource-1",+ ResourceID: "vm-unified-resource-1",+ SourceID: "pve-cluster:pve1:100",ResourceType: unifiedresources.ResourceTypeVM,DisplayName: "web-server",InstanceName: "pbs1",@@ -343,8 +391,8 @@ func TestFromPBSBackups_WithCandidates(t *testing.T) {}p := result[0]- if p.SubjectResourceID == "" {- t.Error("expected SubjectResourceID to be set when candidate matches")+ if got, want := p.SubjectResourceID, "vm-unified-resource-1"; got != want {+ t.Fatalf("SubjectResourceID = %q, want canonical resource ID %q", got, want)}}@@ -365,7 +413,8 @@ func TestFromPBSBackups_DisambiguatesCandidatesByNamespace(t *testing.T) {candidatesByKey := map[string][]GuestCandidate{"ct:112": {{- SourceID: "system-container-fb42a70d89bd20a6",+ ResourceID: "system-container-fb42a70d89bd20a6",+ SourceID: "delly:minipc:112",ResourceType: unifiedresources.ResourceTypeSystemContainer,DisplayName: "debian-go",InstanceName: "delly",@@ -374,7 +423,8 @@ func TestFromPBSBackups_DisambiguatesCandidatesByNamespace(t *testing.T) {BackupTypeKey: "ct",},{- SourceID: "system-container-deadbeefdeadbeef",+ ResourceID: "system-container-deadbeefdeadbeef",+ SourceID: "other:pve-b:112",ResourceType: unifiedresources.ResourceTypeSystemContainer,DisplayName: "other-guest",InstanceName: "other",@@ -390,11 +440,7 @@ func TestFromPBSBackups_DisambiguatesCandidatesByNamespace(t *testing.T) {t.Fatalf("expected 1 point, got %d", len(result))}- expectedRID := unifiedresources.SourceSpecificID(- unifiedresources.ResourceTypeSystemContainer,- unifiedresources.SourceProxmox,- "system-container-fb42a70d89bd20a6",- )+ expectedRID := "system-container-fb42a70d89bd20a6"if got := result[0].SubjectResourceID; got != expectedRID {t.Fatalf("SubjectResourceID = %q, want %q", got, expectedRID)@@ -423,7 +469,8 @@ func TestFromPBSBackupsWithEvidenceAddsProviderScopeAndCorrelation(t *testing.T)candidates := map[string][]GuestCandidate{"vm:100": {{- SourceID: "vm-100",+ ResourceID: "vm-100",+ SourceID: "pve-main:pve-a:100",ResourceType: unifiedresources.ResourceTypeVM,DisplayName: "database",InstanceName: "pve-main",diff --git a/internal/recovery/store/store.go b/internal/recovery/store/store.goindex 5fcfe69f15..dbcd125d9b 100644--- a/internal/recovery/store/store.go+++ b/internal/recovery/store/store.go@@ -1048,6 +1048,68 @@ func normalizePage(page int) int {return page}+func (s *Store) existingSubjectKeysByPointID(+ ctx context.Context,+ points []recovery.RecoveryPoint,+) (map[string]string, error) {+ const chunkSize = 200++ ids := make([]string, 0, len(points))+ seen := make(map[string]struct{}, len(points))+ for _, point := range points {+ id := strings.TrimSpace(point.ID)+ if id == "" {+ continue+ }+ if _, exists := seen[id]; exists {+ continue+ }+ seen[id] = struct{}{}+ ids = append(ids, id)+ }++ out := make(map[string]string, len(ids))+ for start := 0; start < len(ids); start += chunkSize {+ end := start + chunkSize+ if end > len(ids) {+ end = len(ids)+ }+ chunk := ids[start:end]+ placeholders := strings.TrimSuffix(strings.Repeat("?,", len(chunk)), ",")+ args := make([]any, len(chunk))+ for i, id := range chunk {+ args[i] = id+ }+ rows, err := s.db.QueryContext(+ ctx,+ "SELECT id, subject_key FROM recovery_points WHERE id IN ("+placeholders+")",+ args...,+ )+ if err != nil {+ return nil, err+ }+ for rows.Next() {+ var id string+ var subjectKey sql.NullString+ if err := rows.Scan(&id, &subjectKey); err != nil {+ _ = rows.Close()+ return nil, err+ }+ if key := strings.TrimSpace(subjectKey.String); key != "" {+ out[strings.TrimSpace(id)] = key+ }+ }+ if err := rows.Err(); err != nil {+ _ = rows.Close()+ return nil, err+ }+ if err := rows.Close(); err != nil {+ return nil, err+ }+ }+ return out, nil+}+// UpsertPoints inserts or updates recovery points by ID.func (s *Store) UpsertPoints(ctx context.Context, points []recovery.RecoveryPoint) error {if err := s.ensureInitialized(); err != nil {@@ -1064,6 +1126,11 @@ func (s *Store) UpsertPoints(ctx context.Context, points []recovery.RecoveryPoinreturn err}+ existingSubjectKeys, err := s.existingSubjectKeysByPointID(ctx, points)+ if err != nil {+ return err+ }+nowMs := time.Now().UTC().UnixMilli()tx, err := s.db.BeginTx(ctx, nil)if err != nil {@@ -1127,7 +1194,7 @@ func (s *Store) UpsertPoints(ctx context.Context, points []recovery.RecoveryPoin}defer stmt.Close()- affectedSubjectKeys := make(map[string]struct{}, len(points))+ affectedSubjectKeys := make(map[string]struct{}, len(points)*2)for _, p := range points {adoptHistoricalProxmoxPBSGuestIdentity(&p, proxmoxPBSIdentities, proxmoxPBSLooseIdentities)@@ -1142,6 +1209,9 @@ func (s *Store) UpsertPoints(ctx context.Context, points []recovery.RecoveryPoinif provider == "" || kind == "" || mode == "" || outcome == "" {continue}+ if previousKey := strings.TrimSpace(existingSubjectKeys[id]); previousKey != "" {+ affectedSubjectKeys[previousKey] = struct{}{}+ }subjectRef, err := marshalJSON(p.SubjectRef)if err != nil {diff --git a/internal/recovery/store/store_posture_test.go b/internal/recovery/store/store_posture_test.goindex 6fb5767f39..a276b1e994 100644--- a/internal/recovery/store/store_posture_test.go+++ b/internal/recovery/store/store_posture_test.go@@ -167,6 +167,59 @@ func TestStoreProtectionPosturePersistsProviderAwareTruth(t *testing.T) {}}+func TestStoreProtectionPostureMovesWhenPointIdentityIsCorrected(t *testing.T) {+ t.Parallel()++ store, err := Open(filepath.Join(t.TempDir(), "recovery.db"))+ if err != nil {+ t.Fatalf("Open() error = %v", err)+ }+ defer store.Close()++ now := time.Now().UTC().Truncate(time.Millisecond)+ completedAt := now.Add(-time.Hour)+ point := recovery.RecoveryPoint{+ ID: "pbs-backup:vm-100",+ Provider: recovery.ProviderProxmoxPBS,+ Kind: recovery.KindBackup,+ Mode: recovery.ModeRemote,+ Outcome: recovery.OutcomeSuccess,+ CompletedAt: &completedAt,+ SubjectResourceID: "vm-double-hashed",+ ProviderScope: "pbs-main",+ }+ if err := store.UpsertPoints(context.Background(), []recovery.RecoveryPoint{point}); err != nil {+ t.Fatalf("UpsertPoints(old identity) error = %v", err)+ }++ point.SubjectResourceID = "vm-canonical"+ if err := store.UpsertPoints(context.Background(), []recovery.RecoveryPoint{point}); err != nil {+ t.Fatalf("UpsertPoints(corrected identity) error = %v", err)+ }++ var oldCount int+ if err := store.db.QueryRow(+ `SELECT COUNT(*) FROM protection_postures WHERE subject_resource_id = ?`,+ "vm-double-hashed",+ ).Scan(&oldCount); err != nil {+ t.Fatalf("count obsolete posture: %v", err)+ }+ if oldCount != 0 {+ t.Fatalf("obsolete posture count = %d, want 0", oldCount)+ }++ var newCount int+ if err := store.db.QueryRow(+ `SELECT COUNT(*) FROM protection_postures WHERE subject_resource_id = ?`,+ "vm-canonical",+ ).Scan(&newCount); err != nil {+ t.Fatalf("count corrected posture: %v", err)+ }+ if newCount != 1 {+ t.Fatalf("corrected posture count = %d, want 1", newCount)+ }+}+func TestStoreProtectionSchemaMigratesLegacyRecoveryDatabase(t *testing.T) {t.Parallel()