Background TODO scanning parses huge JSON without bounds (56 GB live heap on 0.63.5)
What happened?
A shared ck-aft --subc daemon on 0.63.5 abruptly grew from approximately 0.8 GB RSS to 16.5 GB RSS within five minutes, then showed 56,239,911,712 bytes of allocator-in-use memory. The machine was swapping heavily.
The strongest supported explanation is automatic, parallel TODO scanning of large generated JSON files. The unbounded parsing path and automatic whole-project trigger are confirmed in the version's source. The incident attribution is supported by runtime counters, worker activity, admitted inputs and timing, but no allocation-stack trace was collected, so this report does not claim to have attributed every heap byte to a particular syntax tree or proved a permanent leak.
Expected: opening a project containing large data files should not make an automatic status-bar TODO scan consume tens of gigabytes. Background inspection needs bounded resource use, independently of search-index settings.
Environment
Manually collected diagnostics:
- AFT binary: 0.63.5, confirmed through a read-only status request to the running daemon.
- Pi integration package: @cortexkit/aft-pi 0.63.5.
- Platform: Arch Linux, x86_64, kernel
7.2.14-arch1-1, glibc allocator. - Shared daemon uptime: approximately 22 hours when investigated; the observed jump was sudden, not demonstrated steady growth throughout that uptime.
- Trigram and semantic indexes were disabled for the affected root; inspection and TODO scanning were enabled.
- Multiple Pi sessions used the shared service. No AFT code/configuration changes, restarts, or giant-input replay were performed during diagnosis.
Observed trigger and inputs
A Pi worker was started with a task-results directory as its working directory. AFT attached that directory as a new project root. The worker's intended reads were small files and explicitly excluded the largest generated JSON; a direct tool read of a huge JSON is not necessary for the background path below.
The root contained approximately 4,384 regular files / 2.76 GB total, including 2.10 GB of generated JSON. Largest individual JSON files were:
| Size, bytes | Content type |
|---|---|
| 508,028,159 | Generated analysis evidence bindings |
| 351,515,447 | Generated analysis evidence bindings |
| 302,405,936 | Generated analysis evidence bindings |
| 242,525,713 | Generated analysis evidence bindings |
| 227,621,432 | Generated analysis evidence bindings |
Python sources totaled only approximately 0.97 MB across 72 files. Private absolute paths and data contents are omitted.
Read-only inspection of the existing inspect database confirmed that the shared inspection inventory actually admitted the large JSON paths: each completed Tier-2 category contained 1,005 file contributions totaling 2,104,807,246 input bytes, maximum 508,028,159 bytes. The JSON contributions themselves were empty/skipped (for example, complexity reported language_skipped: json), so their database presence is not evidence that Tier-2 parsed the JSON. The expensive candidate is the separately scheduled Tier-1 TODO job.
Timeline
UTC, 2026-11-02; summarized from the daemon log and measurements, not verbatim log excerpts:
| Time | Observation |
|---|---|
| 22:11:37 | Task-results directory attached as a new root. |
| 22:11:56 | Allocator-relief log: RSS after relief 814,759,936 bytes. |
| 22:12:11 | First logged inspect response for that root. |
| 22:14:25–27 | Automatic Tier-2 refresh scheduled/completed over the 1,005-file inventory. The same scheduler submits a separate whole-project TODO job immediately before the logged Tier-2 batch; see source below. |
| 22:16:57 | Relief log: RSS before 16,419,569,664 bytes, after 16,515,416,064 bytes; allocator-accounting drop zero. |
| Around 22:17 | /proc showed approximately 14 GiB resident plus 30 GiB swapped for the daemon. |
Memory and activity evidence
Initial /proc/<pid>/status snapshot:
VmRSS: 14703240 kB
RssAnon: 14668212 kB
VmSwap: 31135880 kB
VmHWM: 16925628 kB
Threads: 116
Later read-only status snapshot, all values below in bytes:
| Counter | Value |
|---|---|
Allocator bytes_in_use |
56,239,911,712 |
Allocator size_allocated |
62,655,545,584 |
| Allocator slack | 6,415,633,872 |
| Total attributed AFT subsystem estimates | 172,999,319 (~165 MiB) |
| SQLite memory | 29,574,616 |
| Embedding model/session bytes | 0 |
Additional observations:
- Five
aft-rayon-inspethreads were active. A one-second sample measured approximately 99.5%, 41.8%, 40.8%, 33.8% and 33.8% of one CPU respectively. - The affected root's status still had
todos: nulland diagnostics pending, while the five Tier-2 categories had memory aggregates. - Generic parser-pool estimates do not account for this scanner's separate thread-local parsers or active trees. Small retained-cache estimates therefore cannot exclude a large transient parser working set.
- A later snapshot had allocator in-use fall to 41,804,347,472 bytes, while allocated size remained approximately 62.66 GB. This is why I am reporting unbounded processing / a huge live peak, not asserting a permanent leak.
- Linux allocator relief was already implemented and running. Free allocator retention may contribute after parsing, but cannot by itself explain the snapshot with 56.24 GB reported in use.
Confirmed source path in v0.63.5
-
Automatic whole-project trigger, even without an explicit TODO inspect.
context.rs:13494–13547schedules enabled TODO scanning usingJobScope::for_project(snapshot.project_root.clone())before submitting the automatic Tier-2 batch. The comment explicitly says this populates the status-bar TODO count even when no explicit inspect requested it.A narrow explicit inspect is not being assumed to widen its Tier-1 scope:
manager.rs:4737–4764preserves that scope. The separate automatic scheduler is the whole-root trigger here. -
Parallel scan, whole-file read before any size budget.
todos.rs:51–83scansjob.scope_files.par_iter().scan_file:165–190reads each file completely before dispatching recognized languages to parser-based comment scanning.read_text_file:511–527has no size guard;project_content::readusesread_to_end, with storage/SQLite admission checks but no source-size cap. -
JSON receives a complete tree-sitter parse solely to find comments.
parser.rs:763–845maps.json/.jsonctoLangId::Jsonand selectstree_sitter_json.todos.rs:192–274creates a full tree through thread-localTODOS_PARSERS. The progress callback checks cancellation/file existence, not a byte, allocation or elapsed-time budget.276–301then traverses the tree, including comment-free JSON. -
Existing limits do not protect this path.
MAX_LINES_PER_FILE = 100_000only limits the fallback lexical scanner for unrecognized languages (definition, use). It does not cap the initial read or recognized JSON parse. A result-count cap similarly cannot bound the work performed before finding any comments. The caller's stale/pending return after a soft wait deadline is also not a parser-memory bound (manager.rs:4854–4880).
Together, full JSON trees, several simultaneous parses and subsequent traversal provide a concrete mechanism for a working set much larger than the raw input size.
Reproduction status and requested behavior
This is a production-incident diagnosis plus pinned-source inspection, not a completed minimal synthetic reproduction. I did not deliberately replay hundreds-of-megabytes JSON on a machine already under severe memory pressure. No heap/native-stack profile was collected; exact allocation ownership remains a limitation.
Please make automatic TODO/comment scanning bounded before reading/parsing huge files, and account for the aggregate parallel working set. Skipped inputs should remain visible as incomplete/skipped coverage rather than being presented as successfully scanned. Merely limiting returned TODO items, disabling search indexes, or trimming free allocator arenas does not bound this path.
Related context: #359 tracks broader memory complaints, without establishing this cause. #201 addressed missing Linux allocator relief; this daemon already had that relief, and the live-usage counters above distinguish this case from free-arena retention alone.
Thanks for the careful report and the memory evidence. Your diagnosis is right: the automatic TODO scan read and fully parsed large JSON files, several at once, just to look for comments.
The fix changes three things:
- Plain JSON is no longer scanned for TODOs, since it can't contain comments.
- The TODO, metrics, complexity and duplicate scanners check a file's size before reading it. Files over 1 MiB are skipped and listed as skipped, so the result shows as incomplete rather than as fully scanned.
- These scanners share a limit on how much source they read and parse at once, so several large files can no longer be processed together.
On a reproduction with 393 MB of generated JSON, the TODO scan's peak memory fell from about 625 MB to about 73 MB, and the scan is slightly faster on ordinary projects. It will ship in the next release.
This is addressed in AFT 0.64.0. TODO counts now use markers saved by the index store rather than reparsing the project. Plain JSON is excluded, oversized source files are skipped before reading, and skipped coverage is reported as incomplete. The scanner paths also share a source-byte budget. Please reopen if you still see this behavior on 0.64.0, with the health report and the affected file sizes.