fix(identity): 允许清理未收到 Manifest 的配对

0090 的 Manifest 约束要求无 issuer 的 Revision 保持 draft,原取消流程将其改为 failed,导致取消事务被数据库拒绝。现在由 cancelled Pairing 记录终态,并仅允许明确标记 pairing_cancelled 的预 Manifest 草稿完成清理。\n\n验证:IdentityPairing PostgreSQL 定向测试通过;PairingService 定向测试通过。
This commit is contained in:
2026-07-28 18:42:13 +08:00
parent 206e367dbf
commit 021ee9ab8f
2 changed files with 67 additions and 11 deletions
+8 -2
View File
@@ -320,7 +320,10 @@ FROM gateway_identity_configuration_revisions WHERE id=$1::uuid FOR UPDATE`, exc
if revision.State != identity.RevisionDraft && revision.State != identity.RevisionValidated && revision.State != identity.RevisionFailed {
return identity.PairingExchange{}, identity.ErrPairingNotCancellable
}
if _, err := tx.Exec(ctx, `UPDATE gateway_identity_configuration_revisions SET state='failed',
// Before Manifest delivery, issuer is NULL and the schema requires the
// revision to remain draft. The cancelled pairing is the terminal record.
if _, err := tx.Exec(ctx, `UPDATE gateway_identity_configuration_revisions SET
state=CASE WHEN issuer IS NULL AND state IN ('draft','failed') THEN 'draft' ELSE 'failed' END,
last_error_category='pairing_cancelled',last_trace_id=NULLIF($2,''),last_audit_id=NULLIF($3,''),
version=version+1,updated_at=now() WHERE id=$1::uuid`, exchange.RevisionID, traceID, auditID); err != nil {
return identity.PairingExchange{}, err
@@ -358,7 +361,10 @@ WHERE id=$1::uuid AND version=$2 AND status='cancelled' AND cleanup_status='pend
return identity.PairingExchange{}, err
}
tag, err := tx.Exec(ctx, `UPDATE gateway_identity_configuration_revisions SET machine_credential_ref=NULL,
session_encryption_key_ref=NULL,version=version+1,updated_at=now() WHERE id=$1::uuid AND state='failed'`, revisionID)
session_encryption_key_ref=NULL,version=version+1,updated_at=now()
WHERE id=$1::uuid AND (
state='failed' OR (state='draft' AND issuer IS NULL AND last_error_category='pairing_cancelled')
)`, revisionID)
if err != nil {
return identity.PairingExchange{}, err
}