{"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":"anyhow::Error","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/01e15490f04e29cfefe3896951f43db46994d8ee/ecc2/src/session/manager.rs#L1775-L1811","documentation":"The merge_session_worktree function, after verifying the session is in a terminal state, requires an attached worktree to merge. If session.worktree is None, there is nothing to merge. This happens when the session was created without a worktree (e.g., a main-repo session) or the worktree was already removed.","triggerScenarios":"Calling merge_session_worktree on a session where session.worktree is None — the session was created without a worktree branch or the worktree was already cleaned up.","commonSituations":"Session ran in the main repository without a worktree. Worktree was already merged and removed by a previous call. Worktree path was manually deleted outside ECC.","solutions":["Check session.worktree.is_some() before calling merge_session_worktree","If the worktree was already cleaned up, treat the operation as a no-op success","Ensure sessions that need merging are created with a worktree from the start","Avoid calling merge twice on the same session — track which sessions have been merged"],"exampleFix":"// before\nmerge_session_worktree(db, &id, true).await?;\n\n// after\nlet session = resolve_session(db, &id)?;\nif session.worktree.is_none() {\n    tracing::info!(\"session {} has no worktree to merge\", id);\n    return Ok(WorktreeMergeOutcome::noop(id));\n}\nmerge_session_worktree(db, &id, true).await?;","handlingStrategy":"validation","validationCode":"let session = resolve_session(db, id)?;\nif session.worktree.is_none() {\n    return Ok(WorktreeMergeOutcome::noop(id));\n}","typeGuard":"fn has_worktree(session: &Session) -> bool {\n    session.worktree.is_some()\n}","tryCatchPattern":"match merge_session_worktree(db, id, cleanup).await {\n    Ok(outcome) => Ok(outcome),\n    Err(e) if e.to_string().contains(\"no attached worktree\") => {\n        Ok(WorktreeMergeOutcome::noop(id))\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Track which sessions have worktrees in the caller to avoid merge on worktreeless sessions","Treat 'no worktree' as a no-op success rather than an error in automated pipelines","Ensure sessions that need merging are created with a worktree from the start"],"tags":["sessions","worktree","merge","not-found"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}