charmbracelet/crush · error
session id missing from context
Error message
session id missing from context
What it means
After validating the prompt, validateAgenticFetchParams reads the session id from the context (tools.GetSessionFromContext). The agentic_fetch sub-agent needs the parent session to record messages and stream events; an empty id means the execution context was not properly set up, so validation fails.
Source
Thrown at internal/agent/agentic_fetch_tool.go:36
//go:embed templates/agentic_fetch.md
var agenticFetchToolDescription string
// agenticFetchValidationResult holds the validated parameters from the tool call context.
type agenticFetchValidationResult struct {
SessionID string
AgentMessageID string
}
// validateAgenticFetchParams validates the tool call parameters and extracts required context values.
func validateAgenticFetchParams(ctx context.Context, params tools.AgenticFetchParams) (agenticFetchValidationResult, error) {
if params.Prompt == "" {
return agenticFetchValidationResult{}, errors.New("prompt is required")
}
sessionID := tools.GetSessionFromContext(ctx)
if sessionID == "" {
return agenticFetchValidationResult{}, errors.New("session id missing from context")
}
agentMessageID := tools.GetMessageFromContext(ctx)
if agentMessageID == "" {
return agenticFetchValidationResult{}, errors.New("agent message id missing from context")
}
return agenticFetchValidationResult{
SessionID: sessionID,
AgentMessageID: agentMessageID,
}, nil
}
//go:embed templates/agentic_fetch_prompt.md.tpl
var agenticFetchPromptTmpl []byte
func (c *coordinator) agenticFetchTool(_ context.Context, client *http.Client) (fantasy.AgentTool, error) {
if client == nil {View on GitHub (pinned to 7944b8e522)
Solutions
- Execute the tool via the standard agent loop so the session context value is installed.
- In custom code, wrap the context with the session context helper (tools.WithSessionContext) before calling.
- Update tests to mirror the production context setup.
Example fix
// before res, err := validateAgenticFetchParams(context.Background(), params) // after ctx := tools.WithSessionContext(ctx, sessionID) ctx = tools.WithMessageContext(ctx, agentMessageID) res, err := validateAgenticFetchParams(ctx, params)
Defensive patterns
Strategy: validation
Validate before calling
if tools.GetSessionFromContext(ctx) == "" {
return errors.New("agentic fetch requires session context")
} Try / catch
res, err := validateAgenticFetchParams(ctx, params)
if err != nil && strings.Contains(err.Error(), "session id missing from context") {
ctx = tools.WithSessionContext(ctx, sessionID)
res, err = validateAgenticFetchParams(ctx, params)
} Prevention
- Build tool contexts with a single constructor that sets session and message values.
- In tests, reuse the production context-setup helper rather than raw contexts.
- Gate tool execution behind middleware that asserts required context values.
When it happens
Trigger: agentic_fetch tool executed with a context that lacks the session context value — typically a direct/test invocation bypassing the coordinator's dispatch path that normally installs it.
Common situations: Unit tests calling the tool handler with context.Background(); custom tool runners that forget the session decorator; invoking the tool from a non-standard integration.
Related errors
- agent message id missing from context
- session id missing from context
- prompt is required
- session ID is required for downloading files
- session ID is required for creating a new file
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/bdc2f73252d6d8b2.
Report an issue: GitHub.