{"record":{"id":"31025dc9c03e6661","repo":"clockworklabs/SpacetimeDB","slug":"spacetime-json-not-found-in","errorCode":null,"errorMessage":"spacetime.json not found in {}","messagePattern":"spacetime\\.json not found in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/spacetime_config.rs","lineNumber":1030,"sourceCode":"/// Loading order (each overlays the previous via top-level key replacement):\n/// 1. `spacetime.json` (required)\n/// 2. `spacetime.local.json` (if exists)\n/// 3. `spacetime.<env>.json` (if env specified and file exists)\n/// 4. `spacetime.<env>.local.json` (if env specified and file exists)\npub fn find_and_load_with_env(env: Option<&str>) -> anyhow::Result<Option<LoadedConfig>> {\n    find_and_load_with_env_from(env, std::env::current_dir()?)\n}\n\n/// Find and load config with environment layering starting from a specific directory.\npub fn find_and_load_with_env_from(env: Option<&str>, start_dir: PathBuf) -> anyhow::Result<Option<LoadedConfig>> {\n    let config_dir = match find_config_dir(start_dir) {\n        Some(dir) => dir,\n        None => return Ok(None),\n    };\n\n    let base_path = config_dir.join(\"spacetime.json\");\n    let mut merged = load_json_value(&base_path)?\n        .ok_or_else(|| anyhow::anyhow!(\"spacetime.json not found in {}\", config_dir.display()))?;\n    mark_source_config(&mut merged, \"spacetime.json\");\n\n    let mut loaded_files = vec![base_path];\n    let mut has_dev_file = false;\n\n    // Overlay local file\n    let local_path = config_dir.join(\"spacetime.local.json\");\n    if let Some(local_value) = load_json_value(&local_path)? {\n        overlay_json(&mut merged, local_value, \"spacetime.local.json\");\n        loaded_files.push(local_path);\n    }\n\n    // Overlay environment-specific file\n    if let Some(env_name) = env {\n        let env_path = config_dir.join(format!(\"spacetime.{env_name}.json\"));\n        if let Some(env_value) = load_json_value(&env_path)? {\n            overlay_json(&mut merged, env_value, &format!(\"spacetime.{env_name}.json\"));\n            loaded_files.push(env_path);","sourceCodeStart":1012,"sourceCodeEnd":1048,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/cli/src/spacetime_config.rs#L1012-L1048","documentation":"A time-of-check/time-of-use race in config discovery: find_config_dir walks up from the current directory and only returns a directory where spacetime.json exists, then load_json_value immediately re-stats the same path and returns None if it no longer exists. So this error means spacetime.json was deleted or renamed between those two checks, inside a single command. The window is tiny, which is why this error is rare.","triggerScenarios":"Something removes or atomically replaces spacetime.json concurrently with a spacetime CLI invocation: another spacetime process (e.g. `spacetime init`) rewriting the config, an editor's atomic save (write temp + rename), a file watcher/formatter, or scripted cleanup.","commonSituations":"Two CLI commands racing in a Makefile/CI job (one deletes or re-inits the project while another runs); editors like VS Code or formatters doing rename-on-write saves at the moment of invocation.","solutions":["Re-run the command — the race window is microseconds and a retry after the file settles almost always succeeds","Serialize concurrent invocations: don't run `spacetime init`/config-rewriting steps in parallel with other spacetime commands in the same project","If it persists, confirm the file actually exists in the reported directory (`ls <dir>/spacetime.json`) and that no daemon is deleting it"],"exampleFix":"# before: racing jobs\nmake init & make publish &   # init rewrites spacetime.json while publish discovers it\n\n# after: serialized\nmake init && make publish","handlingStrategy":"retry","validationCode":"# Pre-flight: assert the config file is present and stable before invoking the CLI\n[ -f spacetime.json ] || { echo 'spacetime.json missing' >&2; exit 1; }\n# guard against a formatter/init step rewriting it concurrently: wait until mtime settles\nwhile [ \"$(find spacetime.json -newermt '-2 seconds')\" ]; do sleep 0.2; done","typeGuard":null,"tryCatchPattern":"for attempt in 1 2 3; do\n  if spacetime \"$@\"; then exit 0; fi\n  # this error is a discovery/load race; brief backoff then retry\n  sleep 0.5\ndone\nexit 1","preventionTips":["Never run config-rewriting commands (`spacetime init`, formatters) concurrently with other spacetime commands in one project","In CI, create/repair spacetime.json in an earlier, serialized step before any command that reads it"],"tags":["spacetimedb","cli","config","race-condition","file-not-found"],"backgroundTag":"missing-config-file","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}