fix(ui): 接通取件后自动解析与一次性定位
build / build (push) Successful in 1m42s

F17:MarkArtifactFetched 与已验证内容复用都在同一事务内经过策略、来源启用、
过滤、superseded 和当前绑定的复核后,自动把 planned 转 pending 并入队唯一
test.upload;确认与作业幂等,失败整笔回滚。356 已卡记录可对同一文件再次保存
当前策略,经同一路径恢复,不做全库补扫或手工补队列。来源页提示改为自动接续。

F14:来源→监控定位清空未结束/动作/阶段/时间筛选;来源目录定位改为一次性请求
并由父消费,revision/sources 重载不再重放旧请求,手工换目录保持。

F13:抽出 readiness.Resolver 作为端点/绑定/凭据唯一来源;worker 上传/轮询/
校验/移除改用动态客户端,每次调用重读有效配置,不再固化启动 env 客户端。

验证:隔离 PG 的 F17 正负例与恢复用例、前端挂载定位回归、全量 Go/前端测试
及 make verify 17 项通过。未部署、未做 8088 UI 验收。
This commit is contained in:
姚章浩
2026-11-05 11:46:42 +08:00
parent 1c80b07f2c
commit 5bf4aae30e
17 changed files with 873 additions and 46 deletions
+102 -3
View File
@@ -23,14 +23,14 @@ import (
// 开始处理 promotes them within the configured concurrency budget. Blocked
// intents retire any planned publication and flip the item policy so the
// knowledge-base diff demands removal of anything still live.
func fulfillCatalogIntentsTx(ctx context.Context, tx pgx.Tx, request governance.CatalogRouteRequest, files []governance.CatalogRouteFile, now time.Time) (governance.CatalogRouteResult, error) {
func fulfillCatalogIntentsTx(ctx context.Context, tx pgx.Tx, store *Store, request governance.CatalogRouteRequest, files []governance.CatalogRouteFile, now time.Time) (governance.CatalogRouteResult, error) {
targetKnowledgeBaseIDs := request.TargetKnowledgeBaseIDs
if len(targetKnowledgeBaseIDs) == 0 && request.TargetKnowledgeBaseID != "" {
targetKnowledgeBaseIDs = []string{request.TargetKnowledgeBaseID}
}
result := governance.CatalogRouteResult{SelectedFiles: len(files)}
for _, file := range files {
recorded, fetchQueued, planned, blocked, err := fulfillCatalogIntent(ctx, tx, request, file, targetKnowledgeBaseIDs, now)
recorded, fetchQueued, planned, blocked, err := fulfillCatalogIntent(ctx, tx, store, request, file, targetKnowledgeBaseIDs, now)
if err != nil {
return governance.CatalogRouteResult{}, err
}
@@ -54,7 +54,7 @@ func fulfillCatalogIntentsTx(ctx context.Context, tx pgx.Tx, request governance.
// fulfillCatalogIntent applies one file decision. It returns recorded=false
// only when the node vanished mid-transaction; fetchQueued reports a newly
// enqueued artifact.fetch job and planned the number of publications created.
func fulfillCatalogIntent(ctx context.Context, tx pgx.Tx, request governance.CatalogRouteRequest, file governance.CatalogRouteFile, targetKnowledgeBaseIDs []string, now time.Time) (bool, bool, int, bool, error) {
func fulfillCatalogIntent(ctx context.Context, tx pgx.Tx, store *Store, request governance.CatalogRouteRequest, file governance.CatalogRouteFile, targetKnowledgeBaseIDs []string, now time.Time) (bool, bool, int, bool, error) {
policy := string(request.Visibility)
if _, err := tx.Exec(ctx, `INSERT INTO catalog_import_intents(
source_connection_id,node_id,visibility,decided_by,reason,relative_path,name,size_bytes,modified_at,content_sha256,
@@ -240,6 +240,11 @@ ON CONFLICT (source_item_version_id,test_kb_id) DO NOTHING`,
}
planned += int(tag.RowsAffected())
}
if contentState == string(governance.ContentVerified) {
if err := store.autoStartVerifiedPublicationsTx(ctx, tx, versionID, now); err != nil {
return false, false, 0, false, err
}
}
fetchQueued := false
if contentState != string(governance.ContentVerified) {
@@ -295,6 +300,97 @@ func sha256Hex(value string) string {
return hex.EncodeToString(sum[:])
}
// autoStartVerifiedPublicationsTx continues the normal ingestion chain in the
// SAME transaction that made the bytes verified. It deliberately re-checks the
// saved policy, the current binding and the live source state: a file routed
// before a policy/binding change must not be uploaded to a stale target.
func (s *Store) autoStartVerifiedPublicationsTx(ctx context.Context, tx pgx.Tx, versionID string, now time.Time) error {
if versionID == "" {
return errors.New("auto-start requires a version")
}
rows, err := tx.Query(ctx, `
WITH binding AS (
SELECT COALESCE(NULLIF(internal_kb_id,''), $3::text) AS internal_kb_id,
COALESCE(NULLIF(external_kb_id,''), $4::text) AS external_kb_id
FROM routing_kb_bindings WHERE id='active'
), eligible AS (
SELECT publication.id
FROM test_publications publication
JOIN source_item_versions version ON version.id=publication.source_item_version_id
JOIN content_objects content ON content.id=version.content_object_id
JOIN source_items item ON item.id=version.source_item_id
JOIN source_connections connection ON connection.id=item.source_connection_id
LEFT JOIN LATERAL (
SELECT intent.visibility FROM catalog_import_intents intent
WHERE intent.source_item_id=item.id AND intent.source_connection_id=item.source_connection_id
ORDER BY intent.updated_at DESC,intent.node_id LIMIT 1
) intent ON TRUE
CROSS JOIN binding
WHERE version.id=$1
AND publication.superseded_at IS NULL
AND publication.processing_state='planned'
AND publication.ingest_state='pending'
AND publication.knowledge_id=''
AND publication.retrieval_state='unpublished'
AND version.content_state='verified'
AND content.content_state='verified'
AND content.local_spool_ref<>''
AND content.size_bytes>0
AND connection.enabled
AND item.policy_state IN (publication.target_scope,'both')
AND intent.visibility IN (publication.target_scope,'both')
AND NOT filename_is_filtered(item.source_connection_id,item.normalized_path,item.title)
AND NOT EXISTS (SELECT 1 FROM jobs job WHERE job.type='test.upload' AND job.payload->>'publication_id'=publication.id)
AND ((publication.target_scope='internal' AND binding.internal_kb_id<>'' AND publication.test_kb_id=binding.internal_kb_id)
OR (publication.target_scope='external' AND binding.external_kb_id<>'' AND publication.test_kb_id=binding.external_kb_id))
)
UPDATE test_publications publication SET processing_state='pending',updated_at=$2
FROM eligible WHERE publication.id=eligible.id
RETURNING publication.id`, versionID, now, s.defaultInternalKBID, s.defaultExternalKBID)
if err != nil {
return fmt.Errorf("auto-start verified publications: %w", err)
}
ids := make([]string, 0, 2)
for rows.Next() {
var id string
if err := rows.Scan(&id); err != nil {
rows.Close()
return fmt.Errorf("scan auto-started publication: %w", err)
}
ids = append(ids, id)
}
if err := rows.Err(); err != nil {
rows.Close()
return fmt.Errorf("iterate auto-started publications: %w", err)
}
rows.Close()
for _, publicationID := range ids {
confirmationID, err := newOpaqueID("pc-")
if err != nil {
return err
}
jobID, err := newOpaqueID("job-")
if err != nil {
return err
}
payload, err := json.Marshal(map[string]string{"publication_id": publicationID})
if err != nil {
return errors.New("encode auto upload job")
}
if _, err := tx.Exec(ctx, `INSERT INTO processing_confirmations(id,publication_id,operator_ref,reason,confirmed_at,created_at)
VALUES($1,$2,'system:auto','取件 verified 自动接续',$3,$3)
ON CONFLICT (publication_id) DO NOTHING`, confirmationID, publicationID, now); err != nil {
return fmt.Errorf("record auto processing confirmation: %w", err)
}
if _, err := tx.Exec(ctx, `INSERT INTO jobs(id,type,payload,state,priority,available_at,max_attempts,idempotency_key,created_at,updated_at)
VALUES($1,'test.upload',$2::jsonb,'pending',10,$3,5,$4,$3,$3)
ON CONFLICT (idempotency_key) DO NOTHING`, jobID, payload, now, "auto-test-upload:"+publicationID); err != nil {
return fmt.Errorf("enqueue auto upload: %w", err)
}
}
return nil
}
// MarkArtifactFetched finalizes one artifact.fetch success: it (re)uses the
// content_objects row for the verified hash (content-level dedupe), attaches it
// to the pending version and flips the intent to ready. matchedLocal records
@@ -358,6 +454,9 @@ WHERE id=$1`,
WHERE source_connection_id=$1 AND node_id=$2`, connectionID, nodeID); err != nil {
return fmt.Errorf("mark intent fetched: %w", err)
}
if err := s.autoStartVerifiedPublicationsTx(ctx, tx, versionID, now); err != nil {
return fmt.Errorf("continue fetched artifact into upload: %w", err)
}
if ownsTransaction {
if err := tx.Commit(ctx); err != nil {
return fmt.Errorf("commit artifact fetch: %w", err)