fix(test-ingest): 上传记录 SQL 参数错位导致 test.upload 永远 state_conflict
build / build (push) Successful in 2m6s

recordUploadAndSchedulePollSQL 在加入 retry_count 幂等键后仍按旧顺序取参数:
payload 取到 $4(时间戳)→ 报 cannot cast timestamptz to jsonb,调用方把任何
error 都折成 test_upload_state_conflict,于是文件其实已经传上 0.9、对账面却
永远记不下来,publication 卡在 uploading。

- 参数按 $1..$8 对齐(payload $5 / priority $6 / available_at $7 / max $8);
- 记录失败时把底层原因带进 job.last_error,不再吞掉;
- 用隔离 PG 的集成用例验证:修复前 42846,修复后通过。
This commit is contained in:
Zhero & 助理
2026-12-03 18:10:31 +08:00
committed by 姚章浩
parent 5c2ba3e06f
commit 9eeb4c7206
2 changed files with 5 additions and 4 deletions
@@ -273,8 +273,8 @@ WITH updated AS (
max_attempts, idempotency_key, created_at, updated_at
)
SELECT 'job-' || substring(md5($1 || '#test.poll#' || updated.retry_count || '#1') from 1 for 32),
'test.poll', $4::jsonb, 'pending', $5, $6, $7,
'test-poll:' || $1 || ':' || updated.retry_count || ':1', $3, $3
'test.poll', $5::jsonb, 'pending', $6, $7, $8,
'test-poll:' || $1 || ':' || updated.retry_count || ':1', $4, $4
FROM updated
ON CONFLICT (idempotency_key) DO NOTHING
)
+3 -2
View File
@@ -7,6 +7,7 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"path/filepath"
"strings"
@@ -123,7 +124,7 @@ func (handler *UploadHandler) Handle(ctx context.Context, job jobs.Job) error {
uploadMD5, _ := handler.hashSpool(candidate)
now := handler.now()
if _, err := handler.store.RecordUploadAndSchedulePoll(ctx, candidate.ID, knowledge.ID, uploadMD5, now, now.Add(handler.firstPollDelay)); err != nil {
return ErrUploadStateConflict
return fmt.Errorf("%w: %v", ErrUploadStateConflict, err)
}
return nil
}
@@ -194,7 +195,7 @@ func (handler *UploadHandler) Handle(ctx context.Context, job jobs.Job) error {
}
now := handler.now()
if _, err := handler.store.RecordUploadAndSchedulePoll(ctx, candidate.ID, knowledge.ID, uploadMD5, now, now.Add(handler.firstPollDelay)); err != nil {
return ErrUploadStateConflict
return fmt.Errorf("%w: %v", ErrUploadStateConflict, err)
}
return nil
}