#3331·CowAgent

Knowledge graph node paths keep backslashes on Windows, so categories and tree highlighting break

Author: LesereingrapeCreated Sep 29, 2026Updated Sep 29, 2026

Self check

  • I'm on the latest version and searched existing issues (incl. closed) — no duplicate.

Environment

  • Version: master @ 25a44908
  • OS: Windows 11 (the defect is Windows-only by nature, see below)
  • Install: from source, Python 3.11
  • Channel: Web console -> Knowledge -> graph view

What happened?

The knowledge graph view colors its nodes by category and opens a page when you click a node. Both come from KnowledgeService.build_graph(), which builds its path strings with str(...):

  • agent/knowledge/service.py:622 — rel = str(md_file.relative_to(knowledge_path))
  • agent/knowledge/service.py:641 — target_rel = str(resolved.relative_to(knowledge_path))

str() of a relative Path keeps the platform separator, so on Windows a page under knowledge/concepts/ is reported as concepts\rag.md instead of concepts/rag.md. Every other method in the same class already normalizes (.replace(os.sep, "/") at lines 384, 405 and 467, .as_posix() at line 167), which is why only the graph is affected.

Three things break downstream in channel/web/static/js/views/knowledge.js:

  1. category = parts[0] if len(parts) > 1 else "root" — the backslash path has no /, so every nested page is labelled root. The category counts at :803 and the d3 color scale domain that follows them collapse to a single bucket, so the whole graph renders in one color and the legend is wrong.
  2. Clicking a node calls openKnowledgeFile(d.id) (:927), whose tree highlight compares el.dataset.path === path (:702) and whose ancestor expansion returns early unless path.includes("/") (:141). The tree rows are built with /, so on Windows the sidebar never highlights or reveals the page that the graph just opened.
  3. The returned JSON is platform-dependent: the same knowledge base yields different node ids on Windows than on macOS/Linux.

Expected behavior

build_graph() returns /-separated relative paths on every platform, like list_tree() and the document APIs already do.

How to reproduce

python -m pytest tests/test_knowledge_service.py::test_build_graph_resolves_encoded_and_anchored_links -q

on Windows. That existing test already asserts the forward-slash contract, so it fails today:

>       assert ("concepts/health.md", "sources/训练记录 07.md") in edges
E       AssertionError: assert (...) in {('concepts\\health.md', 'concepts\\rag.md'),
E          ('concepts\\health.md', 'sources\\训练记录 07.md')}

The CI test job only runs on ubuntu-latest (.github/workflows/test.yml:16), so nothing catches this there.

Proposed fix: use .as_posix() at both sites, plus a regression test that pins the category, the node ids and their agreement with the file tree.