{"record":{"id":"3dc226630172af1a","repo":"affaan-m/ECC","slug":"cannot-rebase-active-session-while-it-is","errorCode":null,"errorMessage":"Cannot rebase active session {} while it is {}","messagePattern":"Cannot rebase active session (.+?) while it is (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/session/manager.rs","lineNumber":1817,"sourceCode":"    }\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)?;\n\n    if matches!(\n        session.state,\n        SessionState::Pending | SessionState::Running | SessionState::Idle | SessionState::Stale\n    ) {\n        anyhow::bail!(\n            \"Cannot rebase 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::rebase_onto_base(&worktree)?;\n\n    Ok(WorktreeRebaseOutcome {\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    })","sourceCodeStart":1799,"sourceCodeEnd":1835,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/session/manager.rs#L1799-L1835","documentation":"The rebase operation refuses to rebase a session that is still active (Pending, Running, Idle, or Stale). Rebasing an active session's worktree would race with the live process, corrupting the rebase or the session's work. Only sessions in terminal states may be rebased.","triggerScenarios":"Calling the rebase-session API (manager.rs:1817) on a session whose state matches Pending | Running | Idle | Stale.","commonSituations":"Triggering rebase onto an updated main branch while the agent is still working; crashed sessions left in Idle/Stale; attempting rebase on a queued session; automation pipelines firing rebase before session completion.","solutions":["Wait for the session to finish before rebasing","Stop/cancel the session, wait for terminal state, then rebase","Reap Stale sessions and finalize their state before rebase","Gate rebase triggers on session state checks"],"exampleFix":"// before\nrebase_session(db, id)?;\n// after\nlet session = resolve_session(db, id)?;\nif matches!(session.state, SessionState::Pending | SessionState::Running | SessionState::Idle | SessionState::Stale) {\n    eprintln!(\"session {} still active ({:?}); deferring rebase\", id, session.state);\n} else {\n    rebase_session(db, id)?;\n}","handlingStrategy":"validation","validationCode":"let session = resolve_session(db, id)?;\nif matches!(session.state, SessionState::Pending | SessionState::Running | SessionState::Idle | SessionState::Stale) {\n    return Err(format!(\"session {} not rebaseable in state {:?}\", id, session.state));\n}","typeGuard":"fn is_rebaseable(s: &Session) -> bool { !matches!(s.state, SessionState::Pending | SessionState::Running | SessionState::Idle | SessionState::Stale) }","tryCatchPattern":"match rebase_session(db, id) {\n    Err(e) if e.to_string().starts_with(\"Cannot rebase active session\") => retry_after_completion(id),\n    other => other,\n}","preventionTips":["Wait for session completion events before rebasing","Stop long-running sessions before rebasing onto updated branches","Reap Stale sessions before batch rebase operations"],"tags":["session","git-rebase","state-machine"],"backgroundTag":"invalid-state-transition","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"}