diff --git a/adapters/postgres/capability_repository.go b/adapters/postgres/capability_repository.go index fdb517d..7568a80 100644 --- a/adapters/postgres/capability_repository.go +++ b/adapters/postgres/capability_repository.go @@ -568,11 +568,9 @@ func (r *CapabilityRepository) SaveCognitiveDiscovery(ctx context.Context, value if err != nil { return err } - // Discovery creates immutable binding revisions. The durable head must - // follow the revision accepted by this transaction; leaving the - // existing head untouched strands refreshed providers behind an older - // inactive snapshot. - _, err = tx.Exec(ctx, `INSERT INTO capability.cognitive_binding_revision_heads (binding_id,revision) VALUES ($1,$2) ON CONFLICT (binding_id) DO UPDATE SET revision=EXCLUDED.revision,updated_at=CURRENT_TIMESTAMP`, binding.ID, binding.Revision) + // Discovery may advance a head, but must never roll back a governed + // CANARY/ACTIVE revision to an older discovered snapshot after restart. + _, err = tx.Exec(ctx, `INSERT INTO capability.cognitive_binding_revision_heads (binding_id,revision) VALUES ($1,$2) ON CONFLICT (binding_id) DO UPDATE SET revision=EXCLUDED.revision,updated_at=CURRENT_TIMESTAMP WHERE capability.cognitive_binding_revision_heads.revision < EXCLUDED.revision`, binding.ID, binding.Revision) if err != nil { return err }