{"record":{"id":"cf6b2f814786db2c","repo":"JuliusBrussee/caveman","slug":"invalid-native-session-identity","errorCode":null,"errorMessage":"invalid native session identity","messagePattern":"invalid native session identity","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/store/store.go","lineNumber":727,"sourceCode":"\t\t\treturn nil, err\n\t\t}\n\t\tout = append(out, item)\n\t}\n\treturn out, rows.Err()\n}\n\n// SessionUsage returns content-blind provider telemetry for one exact correlated\n// native session. Dollar values remain catalog list-price subtotals/inferred\n// standalone savings; neither is a provider invoice or verified savings.\nfunc (s *Store) SessionUsage(sessionID string) (sessionusage.Snapshot, error) {\n\tout := sessionusage.Snapshot{\n\t\tStatus:       \"not_observed\",\n\t\tSessionID:    sessionID,\n\t\tCostBasis:    \"catalog_list_price_subtotal_provider_complete_priced_rows\",\n\t\tSavingsBasis: \"inferred_standalone_not_verified\",\n\t}\n\tif !validEvidenceToken(sessionID, 256) {\n\t\treturn out, fmt.Errorf(\"invalid native session identity\")\n\t}\n\tvar compressionBases, correlationBases string\n\terr := s.db.QueryRow(\n\t\t`SELECT COUNT(*),\n\t\t        COALESCE(SUM(CASE WHEN token_usage_basis = 'provider_complete' THEN 1 ELSE 0 END),0),\n\t\t        COALESCE(SUM(input_tokens),0), COALESCE(SUM(output_tokens),0),\n\t\t        COALESCE(SUM(cached_input_tokens),0), COALESCE(SUM(cache_creation_input_tokens),0),\n\t\t        COALESCE(SUM(reasoning_tokens),0), COALESCE(SUM(total_cost_usd),0),\n\t\t        COALESCE(SUM(savings_usd),0), COALESCE(SUM(compression_tokens_before),0),\n\t\t        COALESCE(SUM(compression_tokens_after),0),\n\t\t        COALESCE(GROUP_CONCAT(DISTINCT NULLIF(compression_token_count_basis,'')),''),\n\t\t        COALESCE(GROUP_CONCAT(DISTINCT NULLIF(session_correlation_basis,'')),'')\n\t\t   FROM requests WHERE session_id = ?`,\n\t\tsessionID,\n\t).Scan(\n\t\t&out.Requests, &out.ProviderCompleteRequests, &out.InputTokens, &out.OutputTokens,\n\t\t&out.CachedInputTokens, &out.CacheCreationInputTokens, &out.ReasoningTokens,\n\t\t&out.CatalogListPriceSubtotalUSD, &out.InferredSavingsUSD,","sourceCodeStart":709,"sourceCodeEnd":745,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/store/store.go#L709-L745","documentation":"SessionUsage returns a summary prefilled with status \"not_observed\" but fails closed with this error when sessionID fails validEvidenceToken (empty, too long, or illegal characters). It indicates the session identifier supplied is not a recognized native session token.","triggerScenarios":"Calling Store.SessionUsage(sessionID) with an empty string, a string longer than 256 chars, or one containing characters outside the evidence-token alphabet.","commonSituations":"Passing a user-supplied or URL-decoded session value without sanitizing it, passing a filename or display label instead of the stored session ID, or truncated IDs from log parsing.","solutions":["Validate the session ID in the caller before calling (non-empty, <=256 chars, allowed characters only).","Confirm the value comes from the store's own session records, not from free-form input or a filename.","Trim whitespace and check for accidental prefixes/suffixes added by log scraping.","If input is user-supplied, reject it with a clear CLI/API message instead of forwarding it."],"exampleFix":"// before\nusage, err := store.SessionUsage(strings.TrimSpace(rawArg))\n// after\nsid := strings.TrimSpace(rawArg)\nif sid == \"\" || len(sid) > 256 { return fmt.Errorf(\"usage requires a valid session id\") }\nusage, err := store.SessionUsage(sid)","handlingStrategy":"validation","validationCode":"func usableSessionID(sid string) bool {\n    sid = strings.TrimSpace(sid)\n    return sid != \"\" && len(sid) <= 256\n}","typeGuard":null,"tryCatchPattern":"usage, err := store.SessionUsage(sid)\nif err != nil && strings.Contains(err.Error(), \"invalid native session identity\") {\n    return fmt.Errorf(\"%q is not a valid session id\", sid)\n}","preventionTips":["Sanitize/trim session IDs read from logs or URLs.","Pass IDs straight from store records, not display labels or filenames.","Enforce length/charset limits in the CLI flag parsing."],"tags":["validation","session","identity"],"backgroundTag":"invalid-identifier-format","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}