bug(index): .mjs ES modules omitted from semantic index and preflight; verified fix + regression tests
What happened
The shared semantic-index extension allowlist does not recognize .mjs. JavaScript ES modules are omitted before chunking/embedding, so semantic search cannot retrieve their contents even though read_file can read them. This is incomplete indexing, not a model-quality problem.
An isolated copy of a JavaScript/TypeScript corpus reproduced 0/30 .mjs files indexed before the fix and 30/30 afterward. No original repository or daily installation was modified for that reproduction.
A minimal fix and two regression tests have been implemented and verified locally. The complete patch is included below; it has not been committed, pushed, or merged upstream.
Version and environment
- Reproduced and runtime-validated on
experimentsbase86dba52d078fcd07f2a04c6c3ba87cabe7fb778f, CodeScout0.15.0. - Latest public
experimentstip checked on 2026-10-16:857c30c6c0e772af0334c7462f1b2dc155f95fd7. Source inspection confirms that.mjsis still absent from the shared mapping. The runtime reproduction/full gate below were not rerun on this newer commit. - Linux x86_64, Rust
1.97.1; locked dependencies; release build. - Runtime: SQLite-backed
sqlite-vec, local/offline 384-dimensional embeddings. No external embedding service was involved. The defect is in the shared file-selection path, before a backend or embedding model processes the file.
Expected behavior
Non-ignored .mjs files should be treated as JavaScript by code indexing and by the corresponding preflight file/byte count. Existing ignore rules must continue to exclude dependency directories.
Steps to reproduce
Use a disposable project with a working embedding/backend configuration and indexing enabled. Include a .js control so a misconfigured backend is distinguishable from the extension omission:
mjs-repro/
src/reset.mjs
test/reset.mjs
legacy.js
node_modules/ignored.mjs
.gitignore
Synthetic file contents:
// src/reset.mjs
export function resetQuotaWindow(now) { return now + 60000; }
// test/reset.mjs
export function checkReset() { return true; }
// legacy.js
function legacyControl() { return 1; }
// node_modules/ignored.mjs
export function ignoredDependency() { return 0; }
Put node_modules/ in .gitignore and/or the project's configured ignore patterns.
- Start CodeScout with that disposable project as the active root.
- Call MCP tool
indexwith{"action":"build","force":true,"scope":"project"}; pollindexwith{"action":"status"}until complete. - Check actual stored file paths independently of the indexer's eligible-file list. On the disposable SQLite code database, the ordinary table query is:
SELECT DISTINCT file_path FROM code_chunk ORDER BY file_path; - Search for the reset-window implementation with
semantic_search, e.g.{"query":"reset the quota window using the current time","mode":"code","limit":5}. Useread_fileonsrc/reset.mjsas a control.
Before the fix: the .js control reaches the index, the two non-ignored .mjs paths do not, and no search hit can point to the omitted module. read_file remains able to read it. The ignored dependency must remain excluded both before and after the fix.
For the deterministic regression, apply only the two test additions from the patch, keeping the original mapping, then run:
cargo test --offline --locked --release --lib mjs_
Recorded result: two assertion failures. Add the one-line mapping fix and run the same command: two tests pass. --offline assumes the locked dependencies are already cached.
Root cause — inspected code
At the current checked public tip:
src/embed/mod.rs:34–47:lang_for_extacceptsjsandjsx, but notmjs.src/retrieval/sync.rs:503–506: the indexable-file walk continues past extensions for whichlang_for_extreturnsNone.src/embed/preflight.rs:148: the scope estimator uses the same allowlist, so it also excludes.mjsfiles and their bytes.
The JavaScript index chunker is already registered; no new parser or embedding model is necessary. Separately, AST extension detection in src/ast/mod.rs already recognizes .mjs, which makes the mismatch particularly easy to overlook. This patch intentionally leaves .cjs, case-sensitivity and all other extension policy unchanged.
Implemented fix
- "js" | "jsx" => "javascript",
+ "js" | "jsx" | "mjs" => "javascript",
The same mapping feeds indexing and preflight, so the one production-line change covers both paths. No database schema, memory format, storage-path, tool-schema or protocol changes are introduced.
The patch adds:
mjs_stream_index_keeps_modules_and_respects_ignores: exercises the realstream_indexwith a recording store and fake embedder; asserts the exact three expected source paths, verifies both modules reach the embedder, and keeps the ignored dependency out.mjs_preflight_counts_modules_toward_size_limit: asserts one eligible.mjsfile / 128 bytes trips a 64-byte threshold while an ignored dependency does not contribute.
Validation — reproduced on the tested base plus patch
- New regressions: RED 2 failed → GREEN 2 passed.
- Release build succeeded.
- An isolated corpus replay, using an independent expected-path list, changed
.mjscoverage from 0/30 to 30/30, and total JavaScript/TypeScript coverage from 2/32 to 32/32. - Two implementation queries that could not return their omitted modules before the fix found the expected file in the top five afterward, in two fresh CodeScout processes.
- The rebuilt copied index had 503 chunks/vectors at 384 dimensions, with zero missing, orphaned or invalid vectors. Existing copied source and memory data passed preservation checks. No private data is included here.
- Final upstream
scripts/gate.sh --check: exit 0 on this tested base plus patch. Python light: 1,223 tests + 424 subtests. Main Rust lean group: 4,508 passed / 8 ignored. Main Rust default group: 6,805 passed / 9 ignored. Formatting, Clippy and the integration/doc-test groups run by the gate passed. These configurations overlap; the numbers are not distinct tests to add together. - Gate limits remain explicit: three Python-heavy files, the server-stack configuration and two dedicated ONNX-weight tests were excluded by the upstream gate/test settings. The actual local embedding model was exercised separately in the runtime replay.
- Initial setup attempts failed because the isolated harness lacked pytest / a required child import-path layout /
/dev/zeroand/dev/full. Only the isolated harness was corrected; product code and existing tests were not changed to bypass those failures. The complete gate was rerun successfully afterward.
Limits: no full rebuild/runtime certification of 857c30c6 is claimed. Synthetic tests are the portable reproduction; the private corpus, databases and raw logs are deliberately not attached. This issue concerns .mjs indexing only, not a general rollout or client-integration certification.
Maintainer acceptance / rollout
- Integrate the mapping change and both tests (or equivalent coverage).
- Confirm the regressions and normal project gate on the target branch.
- Recheck an independent expected
.mjspath list against actual stored index paths; a successful build or skip count alone is insufficient evidence of coverage. - Rebuild/update affected code indexes using the supported indexing operation after the fix is shipped; previously omitted modules cannot be retrieved from an old index until indexed. No memory-vector rebuild or memory-format migration is part of this patch.
Complete patch
The following diff uses only repository-relative paths and synthetic fixtures. Patch SHA-256: 17eea6442210b499b03293d9d89dee7f462c96debbf0f32bf424190022312d77.
One-line production fix and two regression tests
diff --git a/src/embed/mod.rs b/src/embed/mod.rs
index 4518a64c..645173ac 100644
--- a/src/embed/mod.rs
+++ b/src/embed/mod.rs
@@ -36,7 +36,7 @@ pub fn lang_for_ext(ext: &str) -> Option<&'static str> {
"rs" => "rust",
"py" => "python",
"ts" | "tsx" => "typescript",
- "js" | "jsx" => "javascript",
+ "js" | "jsx" | "mjs" => "javascript",
"go" => "go",
"java" => "java",
"kt" => "kotlin",
diff --git a/src/embed/preflight.rs b/src/embed/preflight.rs
index e07b1ba2..5f9b8128 100644
--- a/src/embed/preflight.rs
+++ b/src/embed/preflight.rs
@@ -343,6 +343,23 @@ mod tests {
}
}
+ #[test]
+ fn mjs_preflight_counts_modules_toward_size_limit() {
+ let dir = tempfile::tempdir().unwrap();
+ std::fs::write(dir.path().join("app.mjs"), vec![b'x'; 128]).unwrap();
+ std::fs::create_dir(dir.path().join("node_modules")).unwrap();
+ std::fs::write(dir.path().join("node_modules/ignored.mjs"), vec![b'x'; 512]).unwrap();
+ let verdict = check_index_scope(dir.path(), 64, &["node_modules".to_string()]).unwrap();
+ match verdict {
+ PreflightVerdict::RequiresConfirmation(info) => {
+ assert!(info.size_exceeds_threshold);
+ assert_eq!(info.file_count, 1);
+ assert_eq!(info.approx_bytes, 128);
+ }
+ other => panic!("module bytes must trigger the size guard, got {other:?}"),
+ }
+ }
+
#[test]
fn check_index_scope_respects_gitignore() {
let dir = tempfile::tempdir().unwrap();
diff --git a/src/retrieval/sync.rs b/src/retrieval/sync.rs
index c3fec5f3..8e2415f8 100644
--- a/src/retrieval/sync.rs
+++ b/src/retrieval/sync.rs
@@ -1212,6 +1212,72 @@ mod tests {
use crate::retrieval::search::Hit;
use std::sync::{Arc, Mutex};
+ #[tokio::test]
+ async fn mjs_stream_index_keeps_modules_and_respects_ignores() {
+ let dir = tempfile::tempdir().unwrap();
+ for folder in ["src", "test", "node_modules"] {
+ std::fs::create_dir_all(dir.path().join(folder)).unwrap();
+ }
+ for (path, content) in [
+ (
+ "src/reset.mjs",
+ "export function resetAt() { return 42; }\n",
+ ),
+ (
+ "test/reset.mjs",
+ "export function checkReset() { return true; }\n",
+ ),
+ ("legacy.js", "function legacy() { return 1; }\n"),
+ (
+ "node_modules/ignored.mjs",
+ "export function ignoredDependency() {}\n",
+ ),
+ ] {
+ std::fs::write(dir.path().join(path), content).unwrap();
+ }
+ let emb = FakeEmbedder {
+ dim: 4,
+ seen: Mutex::new(Vec::new()),
+ };
+ let store = RecordingStore::default();
+ let (added, _, skipped) = stream_index(
+ dir.path(),
+ "p",
+ "coll",
+ &[],
+ &emb,
+ &store,
+ false,
+ 1200,
+ 256,
+ &["node_modules".to_string()],
+ )
+ .await
+ .unwrap();
+ let paths: std::collections::BTreeSet<String> = store
+ .upserted
+ .lock()
+ .unwrap()
+ .iter()
+ .map(|chunk| chunk.file_path.clone())
+ .collect();
+ let expected: std::collections::BTreeSet<String> =
+ ["src/reset.mjs", "test/reset.mjs", "legacy.js"]
+ .into_iter()
+ .map(str::to_string)
+ .collect();
+ assert_eq!(
+ paths, expected,
+ "module sources must reach the stored index"
+ );
+ assert!(added >= 3);
+ assert!(skipped.is_empty());
+ let seen = emb.seen.lock().unwrap();
+ assert!(seen.iter().any(|text| text.contains("resetAt")));
+ assert!(seen.iter().any(|text| text.contains("checkReset")));
+ assert!(seen.iter().all(|text| !text.contains("ignoredDependency")));
+ }
+
#[test]
fn always_skipped_covers_git_and_codescout_state_only_as_directories() {
// `.hidden(false)` on the walker is what lets tracked dotfiles in, and it is