aaif-goose/goose · error

Session '{}' not found or failed to read: {}

Error message

Session '{}' not found or failed to read: {}

What it means

Thrown by `goose session export` when SessionManager::get_session(&session_id, true) fails; the boolean true means the session is loaded including its message history. The message appends the underlying error, so the cause is either a missing ID (same lookup as removal) or a session file that exists but cannot be read/parsed.

Source

Thrown at crates/goose-cli/src/commands/session.rs:237

                }
            }
        }
    }
    Ok(())
}

pub async fn handle_session_export(
    session_id: String,
    output_path: Option<PathBuf>,
    format: String,
    nostr: bool,
    #[cfg_attr(not(feature = "nostr"), allow(unused_variables))] relays: Vec<String>,
) -> Result<()> {
    let session_manager = SessionManager::instance();
    let session = match session_manager.get_session(&session_id, true).await {
        Ok(session) => session,
        Err(e) => {
            return Err(anyhow::anyhow!(
                "Session '{}' not found or failed to read: {}",
                session_id,
                e
            ));
        }
    };

    let output = match format.as_str() {
        "json" => serde_json::to_string_pretty(&session)?,
        "yaml" => serde_yaml::to_string(&session)?,
        "markdown" => {
            let conversation = session
                .conversation
                .ok_or_else(|| anyhow::anyhow!("Session has no messages"))?;
            export_session_to_markdown(conversation.user_visible_messages(), &session.name)
        }
        _ => return Err(anyhow::anyhow!("Unsupported format: {}", format)),
    };

View on GitHub (pinned to 3810898a74)

Solutions

  1. Get the exact ID from `goose session list` and retry
  2. Read the appended underlying error — a parse/read failure points at a corrupt file, not a wrong ID
  3. Inspect the <id>.jsonl file in the sessions directory (is it present, readable, valid JSONL?)
  4. If the file is corrupt, restore it from backup or export a different session

Example fix

# before
goose session export 20260101_badid -f json
# after
goose session list                       # exact id + note any read errors
goose session export 20260101_000000_full-id -f json
Defensive patterns

Strategy: validation

Validate before calling

let session = session_manager.get_session(&session_id, true).await?; // preflight load
let output = serde_json::to_string_pretty(&session)?;

Type guard

async fn session_exportable(sm: &SessionManager, id: &str) -> bool {
    sm.get_session(id, true).await.is_ok()
}

Try / catch

match handle_session_export(id.clone(), None, "json".into(), false, vec![]).await {
    Err(e) if e.to_string().starts_with(&format!("Session '{}' not found", id)) => {
        // stale id: refresh the id list and skip
    }
    Err(e) => {
        // underlying error text after ':' indicates a corrupt session file
        return Err(e);
    }
    ok => ok,
}

Prevention

When it happens

Trigger: Exporting a wrong or deleted session ID; the session .jsonl file is corrupt (truncated write, manual edit) or unreadable due to permissions; storage directory moved while goose was running.

Common situations: Exporting from scripts with hard-coded IDs after sessions were cleaned; copying sessions between machines incompletely; disk issues or editors corrupting session files.

Related errors


AI-assisted analysis of aaif-goose/goose@3810898a74 (2026-08-16). Data as JSON: /api/errors/4c19561524702f66. Report an issue: GitHub.