From 9eeb4c7206d62a63d832172c3549f7e0ac01067f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zhero=20=26=20=E5=8A=A9=E7=90=86?= Date: Thu, 3 Dec 2026 18:10:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(test-ingest):=20=E4=B8=8A=E4=BC=A0=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=20SQL=20=E5=8F=82=E6=95=B0=E9=94=99=E4=BD=8D=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=20test.upload=20=E6=B0=B8=E8=BF=9C=20state=5Fconflict?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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,修复后通过。 --- internal/platform/postgres/test_publications.go | 4 ++-- internal/workflows/testweknora/upload.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/platform/postgres/test_publications.go b/internal/platform/postgres/test_publications.go index 771888b..d44afb0 100644 --- a/internal/platform/postgres/test_publications.go +++ b/internal/platform/postgres/test_publications.go @@ -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 ) diff --git a/internal/workflows/testweknora/upload.go b/internal/workflows/testweknora/upload.go index 7d39feb..b64a380 100644 --- a/internal/workflows/testweknora/upload.go +++ b/internal/workflows/testweknora/upload.go @@ -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 }