Commit Graph

1151 Commits (de2dfd3034a7b506fa269910401bbdcbd4efc71d)

Author SHA1 Message Date
linus-liu-web 4eb23a8560
fix(qdrant): CopyIndices 用服务端返回的 next_page_offset 翻页,不再按页尾 id 回填 (#3882)
* fix(qdrant): 复制索引改用服务端返回的游标,重复游标报错并给分页加跳数上限

CopyIndices 用"上一页最后一个点的 id"当游标(repository.go:987)。Qdrant 的
scroll offset 是**包含**语义 —— proto 里写的是 "Start with this ID",实测下一页
正是从该 id 本身开始返回,所以每翻一页都会把上一页的最后一个点再读一次、再写一份
到目标库。服务端本来就把下一页该用的游标放在 ScrollResponse.next_page_offset
("Use this offset for the next query")里,而客户端只在 ScrollAndOffset() 中返回它,
本函数调用的 Scroll() 恰好把它丢掉了;终止条件也只能退化成"这一页比 64 短"。

在真实 Qdrant 1.19.1 上实测:150 个源 chunk 复制出 152 个目标点,chunk-63 与
chunk-126 各被复制两次(每个页边界一个),totalCopied 同步虚高。源库只要超过一页
(>64 个 chunk)就会命中,不需要服务端有任何异常行为。

本次修改:

- 改用 q.client.ScrollAndOffset,游标直接取服务端返回的 next_page_offset;终止
  条件改为"服务端没有下一页"(next_page_offset == nil),不再用短页推断读完。
- 记录用过的游标,重复即返回 "copy indices made no progress at cursor ...",
  检测点在整页处理之前,重复的那一页不会再多写一份。
- 分页跳数上限 maxCopyPaginationHops(10000 页);触顶打印 Warn 并返回错误,
  而不是把这一轮复制当成成功。
- 修复后同一份数据在真实 Qdrant 上测得 150 个目标点、0 重复。

回归用例用假 gRPC 服务端(拦截 unary RPC,对齐 repository_test.go 的
newInterceptedQdrantClient)复刻真实服务端的游标语义:150 个源 chunk 必须各复制
一次(修复前 152 个点、2 个重复);游标恒定不动的源端必须报 no progress
(修复前 5 秒写入 3127040 个点仍未返回);一直推进但永不结束的源端在第 10000 页
被拦下。

* fix(qdrant): drop the CopyIndices page cap

10000 pages of 64 points capped a copy at 640k points and failed the
whole clone beyond that. The scroll walks every point of the source
knowledge base (a single-knowledge clone included), so a cap derived from
the chunk map would cut off small clones out of large bases too.
next_page_offset only moves forward, so the repeated-cursor check already
stops a walk that cannot finish, and the task context bounds the rest.

---------

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-08 13:04:43 +08:00
Fei.Chen b8d83eab1c
fix(skills): skip vendored dep trees in install verification script enumeration (#3943)
* fix(skills): skip vendored dep trees in install verification script enumeration

sortedScriptPaths fed every .py/.js/.sh in the bundle into one shell 'for
f in ...' command. A skill that vendors a scientific venv (pandas/scipy/
matplotlib etc.) carries thousands of .py files under .venv/, and the
generated command exceeds the exec single-argument limit (MAX_ARG_STRLEN,
128KiB): /bin/sh fails with 'argument list too long' (exit 255) before
any check runs, so no dependency-heavy skill can ever install.

Vendored trees are installed dependencies, not scripts the model can
name; their health is already covered by the dependency verification
passes. Skip .venv/ and node_modules/ prefixes in sortedScriptPaths,
which fixes the tree check, the per-language parse passes and the
runtime prerequisite pass at once.

Verified by installing a 4862-file / 105MB quant skill (pandas+numpy+
scipy+statsmodels+matplotlib venv, real interpreter binary instead of
symlinks since zips cannot carry them): install failed before the fix,
reaches ready after it.

* fix(skills): skip vendored trees at any depth, not only at the bundle root

Bundles are author-zipped, so tools/.venv/ or sub/package/node_modules/
are as legal as root-level trees and enumerated just the same. The
filter now matches vendored trees under any prefix; nested placements
are covered by a regression test.

---------

Co-authored-by: vicfei <vicfei@users.noreply.github.com>
2026-10-08 01:28:45 +08:00
linus-liu-web 626185a120
fix(wiki): 重建链接逐页写失败不再静默,半成品不再回 200 (#3884)
RebuildLinks 的保存循环把每页 UpdateMeta 的失败降级成一条 Warn,函数最后
无条件 return nil,于是 handler 里既有的 err != nil 分支永远进不去:任意
一页写失败(行锁等待、死锁、连接中断、超时)时调用方仍拿到
200 "Links rebuilt successfully",而这些页面的 in_links/out_links 保持旧
值,反向链接与图谱继续显示过期关系,且没有任何途径知道"只重建了一部分"。

保持尽力而为的语义不变(一页失败不影响其余页面继续写入),但把失败页聚合
起来在结尾返回,沿用同仓库 knowledge_delete.go / wiki_ingest.go 的
errors.Join 写法,以及同文件 MovePage 对同一个 UpdateMeta 调用的报错写法。
handler 无需改动:其既有 500 分支会如实返回 "N of M pages failed" 与失败页
slug。

回归用例用 SQLite 触发器让指定页的 UPDATE 真的报错(不是 mock),走真实仓库
与真实 handler:
- 部分失败:RebuildLinks 返回聚合错误,可写页仍被刷新,失败页保持旧值;
- 全部失败:错误里含 3 of 3 与全部 slug;
- HTTP 层:部分失败回 500 且错误体含失败页与底层原因,全部成功才回 200。

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-08 01:25:53 +08:00
xxxxx 4d7e663128
fix(wiki): preserve pending work when source lookups fail (#3715)
* fix(wiki): preserve pending work when source lookups fail

* test(weaviate): snapshot schema state before probe barrier
2026-10-08 01:25:45 +08:00
sun fac9ebabf2
fix(knowledge): close spans left open on terminal rows and superseded attempts (#3855)
Sweep A only selects pending/processing/finalizing, so a row that reaches a
terminal state while its attempt is still open is never revisited: its spans
stay "running" and the document timeline shows a permanent 进行中. Found in
production with four root spans stuck for 11 and 27 days.

- housekeeping: add Sweep D (reapTerminalSpans) closing spans still open on
  terminal rows, carrying the row own error_message so the timeline still
  names the real cause. A self-healing backstop for every failure path that
  forgets to close its attempt, including rows stranded by older releases.
- span tracker: OpenAttempt now cancels spans left open by earlier attempts
  (ATTEMPT_SUPERSEDED). A reparse used to open its new root alongside the
  previous attempt dead root, which is what made historical runs look
  like they had been reactivated.

Co-authored-by: asmh1989 <minhua.sun@velavigo.com>
2026-10-08 01:25:38 +08:00
诉说晚秋 95691daab2
fix(knowledge): retry document processing after transient indexing failures (#3915)
processChunks marked the knowledge failed and returned nil when BatchIndex
failed, so ProcessDocument acked the task and the configured document-task
retries never ran. A short embedding or vector-store outage left the row
permanently failed; unchanged data-source syncs did not reprocess it.

While attempts remain, still clean up the partial chunks and vectors but
keep the row processing and return the error to the queue. The final
attempt (or a caller without a retry loop) records the failure as before.
2026-10-08 01:25:31 +08:00
linus-liu-web a15dfdd941
fix(summary): 坏 JSON 不再冒充文档摘要(截断/畸形 JSON 走失败路径,纯文本兜底保留) (#3769)
* fix(summary): 坏 JSON 不再冒充文档摘要

非流式文档摘要(Chat)解析失败时原先把模型原文当摘要落库:被 MaxTokens
截断的半截 JSON 会写进 knowledges.description、置 SummaryStatus=Completed
(Asynq 不再重试),同一段文本还会被 buildSummaryChunkContent 索引进 RAG。

- parseDocumentSummaryOutput 改为返回 (*documentSummaryResult, error):
  回复形如 JSON(含 markdown 代码围栏)却解析失败、或解析成功但取不到
  summary/gist 时返回 errSummaryOutputNotParsable,绝不回退成原文;
  非 JSON 的纯文本仍走原有的原文兜底,自定义模板 / 老模型不受影响。
- validateSummaryOutput 复用 chatpipeline.IsLengthFinishReason,
  FinishReason 为 length 类取值时返回 errSummaryOutputTruncated。
- 两个 sentinel 经 getSummary 汇入既有失败路径(ProcessSummaryGeneration
  的 handleRetryableSummaryFailure、RegenerateKnowledgeSummary 的
  handleGenerationFailure):保留旧描述、置 pending/failed 交给 Asynq 重试,
  不再以 Completed 落库。

测试:TestParseDocumentSummaryOutput 改为表驱动(截断 JSON、含裸换行 JSON、
无文本 JSON 必须报错且不能把原文当 Summary;纯文本兜底继续通过);
TestValidateSummaryOutput 增加 length / max_tokens 截断用例;
TestGetSummaryRejectsUnusableModelOutput 锁住 getSummary 的错误传播。

* fix(summary): length 截断判定收窄到 JSON 形状回复

非流式文档摘要在校验模型回复时先看 finish_reason:只要 provider 报告
length/max_tokens 就返回 errSummaryOutputTruncated。该判定不认识内容形状,
于是自定义纯文本模板一旦顶到输出预算,就从「截断但可用」变成重试直到
SummaryStatusFailed,与上一提交承诺的「非 JSON 的纯文本仍走原兜底」相反。

- validateSummaryOutput 恢复为只看内容是否为空;新增
  validateStructuredSummaryDocument 供 getSummary 使用:先判形状再判
  length,只有确实在产结构化摘要(能解析成对象/数组,或 { 开头、[ 开头接
  对象/数组/字符串元素)且被预算截断时才返回 errSummaryOutputTruncated。
- 形状判定剥离 UTF-8 BOM、前后空白与一层 markdown 围栏后再尝试
  json.Unmarshal;「[文档摘要] …」「[1] …」这类带方括号引用的纯文本不再被
  误判成坏 JSON,而截断的 {summary: 与截断的 JSON 数组仍然报错。
- parseDocumentSummaryOutput 同步剥离 BOM:BOM 前缀的截断 JSON 之前会被
  当成纯文本落库。
- 表格描述 / 列描述仍走 validateSummaryOutput,截断的描述照旧可索引。

---------

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-08 01:21:01 +08:00
Ankit Jha 27b9ee74a0
fix(storage): use virtual-hosted addressing for Tencent COS through the S3 driver (#3722)
newS3Client forced path-style for every non-AWS endpoint, so a COS
endpoint such as https://cos.ap-shanghai.myqcloud.com sent requests to
cos.<region>.myqcloud.com/<bucket>/<key>. COS rejects path-style for
buckets created from 2024-01-01, so STORAGE_TYPE=s3 could not reach new
COS buckets, and force_path_style=false had no way to turn it off.

Treat *.myqcloud.com like AWS and use virtual-hosted style. An explicit
force_path_style still wins, and other S3-compatible endpoints keep
path-style.

Fixes #3134

Signed-off-by: Ankit Jha <ankit.jha@tradomate.one>
2026-10-08 01:20:54 +08:00
诉说晚秋 7c284e7fc9
fix(faq): 保留克隆状态同步时的正文和索引状态 (#3993) 2026-10-08 01:20:39 +08:00
knqiufan e29301115a
fix(graph): preserve relationship direction and document provenance (#3950)
* fix(graph): preserve direction and document provenance in graph retrieval

* test(graph): verify live query bounds and seed evidence ordering

* fix(graph): deduplicate expansion using bounded seed identities

* ci: retry upstream scan after missing CodeCC report
2026-10-08 00:48:51 +08:00
AI即世界 afc6cbd502
fix(milvus): validate connections and preserve gRPC resolver defaults (#3654)
* fix(docreader): preserve gRPC resolver defaults

* fix(milvus): validate connection with SDK handshake

* fix(docparser): preserve gRPC resolver defaults

* fix(milvus): satisfy connection check lint

---------

Co-authored-by: tunan <tunan@ahyk.com>
2026-10-08 00:48:45 +08:00
Mohamed Arbi 9fa9e7c29d
fix: use consistent qdrant env settings (#3960)
* fix qdrant env settings

* fix test formatting
2026-10-07 23:59:56 +08:00
linus-liu-web 5648d24a93
fix(retriever/milvus): CopyIndices 按映射分块读源行,去掉会静默漏向量的 offset 窗口 (#3883)
CopyIndices 用 offset/limit 窗口遍历源知识库:offset 是"跨请求保持不变的结果
顺序"上的游标,而普通 query 不承诺这个顺序(结果按 segment 合并,且本次拷贝
每页都在往同一个 collection 写目标行),窗口一漂移就会跳过落在新窗口之前的行、
并重读被窗口退回的行;终止条件"短页即结束"(count < batchSize)又把因此提前
出现的短页当成读完了,剩余向量被静默丢掉,函数仍然返回 nil。用进程内假 Milvus
(gRPC 服务 + DisableConn,走真实 client.Query/Upsert 路径)在每次写入被确认后
旋转结果顺序复现:200 个源 chunk 全部返回成功、日志 total copied: 200,但
3 个 chunk 的向量从未写入目标库、另有 3 个被写了两遍(offsets=[0 64 128 192])。

改成按映射里的源 chunk ID 分块读:谓词 = knowledge_base_id 相等 + chunk_id in
(本批 64 个),读到的行集合由谓词唯一确定,没有游标可漂。拷贝的集合与改动前一致
(原先读到但不在映射里的行本来也会被跳过),只是不再按 offset 前进。同一文件的
chunk_id 批量读(updateChunkEnabledStatusInCollection、BatchUpdateChunkTagID)与
SQLite 版 CopyIndices 用的就是这个形状。

回归用例用进程内假 gRPC Milvus 注入跨页顺序漂移:去掉本修复该用例必失败
(missing=[target-chunk-064 target-chunk-129 target-chunk-194]、
repeated=[target-chunk-000 target-chunk-001 target-chunk-002] 而函数返回 nil),
修复后 offsets 全为 0、无缺失无重复。

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-07 23:59:44 +08:00
linus-liu-web 5f5093b9f7
fix(retriever): Qdrant/Milvus 关键词检索整批失败返回 error,不再当成「没有匹配」 (#3847)
* fix(retriever): Qdrant/Milvus 关键词检索整批失败不再当成没有匹配

Qdrant 与 Milvus 的 KeywordsRetrieve 逐个 collection 检索,单个 collection 失败只降级成
一条日志后 continue。循环结束后按结果条数分支:全部 collection 失败与确实零命中都会打印
"No keyword matches found"、返回空结果与 nil error。上层只看第二个返回值,据此判定知识库
没有相关内容,用户与模型都无法区分"没有这个词"和"检索没有执行成功"。

改为在循环内累计匹配到的 collection 数与失败的 collection 数,全部匹配 collection 都失败
时返回带底层原因的聚合 error,例如
"qdrant keyword search failed in all 2 matched collections: <cause>"。计数放在 collection
名前缀/维度匹配之后,名字不匹配的 collection 不参与统计;匹配到的 collection 为 0 时维持
原行为,不报错。Milvus 的三处 continue(Search / convertResultSet /
buildMilvusIndexResults)全部计入,另有两处同样会跳过 collection 的失败路径(analyzer mode
探测、过滤器构建)一并计入,这三处的日志补上 collection 名。

部分失败时不再打印结论性的 "No keyword matches found":有结果时改为提示结果不完整,无结果
时说明有多少个 collection 应答过、多少个失败;只有本次调用没有发生任何错误时才继续打印该
结论。RetrieveResult.Error 保持原样(仓库内没有读取方),改动面最小、语义最清晰的暴露方式
是整批失败返回 error。

回归测试:
- Qdrant(repository_test.go):假 Qdrant gRPC 服务让 Scroll 全失败时返回 error 且不打印
  结论日志;只有一个 collection 失败时结果与 nil error 不变;全部成功且零命中时仍返回空结果
  + nil error 并保留结论日志。
- Milvus(新增 keywords_test.go):*client.Client 没有接口缝隙,改用进程内 Milvus gRPC 假
  服务(ShowCollections / DescribeCollection / Search)覆盖同样三种情形,走真实 Search 与
  结果转换路径。
- go.mod:milvus-proto 由新测试直接导入,去掉该依赖的 // indirect 标记。

反向验证:把两个 repository.go 改回原样后,两条"全部失败"用例分别以
"all-collections failure must surface as an error, got <nil>" 与
"An error is expected but got nil" 失败,部分失败与零命中两条用例保持通过;随后逐字节还原
修复。

* fix(retriever): 关键词检索部分失败随结果一起暴露,不再被当成完整结果

Qdrant/Milvus 的 KeywordsRetrieve 逐 collection 检索,部分 collection 失败时保留其余
collection 的结果并返回 nil error。上层拿到的是"结果 + nil error":既不知道少了几个
collection 的内容,也没有任何读取方,RetrieveResult.Error 因此长期是死字段。上一个
commit 只处理了"全部匹配 collection 都失败",部分失败仍然静默降级,模型与用户看到的
都是不完整结果。

让部分失败沿着结果走完这条链路:

- repository(qdrant/milvus):部分失败时把
  "… keyword search failed in N of M matched collections: <cause>" 写进
  RetrieveResult.Error —— 结果照常返回、调用级 error 仍为 nil;全部失败仍是调用级
  error,真正的零命中仍然 Error == nil;
- CompositeRetrieveEngine:读取每个结果集的 Error 并聚合,连同结果一起返回
  ("retrieve returned partial results: …");引擎级 error 仍然丢弃全部结果,
  all-or-nothing 策略不变;
- retrieveFromStores(该接口的唯一消费方):结果与 error 同时非空即"部分失败",打出
  带 store group 与原因的 WARN 并保留结果返回 —— 既不会把降级 store 升级成整次搜索
  失败,也不会让上层把不完整结果当完整结果;
- matched == 0(没有任何 collection 匹配 base name)单独打一条 Warn,与"检索成功但
  零命中"区分开;
- milvus/repository.go 的 allFields 块按 gofumpt 重排,四个包 gofumpt -l 干净。

回归测试:

- qdrant/milvus:部分失败(有命中 / 零命中)结果集带 Error 且调用 error 为 nil;全部
  成功零命中仍 Error == nil 且保留结论日志;全部失败仍是 error;matched == 0 打专属
  Warn 且不发任何 Scroll/Search;
- CompositeRetrieveEngine:结果集带 Error → (结果, error) 同时返回;结果集完整(含零
  命中)→ 无 error;引擎级 error → 丢弃全部结果;
- retrieveFromStores:单 store / 多 store 部分失败都打 WARN 且保留结果,完整零命中不
  打 partial 日志,引擎级 error 仍然失败。

反向验证:去掉四个源文件的可见性改动后,17 条新/改用例中 9 条失败(qdrant 3、milvus 3、
composite 1、retrieveFromStores 2),钉住"行为不变"的 8 条保持通过;还原后 diff 与
改动前逐字节一致。

---------

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-07 23:59:38 +08:00
linus-liu-web f9eeb8dc85
fix(retriever/es): _bulk 的 per-item 失败不再被吞,全部被拒时 BatchSave 返回错误 (#3842)
Elasticsearch 受理 _bulk 请求即返回 HTTP 200,单个文档的写入失败只体现在响应体的
errors 与 items[].<op>.error。v8 把响应对象整个丢弃,只看传输层错误;v7 读了响应,
却只把结论降级成一行告警,响应体解析失败同样返回 nil。两个驱动的 BatchSave 因此在
文档被逐条拒绝时仍返回成功:调用方不标记 failed、不清理 chunks,阶段数据照写全部
条数,文档从此搜不到也不会重试。触发条件都是常规运维事件——mapping 不符、磁盘水位
只读、index 缺失、写压力下的 item 级拒绝。

修复:
- v8 接收 typed bulk 响应对象,resp.Errors 为真时遍历 resp.Items 聚合失败项。
- v7 把 countBulkErrors 的结论从"仅告警"升级为返回错误;响应体解析失败同样返回
  错误,不再把结果未知当成成功。
- 错误信息只带文档 _id 与有界的 error.type,最多摘要 5 条,失败条数覆盖全部失败
  项;error.reason 可能含文档正文,只写 debug 日志。写法对齐 OpenSearch 驱动既有
  的 inspectBulkResponse。

回归测试(v7/v8 各一份,httptest 假 ES + 真实构造函数):全部被拒返回错误、部分
失败返回错误且能看出失败条数、全部成功返回 nil;v7 另覆盖响应体损坏。断言同时确认
返回的错误不含 error.reason 中的文档内容。

反向验证:把两个驱动改回原实现后,新增用例 v7 失败 3 条、v8 失败 2 条;恢复修复后
全部通过。

Fixes #3832

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-07 23:59:32 +08:00
linus-liu-web a8a2c17b89
fix(sqlite): 索引行写入失败不再被丢弃,BatchSave 回滚而不是留下「主行在、索引行不在」 (#3843)
* fix(sqlite): 索引行写入失败让 Save/BatchSave 报错并回滚

Lite(DB_DRIVER=sqlite)的 vec0 / FTS 索引行 helper 丢弃 Exec 返回值:
BatchSave 的事务末尾无条件 return nil,于是 chunk 主行提交而索引行缺失,
Save/BatchSave 仍报成功,向量与关键词两条检索路径都静默漏召回;CopyIndices
的 copyVec 同样可能报成功而向量行没有复制过去。

- insertVec / syncFTS5Insert / copyVec / deleteRowsAndVecs 返回 error,在
  BatchSave(事务内)与 CopyIndices 的调用点检查并上抛:事务回滚,
  BatchIndex 报错后走 knowledge_process.go 既有的清理与 failed 标记路径;
  删除路径在索引行删除失败时不再删除主行。
- ensureVecTable 校验同名对象确实是 vec0 表之后才缓存"已就绪",失败上抛
  (BatchSave 与 vectorRetrieve);向量写失败时清掉该维度的缓存,下一次写入
  重新建表,而不是被永久短路。
- initFTS5 返回 error,并把建表与回填放进同一个事务(半回填的索引会静默丢
  召回);驱动未编译 fts5 模块(上游 go test 不带 -tags sqlite_fts5)时只
  记录一次并跳过关键词写入,而不是让每次入库失败;Lite 发布构建始终带该 tag。

新增 index_write_errors_test.go:覆盖 vec0 / FTS 表缺失、vec0 维度不匹配、
同名对象占位、索引删除失败、CopyIndices 向量复制失败,以及正常路径与无 fts5
模块构建。把修复改回原样后,其中 6 个用例必失败。

Fixes #3833

* fix(sqlite): CopyIndices 行复制失败累计上报,不再 Warn 后跳过

克隆/搬运知识库时逐行 Create 失败原先只记 Warn 并 continue:目标库会缺
主行/索引行却仍报成功。现改为逐行累计错误,FTS 与向量复制失败同样累计
而不是遇到第一条就返回,最后 errors.Join 交给调用方;错误里带源/目标
chunk id 便于定位失败行,不含正文。调用方沿用既有 rollbackIndices 回滚
与 failed 标记路径。

新增回归用例:触发器拒单行 -> 调用方拿到可定位到该行的错误、同 chunk 的
其它行照常复制;DROP FTS 表 -> 错误带上表和 chunk id 且向量行仍写入。

---------

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-07 23:59:26 +08:00
linus-liu-web 72b8a106c7
fix(sqlite): 检索后端批量更新索引副本失败不再吞掉错误 (#3768)
* fix(sqlite): 检索后端批量更新索引副本失败不再吞掉错误

Lite(DB_DRIVER=sqlite)的 BatchUpdateChunkEnabledStatus 与
BatchUpdateChunkTagID 逐条执行 Update 后丢弃 gorm 的 .Error 并无条件
return nil:索引副本更新失败被吞,接口仍报成功。

服务层是"先写权威 chunks 行(成功)→ 再同步检索索引副本"
(knowledge_faq.go:877-889 等),而检索只读索引副本
(lite_embeddings.is_enabled / tag_id)。因此索引 UPDATE 失败
(SQLITE_BUSY、磁盘满)或未命中任何行时,接口返回成功、UI 显示新标签
或已停用,但按新标签过滤搜不到、刚停用的条目仍会被召回。postgres 后端
同名函数在 result.Error != nil 时本就 return result.Error,sqlite 与之
对齐:逐条检查 .Error,非 nil 时用 fmt.Errorf 包装 chunkID 与操作名
返回。postgres 不把 0 行当错误(仅记录 RowsAffected 日志),故此处也
不引入"0 行即错误"。

新增 batch_update_test.go:用 DROP TABLE 与触发器构造必然失败的
UPDATE,断言返回非 nil 错误(修复前返回 nil),并覆盖成功路径。

注:本条是 sqlite 后端"执行了但吞掉错误",与 #3426 的 weaviate 后端
"未真正执行操作"属于不同后端的不同机制。

* fix(sqlite): 批量更新索引副本累计错误后汇总返回,并让 0 行可见

BatchUpdateChunkEnabledStatus / BatchUpdateChunkTagID 逐条执行 UPDATE,上一版
改成"首个错误即 return":语义从"尽力更新全部"退化成"只更新一个前缀",而前缀
取决于 map 迭代顺序。同类后端不是这么做的:milvus 与 qdrant 都是把每条错误
累计进切片后 errors.Join 并继续跑完。因此改为循环内累计错误、跑完全部行,最后
errors.Join 返回;错误信息仍带 chunkID 与操作名,调用方观察到的"失败即 error"
不变。

另外上一版只检查 .Error,没有看 RowsAffected:"索引 UPDATE 匹配 0 行"在
sqlite 上依然完全不可见。0 行仍不算错误(索引副本允许落后于权威 chunks 行,
postgres 后端同样只记日志),但现在会打一条 Warn,带表名、列名与 chunk_id,
不含正文内容。

测试(internal/application/repository/retriever/sqlite/batch_update_test.go):
- ReportsEveryFailingStatementInBatch:触发器让批内 5 条全部失败,断言
  errors.Join 中 5 个 chunk 都出现、失败消息出现 5 次。首错即 return 时只有
  1 条,用例必失败。
- KeepsUpdatingAfterStatementFailure:批内 chunk-3 失败时 chunk-4/5 仍被更新;
  断言落在结果行而非"第几条",因为 map 迭代顺序随机。
- WarnsWhenStatementMatchesNoRow:命中 0 行仍成功返回,但日志里有带
  lite_embeddings.<列名> 与 chunk_id 的 Warn。

顺带补 gofumpt 要求的函数间空行(main 上既有的格式差异),使该文件 gofumpt 干净。
默认构建与 -tags sqlite_fts5 两种构建下
go test ./internal/application/repository/retriever/sqlite/... -count=1 均通过。

---------

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-07 23:59:19 +08:00
hailongzhao bccb4b151b fix(embed): 内嵌网页只传图片不输入文字时不再返回 400
内嵌网页的输入框允许只带图片或附件就点击发送,但 CreateKnowledgeQARequest.Query
带有 binding:"required",parseQARequest 也拒绝空 query,于是只传图片直接返回
400 "Query content cannot be empty"。

入口处理:去掉 binding:"required";文字为空但带有内联图片数据或内联附件时,
用 types.UploadOnlyQuestion 生成一句替用户提问的问题(中文界面为「请根据我
上传的内容回答。」,其他语言为英文),交给模型、检索、标题、会话历史索引、
追问建议和记忆使用。只有 URL 的图片不算上传,因为客户端传入的图片 URL 会被
清掉;预上传的 attachment_ids 也不算,这类文件在流开始后才解析,可能失败或
超时,届时模型没有任何内容可答。其余空 query 仍返回 400。

存储与显示:qaRequestContext 新增 userInput,保存用户消息时只存用户实际
输入,只传图片时为空,刷新后与发送当下显示一致;query 仍是给模型的问题。
steer 追问复制上一轮的请求上下文,显式设置 userInput,避免在只传图片的一轮
之后把追问存成空消息。

会话历史:文字为空但带图片或附件的用户消息,在两处历史重建里补上同一句
问题。知识问答流水线(loadAndProcessHistory)原先会整轮丢弃;Agent 历史
(LoadAgentHistory)原先会发出空的用户消息,被 SanitizeMessages 剔除后
前后两条回答被合并。

去掉 binding 标签会让 gofmt 重新对齐整个 CreateKnowledgeQARequest 的行尾
注释,这些既有的超长行因此会被 PR 的增量 lint 视为新增。按仓库惯例把字段
注释移到字段上一行(注释文字不变,swagger 描述不受影响),并把 Go 字段
KnowledgeIds 改名为 KnowledgeIDs(JSON 名仍是 knowledge_ids,接口不变)。

同步更新 swagger 文档,query 不再是必填字段。
2026-09-30 15:26:51 +08:00
linus-liu-web 2ec1774623 fix(auth): 令牌写入失败不再当成登录成功,查询失败不再谎称已撤销
generateTokensForTenant 把两次 CreateToken 的错误都丢给了 `_`,然后照常返回
token 对。签发出去的 JWT 签名正确、语法合法,但 auth_tokens 里没有行,
ValidateToken / RefreshToken 在下一次请求就把它拒掉——用户看到的是"刚登录就掉
线,反复登录都一样"。更糟的是校验侧把"查不到"和"已撤销"合并成同一个分支:

    if err != nil || tokenRecord == nil || tokenRecord.IsRevoked {
        return nil, 0, errors.New("token is revoked")
    }

于是真实的插入错误既没有落日志,也被贴上了一个从未发生过的原因("token is
revoked"),把排查方向引向"会话被踢"。触发条件只是常规基础设施抖动:语句超时、
连接池耗尽、连接被重置。

同文件的对照写得很清楚:SwitchTenant 对同类写入 `return fmt.Errorf(...)`("a
200 response is also a durable landing-preference update"),Logout 直接返回
RevokeTokensByUserID 的错误;这两处是全文件唯一"写完不检查"的地方。

改动:
- 两次 CreateToken 都检查错误,失败即 `persist access token/refresh token: %w`
  返回,保证"登录成功"一定对应已持久化。正常路径不变:两行都写成功才返回令牌对。
- ValidateToken / RefreshToken 把查询错误与"已撤销/不存在"拆开:查询失败按基础
  设施错误上报(`look up token: %w`),`IsRevoked` 仍然报 "token is revoked",
  不再用一句假话掩盖查询失败。

新增用例(internal/application/service/user_token_persistence_test.go):
- 写入失败时 Login 必须 Success=false 且不下发任何令牌;
- 访问令牌/刷新令牌任一写入失败都不得返回令牌;
- 正常路径回归:两行都落库、access token 随后能通过 ValidateToken;
- 查询失败如实上报(errors.Is 命中原始错误,且不含 "token is revoked");
- 真的被撤销时 "token is revoked" 仍然保留。

L2 复现(假 token repo 返回写失败):修复前 Login 返回 success=true、
tokenIssued=true,紧接着用该 token 请求得到 "token is revoked";修复后 Login
返回 success=false、message="Login failed"、不下发令牌。去掉 user.go 的改动后
新增用例 5 个子用例全红,两条正常路径回归用例仍绿。整个 service 包
`go test ./internal/application/service/` 通过,scoped golangci-lint 0 issues。
2026-09-30 13:40:51 +08:00
lyingbug 5225edc0f7
feat(auth): 新增仅限邀请注册档位 (#3900)
* feat(auth): add invitation registration mode

* fix(auth): resolve registration mode lint errors
2026-09-30 13:32:55 +08:00
LL_Ricky 9842e51d40
fix(frontend): 修复复制模型时模型名称被改写的问题 (#3830)
* fix(frontend): 修复复制模型时模型名称被改写的问题

* fix(model): preserve model name and credentials when copying a config

Copying rewrote the upstream model name and posted redacted parameters, so the duplicate could not authenticate. Clone the stored row, cap the display name, and skip a new download when the local model is already active.

* fix(lint): clear new golangci-lint findings on model copy

Check c.Error results, wrap the long test line, and format the stub. The pull request lint range also includes the new HTTP error test, whose unused request parameter failed revive.

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-29 19:32:08 +08:00
hailongzhao f46c990567 fix(embed): 开启 Host context 后点击追问建议不再返回 400
嵌入渠道调用 WeKnora.setContext 后,前端 buildQueryWithHostContext 会把
query 包成 "[Host context]\n<k: v 行>\n\n<问题>" 再发出,而
ValidateAttribution 用 TrimSpace 后的全文与建议文本做精确比较,带信封的
query 永远不相等,于是每次点击追问建议都返回 400
"invalid suggestion attribution"。

后端:新增 queryMatchesSuggestionText,精确匹配失败时识别 host context
信封——要求以 "[Host context]\n" 开头、信封内容非空、以空行结束,且空行后
紧跟的正好是被点击的建议文本。宿主传入的 value 可以含换行甚至空行,所以用
建议文本从尾部锚定切分,而不是取第一个 "\n\n"。不校验信封里每行的 key/value
形态:前端对 key 不做约束(带空格、空 key、value 以换行开头都会原样拼进去),
校验只会误伤合法 context,而归因只用于统计点击与实际发送,不涉及权限。
在信封与问题之间或问题之后夹带额外文本、任意前缀、空信封仍会被拒绝。

前端:handleFollowUpSelect 原先在回复生成中点击建议时也会写入待发送归因,
但跳过发送,归因会泄漏到用户下一条手动输入的消息上,同样导致 400。改为只在
真正发送时写入归因,click 事件照常上报。

Fixes #3820
2026-09-29 12:16:46 +08:00
linus-liu-web 1912ba26c5 test(weaviate): 让并发建表的用例真的每个 worker 都去创建,消掉随机失败
TestEnsureCollectionToleratesConcurrentCreation 用 barrier 让 8 个 worker 都先探到
"class 不存在",再一起冲创建,最后断言 server.creates == workers。但假服务器的 GET
分支是「先等 barrier、再采样 s.exists」:barrier 一放开,赢家的 POST 可能已经把
exists 置为 true,排在后面的 worker 采样到"已存在",就在创建之前返回了,从来没去
尝试创建。实际创建数取决于调度(本地 100 次里挂 1 次;CI 上是 4 或 6),断言于是
随机失败 —— main 自己的 CI 与多个 PR 都挂在这条上。

把采样挪到 barrier 之前:每个 worker 读到的是它到达时的状态(此刻必然为 false),
8 个创建请求全部到达服务端,断言稳定。测试注释里写的意图本来就是"让每个 worker 都
看到 class 缺失",这里只是让实现与意图一致。

只改测试,不碰生产代码。
2026-09-29 01:32:23 +08:00
linus-liu-web e39043f34b fix(repository): 关键词 LIKE/ILIKE 检索补显式 ESCAPE,修复 Lite 上静默漏结果
SQLite(Lite 版所用数据库)没有默认的 LIKE 转义字符,而 Postgres 的默认转义字符是
反斜杠。escapeLikeKeyword / escapeLikePattern 会把关键词里的 %、_、\ 转义成 \%、\_,
但只有在 SQL 中显式声明 ESCAPE 时才有意义:缺少 ESCAPE 时 SQLite 会把反斜杠当成普通
字符,于是任何含 _ 或 % 的关键词(如 IMG_2534、100%)都匹配 0 行——不报错、不打日志,
total 同样为 0,前端只显示"暂无数据"。Postgres 因默认反斜杠转义而表现正常,所以问题
只在 Lite / SQLite 上静默出现。

本次修改统一在 LIKE 表达式后补 ESCAPE,并把 escape 字符作为参数传入(Postgres 的
ILIKE 分支同样处理),写法对齐 message.go / message_artifact.go / chunk_image_assets.go
中已有的正确站点,转义字符复用 knowledge.go 既有的 likeEscapeChar 常量。

修复站点:
- knowledge.go applyKnowledgeListFilter 文档列表关键词过滤
  (agent 工具 list_documents、mcp-server tools_retrieve 复用)
- knowledge.go SearchKnowledge
- knowledge.go SearchKnowledgeInScopes(GET /api/v1/knowledge/search)
- tag.go ListByKB 标签搜索(count 与 data 两条查询)
- tenant.go SearchTenants 租户搜索(带/不带 tenantID 两个分支)
- tenant_member.go CountFilteredByTenant / ListPagedByTenant 成员邮箱、用户名搜索
- session.go QueryPaged 会话列表/侧栏标题搜索(LOWER LIKE 与 Postgres ILIKE 分支)
- chunk.go ListPagedChunksByKnowledgeID 分块/FAQ 搜索

chunk.go 属反向错误:关键词完全没有转义,% 和 _ 被当作通配符导致多匹配。这里同样改为
escapeLikeKeyword + ESCAPE,而不是把别处的转义去掉——关键词里的 % 和 _ 是用户想按字面
匹配的字符(文档名 IMG_2534、进度 100% 都很常见),去掉转义会让它们又变成通配符、匹配
到无关结果;只有显式 ESCAPE 才能让 Postgres 与 SQLite 行为一致。

顺带把 escapeLikePattern 收敛为 escapeLikeKeyword 的薄封装(wiki_page.go 一处),
两者原本是逐字符等价的重复实现,调用点语义不变。转义字符常量仍复用 likeEscapeChar,
未新增常量。

新增 SQLite 回归测试 internal/application/repository/like_escape_sqlite_test.go,覆盖上述
全部站点:每个用例同时埋入"字面命中行"和"通配符诱饵行",缺 ESCAPE 会因 0 行失败,缺
转义会因多匹配失败。已逐站点反向验证:去掉 ESCAPE(或去掉 chunk.go 的转义)后测试确实
失败,随后逐字节还原。

注:organization.go ListSearchable 与 user.go SearchUsers 的关键词同样未转义,但它们是
Postgres 专用路径(ILIKE / ::text),属另一类问题,不在本次改动范围内。
2026-09-29 01:31:37 +08:00
Fei.Chen ec0ca46334
fix(server): run ResourceCleaner on signal shutdown instead of racing Fatalf exit (#3804)
* fix(server): signal shutdown raced Fatalf exit before ResourceCleaner ran

The signal goroutine closed the listener before calling server.Shutdown,
so Serve returned the raw accept error ('use of closed network connection')
instead of ErrServerClosed. The invoke error path then hit logger.Fatalf
(os.Exit(1)) in the same millisecond, killing the process before the
shutdown goroutine reached resourceCleaner.Cleanup. Every registered
cleaner — BrowserSkill daemon, sandbox reapers, IMService, AntsPool,
Langfuse — was skipped on every SIGTERM/SIGINT, leaking the shared bsk
daemon process and its temp home on each restart.

Two changes:
- Drop the manual listener.Close(): Shutdown closes all listeners as its
  first step, releasing the port just as fast without racing Serve.
- Give resourceCleaner.Cleanup its own fresh timeout context so a slow
  connection drain cannot leave Cleanup with an already-expired context,
  which made it skip every entry without running any.

* fix(server): keep signal cleanup inside one grace period

Desktop quit still closed the listener before Shutdown and returned
before ResourceCleaner finished, so Fatalf could skip every hook.
Share ShutdownTimeout between drain and cleanup, run BrowserSkill
first, and do not drop later hooks when the deadline expires.

* fix(server): satisfy errcheck and line-length lint

---------

Co-authored-by: vicfei <vicfei@users.noreply.github.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-28 23:37:36 +08:00
wizardchen c819abd958 fix(wiki): bound outstanding follow-up tasks 2026-09-28 22:02:07 +08:00
Duke 4ba85e2edf fix(wiki): fan out follow-up triggers so backlogs drain at ingest_max_inflight
Since Phase 3 the consumption side (disjoint claiming, per-slug locks,
the inflight cap) fully supports concurrent batches, but nothing created
more than one trigger per completed batch: once uploads stopped, a KB
with a standing backlog drained at 1 batch x batch-size per cycle
regardless of ingest_max_inflight, leaving the wiki pool and the model
server idle.

followUpTriggerCount now re-arms min(batches the remaining rows still
need, slots that could be free when the triggers fire). The caller's
own slot releases right after scheduleFollowUp returns, hence the +1.
activeInflightSlots is a read-mostly Lua companion to the reserve
script (purge expired, then ZCARD); -1 means unknown (no Redis / Redis
error) and collapses to a single follow-up, as do maxInflight <= 1 and
Lite mode (liteLocks serialize per KB anyway). Fan-out is deliberately
skipped on a rate-limited exit so a 429 storm is not amplified.

Over-issued triggers are harmless: the ones that cannot get a slot are
acked and coalesced by scheduleCappedRetry's fixed TaskID. The slot
count renders as "unknown" in the log when it was not consulted.
2026-09-28 22:02:07 +08:00
Perfecto 675b06addc test: consolidate table summary regressions 2026-09-28 21:24:02 +08:00
Perfecto d270a844ac fix: reject empty table-summary model responses 2026-09-28 21:24:02 +08:00
Perfecto d528d1fc3c fix: skip table-summary tasks for missing documents 2026-09-28 21:22:45 +08:00
Victor Maznyuk 0b463e459a test(skills): wait for the host install to release its lock before asserting
TestHostInstallActivatesVersionAndMarksReady waited for the row to reach
ready and then read the fake tree and installer. runHostInstall records
ready while it still holds the skill lock; pruning old versions, unbinding
the install session and unlocking come after, so the test could observe
tree.pruned as nil or installer.bound still populated, and the race
detector reported the unsynchronised reads.

The fake tree now counts runs between Lock and unlock, and the wait
helpers block until no run holds it. The run unlocks last, so everything
it wrote is visible once the wait returns. waitRemoveDone had the same
gap (the row is deleted before the stale marks are recorded) and uses the
same wait.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 21:07:04 +08:00
Victor Maznyuk 5bf2ae1cc2 fix(faq): actually clean FAQ entry payloads before validation and storage
sanitizeFAQEntryPayload called meta.Normalize() and discarded the result.
Normalize returns a normalized copy for hashing and indexing and does not
touch its receiver, so no cleaning happened: blank, whitespace-only and
duplicate similar/negative questions and answers were stored as sent, two
empty similar questions were reported as a duplicate, and answers: ["  "]
passed the "at least one answer" check.

Call meta.Sanitize(), the in-place method meant for storage (trim, drop
empties, de-duplicate, keep the original text).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 20:29:29 +08:00
linus-liu-web a570dffcfa test(wiki): 表格夹具改用合成数据
`certLedgerRow` / `certLedgerBlock` 里的机构名、页面标题与行数都取自某一份具体
数据,而回归测试需要的只是形状:一张有很多行的 markdown 表格 + 表头 + 分隔行。
取值换成中性的示例数据 —— 机构名 `示例科技有限公司`、行标识 `成员 N`、标题
`证书台账`、行数 90(切 1..61 + 62..90),断言里的 92 = 90 行 + 表头 + 分隔行。

断言逻辑一行未动,5 个续写/上限/哨兵用例全 PASS。
2026-09-28 20:19:52 +08:00
lyingbug 9114e4e4f9
fix(citations): 修复原文定位、高亮范围与 DocReader 启动失败 (#3794)
* fix(citations): verify source locations and recover document previews

* chore: exclude local research notes from pull request
2026-09-27 20:32:26 +08:00
wizardchen 6c83d7ab47 revert: take the plugin system back out of main
Reverts the eleven plugin system PRs merged on 2026-09-26 so they can be
reviewed before landing:

* a829d7cc9 agent tools served by plugins (#3733)
* 4f5d475c3 Jira example plugin (#3730)
* 01222aac8 dynamic form options, OAuth connections and resource limits (#3729)
* cf502ba46 event delivery and webhooks (#3728)
* 996696057 sandboxed plugin pages (#3727)
* da4ef68d9 standalone plugin hosts (#3725)
* 728007ada remote runtime, Python SDK (#3724)
* ff49f9491 Host API and document parsers (#3721)
* 4328ab26a code plugins (#3720)
* ed63e35cc declarative plugins (#3716)
* c91a8d11f plugin system foundation (#3711)

The tree is back to 47773b5bd, migrations included: no environment ran
the plugin migrations (versioned 000115-000119, sqlite 000034-000038).
2026-09-26 14:58:18 +08:00
lyingbug 01222aac8e
feat(plugin): dynamic form options, OAuth connections and resource limits (P2 batch 7) (#3729)
* feat(plugin): dynamic form options, OAuth connections and resource limits
* fix(plugin): show what an options list waits for as a hint, not an error
2026-09-26 14:47:37 +08:00
lyingbug cf502ba46a
feat(plugin): event delivery and webhooks for plugins (P2 batch 6) (#3728)
* feat(plugin): event delivery and webhooks for plugins
2026-09-26 14:47:13 +08:00
lyingbug 728007ada9
feat(plugin): remote runtime, Python SDK and python host plugins (P2 batch 3) (#3724)
* feat(plugin): remote runtime
* feat(plugin): Python SDK and python host plugins
* fix(pluginsdk): skip reverse DNS when a Python plugin binds
2026-09-26 14:46:03 +08:00
lyingbug ff49f9491d
feat(plugin): Host API with a key-value store, and document parsers from plugins (#3721)
* feat(plugin): Host API with plugin tokens and a key-value store
* feat(plugin): document parsers from code plugins
* docs(pluginsdk): parsers and the Host API
2026-09-26 14:45:39 +08:00
lyingbug 4328ab26a9
feat(plugin): code plugins — extension protocol, Go SDK, plugin host, web search and data source adapters (#3720)
* feat(pluginsdk): extension protocol v1, Go SDK and conformance suite
* feat(plugin): run code plugins in an embedded plugin host
* feat(plugin): remote adapters for web search and data sources
* fix(plugin): show plugin errors by their message
* feat(frontend): plugin connectors and web search providers in the UI
* docs(pluginsdk): how to write, package, test and install a plugin
* fix(plugin): gofmt two files and read openapi.yaml line-ending agnostic
* fix(plugin): mark a host plugin ready before Activate returns
2026-09-26 14:45:15 +08:00
lyingbug ed63e35cc7
feat(plugin): install declarative plugins — MCP servers, skills and model vendors (#3716)
* feat(plugin): install declarative plugin packages across nodes
* feat(plugin): serve installed plugins' MCP servers in each workspace
* feat(plugin): let installed plugins contribute skills and model vendors
* feat(plugin): register plugin skills into the workspace skill catalog
* feat(frontend): manage installed plugins and their configuration
* test(weaviate): read the class state before the probe barrier
* fix(plugin): keep MCP tool directories reachable behind the plugin wrapper
* test(plugin): wrap a long line
2026-09-26 14:44:34 +08:00
lyingbug c91a8d11f8
feat(plugin): plugin system foundation — builtin plugins, config schemas and workspace switches (#3711)
* feat(plugin): add plugin manifest, registry and builtin catalog
* feat(plugin): add config schemas with unified secret handling
* feat(frontend): render config schemas with SchemaForm
* feat(datasource): serve connector credential forms from the backend
* feat(im): describe IM platforms and credentials from the backend
* feat(frontend): render model vendor extra fields from the config schema
* feat(frontend): build the settings modal from an extension registry
* refactor(agent): register builtin tools and their chat views
* feat(plugin): let workspaces enable and disable plugins
* feat(plugin): add the runtime driver interface and gather builtins
2026-09-26 14:43:28 +08:00
xiaojunxiang 0bf105499b
fix(knowledge): reject invalid JSON uploads before async parse (#3360)
* fix(knowledge): reject invalid JSON uploads before async parse

Validate .json payloads at HTTP upload/replace time with the same gate used
by the simple JSON reader, so JSONC or truncated files fail with HTTP 400
instead of after document-process retries. CreateKnowledgeFromFile itself
skips the gate so datasource sync and IM still create a knowledge row that
fails in async parse.

Signed-off-by: xiaojunxiang <xiaojunxiang@kingsoft.com>

* fix(knowledge): localize JSON upload validation messages

The upload queue shows the backend message verbatim and the rest of the
upload handler speaks Chinese. Map ValidateJSONContent's errors (now
sentinels with unchanged text, still shared with the async JSON reader)
to Chinese messages at the upload/replace boundary.

---------

Signed-off-by: xiaojunxiang <xiaojunxiang@kingsoft.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
Co-authored-by: lyingbug <xiayula2014@gmail.com>
2026-09-25 22:23:27 +08:00
Perfecto 00e6366fd2
fix(datasource): validate cron schedules and persist manual-only mode (#3653)
* fix(datasource): preserve schedule state on invalid updates

* docs(datasource): document PUT /datasource/:id as a full replace

The update now always persists sync_schedule, so a partial body clears
the schedule. Show a full-object example and state that omitted fields
are reset rather than preserved.

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-25 22:23:18 +08:00
MercuialC c7601b2d2a
feat(wiki): 增加跨知识库 Wiki 搜索 POST /wiki-search (#3535)
* feat(wiki): add cross-KB wiki search POST /wiki-search

Give external callers a knowledge-search counterpart for wiki pages: one
SQL IN query ranked by title/slug/summary/content, slim hits with
match_snippet, and Viewer retrieve auth including shared KBs.

* fix(wiki): satisfy golangci-lint on cross-KB wiki search

Check c.Error returns, wrap lines over 120 columns, and use wikiDialect
instead of the embedded Dialector selector.

* fix(wiki): address review on cross-KB search helpers

Share KB viewer auth and snippet extraction, keep ID limits in the
service layer, and escape SQLite LIKE wildcards.

* fix(lint): wrap knowledge span fixtures over 120 columns

Go Lint still diffs from the original PR base, so later main tests
in knowledge_spans_test.go were reported as new line-length issues.

* fix(wiki): authorize KB access before checking wiki enablement in cross-KB search

Checking IsWikiEnabled before AuthorizeKBAccess let a caller tell apart a
foreign KB with wiki disabled (400) from one it cannot see (404), leaking
the KB's existence and settings. Run the access check first.

---------

Co-authored-by: root <root@localhost.localdomain>
Co-authored-by: wizardchen <wizardchen@tencent.com>
Co-authored-by: lyingbug <xiayula2014@gmail.com>
2026-09-25 22:22:58 +08:00
wizardchen 22404e92b7 style(files): wrap long test case to satisfy lll 2026-09-25 21:46:12 +08:00
dzc-bit e5a301ed3a
fix(files): accept canonical storage:// paths in bare provider services (#3166)
Signed-off-by: dzc-bit <210145775+dzc-bit@users.noreply.github.com>
Co-authored-by: dzc-bit <210145775+dzc-bit@users.noreply.github.com>
2026-09-25 18:48:04 +08:00
Captain 929dad5747
fix(weaviate): accept a class another worker created first (#3689)
The indexer saves embeddings in batches of 40, up to five at a time,
and every BatchSave calls ensureCollection first. On the first write at
a new dimension each of them can find the class missing and try to
create it. Weaviate lets one create win and refuses the rest with 422:
"class name X already exists" when the loser is filtered before the
Raft apply, or "updating schema: TYPE_ADD_CLASS: class already exists"
when it loses inside the apply. ensureCollection returned either as
"failed to create collection", and the errgroup then failed the whole
document although the class was fine. A replica racing this one takes
the same path.

After a 422, look the class up again and carry on if it exists now,
which does not depend on how the refusal is worded. The class is
created with all of its properties in one call, so there is nothing
left to set up. Other failures are returned as before.

This is the Weaviate side of the race #2855 reports for Qdrant.
2026-09-25 18:47:30 +08:00
wizardchen 8356742dd5 fix(llm): treat cut-off streams as broken and tighten LLM retries
A stream body that ran out without a finish reason (a proxy cutting the
connection) was closed as a clean stop on the Completions, Responses and
Gemini paths, so a half-written answer was stored as complete. It is now
marked incomplete, as the Anthropic path already did, and both the chat
pipeline and the agent treat an incomplete answer as a stream error.

Retry classification checks typed HTTP/transport errors first and matches
status codes as whole numbers, so "max_tokens 5000" no longer reads as a
500. The retry backoff returns as soon as the turn is cancelled.
2026-09-25 18:22:14 +08:00
lyingbug ab115c0944
fix(knowledge): stop parses from getting stuck in processing or finalizing (#3696)
Reparse:
- Open the new attempt only after override validation and cleanup pass.
  A rejected reparse used to leave the previous run's subtasks treating
  themselves as superseded, so the row stayed in finalizing for good.
- Cancel the previous run's queued tasks when it is still in flight.
  ProcessDocument, processChunks, post-process, image tasks, wiki ops and
  the dead-letter callback now skip work that belongs to a superseded
  attempt.
- Summary tasks write only their own columns. A full-row save after the
  LLM call could put finalizing over the new run's processing row.

Errors that were acked with the row still in flight:
- A failed post-process enqueue is retried in place and then returned,
  so the task retries instead of leaving the row in processing.
- Transient tenant/knowledge reads and the processing write now retry.
- An image whose orphan check fails on its final attempt is still
  counted. Empty manual content fails the row.

Counters:
- FinalizeSubtask runs its decrement and promote in one transaction.
  Slot releases retry, and the post-process shortfall release keeps
  going past a failed release.

Wiki:
- A synthesis model that cannot be built releases the KB's pending
  documents on the final attempt instead of retrying forever.
- Panics in map/reduce workers become per-document failures.
- Housekeeping protects a row held by a wiki op for at most 48h.

Lite mode:
- SyncTaskExecutor honours options set on asynq.NewTask (MaxRetry,
  Timeout, Deadline, ProcessIn/At), stops on SkipRetry, and runs the
  same final-failure callback as the dead-letter middleware.
- The multimodal fan-in counter is kept in process, so post-process
  waits for every image.

Also:
- Housekeeping recovers summaries left pending on finished rows. Cancel
  and stall recovery close unfinished summaries.
- Housekeeping sweeps no longer overlap.
- Data source URL ingest writes only the metadata column.
- The document list drops cards the batch endpoint no longer returns.
2026-09-25 13:26:38 +08:00