[Bug]: ckg silently skips source files whose extension is not lowercase, then reports the symbol as not found

Author: sxh313Created Sep 28, 2026Updated Sep 28, 2026

What happened?

The code knowledge graph silently ignores every source file whose extension is not lowercase, and then tells the model the symbol does not exist. A .PY, .JS, .TS or .H file is never parsed, so ckg search_function / search_class / search_class_method return No functions named X found. for code that is plainly in the codebase — a confident false negative, which is worse than an error because the agent stops looking.

The lookup compares Path.suffix, which preserves the case on disk, against a mapping whose 13 keys are all lowercase literals:

trae_agent/tools/ckg/ckg_database.py:539-550

python
        for file in self._codebase_path.glob("**/*"):
            ...
                extension = file.suffix
                # ignore files with unknown extensions
                if extension not in extension_to_language:
                    continue
                language = extension_to_language[extension]

trae_agent/tools/ckg/base.py:40-54

python
extension_to_language = {
    ".py": "python",
    ...
    ".h": "c",
    ...
}

The continue has no log line and no counter, so nothing distinguishes "your file is not a language we parse" from "your file is Utils.PY and I could not read it". CKGTool.get_description even hedges — "The CKG is not completely accurate, and may not be able to find all functions or classes in the codebase" — which makes the model trust the miss.

Reproduction

No server, no key, no network: a temp directory, real tree-sitter parsing, and the CKG cache pointed at that temp directory. Run against main (e839e55), Python 3.12:

extension_to_language keys: ['.c', '.c++', '.cc', '.cpp', '.cxx', '.h', '.hpp', '.java', '.js', '.jsx', '.py', '.ts', '.tsx']
on-disk files: ['a_lower.py', 'a_upper.PY', 'b_lower.py', 'b_upper.PY', 'c_lower.js', 'c_upper.JS']
functions: ['alpha_lower']
classes: ['BetaLower', 'GammaLower']
  search_function(alpha_lower) -> hits=1
  search_function(alpha_upper) -> hits=0
  search_class(BetaLower)      -> hits=1
  search_class(BetaUpper)      -> hits=0
  search_class(GammaLower)     -> hits=1
  search_class(DeltaUpper)     -> hits=0

Each pair is the same grammar with the same content and the same parser language; the only difference is the case of the extension. All three uppercase files were dropped without a word.

Reproducer files, all one-liners:

a_lower.py    def alpha_lower(): return 1     -> indexed
a_upper.PY    def alpha_upper(): return 2     -> dropped
b_lower.py    class BetaLower: pass           -> indexed
b_upper.PY    class BetaUpper: pass           -> dropped
c_lower.js    class GammaLower {}             -> indexed
c_upper.JS    class DeltaUpper {}             -> dropped

Mixed-case extensions are not exotic: legacy and DOS-derived trees carry .PY/.BAS, C/C++ projects use .H headers (and the mapping lists .h as c), and JS/TS trees written on Windows routinely end up with .JS. This box indexes the same bytes fine as soon as the extension is lowercase, so nothing about the parsers is at fault.

What did you expect to happen?

Path.suffix should be normalised before the lookup, so Utils.PY is indexed as Python exactly like utils.py is — the mapping is already keyed in lowercase, so the lookup is the only place the case matters.

Direction

One line in _construct_ckg: extension = file.suffix.lower(). That is the whole fix; the mapping, the visitors and the cache logic stay as they are, and a file with a genuinely unsupported extension is still skipped as it is today.

I checked the two adjacent questions and am deliberately leaving them out of this: (a) whether the skip should say anything at all when a codebase has thousands of unparseable files, and (b) the JavaScript/TypeScript visitors only record class_declaration and method_definition, so a top-level function foo() {} is missing even with a lowercase .js — that second one is a real gap, but it is a different change and partly documented in the module's own "Known issues" note.

Of the open PRs that touch trae_agent/tools/ckg/ckg_database.py (#434 #435 #436 #437 #439 #484), none has an added line containing extension_to_language or file.suffix: #434–#437 rate-limit clear_older_ckg with a module-level timestamp, #439 only adds encoding="utf-8" to the two open(CKG_STORAGE_INFO_FILE, …) calls at :158 and :181, and #484 adds Java/C++ return-type tests. So the file walk is unclaimed.

I'll take this, with a test that indexes the same grammar under both extension cases.