{"record":{"id":"acea560dfd5ef58d","repo":"Hmbown/CodeWhale","slug":"fleet-session-capture-id-is-already-in-use-or-unavailable","errorCode":null,"errorMessage":"Fleet session capture id is already in use or unavailable","messagePattern":"Fleet session capture id is already in use or unavailable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/exec_agent.rs","lineNumber":354,"sourceCode":"        .unwrap_or_default();\n    if let Some(envelope) = fleet_authority {\n        crate::tools::spec::install_process_tool_authority(envelope).map_err(anyhow::Error::msg)?;\n    }\n\n    let fleet_capture = match (\n        std::env::var(\"CODEWHALE_FLEET_CAPTURE_ID\").ok(),\n        std::env::var_os(\"CODEWHALE_FLEET_CAPTURE_DIR\"),\n    ) {\n        (Some(id), Some(dir)) => {\n            uuid::Uuid::parse_str(&id).context(\"invalid Fleet session capture id\")?;\n            anyhow::ensure!(\n                resume_session.is_none(),\n                \"Fleet capture cannot resume a session\"\n            );\n            let manager = SessionManager::new(PathBuf::from(dir))?;\n            match manager.load_session(&id) {\n                Err(err) if err.kind() == std::io::ErrorKind::NotFound => {}\n                _ => anyhow::bail!(\"Fleet session capture id is already in use or unavailable\"),\n            }\n            Some((id, manager))\n        }\n        (None, None) => None,\n        _ => anyhow::bail!(\"incomplete Fleet session capture destination\"),\n    };\n\n    let route = resolve_cli_exec_route(config, model, prompt, force_configured_route).await?;\n    let execution_config = config_for_cli_route(config, &route);\n    let auto_model = route.auto_model;\n    let effective_provider = route.provider;\n    let effective_model = route.model;\n    let validated_route = crate::route_runtime::resolve_runtime_route(\n        &execution_config,\n        effective_provider,\n        Some(&effective_model),\n    )\n    .map_err(anyhow::Error::msg)?","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/exec_agent.rs#L336-L372","documentation":"When a Fleet capture destination is configured (both CODEWHALE_FLEET_CAPTURE_ID and CODEWHALE_FLEET_CAPTURE_DIR are set), run_exec_agent requires the capture session id to be free: it loads the session from the SessionManager and only tolerates a NotFound error. Any other load result — the session already exists, or loading failed with a non-NotFound I/O error — throws this error to prevent overwriting or appending to an existing capture.","triggerScenarios":"Starting `codewhale exec` with CODEWHALE_FLEET_CAPTURE_ID set to a UUID that already has a stored session file in CODEWHALE_FLEET_CAPTURE_DIR, or where `SessionManager::load_session` fails with an error other than NotFound (e.g. permission or corruption).","commonSituations":"Re-running the same fleet worker dispatch without rotating the capture id; a stale capture directory left over from a previous run; the capture directory contains a session file written by an older Codewhale version that now fails to deserialize.","solutions":["Generate a fresh CODEWHALE_FLEET_CAPTURE_ID (new UUID) for this run instead of reusing the old one.","Inspect CODEWHALE_FLEET_CAPTURE_DIR and remove or archive the existing session file for that id if it is no longer needed.","Check permissions on the capture directory; a non-NotFound load error (e.g. EACCES) is reported under the same message — fix the permission problem.","If the intent was to continue an existing session, that is unsupported for Fleet capture (`Fleet capture cannot resume a session`); drop the resume flag and use a new id."],"exampleFix":"// before\nCODEWHALE_FLEET_CAPTURE_ID=3f9c... (already captured)\n// after\nCODEWHALE_FLEET_CAPTURE_ID=$(uuidgen) CODEWHALE_FLEET_CAPTURE_DIR=/tmp/fleet-captures codewhale exec ...","handlingStrategy":"validation","validationCode":"# Shell pre-check before launching exec with capture\nid=\"$CODEWHALE_FLEET_CAPTURE_ID\"; dir=\"$CODEWHALE_FLEET_CAPTURE_DIR\"\n[ -n \"$id\" ] && [ -n \"$dir\" ] || { echo \"capture pair incomplete\"; exit 2; }\n[ -f \"$dir/$id.session\" ] && { echo \"capture id already in use\"; exit 3; }","typeGuard":null,"tryCatchPattern":"match run_exec_agent(...).await {\n    Err(e) if e.to_string().contains(\"already in use\") => {\n        eprintln!(\"rotate CODEWHALE_FLEET_CAPTURE_ID and retry\");\n    }\n    other => other,\n}","preventionTips":["Always generate a fresh UUID per capture run; never replay a used capture id.","Archive or delete finished capture sessions before reuse of a directory.","Ensure the capture directory is writable by the exec process to avoid non-NotFound load errors."],"tags":["fleet","sessions","cli","id-conflict"],"backgroundTag":"file-already-exists","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}