You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(ai): rag chunks stay under the embedder's real token limit, not a four-characters-per-token estimate #1300
priority/p2-mediumPriority P2: standard workscope/aiAI review pipeline, personas, prompts, LLM client, or RAGtype/bugType bug: the code does not do what it must
Copilot thread 6 on #1283, verified at 61f9b67. Chunks are bounded at 8,192 estimated tokens using four characters per token [code: src/devops_cli/ai/rag/chunker.py:26]. Text made of short identifiers or punctuation can exceed the embedding model's real limit and fail indexing. For v0.2.28, #1296 only corrects the wording. Note that context_budget.count_tokens uses gpt-4o's tokenizer, not the embedder's.
Acceptance criteria
Chunk boundaries are decided with a tokenizer that matches the configured embedding model, or with a documented, safe bound for it, and the duplicate estimate_tokens goes. A test with dense punctuation stays under the limit.
The 2026-10-08 comment folds the chunker refactor in: code chunks on ai/ast spans, YAML per document, Markdown on markdown-it headings, and _LANGUAGE_PATTERNS, _C_LIKE_PATTERN, _chunk_by_regex_symbols and the wrappers (ai/rag/chunker.py:79-486) go.
Folded here instead of a new issue: the agent filing quota (#1153) is spent for this cycle, and this refactor shares this item's change surface. It is recorded here in full so it is not lost.
refactor(ai): the rag chunker splits code on ai/ast's tree-sitter symbols, YAML on PyYAML nodes and markdown on markdown-it headings
Problem
Checked at release/v0.2.29 (05e9388). The RAG chunker (ai/rag/chunker.py) finds structure with regexes and line prefixes, although the parsers it needs are already dependencies.
Code. Go, Rust, TypeScript, JavaScript, Terraform and HCL, SQL and every C-like language are split on line-anchored regexes (_LANGUAGE_PATTERNS and _C_LIKE_PATTERN, :79-158; _chunk_by_regex_symbols, :486).
They miss indented definitions, such as a Rust fn inside an impl block or a TypeScript class method, and multi-line signatures.
They match symbol-like lines inside block comments and strings.
YAML. Chunk symbols come from lines starting with kind: and name: (:571-574), so a nested name: becomes a symbol. PyYAML is a direct dependency.
Markdown. Sections start at lines matching ^(#{1,4})\s+(.+)$ (:605), so a # comment line inside a fenced code block starts a section. markdown-it-py is a direct dependency, already used at release/changelog_fragments.py:126 and roadmap/close.py:131.
Proposed remedy
Code: chunk on the PolyglotSymbol spans that ai/ast returns, for every language it parses. A language without a grammar falls back to line windows, not a regex table. Delete _LANGUAGE_PATTERNS, _C_LIKE_PATTERN, _chunk_by_regex_symbols and the per-language wrappers (_chunk_go, _chunk_rust, _chunk_js_ts, _chunk_c_like, _chunk_terraform, _chunk_sql).
YAML:yaml.compose_all with the safe loader. Each document is one chunk; its symbols come from the document's top-level kind and metadata.name nodes and its lines from the nodes' marks.
Markdown: sections come from the map line ranges of the heading tokens MarkdownIt("commonmark").parse returns. This is one public function, so the docs ingester can share it.
AsciiDoc and reStructuredText keep line windows; no dependency parses them.
Does the change need a re-index? (proposed) Yes. Chunk boundaries and ids change, so the changelog fragment tells users to run devops ai rag index --force.
Acceptance criteria
A table test per language with a grammar: an indented definition (a Rust fn in an impl, a TypeScript class method), a multi-line signature and a symbol-like line inside a block comment give the chunks tree-sitter reports. The indented-definition and comment rows fail on the current code.
A Markdown file whose fenced code block contains # comment lines gets no section boundary inside the fence. The test fails on the current code.
A two-document YAML file with a nested name: gives one chunk per document, whose symbols are the top-level kind and metadata.name only. The test fails on the current code.
A Hypothesis property test feeds generated input to each chunker and checks that it never raises and that every chunk's line range lies inside the file.
rg -n '_LANGUAGE_PATTERNS|_C_LIKE_PATTERN|_chunk_by_regex_symbols' src prints nothing.
The tests are pure parsing: offline, with no fakes and no patches.
Each new or changed test runs in under 1 s.
changelog.d/<n>.md records the change; CHANGELOG.md is not edited.
uv run devops ci passes.
(person-run) After devops ai rag index --force, devops ai rag query for a Rust impl method and a TypeScript class method returns the method's chunk.
Linked: #540, which settles one language classifier; this item chunks on ai/ast spans but picks the language with the scanner's, so it builds on #540's answer. Found by the 2026-10-08 backlog review.
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
Priority: P2-Medium. It causes indexing failures for certain text patterns but is an edge case rather than a total outage, and no security advisory or failed CI run is cited.
Value: Medium. Fixes a real correctness bug that breaks RAG indexing for text with short identifiers or dense punctuation, but only affects a subset of inputs.
Effort: High. Beyond swapping the estimator, the refinement requires a full per-language chunker rewrite, removal of legacy regex chunking, and Hypothesis property tests.
priority/p2-mediumPriority P2: standard workscope/aiAI review pipeline, personas, prompts, LLM client, or RAGtype/bugType bug: the code does not do what it must
Activity
dan-petty commentedon Oct 8, 2026
Folded here instead of a new issue: the agent filing quota (#1153) is spent for this cycle, and this refactor shares this item's change surface. It is recorded here in full so it is not lost.
refactor(ai): the rag chunker splits code on ai/ast's tree-sitter symbols, YAML on PyYAML nodes and markdown on markdown-it headings
Problem
Checked at release/v0.2.29 (05e9388). The RAG chunker (
ai/rag/chunker.py) finds structure with regexes and line prefixes, although the parsers it needs are already dependencies._LANGUAGE_PATTERNSand_C_LIKE_PATTERN,:79-158;_chunk_by_regex_symbols,:486).fninside animplblock or a TypeScript class method, and multi-line signatures.ai/ast/engine.pyreturns symbols with spans (parse_code,:471;parse_file,:519). fix(ai): polyglot outlines parse with tree-sitter, token estimates match the outline, and ast commands check size first #959 moved outlines onto it; the chunker did not follow.kind:andname:(:571-574), so a nestedname:becomes a symbol. PyYAML is a direct dependency.^(#{1,4})\s+(.+)$(:605), so a#comment line inside a fenced code block starts a section. markdown-it-py is a direct dependency, already used atrelease/changelog_fragments.py:126androadmap/close.py:131.Proposed remedy
PolyglotSymbolspans thatai/astreturns, for every language it parses. A language without a grammar falls back to line windows, not a regex table. Delete_LANGUAGE_PATTERNS,_C_LIKE_PATTERN,_chunk_by_regex_symbolsand the per-language wrappers (_chunk_go,_chunk_rust,_chunk_js_ts,_chunk_c_like,_chunk_terraform,_chunk_sql).yaml.compose_allwith the safe loader. Each document is one chunk; its symbols come from the document's top-levelkindandmetadata.namenodes and its lines from the nodes' marks.mapline ranges of the heading tokensMarkdownIt("commonmark").parsereturns. This is one public function, so the docs ingester can share it.astpath.Key questions
devops ai rag index --force.Acceptance criteria
fnin animpl, a TypeScript class method), a multi-line signature and a symbol-like line inside a block comment give the chunks tree-sitter reports. The indented-definition and comment rows fail on the current code.# commentlines gets no section boundary inside the fence. The test fails on the current code.name:gives one chunk per document, whose symbols are the top-levelkindandmetadata.nameonly. The test fails on the current code.rg -n '_LANGUAGE_PATTERNS|_C_LIKE_PATTERN|_chunk_by_regex_symbols' srcprints nothing.changelog.d/<n>.mdrecords the change;CHANGELOG.mdis not edited.uv run devops cipasses.devops ai rag index --force,devops ai rag queryfor a Rustimplmethod and a TypeScript class method returns the method's chunk.Related: #959, #1300, #1329, #1388, #1066
Found by the 2026-10-08 client-library audit.
dan-petty commentedon Oct 8, 2026
Linked: #540, which settles one language classifier; this item chunks on
ai/astspans but picks the language with the scanner's, so it builds on #540's answer. Found by the 2026-10-08 backlog review.dan-petty-bot commentedon Oct 8, 2026
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
It causes indexing failures for certain text patterns but is an edge case rather than a total outage, and no security advisory or failed CI run is cited.Fixes a real correctness bug that breaks RAG indexing for text with short identifiers or dense punctuation, but only affects a subset of inputs.Beyond swapping the estimator, the refinement requires a full per-language chunker rewrite, removal of legacy regex chunking, and Hypothesis property tests.