{"record":{"id":"bdc2f73252d6d8b2","repo":"charmbracelet/crush","slug":"session-id-missing-from-context-bdc2f7","errorCode":null,"errorMessage":"session id missing from context","messagePattern":"session id missing from context","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/agentic_fetch_tool.go","lineNumber":36,"sourceCode":"\n//go:embed templates/agentic_fetch.md\nvar agenticFetchToolDescription string\n\n// agenticFetchValidationResult holds the validated parameters from the tool call context.\ntype agenticFetchValidationResult struct {\n\tSessionID      string\n\tAgentMessageID string\n}\n\n// validateAgenticFetchParams validates the tool call parameters and extracts required context values.\nfunc validateAgenticFetchParams(ctx context.Context, params tools.AgenticFetchParams) (agenticFetchValidationResult, error) {\n\tif params.Prompt == \"\" {\n\t\treturn agenticFetchValidationResult{}, errors.New(\"prompt is required\")\n\t}\n\n\tsessionID := tools.GetSessionFromContext(ctx)\n\tif sessionID == \"\" {\n\t\treturn agenticFetchValidationResult{}, errors.New(\"session id missing from context\")\n\t}\n\n\tagentMessageID := tools.GetMessageFromContext(ctx)\n\tif agentMessageID == \"\" {\n\t\treturn agenticFetchValidationResult{}, errors.New(\"agent message id missing from context\")\n\t}\n\n\treturn agenticFetchValidationResult{\n\t\tSessionID:      sessionID,\n\t\tAgentMessageID: agentMessageID,\n\t}, nil\n}\n\n//go:embed templates/agentic_fetch_prompt.md.tpl\nvar agenticFetchPromptTmpl []byte\n\nfunc (c *coordinator) agenticFetchTool(_ context.Context, client *http.Client) (fantasy.AgentTool, error) {\n\tif client == nil {","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/agent/agentic_fetch_tool.go#L18-L54","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nres, err := validateAgenticFetchParams(context.Background(), params)\n// after\nctx := tools.WithSessionContext(ctx, sessionID)\nctx = tools.WithMessageContext(ctx, agentMessageID)\nres, err := validateAgenticFetchParams(ctx, params)","handlingStrategy":"validation","validationCode":"if tools.GetSessionFromContext(ctx) == \"\" {\n    return errors.New(\"agentic fetch requires session context\")\n}","typeGuard":null,"tryCatchPattern":"res, err := validateAgenticFetchParams(ctx, params)\nif err != nil && strings.Contains(err.Error(), \"session id missing from context\") {\n    ctx = tools.WithSessionContext(ctx, sessionID)\n    res, err = validateAgenticFetchParams(ctx, params)\n}","preventionTips":["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."],"tags":["context","session","validation","agentic-fetch"],"backgroundTag":"missing-context-value","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}