Compare commits

...

1 Commits

Author SHA1 Message Date
zheromiku f4b3f4c4c8 fix(reconciliation): 定时批占位语句修 42P08,真实 PG 上首次 claim 即可建批
build / build (push) Successful in 2m26s
白盒在真实 PostgreSQL 上跑新集成用例时,ClaimScheduledReconciliationRun 首次
claim 就报 inconsistent types deduced for parameter $2 (42P08):同一个 KB id
既进 INSERT 目标列(varchar(255))又参与子查询比较(varchar),参数被推断成两种
类型。把比较侧改成独立参数 $7,并在语句上方写明原因。

存量缺陷,改动前同样报错(reconciliation_schedules 一直建不出批次,C-105 无法通过)。

验证:
- TEST_DB 指向一次性 PostgreSQL 16,TestScheduledReconciliationClaimsOncePerDayAfterFailure 通过
  (首日占位一次;失败后同日不再建;次日可建)
- TestReconciliationRunUniquenessStaleAndRetentionIntegration 同库通过
- make verify 17 项 = 16 success + identity skipped
2026-12-01 19:12:00 +08:00
@@ -72,16 +72,19 @@ func (s *Store) ClaimScheduledReconciliationRun(ctx context.Context, run governa
if err != nil {
return governance.ReconciliationRun{}, false, err
}
// The KB id is passed twice on purpose: PostgreSQL deduces varchar(255) for
// the INSERT target and varchar for the comparison, and one parameter used in
// both positions fails with 42P08 "inconsistent types deduced".
row := s.db.QueryRow(ctx, `INSERT INTO reconciliation_runs
(id,test_kb_id,state,trigger,started_at,counts,created_at)
SELECT $1,$2,'running','schedule',$3,$4::jsonb,$5
WHERE NOT EXISTS(
SELECT 1 FROM reconciliation_runs
WHERE test_kb_id=$2 AND trigger='schedule' AND state IN ('running','succeeded','failed') AND started_at >= $6
WHERE test_kb_id=$7 AND trigger='schedule' AND state IN ('running','succeeded','failed') AND started_at >= $6
)
ON CONFLICT DO NOTHING
RETURNING `+reconciliationRunColumns,
run.ID, run.KBID, run.StartedAt, counts, now, since)
run.ID, run.KBID, run.StartedAt, counts, now, since, run.KBID)
claimed, err := scanReconciliationRun(row)
if errors.Is(err, pgx.ErrNoRows) {
return governance.ReconciliationRun{}, false, nil