---
type: Technical Diagnosis
title: Cold impact queries time out before they start working
description: A measured diagnosis of a silent degradation in Gentle Graph's cold query path, where a 1500 ms budget is consumed by engine startup before any indexing begins.
tags: [performance, diagnosis, gentle-graph, sveltekit, query-budget]
status: draft
generated: { by: agent:CODY/senior-architect, at: 2026-11-28T01:05:00Z }
sources:
  - id: own-measurements
    resource: local
    title: Measurements taken by the author on commit 0c286bf
    author: agent:CODY/senior-architect
---

# Cold `impact` queries time out before they start working

A measured diagnosis of a silent degradation in Gentle Graph's cold query
path. Measured on 2026-11-28 at commit `0c286bf`.

## Summary

A cold `impact` query returns `{ mode: "unknown", indexed: null, partial: true }`
on repositories as small as 50 files. The 1500 ms budget in
`lib/gentle-graph/query-session.ts` covers four separate costs at once: process
startup, engine module evaluation, Git subprocesses, and the query itself.
Engine module evaluation alone consumes almost the whole budget, so the query
often gives up before it begins to index.

With the budget raised in a throwaway copy, the same queries **complete
successfully** in 887-1765 ms. This is not a correctness defect. It is a budget
that does not match the work it is meant to bound.

## The three causes, separated

### 1. Design: one budget for four costs (root cause)

`lib/gentle-graph/query-session.ts:78` starts a 1500 ms timer for `impact`
queries. `lib/gentle-graph/query-worker.ts:52` sets an internal deadline of
1450 ms to answer before the parent gives up.

Everything below happens inside that single window:

| Stage | Measured cost |
| --- | --- |
| Bare Node process start | 250-830 ms |
| Engine module evaluation (`import` of the graph entry point) | 1428-1480 ms |
| Git subprocesses (`ls-files`, `status`, `diff`) on 50 files | ~106 ms total |
| Actual indexing and query work | remainder |

Module evaluation is the dominant term and it is **not** disk cache: repeating
the import with the files already in the OS cache still measured 1472 ms. The
cost is evaluating the module graph itself.

Isolating modules shows no single hotspot to blame. Measured independently,
each in a fresh process: `git-scope.ts` 1935 ms, `store.ts` 1817 ms,
`indexer.ts` 1784 ms, `index.ts` 1428 ms, `registry.ts` 883-1380 ms,
`store-sqlite.ts` 1212 ms, `query-session.ts` 954 ms. Loading any one of them
costs about what the whole budget allows.

### 2. Threshold: calibrated without separating startup from work

File count barely moves the result. Each repository below was generated for the
test, with the worker closed before every run, so every measurement is a genuine
cold start.

| Files | run 1 | run 2 | run 3 | median |
| --- | --- | --- | --- | --- |
| 3 | 1212 | 1088 | 887 | 1088 ms |
| 50 | 1738 | 1566 | 1308 | 1566 ms |
| 555 | 1593 | 1265 | 1765 | 1593 ms |

Three files cost 1088 ms and 555 files cost 1593 ms. A 185-fold difference in
project size changes the elapsed time by 46%. The budget is paying for startup,
not for the graph.

A second signal that the timeout is not a measurement of work: on every run that
fails, elapsed time lands at 1502-1530 ms. That is the timer cutting, not the
engine finishing.

### 3. Hardware: an aggravating factor, not the cause

The measurements above were taken on an Intel Core i3-6006U (4 threads) with a
load average between 16 and 20, so the machine was oversubscribed roughly four
to five times. Under that load, bare Node measured 250-830 ms and Node plus the
engine measured 2240-3190 ms.

On an idle machine the same work would probably fit inside 1500 ms. It would
still have no margin, because startup alone consumes most of the budget. That is
consistent with the observed behavior: the failure is intermittent rather than
constant. Two consecutive full-suite runs on the same checkout produced 73/73 and
72/73.

## Effect

The degradation is silent and semantically false. `mode: "unknown"` with
`partial: true` reads as "no results" to a reasonable consumer, not as "gave
up". A caller cannot distinguish an empty answer from a surrender, so it never
retries and never widens its search. The result is a plausible answer to the
wrong question.

## Proposal

1. **Make the budget a work budget, not a process budget.** Start the timer
   after the engine is loaded and the worker is ready, so startup cannot consume
   the allowance meant for indexing.
2. **Report startup and work separately**, using the `graphProfile` timestamps
   the worker already emits for `scope` and `reply`.
3. **Make `unknown` distinguishable from "no results"** in the public output,
   so a consumer can retry instead of reading a false negative.

Raising the number alone would hide the symptom. The cost is startup, so cold
queries would keep brushing against whatever new limit is chosen.

## Reproduction

```
# Generate a repository of N files, close the worker before each run
git init -q . && for i in $(seq 1 50); do echo "export function f$i() {}" > f$i.ts; done
printf 'import { helper } from "./support";\nexport function targetFn() { return helper(); }\n' > billing.ts
echo 'export function helper() {}' > support.ts
git add . && git commit -qm fixture
```

Then call `sessionQueryDetails({ kind: "impact", root, term: "targetFn" })` and
`closeQuerySessions()` between runs. Reproduced on pristine `main` extracted with
`git archive` into a temporary directory, both with and without `node_modules`.

The failing test is `reports cold query telemetry and finds an untracked consumer
in a fresh worktree` in `tests/gentle-graph.test.ts`, which asserts
`mode === "jit"`. It is intermittent, so a single green run does not clear it.

## Relationship to the benchmark gate

`scripts/bench-jit.mjs:52` enforces `coldGuideMs: 150` and `architectureMs: 15`.
Both fail on pristine `main` (cold guide p95 measured at 458-656 ms). That is a
contribution gate that blocks visibly; this is production behavior that degrades
silently. They share a calibration problem but are separate defects, and this one
merits its own fix because it produces wrong answers rather than a red build.
