Windows: `CCE_ORT_THREADS` cap not observed during indexing (~18 cores), and a second concurrent `cce serve` crashes at startup with `database is locked`
Environment
- code-context-engine 0.4.26 (PyPI,
[local]extra), Python 3.14, Windows 11 - 36 logical / 18 physical cores
- Two
cce servestdio processes started at the same time on the same project, empty index, default config, withCCE_ORT_THREADS=2andCCE_EMBED_PARALLEL=0set explicitly
Finding 1: thread cap not observed while indexing
During the lazy first index, the one serve process that started was sampled every ~3 s for ~95 s (32 samples, CPU summed over the client's child processes): median 17.8 cores, max 17.9, ~2.5 GB RSS. A single spot check of that process showed 78 threads.
Suspected cause (from reading the code, not verified by a separate test):
cap_ort_threads()only sets environment variables (OMP_NUM_THREADS,MKL_NUM_THREADS,OPENBLAS_NUM_THREADS,ORT_NUM_THREADS): https://github.com/elara-labs/code-context-engine/blob/75071156e08a145fab17c8ce30bb5f418286f434/src/context_engine/resource_governor.py#L46-L84- The embedder constructs
TextEmbeddingwithoutthreads=: https://github.com/elara-labs/code-context-engine/blob/75071156e08a145fab17c8ce30bb5f418286f434/src/context_engine/indexer/embedder.py#L209 - In the installed fastembed,
SessionOptions.intra_op_num_threads/inter_op_num_threadsare only set whenthreadsis passed. If ONNX Runtime does not read those environment variables, the session would use its own default. ~18 cores matches the physical core count here, but that alone does not prove it.
Possible fix: pass the resolved cap to fastembed, e.g. TextEmbedding(resolved, cache_dir=..., threads=n) when n > 0.
Finding 2: second concurrent serve crashes at startup
The other process exited before serving any request:
File ".../context_engine/storage/vector_store.py", line 72, in _connect
conn.execute("PRAGMA journal_mode=WAL")
sqlite3.OperationalError: database is locked
The connection is opened with the default sqlite3.connect timeout, then journal_mode=WAL is set: https://github.com/elara-labs/code-context-engine/blob/75071156e08a145fab17c8ce30bb5f418286f434/src/context_engine/storage/vector_store.py#L52-L74
Possible fix: check whether a longer timeout or a retry around the WAL pragma avoids the startup failure when another process is writing. I have not confirmed this is the only cause.
Separate observation: Windows-specific guards
These are separate from the crash above. I have not established a link between them.
- The per-project index lock relies on
fcntland returnsTruewhen it is unavailable, so it is not enforced on Windows: https://github.com/elara-labs/code-context-engine/blob/75071156e08a145fab17c8ce30bb5f418286f434/src/context_engine/resource_governor.py#L111-L114 - The memory-pressure check reads Linux PSI and returns
Falseon other platforms: https://github.com/elara-labs/code-context-engine/blob/75071156e08a145fab17c8ce30bb5f418286f434/src/context_engine/resource_governor.py#L158-L165
Possible fix: a Windows lock (e.g. msvcrt.locking, or an O_CREAT | O_EXCL lock file).
What worked
Closing the client's stdin made serve exit, and no processes were left behind.
Links point to main at 75071156, which I checked against the installed 0.4.26 for the lines above. Happy to test a patch.