Commit Graph

3362 Commits (de2dfd3034a7b506fa269910401bbdcbd4efc71d)

Author SHA1 Message Date
Wen.Vale de2dfd3034
fix(multimodal): bound remote image downloads by the file size limit (#3906)
* fix(multimodal): bound remote image downloads by the file size limit

* style(utils): wrap over-long lines in the DownloadBytes test

---------

Co-authored-by: Wen.Vale <224270013+SEVEN-us@users.noreply.github.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-08 13:14:04 +08:00
SIRIUS 49e262147c
fix(cli): preserve directory structure in doc upload --recursive (#3753)
* fix(cli): preserve directory structure in doc upload --recursive

`doc upload --recursive` passed an empty customFileName to
CreateKnowledgeFromFile, so every file landed in the knowledge base root
and the directory tree it was asked to walk was lost. The web UI's folder
upload does not have this problem -- it passes the browser-supplied
relative path, which the server splits into folder_path + file_name via
types.SplitKnowledgeRelativePath.

Pass the path relative to the walked directory instead. Files directly
under that directory still send "" so the request stays byte-identical to
the previous behaviour for the common flat-directory case; only nested
files gain a folder prefix.

- knowledgeRelativePath() converts to forward slashes (the server splits on
  "/", so Windows backslashes would not separate) and returns "" for paths
  outside the walked root rather than leaking a "../" chain into the folder
  tree.
- The test double previously discarded customFileName with `_,` -- which is
  why this could regress with the suite green. It now records the value and
  two tests cover the nested and flat cases.

* fix(cli): reject only the parent component in knowledgeRelativePath

Review feedback on the recursive-upload folder path:

- `strings.HasPrefix(rel, "..")` also rejected children whose name merely
  starts with dots, e.g. `..drafts/report.pdf`. Replaced with a
  component-wise check (`rel == ".."` or `".."+separator` prefix).
- Root-level files must send ""; the guard now returns "" for
  `filepath.Dir(rel) == "."` explicitly rather than relying on the
  accidental prefix match to encode that rule.

Covered by a `..drafts/report.pdf` case in
TestUploadRecursive_PreservesFolderStructure.

* test(cli): expect an empty name for root files in knowledgeRelativePath

knowledgeRelativePath returns "" for files directly under the walked
root, so the test must expect that. Also wrap an over-long line.

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-08 13:13:57 +08:00
LingYi e6ecb9adcc
fix(dataset): allow selecting the QA answer model (#3944)
* fix(dataset): allow selecting the QA answer model

* test(dataset): expect gpt-5.6-sol as the default QA model

The default moved from gpt-4o-2024-05-13 to gpt-5.6-sol on main (#3965).

---------

Co-authored-by: LingYi-Liang <270316896+LingYi-Liang@users.noreply.github.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-08 13:04:49 +08:00
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
MLYoshi 4dd19b5356
fix(frontend): render single tilde literally instead of GFM strikethrough (#3963)
* fix(markdown): 单个波浪号不再被解析成删除线

GFM 会把区间标记(如 2020~2035)里的单个 `~` 误解析成删除线。
覆盖 marked 的 del tokenizer:`~~...~~` 仍走默认删除线规则,
单个 `~` 则按字面保留;并新增单测覆盖时间/区间场景。

* fix(markdown): register the literal single-tilde tokenizer once

doc-content.vue and WikiBrowser.vue called marked.use() for the del
tokenizer override inside <script setup>, so every mount wrapped the
global marked tokenizer one more time. Move the extension into
utils/markedLiteralTilde.ts and register it on the global marked behind
a once-only guard; the preview Marked instance reuses the same
extension object. Add a test that repeated registration does not
re-wrap tokenizer.del.

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-08 13:04:36 +08:00
Perfecto 336f84c3be
fix(data-analysis): skip style-only worksheets before DuckDB loading (#3660)
* fix(data-analysis): skip style-only worksheets before DuckDB loading

* chore: retrigger CI for XLSX sheet fix

* fix(data-analysis): keep all sheets when the worksheet preflight fails

The style-only sheet preflight is best-effort: if it cannot read the
workbook parts, log a warning and load the sheets DuckDB enumerated
instead of failing the whole workbook. Context cancellation still
aborts the load.

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-08 13:04:29 +08:00
Lukas e7aaf8ae02
fix(docreader): keep the space held by a whitespace-only inline element (#3978)
markdownify renders an emphasis, code or link element whose text is only
whitespace as "", and the whitespace goes with it. HTML and MHTML
uploads therefore lost word boundaries: `further<strong> </strong>
reference` became `furtherreference`, and `<b>First</b><b> </b><b>Last</b>`
became `**First****Last**`. Editors produce that markup whenever a single
space between two words carries different formatting.

Before conversion, unwrap such elements so their whitespace stays as plain
text. Only elements with no child elements are touched, innermost first,
so a linked image keeps its link and nested wrappers come off completely.
2026-10-08 01:31:48 +08:00
linus-liu-web dabbdaf156
fix(notion): 分页循环补重复游标防护与跳数上限 (#3890)
paginatePages 与 GetBlockChildrenFlat 都只以 has_more / 空 next_cursor 为终止
条件:既不记录用过的游标,也没有页数上限。Notion(或中间网关)只要回
has_more=true 且 next_cursor 不前进——包括"空 results + has_more=true"这种厂商
形状——循环就永远退不出来,同一页被反复抓取:SearchPages(资源发现)与
QueryDatabaseAll(数据库记录)都汇入 paginatePages,客户端自带 3 req/s 限流,
所以表现为以 3 rps 稳定空转到任务 deadline,同步任务永不进终态;若伴随非空
results,allPages 还会无界增长。

同文件的 getBlockChildrenRecursive 已有 maxBlocksPerPage 兜底,Confluence
(seen + maxPaginationHops)、DingTalk(seenTokens + maxPages)也有同族守卫,
这两条循环漏了。

改动:
- 抽一条 advancePaginationCursor:每页取回 next_cursor 后调用,重复游标立即报
  错,页数达到 maxPaginationHops(10000,对齐 Confluence)时 Warn 并报错。触顶
  必须留日志:从外部看这种失败和"还在正常同步"一模一样。
- paginatePages 与 GetBlockChildrenFlat 一并接入(同文件同型缺陷,发现阶段扫子
  页面走的正是后者)。

新增用例:重复游标(第 2 次请求即报错,含"空页 + has_more=true"形态)、跳数上限
(正好 10000 次请求后报错且日志含 "pagination exceeded 10000 pages")、真实多页
仍正常合并。测试把 3 rps 限流换成不限速,否则回归场景要跑 55 分钟。去掉本次改动
后三条用例全部失败(重复游标场景实测跑到 10006 次请求才被假服务器的预算拦下)。

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-08 01:29:20 +08:00
linus-liu-web 5077f35800
fix(notion): 超过 block 上限截断时补 Warn,避免内容与子页面静默缺失 (#3771)
* fix(notion): 超过 block 上限截断时补 Warn,避免内容与子页面静默缺失

单个页面/块超过 maxBlocksPerPage(1000) 时客户端会静默停止分页:第 1000
个 block 之后的正文不会进入 markdown,其后的 child_page/child_database
也不会被 fetchPage 递归同步。又因为游标记录的是 last_edited_time,页面
未变更时同步会直接跳过该页,截断因此长期存在且无任何提示。飞书同类上限
(feishu/core/blocks.go 的 maxDocumentBlocks)已有 Warn,这里对齐其措辞
补齐可观测性。

- cap 触发且 API 仍有下一页时打一条 Warn,含块/页面 ID 与上限数字,说明
  剩余 block 不会被同步;是否真为截断由纯函数 blocksTruncated 判定,恰好
  1000 个 block 的页面不会误报;
- 不改 cap 数值、page_size、递归逻辑与游标语义。

测试 truncation_test.go:伪造返回 1001 个 block 的 children 接口,断言
Warn 内容且第 11 次请求未发出;另覆盖恰好 1000 的边界与 blocksTruncated
真值表。

* fix(notion): has_more 但 cursor 为空时不再静默丢内容

blocksTruncated 的第三个条件 nextCursor != "" 在 Notion 契约下与 has_more
冗余:has_more=false 时 next_cursor 必为 null。于是"has_more=true 但
next_cursor 为空"这种异常响应仍会静默截断——未命中 cap 时循环本就因空游标
break,命中 cap 时又因该条件跳过 Warn,两种情况都不留痕迹。

- 谓词收敛为 currentCount >= maxBlocksPerPage && hasMore,不再要求游标非空:
  cap 命中且 has_more=true 即视为截断;
- has_more=true 而 next_cursor 为空时单独打一条 Warn,带上块 ID 与已取块数,
  说明无法继续翻页、剩余内容不会被同步(无论是否命中 cap 都打);
- 不改 cap 数值、break 条件、page_size、递归深度与游标语义。

测试:真值表去掉游标列,并删掉把"cap 命中 + 空游标 = 不告警"固化成期望的
用例;新增 TestBlockCapWarnsWhenHasMoreHasNoCursor(cap 命中 + has_more=true
+ 空游标须同时出现 cap Warn 与游标 Warn,且不发出第 11 次请求)与
TestHasMoreWithoutCursorWarnsBelowTheCap(cap 以下同样要告警);原有正常翻页
用例补断言:格式正确的分页不得出现游标异常 Warn。反向验证:谓词还原为原样
后两个新用例均失败。

* test(notion): rename block-cap log helper to avoid clashing with #3845

---------

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-08 01:29:12 +08:00
ordinary being 6057a81017
fix(middleware): stop buffering whole request bodies in the access log (#3927)
Logger() runs ahead of Auth and of every route handler, and read the entire
request body with io.ReadAll before any per-route http.MaxBytesReader was
installed. Bound the read to the log budget and hand the unread remainder back
to the handler through io.MultiReader.
2026-10-08 01:29:05 +08:00
kevin 20038cbda6
fix(asynqdl): truncate dead-letter errors on a rune boundary (#3964) 2026-10-08 01:28:59 +08:00
Fei.Chen dad81cb8c1
fix(sandbox): reclassify exec races with the idle sweep as NotFound so rebinding heals (#3980)
An exec that collided with the idle sweeper's delete (#3942 mechanism A)
surfaced as a non-zero exit with an empty stderr, which the filesystem op
wrappers classified as InvalidRequest — outside CanReplaceRemoteBinding's
NotFound/Terminal allow-list, so the rebinding self-heal never ran and the
failure reached the user (empty answer, zero steps). The op wrappers now
re-inspect on failure and reclassify as NotFound when the Engine confirms
the container is gone, making the sweeper's 'deleting needs no coordination
with the binding store' premise hold for the mid-flight window too. Only a
confirmed 404 reclassifies; transport errors keep the original kind.

The shared message now carries the exit code — with an empty stderr it was
the one missing clue during the original diagnosis (#3942).

Co-authored-by: vicfei <vicfei@users.noreply.github.com>
2026-10-08 01:28:53 +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
fhgffy 562127c654
fix(client): accept optional spaces in SSE event fields (#3975) 2026-10-08 01:28:38 +08:00
LeonSGP b413023d28
fix(cli): classify wrapped SDK HTTP errors correctly (#3992) 2026-10-08 01:28:31 +08:00
LeonSGP ff33184433
fix(cli): preserve integer precision in jq output (#3991) 2026-10-08 01:28:25 +08:00
LeonSGP cefd5920f8
fix(cli): apply list limits after filtering and sorting (#3990) 2026-10-08 01:28:19 +08:00
LeonSGP 7d75ce3a6f
fix(client): make multipart uploads replayable (#3989) 2026-10-08 01:28:12 +08:00
dvd233 4a0c7fa91f
fix(cli): render paginated API results in text mode (#3984) 2026-10-08 01:28:05 +08:00
dvd233 4ea94afcb9
fix(cli): propagate paginated response read errors (#3983) 2026-10-08 01:27:58 +08:00
xxxxx 9d4cc233c6
feat(ui): add search to Skills and MCP toolbox lists (#3731) 2026-10-08 01:27:51 +08:00
VictorMaznyuk 3206e15e83
fix(docs): make `make docs` reproduce the committed Swagger again (#3751)
Running `make docs` on main no longer reproduces the committed docs/*:
every definition loses its package-qualified name (types.* instead of
github_com_Tencent_WeKnora_internal_types.*), enums disappear, ErrorCode
becomes a plain integer, and docs/swagger_contract_test.go fails
(TestModelDeleteUsageContract).

Cause: internal/localsandbox is not a dependency of cmd/server (its
importers are behind the `desktop` build tag), but swag's directory walk
reaches it. Its `const X = core.X` aliases make swag load
internal/localsandbox/core again through go/loader, and that second load
re-registers every already-deduplicated type under its short name without
enum values. Excluding the directory removes the second load.

That load was also hiding a second problem: skill_handler.go references
errors.AppError in @Failure without importing internal/errors, so with the
exclude swag stops with "cannot find type definition: errors.AppError".
A blank import lets swag resolve it.

Co-authored-by: Victor Maznyuk <victor@maznyuk.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-08 01:26:08 +08:00
dependabot[bot] 11bfacad97
chore(deps): bump the cli-deps group in /cli with 2 updates (#3920)
Bumps the cli-deps group in /cli with 2 updates: [github.com/mattn/go-runewidth](https://github.com/mattn/go-runewidth) and [github.com/modelcontextprotocol/go-sdk](https://github.com/modelcontextprotocol/go-sdk).


Updates `github.com/mattn/go-runewidth` from 0.0.28 to 0.0.30
- [Commits](https://github.com/mattn/go-runewidth/compare/v0.0.28...v0.0.30)

Updates `github.com/modelcontextprotocol/go-sdk` from 1.7.0 to 1.8.0
- [Release notes](https://github.com/modelcontextprotocol/go-sdk/releases)
- [Commits](https://github.com/modelcontextprotocol/go-sdk/compare/v1.7.0...v1.8.0)

---
updated-dependencies:
- dependency-name: github.com/mattn/go-runewidth
  dependency-version: 0.0.30
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cli-deps
- dependency-name: github.com/modelcontextprotocol/go-sdk
  dependency-version: 1.8.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: cli-deps
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-10-08 01:26:00 +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
洛根 c0c194f625
fix(im/wecom): preserve image in mixed messages with text captions (#3901)
* fix(im/wecom): preserve image in mixed messages with text captions

convertMixedMessage discarded the image whenever a mixed (text+image)
message contained any text, so the most common shape — a question plus
a screenshot — reached the QA pipeline as text-only and the model never
saw the image, despite the IM integration docs promising images are
handled as QA attachments.

Keep the first image as the message attachment and carry the text as
its caption: the IM service already supports captioned images
(prepareIMAttachments downloads the file while fileMessageQAContent
preserves msg.Content as the query), so the adapter just has to emit
MessageTypeImage with Content set instead of MessageTypeText.

Text-only, image-only, and empty mixed messages keep their previous
behavior. Multiple images still collapse to the first one; supporting
several attachments requires a multi-attachment IncomingMessage and is
left out of this minimal fix.

* fix(im/wecom): wrap over-length line in mixed_test to satisfy lll lint
2026-10-08 01:25:25 +08:00
KennySimpson 69a7fd9931
fix(mcp): close legacy chat responses on HTTP errors (#3930) 2026-10-08 01:25:18 +08:00
Wu Shuwen e8cc9c763e
fix(mcp): include shared knowledge bases in endpoint scope (#3848) 2026-10-08 01:25:11 +08:00
Captain 172d0a85ab
fix(mcp): pass embedded resources in tool results to the agent (#3766)
CallTool kept only text and image content from a tool result. A tool
can also return audio, a link to a resource, or a resource embedded in
the result, and GitHub's MCP server returns files that way:
get_file_contents answers with a short message and the file as an
embedded resource. The agent only ever saw the message.

Convert audio, embedded resources (text or blob) and resource links,
recording the resource URI. The agent now follows the reference to a
text resource with its text, and shows links and binary resources as
references. Base64 data of any kind, not only images, is redacted from
the logged content items.
2026-10-08 01:25:04 +08:00
Captain 28734725a3
fix(mcp): reconnect after the server forgets the session (#3765)
On a session-based protocol version, a server answers a request for a
session it no longer knows, after a restart or when the session expired,
with 404, and the spec has the client start a new session. mcp-go
reports it as transport.ErrSessionTerminated. checkErrorAndDisconnectIfNeeded
only looked for two error messages some servers send, so the client
stayed connected and GetOrCreateClient kept handing out the dead
session: every call to the service failed until WeKnora restarted.

Disconnect on ErrSessionTerminated too, so the next use reconnects.
2026-10-08 01:24:57 +08:00
Captain f559473498
fix(mcp): keep the client secret from dynamic client registration (#3763)
StartAuthorization stored only the client ID from dynamic client
registration. When the authorization server registers a confidential
client and returns a client secret, the secret was lost: the callback
rebuilds the OAuth handler from the stored client, so the code exchange,
and every later refresh, went out without it and the server rejected
them as invalid_client.

Store the secret along with the ID. The model already has the column,
encrypts it on save, and both handlers read it back.
2026-10-08 01:24:51 +08:00
林SO 412ce63f0b
fix(chat): clear stale file and tool selections on session restore (#3802)
Signed-off-by: 林SO <142557582+Linxiushen@users.noreply.github.com>
2026-10-08 01:24:43 +08:00
linus-liu-web e394c7adec
fix(agent): 工具自起 goroutine 的 panic 自行兜底,MCP 预热不再带走进程 (#3846)
recover 只对调用它的那个 goroutine 生效。executeRecovered(registry.go)覆盖的是
tool.Execute 这次调用本身,act.go 的 errgroup 回调同理:工具自己起的 goroutine 上
发生 panic,两处都接不到,整个进程退出,正在进行的对话、上传、同步全部中断。

修复站点:
- mcp_exposure.go 的 catalog 预热 goroutine 与最多 8 个 worker 各装一道屏障;worker
  内按服务再兜一层,panic 时沿用文件里既有的 store/status 机制把该服务标记为
  "error"(与加载报错同一个状态)、清掉 partial snapshot,close(preloadDone) 照常
  执行,prepareMCPToolsWithMode 的 select 仍能返回。
- search_knowledge.go 检索扇出的三处 goroutine(embedding 分组、合并 KB 检索、单 KB
  检索):panic 记日志后按既有的 fail() 机制把对应知识库报成失败,工具调用降级为
  失败结果而不是进程退出。
- think.go 的 stream stall 看门狗改用同一屏障(stallTimeout 非正时 NewTicker 会 panic)。

新增 internal/agent/tools/goroutine.go:
- GoRecovered(ctx, fn):起 goroutine 并兜住 panic,供工具内部统一使用;
- RecoverGoroutine(ctx, label, onPanic):defer 形式,onPanic 在同一 goroutine 上记录
  失败单元,panic 值不外传。
registry.go 的 executeRecovered 注释补上"recover 只覆盖本 goroutine,工具自起的
goroutine 必须自己兜底"。

回归测试:
- TestMCPPreloadWorkerPanicIsContained:loader panic 后进程存活、PrepareMCPTools 正常
  返回、该服务 status 为 error 且不保留缓存工具;
- TestMCPPreloadFailureMarkingKeepsReadySnapshots:协调者屏障只标记未完成的加载,
  ready 快照不动;
- TestToolChildGoroutinePanicDegradesToFailedResult:走真实 executeToolCallsParallel,
  子 goroutine panic 降级为失败结果;
- TestGoRecoveredContainsPanicAndRunsDefers / TestRecoverGoroutineReportsPanicToCaller。

去掉屏障后上述用例的测试进程 exit=1,装回后全部通过。

Fixes #3837

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-08 01:24:36 +08:00
诉说晚秋 fa4f85d3dd
fix(agent): 拒绝将断流摘要保存为记忆检查点 (#3994) 2026-10-08 01:24:30 +08:00
澍 52893006ad
fix(agent): validate tool string lengths by Unicode code points (#3937)
Fixes Tencent/WeKnora#3935
2026-10-08 01:22:18 +08:00
诉说晚秋 f6119ae5fd
fix(agent): 保留数据分析 SQL 字符串字面量 (#3812) 2026-10-08 01:22:11 +08:00
tsumon 188d9026d8
fix(models): honor OpenRouter native thinking for legacy defaults (#3807) 2026-10-08 01:22:04 +08:00
linus-liu-web 9de0946e53
fix(docparser): anydoc 内嵌 EMF/WMF 图片的扩展名与 Rust 侧对齐 (#3938)
anydoc 把内嵌图片就地渲染成 `![alt](images/image-N<ext>)`,`<ext>` 来自
asset_links.rs::extension_for;ImageResolver 再拿这个字符串去一张 map 里查,
键是 anydoc.ImageDir + Asset.Name,而 Name 由 backend_cgo.go::extensionFor 拼出。
查表是精确匹配,两边必须逐字符一致。

EMF/WMF 上两边并不一致:anydoc 对这两类 part 硬编码产出 image/emf 与
image/wmf(shared/assets.rs::media_type_for、shared/officeart.rs),Rust 表
落到 `.bin`,而 Go 侧去查平台 MIME 注册表——在装了 media-types 的 Debian
镜像上拿到 `.emf`/`.wmf`。链接与 ref 于是永远对不上,saveReferencedImage
找不到条目,图片字节从不落盘,且没有任何日志。

- asset_links.rs::extension_for 补 image/emf 与 image/wmf
- backend_cgo.go::extensionFor 补同样两项,并改成纯查表

去掉 mime.ExtensionsByType 是有意的:让扩展名取决于宿主的 /etc/mime.types
正是这个 bug 的成因,何况这张表本来就要和 Rust 的静态表逐字符对齐。未知
类型两边都落到 .bin,仍满足「不写出无扩展名 blob」的原意。

新增 TestEmbeddedVectorImageLinksResolve:在内存里构造一个含一张 EMF 与
一张 WMF 的最小 docx,转换后要求每一条 Markdown 图片引用都能在 resolver
建的 ImageRef 表里命中,并固定扩展名为 .emf/.wmf(避免两边一起退化成
.bin 也能通过)。

Co-authored-by: linus-liu-web <linus-liu-web@users.noreply.github.com>
2026-10-08 01:21:57 +08:00
Lukas c9723b1198
fix(docreader): read EPUB chapters in spine order (#3977)
EPUBParser took the chapter order from book.get_table_of_contents(),
which ebooklib's EpubBook does not have. The AttributeError was caught,
so every book fell through to get_items(), which follows the manifest.
The manifest may list files in any order; the spine is the reading order.
Standard Ebooks' Pride and Prejudice, for example, lists its title page
and imprint after chapter 61 in the manifest.

Read the documents in spine order, followed by any the spine leaves out
in manifest order, so the set of documents read is unchanged.
2026-10-08 01:21:50 +08:00
linus-liu-web a6c6c35ad2
fix(ima): 三条游标分页循环补重复游标防护与跳数上限 (#3889)
ListResources 的两条循环(get_addable_knowledge_base_list、search_knowledge_base
兜底)与 listAllKBFiles 的 get_knowledge_list 循环都只以 is_end / 空 next_cursor
为终止条件:既不记录用过的游标,也没有跳数上限。厂商只要回 is_end=false 且
next_cursor 不前进,循环就会一直请求同一页,bases / out 随迭代重复增长,直到任务
deadline —— 资源选择器接口不返回,同步任务永远不进终态。

同族的 DingTalk(seenTokens + maxPages)、Confluence(seen +
maxPaginationHops)、飞书(seenPageTokens)都已有守卫,本包漏了。

改动:
- 抽一条 nextPageCursor:每页取回 next_cursor 后调用,重复游标立即返回错误(不再
  重试),页数达到 maxPaginationHops(10000,对齐 Confluence)时 Warn 并报错。
  触顶必须留日志:从外部看这种失败和"还在正常同步"一模一样。
- 三条循环按同一写法接入;listAllKBFiles 的守卫错误补上 get_knowledge_list 前缀。
- 假 IMA 服务器支持覆盖某个 action 的分页字段(固定游标 / 每次换新游标 / 有限页数 /
  每次换 payload / 请求预算),并给"无防护时会空转"的场景设请求上限,使回归用例失
  败而不是挂死。

新增用例:三条循环的重复游标(都在第 2 次请求即报错)、跳数上限(正好 10000 次
请求后报错且日志含 "pagination exceeded 10000 pages")、真实多页仍正常合并。
去掉本次改动后这四条用例全部失败(重复游标场景实测跑到 10006 次请求才被假服务器
的预算拦下)。

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-08 01:21:44 +08:00
linus-liu-web a2aeb97a01
fix(gitlab): 分页循环补重复页防护与跳数上限 (#3841)
projects() 与 tree() 只依据服务端返回的 X-Next-Page 判断是否继续,
该值重复或不前进时循环不会结束:同一页被反复请求、结果切片持续
增长,只能等上层 context 到期。

两条循环改用 trackPage:页码已请求过即返回错误,不静默当作读完;
页数达到 maxPaginationHops 时记警告并返回错误。正常翻页路径不变。

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-08 01:21:37 +08:00
linus-liu-web b5c74b2dd6
fix(feishu): 多维表格字段分页补重复 page_token 防护与条数上限 (#3840)
内嵌多维表格的 list-fields 分页循环只判断 has_more 与 token 是否为空:
厂商在 has_more=true 时返回已读过的 page_token,循环就会反复请求同一页并把
同一批字段重复追加进 cols,直到任务 deadline(实测 2s 内 5 万余次请求仍未
返回)。该循环也是同文件里唯一既无去重、又无尺寸上限的分页循环。

- 按同库 wiki 空间/节点与云盘分页已有写法加 seenFieldPageTokens 集合,重复的
  非空 token 立即返回 error,不再静默当作读完;
- 补 maxBitableFields = 5000 的条数上限,命中时 Warn 并截断。

测试:重复 token 在第二次出现时报错并停止请求;厂商每页都返回新 token 时在
第 5000 个字段处停止并打 Warn;正常 100 条/页 分页不受影响。

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-08 01:21:31 +08:00
LuckVd 0d3a053eb6
fix(yuque): don't acknowledge failed detail fetches in the incremental cursor (#3702)
A partial sync recorded each doc's new content_updated_at before fetching
its detail. When a detail request failed after client retries, the cursor
still held the new version, so every later incremental sync treated the
doc as unchanged and never re-fetched it (mixed success/failure batches
persist the cursor; only all-failed batches are aborted).

Rewind the cursor entry to the previously synced version (existing docs)
or drop it (new docs) on detail failure so recovery re-syncs the doc.
Deletion detection is unaffected: currentDocs is set at listing time.

Fixes #3690

Co-authored-by: LuckVd <LuckVd@users.noreply.github.com>
2026-10-08 01:21:23 +08:00
Lukas 98feef38de
fix(chunker): count an escaped pipe as cell text when matching table widths (#3979)
The header tracker compares a row's column count with the active table
header's to tell a new table from more rows of the same one.
tableRowColumnCount split rows on every `|`, so a cell holding an escaped
pipe (`\|`, which GFM writers such as anydoc emit for a pipe in a cell)
counted as one more column. The tracker took that row for the start of a
new table and dropped the header, so the chunks after it no longer began
with the column names.

Split rows on unescaped pipes only. A pipe after an odd run of
backslashes is text inside the cell, as in GFM.
2026-10-08 01:21:16 +08:00
Yeager0204 e915adb147
fix(chunker): preserve source offsets for table child chunks (#3969)
Co-authored-by: kwsYegar <331533331+kwsYegar@users.noreply.github.com>
2026-10-08 01:21:08 +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
Perfecto a8c291c6ff
fix: keep failed data-analysis table loads retryable (#3745) 2026-10-08 01:20:48 +08:00