fix: allow documentCount 0 for empty knowledge bases by gokay-ai · Pull Request #19874 · CherryHQ/cherry-studio · GitHub
Skip to content

fix: allow documentCount 0 for empty knowledge bases - #19874

Merged
DeJeune merged 3 commits into
CherryHQ:mainfrom
gokay-ai:cursor/empty-kb-document-count-bb2e
Sep 3, 2026
Merged

DeJeune merged 3 commits into
CherryHQ:mainfrom
gokay-ai:cursor/empty-kb-document-count-bb2e

Conversation

@gokay-ai

@gokay-ai gokay-ai commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Branch strategy

  • Active development targets main.

What this PR does

Thanks — this unblocks listing empty knowledge bases.

Before this PR:

Creating an empty knowledge base stored documentCount=0, but KnowledgeDocumentCountSchema used z.number().int().positive(). GET /knowledge-bases failed Zod validation, so the list never refreshed and stayed broken after restart.

After this PR:

Empty bases with documentCount: 0 pass validation and show up in the list. Negative counts are still rejected.

Fixes #19861

Why we need it and why it was done in this way

The following tradeoffs were made:

None. Empty bases are valid; the schema was just too strict.

The following alternatives were considered:

Coercing stored 0 to undefined on read. The list would then succeed, but it would hide a real persisted value. Allowing non-negative counts (.min(0)) matches storage.

Links to places where the discussion took place: #19861

Breaking changes

None

Special notes for your reviewer

KnowledgeDocumentCountSchema is shared by create/update and the entity/list schemas. .min(0) is the smallest change that lets empty-base list responses parse.

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note

Empty knowledge bases now appear in the knowledge list.

Empty knowledge bases persist documentCount=0. The Zod schema used
.positive(), so GET /knowledge-bases failed validation and the list
never refreshed.

Signed-off-by: GokayAI <60583610+gokay-ai@users.noreply.github.com>

Co-authored-by: GokayAI <gokay-ai@users.noreply.github.com>
Signed-off-by: suyao <sy20010504@gmail.com>
Copilot AI lite review requested due to automatic review settings September 2, 2026 06:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is minimal, aligns validation with persisted data semantics, and includes a focused regression test covering the reported failure case.

Pull request overview

This PR fixes schema validation for knowledge bases by allowing documentCount: 0, which unblocks listing and reloading empty knowledge bases that are valid in storage but previously rejected by Zod parsing.

Changes:

  • Relax KnowledgeDocumentCountSchema from “positive integer” to “integer ≥ 0”.
  • Update existing schema-negative test cases to keep rejecting invalid counts.
  • Add an explicit test that KnowledgeBaseSchema accepts documentCount: 0.
File summaries
File Description
src/shared/data/types/knowledge.ts Changes KnowledgeDocumentCountSchema to accept zero, matching persisted empty-base rows.
src/shared/data/api/schemas/__tests__/knowledges.test.ts Adjusts invalid-count test inputs and adds a regression test for documentCount: 0.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@DeJeune
DeJeune requested a review from eeee0717 September 2, 2026 08:18
Signed-off-by: suyao <sy20010504@gmail.com>
Signed-off-by: suyao <sy20010504@gmail.com>
@DeJeune
DeJeune force-pushed the cursor/empty-kb-document-count-bb2e branch from feb43d6 to c06ed83 Compare September 3, 2026 10:58
@DeJeune
DeJeune merged commit 2771419 into CherryHQ:main Sep 3, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty knowledge base fails documentCount validation and blocks the list

4 participants