JuliusBrussee/caveman · error
invalid native session identity
Error message
invalid native session identity
What it means
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.
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.
Example fix
// before
usage, err := store.SessionUsage(strings.TrimSpace(rawArg))
// after
sid := strings.TrimSpace(rawArg)
if sid == "" || len(sid) > 256 { return fmt.Errorf("usage requires a valid session id") }
usage, err := store.SessionUsage(sid) Defensive patterns
Strategy: validation
Validate before calling
func usableSessionID(sid string) bool {
sid = strings.TrimSpace(sid)
return sid != "" && len(sid) <= 256
} Try / catch
usage, err := store.SessionUsage(sid)
if err != nil && strings.Contains(err.Error(), "invalid native session identity") {
return fmt.Errorf("%q is not a valid session id", sid)
} Prevention
- 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.
When it happens
Trigger: Calling Store.SessionUsage(sessionID) with an empty string, a string longer than 256 chars, or one containing characters outside the evidence-token alphabet.
Common situations: 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.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- invalid agent evidence identity
- Agno middleware requires a nonempty native session_id
- apiKey, baseURL, and agent are required
- arm must be or
- artifact_id is required
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/cf6b2f814786db2c.
Report an issue: GitHub.
Appendix: source
Thrown at proxy/internal/store/store.go:727
return nil, err
}
out = append(out, item)
}
return out, rows.Err()
}
// SessionUsage returns content-blind provider telemetry for one exact correlated
// native session. Dollar values remain catalog list-price subtotals/inferred
// standalone savings; neither is a provider invoice or verified savings.
func (s *Store) SessionUsage(sessionID string) (sessionusage.Snapshot, error) {
out := sessionusage.Snapshot{
Status: "not_observed",
SessionID: sessionID,
CostBasis: "catalog_list_price_subtotal_provider_complete_priced_rows",
SavingsBasis: "inferred_standalone_not_verified",
}
if !validEvidenceToken(sessionID, 256) {
return out, fmt.Errorf("invalid native session identity")
}
var compressionBases, correlationBases string
err := s.db.QueryRow(
`SELECT COUNT(*),
COALESCE(SUM(CASE WHEN token_usage_basis = 'provider_complete' THEN 1 ELSE 0 END),0),
COALESCE(SUM(input_tokens),0), COALESCE(SUM(output_tokens),0),
COALESCE(SUM(cached_input_tokens),0), COALESCE(SUM(cache_creation_input_tokens),0),
COALESCE(SUM(reasoning_tokens),0), COALESCE(SUM(total_cost_usd),0),
COALESCE(SUM(savings_usd),0), COALESCE(SUM(compression_tokens_before),0),
COALESCE(SUM(compression_tokens_after),0),
COALESCE(GROUP_CONCAT(DISTINCT NULLIF(compression_token_count_basis,'')),''),
COALESCE(GROUP_CONCAT(DISTINCT NULLIF(session_correlation_basis,'')),'')
FROM requests WHERE session_id = ?`,
sessionID,
).Scan(
&out.Requests, &out.ProviderCompleteRequests, &out.InputTokens, &out.OutputTokens,
&out.CachedInputTokens, &out.CacheCreationInputTokens, &out.ReasoningTokens,
&out.CatalogListPriceSubtotalUSD, &out.InferredSavingsUSD,View on GitHub (pinned to 3ee70a1026)