{"record":{"id":"642eb3889c6a36a7","repo":"JuliusBrussee/caveman","slug":"invalid-agent-evidence-identity","errorCode":null,"errorMessage":"invalid agent evidence identity","messagePattern":"invalid agent evidence identity","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/store/store.go","lineNumber":670,"sourceCode":"\tContextBill                  string `json:\"context_bill\"`\n\tTransformTrace               string `json:\"transform_trace\"`\n\tTransformLocation            string `json:\"transform_location\"`\n\tCacheEpoch                   string `json:\"cache_epoch\"`\n\tCachePrefixSHA256            string `json:\"declared_cache_prefix_sha256\"`\n\tProviderCachePrefixSHA256    string `json:\"provider_cache_prefix_sha256\"`\n\tProviderCacheComponentSHA256 string `json:\"provider_cache_component_sha256\"`\n\tCacheBoundaryKnown           bool   `json:\"cache_boundary_known\"`\n\tRecoveryHandle               string `json:\"recovery_handle\"`\n\tCompressionTokensBefore      int64  `json:\"compression_tokens_before\"`\n\tCompressionTokensAfter       int64  `json:\"compression_tokens_after\"`\n\tBasis                        string `json:\"basis\"`\n}\n\n// AgentEvidenceForBuild returns all requests for one exact session/build/plan\n// tuple in provider-call order. Partial or malformed identity fails closed.\nfunc (s *Store) AgentEvidenceForBuild(sessionID, buildSHA256, planSHA256 string) ([]AgentEvidence, error) {\n\tif !validEvidenceToken(sessionID, 256) || !validDigest(buildSHA256) || !validDigest(planSHA256) {\n\t\treturn nil, fmt.Errorf(\"invalid agent evidence identity\")\n\t}\n\trows, err := s.db.Query(\n\t\t`SELECT ts, request_id, session_id, agent_build_sha256, efficiency_plan_sha256,\n\t\t        COALESCE(provider,''), COALESCE(model,''), COALESCE(status_code,0),\n\t\t        COALESCE(input_tokens,0), COALESCE(output_tokens,0), COALESCE(cached_input_tokens,0),\n\t\t        COALESCE(cache_creation_input_tokens,0), COALESCE(reasoning_tokens,0),\n\t\t        COALESCE(token_usage_basis,'unavailable'), COALESCE(raw_request_sha256,''),\n\t\t        COALESCE(transformed_request_sha256,''), COALESCE(request_hash_complete,0), COALESCE(optimization_ids,''),\n\t\t        COALESCE(context_bill,''), COALESCE(transform_trace,''), COALESCE(transform_location,''),\n\t\t        COALESCE(cache_epoch,''), COALESCE(cache_prefix_sha256,''),\n\t\t        COALESCE(provider_cache_prefix_sha256,''), COALESCE(provider_cache_component_sha256,''),\n\t\t        COALESCE(cache_boundary_known,0), COALESCE(recovery_handle,''),\n\t\t        COALESCE(compression_tokens_before,0), COALESCE(compression_tokens_after,0), basis\n\t\t   FROM requests\n\t\t  WHERE session_id = ? AND agent_build_sha256 = ? AND efficiency_plan_sha256 = ?\n\t\t  ORDER BY id ASC\n\t\t  LIMIT 500`,\n\t\tsessionID, buildSHA256, planSHA256,","sourceCodeStart":652,"sourceCodeEnd":688,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/store/store.go#L652-L688","documentation":"AgentEvidenceForBuild requires a fully valid identity tuple: sessionID (evidence token, max 256 chars), buildSHA256 and planSHA256 (64-char digests). Any partial or malformed identity fails closed with this error rather than querying with wrong data.","triggerScenarios":"Calling Store.AgentEvidenceForBuild with an empty/malformed sessionID, or a build/plan SHA that is empty, not 64 hex chars, or contains non-hex characters.","commonSituations":"Callers pass placeholder strings like \"unknown\" or \"-\" for build/plan SHAs, truncate a digest, or read a session ID from untrusted request input that fails the token validation.","solutions":["Verify buildSHA256 and planSHA256 are exact 64-character lowercase hex strings from the recorded evidence.","Check the session ID is non-empty, within 256 chars, and contains only accepted token characters.","Log/inspect the three values before the call to see which one fails validation.","If the caller doesn't have real digests, don't call this API — fetch the SHAs from the build/plan records first."],"exampleFix":"// before\nev, err := store.AgentEvidenceForBuild(sessionID, buildSHA, \"\")\n// after\nif buildSHA == \"\" { buildSHA = record.BuildSHA256 }\nif isValidDigest(buildSHA) && isValidDigest(planSHA) {\n    ev, err = store.AgentEvidenceForBuild(sessionID, buildSHA, planSHA)\n}","handlingStrategy":"validation","validationCode":"func validBuildInputs(session, build, plan string) bool {\n    return session != \"\" && len(session) <= 256 &&\n        len(build) == 64 && len(plan) == 64 &&\n        isHex(build) && isHex(plan)\n}","typeGuard":null,"tryCatchPattern":"ev, err := store.AgentEvidenceForBuild(sid, build, plan)\nif err != nil && err.Error() == \"invalid agent evidence identity\" {\n    return fmt.Errorf(\"bad identity tuple: session=%q build=%q plan=%q\", sid, build, plan)\n}","preventionTips":["Always source digests from the build/plan records, never placeholders.","Validate identity tuple at the CLI boundary before calling the store.","Never truncate SHA-256 strings when logging or copying."],"tags":["validation","evidence","identity"],"backgroundTag":"invalid-argument-value","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"}