[Bug]: ckg reports symbols as not found for .hh/.hxx/.tcc, .mjs/.cjs and .mts/.cts files, which the extension table never names
What happened?
ckg reports a symbol as absent when it is in the codebase, because the file that declares it has
an extension that trae_agent/tools/ckg/base.py does not know.
extension_to_language (trae_agent/tools/ckg/base.py:40-54) is the only gate that decides which
files enter the graph. At e839e55 it has 13 keys. It maps five spellings to cpp
(.cpp .hpp .c++ .cxx .cc) and three to javascript/typescript (.js .jsx, .ts .tsx), but it
has none of the other spellings those same three languages use in practice:
| file | language that grammar already supports | in the table at e839e55 |
|---|---|---|
Widget.hh, Vector.hxx, Mask.tcc |
C++ (same grammar as the mapped .hpp) |
no |
Entry.mjs, Legacy.cjs |
JavaScript (same grammar as the mapped .js) |
no |
Config.mts, Module.cts |
TypeScript (same grammar as the mapped .ts) |
no |
The consequence is not an error. CKGDatabase._construct_ckg drops the file without a trace
(trae_agent/tools/ckg/ckg_database.py:546-549):
extension = file.suffix
# ignore files with unknown extensions
if extension not in extension_to_language:
continuenothing records which files were skipped, and ckg_tool then converts the empty result into a
statement to the model (trae_agent/tools/ckg/ckg_tool.py:143):
return f"No functions named {identifier} found."So the agent is told a symbol does not exist, in a codebase where it does, and the tool's answer is indistinguishable from a correct one. That is the expensive part of this bug: the model stops searching, and usually re-writes or re-locates the code from memory instead.
What did you expect to happen?
Every extension that names a language the graph can already walk should reach that language's
visitor. The match language: block in _construct_ckg (ckg_database.py:560-574) handles
python, java, cpp, c, typescript, javascript; the table should cover the standard spellings of
those six, and .hh/.hxx/.tcc, .mjs/.cjs and .mts/.cts are exactly that. No new
grammar, parser or visitor is needed: tree-sitter-languages==1.10.2 already ships cpp,
javascript and typescript, which are the three values the new keys would name.
Traceback
There is none, which is why this is reported as a wrong-answer bug rather than a crash. The build
logs nothing, CKGDatabase returns a normally-populated database, and the query returns [].
What is your system, Python, dependency version?
- OS: Windows 11 (10.0.26200); the code path is pure
pathliband has no platform dependency - Python: 3.12.13
- Dependency Version:
tree-sitter==0.21.3,tree-sitter-languages==1.10.2(both exactly the pins inpyproject.toml:19-20),pytest==8.4.0 - Commit:
e839e559ac61bdd0e057c375dd1dee391fee797d(currentmain)
Additional information that you believe is relevant to this bug
Measured, at e839e55. One temporary codebase of ten files, 24 identifiers: each unmapped
extension is paired with a mapped twin of the same language and the same shape, so a miss can only
be explained by the extension. The fixture contains only classes and their methods (plus free
functions in the C++ files), which every current visitor already handles, so nothing here overlaps
the separate JavaScript/TypeScript function-declaration gap of #514. The same tree was indexed
twice, the only difference being the seven table entries:
extension_to_language |
files that reached the graph | identifiers found |
|---|---|---|
the 13 keys at e839e55 |
3 (Config.ts, Entry.js, Widget.hpp — the twins only) |
7 / 24 |
those 13 plus .hh .hxx .tcc .mjs .cjs .mts .cts |
10 | 24 / 24 |
All 17 recovered identifiers are invisible today and present after the change, with correct spans:
Widget.hh gives hh_free at 1-3, HhClass at 5-10 and hh_method at 7-9; Vector.hxx and
Mask.tcc behave identically; MjsClass/mjsMethod, CjsClass/cjsMethod,
MtsClass/mtsMethod and CtsClass/ctsMethod land on 1-5 and 2-4 in their files. The residue
after the change is zero.
These are not exotic spellings. Verified through GitHub code search
(search/code?q=extension:<ext>+repo:<owner>/<repo>, counts are approximate but the paths are
exact): extension:cjs repo:nodejs/node → 168, extension:mjs repo:vitejs/vite → 22,
extension:mts repo:microsoft/TypeScript → 10, extension:cts repo:microsoft/TypeScript → 1. For
C++, search/code?q=extension:hh+language:C++ returns e.g. goldendict/goldendict :: ex.hh,
extension:hxx+language:C++ returns Taywee/args :: args.hxx and resiprocate/resiprocate :: p2p/p2p.hxx, and extension:tcc+language:C++ returns VcDevel/Vc :: Vc/sse/vector.tcc (the same
spelling libstdc++ uses for its template definitions).
Relation to the two adjacent ckg reports. #510 is a different defect on a different line: the
table keys are all lowercase, so a file spelled Utils.PY is skipped even though .py is present —
fixed in #511 by lowercasing the suffix, which does not add any key. #514 is about named
JavaScript/TypeScript function declarations, which the JS/TS visitors do not index at all; the
measurement above therefore contains no JS/TS free functions, so the two reports cannot be confused
by it. This report is the missing keys, and its fix is seven lines in base.py; no file that #511
or #514 touches is involved.
One ambiguity this fix inherits rather than introduces. .hh is also the source extension of
Hack (HHVM). The table already resolves exactly this kind of collision: .h is mapped to c at
base.py:49, although .h is a C++ header in every C++ codebase too, and ckg has no Hack
grammar. A Hack codebase is unindexed today and would be walked with the C++ grammar after this —
the same trade-off the existing .h entry already makes, which is worth a conscious "yes" from a
maintainer rather than a silent default.
Source: bytedance/trae-agent