charmbracelet/crush · error
failed to get session messages: %w
Error message
failed to get session messages: %w
What it means
Run wraps failures from getSessionMessages with 'failed to get session messages: %w'. After loading the session, the agent lists and post-processes its message history; a storage failure there aborts the run.
Source
Thrown at internal/agent/agent.go:700
agentTools[len(agentTools)-1].SetProviderOptions(a.getCacheControlOptions())
}
agent := fantasy.NewAgent(
largeModel.Model,
fantasy.WithSystemPrompt(systemPrompt),
fantasy.WithTools(agentTools...),
fantasy.WithUserAgent(userAgent),
)
sessionLock := sync.Mutex{}
currentSession, err := a.sessions.Get(ctx, call.SessionID)
if err != nil {
return nil, fmt.Errorf("failed to get session: %w", err)
}
msgs, err := a.getSessionMessages(ctx, currentSession)
if err != nil {
return nil, fmt.Errorf("failed to get session messages: %w", err)
}
// Generate title from the first real (non-shell) user prompt.
// can take tens of seconds. Blocking Run on it delays the
// response to the caller. Use a detached context so the title
// goroutine survives Run's cancel.
if !hasUserTextMessage(msgs) {
titleCtx := context.WithoutCancel(ctx)
go a.GenerateTitle(titleCtx, call.SessionID, call.Prompt)
}
// Add the user message to the session.
_, err = a.createUserMessage(ctx, call)
if err != nil {
return nil, err
}
userMsgCreated = true
View on GitHub (pinned to 7944b8e522)
Solutions
- Check the messages store (DB) health and that message rows for the session are intact
- Retry the run if the underlying failure was transient (lock, cancelled context)
- Inspect the wrapped cause; it is almost always a 'failed to list messages' error from getSessionMessages
Defensive patterns
Strategy: try-catch
Try / catch
out, err := agent.Run(ctx, call)
var storeErr error
if err != nil && errors.As(err, &storeErr) {
log.Printf("history read failed: %v", storeErr) // cause is 'failed to list messages'
} Prevention
- Monitor message-store health; this error is downstream of messages.List
- Retry runs on transient storage errors
- Back up/verify the SQLite message tables
When it happens
Trigger: a.getSessionMessages(ctx, currentSession) returns an error inside Run/Summarize — i.e. a.messages.List on the session ID fails (see error 88) or the summary-message splice logic errors.
Common situations: Message store unavailable or corrupted; session exists but its message rows are missing/inconsistent; context cancelled during the list query.
Related errors
- failed to list messages: %w
- failed to get session: %w
- errors.New(s.Error)
- failed to create user message: %w
- error creating file history: %w
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/93a7aaea6dd31133.
Report an issue: GitHub.