{"record":{"id":"c39d7a95d4f6ee22","repo":"affaan-m/ECC","slug":"session-has-no-attached-worktree","errorCode":null,"errorMessage":"Session {} has no attached worktree","messagePattern":"Session (.+?) has no attached worktree","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ecc2/src/session/manager.rs","lineNumber":1793,"sourceCode":"    cleanup_worktree: bool,\n) -> Result<WorktreeMergeOutcome> {\n    let session = resolve_session(db, id)?;\n\n    if matches!(\n        session.state,\n        SessionState::Pending | SessionState::Running | SessionState::Idle | SessionState::Stale\n    ) {\n        anyhow::bail!(\n            \"Cannot merge active session {} while it is {}\",\n            session.id,\n            session.state\n        );\n    }\n\n    let worktree = session\n        .worktree\n        .clone()\n        .ok_or_else(|| anyhow::anyhow!(\"Session {} has no attached worktree\", session.id))?;\n    let outcome = crate::worktree::merge_into_base(&worktree)?;\n\n    if cleanup_worktree {\n        crate::worktree::remove(&worktree)?;\n        db.clear_worktree(&session.id)?;\n    }\n\n    Ok(WorktreeMergeOutcome {\n        session_id: session.id,\n        branch: outcome.branch,\n        base_branch: outcome.base_branch,\n        already_up_to_date: outcome.already_up_to_date,\n        cleaned_worktree: cleanup_worktree,\n    })\n}\n\npub async fn rebase_session_worktree(db: &StateStore, id: &str) -> Result<WorktreeRebaseOutcome> {\n    let session = resolve_session(db, id)?;","sourceCodeStart":1775,"sourceCodeEnd":1811,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/session/manager.rs#L1775-L1811","documentation":"Thrown when performing a worktree merge/cleanup for a session whose optional worktree field is None. The operation requires an attached git worktree, so the code converts the missing value into 'Session {id} has no attached worktree' rather than proceeding with a default.","triggerScenarios":"Calling the merge/worktree-cleanup flow for a session created without worktrees (auto_create_worktrees disabled) or one whose worktree was already merged/removed.","commonSituations":"Running the merge command twice (second time the worktree was cleared), sessions started with --no-worktree, or config where auto_create_worktrees=false.","solutions":["Check session.worktree before invoking the merge; skip sessions without one.","Only run the merge for sessions created with worktree support (enable auto_create_worktrees or recreate the session with a worktree).","If the worktree was already merged and cleaned up, treat this outcome as a no-op, not an error.","Inspect the session record (e.g. session show) to confirm worktree state first."],"exampleFix":"// before\nmerge_worktree(db, &session_id, true)?; // session has no worktree\n// after\nlet session = db.get_session(&session_id)?.ok_or_else(|| anyhow::anyhow!(\"no such session\"))?;\nif session.worktree.is_some() {\n    merge_worktree(db, &session_id, true)?;\n} else {\n    eprintln!(\"session {session_id} has no worktree; nothing to merge\");\n}","handlingStrategy":"type-guard","validationCode":"let has_worktree = db.get_session(&session_id)?\n    .and_then(|s| s.worktree)\n    .is_some();","typeGuard":"fn has_worktree(s: &Session) -> bool { s.worktree.is_some() }\n// if !has_worktree(&session) { skip merge }","tryCatchPattern":"match merge_worktree(db, id, cleanup) {\n    Err(e) if e.to_string().contains(\"has no attached worktree\") => {\n        eprintln!(\"nothing to merge for {id}\");\n        Ok(())\n    }\n    other => other,\n}","preventionTips":["Check session.worktree before any merge/cleanup call","Make merge idempotent: already-merged sessions should no-op","Enable auto_create_worktrees if merges are part of your workflow","Inspect session state after failed merges to avoid double-cleanup"],"tags":["worktree","git","sessions"],"backgroundTag":"resource-not-found","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}