From 433cb2de2cdc705a5cbb3a9eee77be8569cf2003 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Sat, 29 Aug 2026 21:53:46 +0300 Subject: [PATCH] prevent discovery from rolling back governed binding head --- adapters/postgres/capability_repository.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 }