{"record":{"id":"ecabbdb964812695","repo":"HKUDS/Vibe-Trading","slug":"unknown-evidence-id-evidence-id","errorCode":null,"errorMessage":"unknown evidence_id: {evidence_id}","messagePattern":"unknown evidence_id: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/goal/store.py","lineNumber":922,"sourceCode":"        criteria = self.list_criteria(goal.goal_id)\n        rows_by_criterion = {row.criterion_id: row for row in audit}\n        for criterion in criteria:\n            if not criterion.required:\n                continue\n            row = rows_by_criterion.get(criterion.criterion_id)\n            if row is None:\n                raise ValueError(f\"missing audit row for criterion {criterion.criterion_id}\")\n            if row.result not in _COMPLETION_RESULTS:\n                raise ValueError(f\"criterion {criterion.criterion_id} is not satisfied\")\n            if row.result in {\"satisfied\", \"satisfied_with_caveat\"} and not row.evidence_ids:\n                raise ValueError(\"complete goals require verified evidence\")\n            if row.result == \"not_applicable_user_accepted\" and not row.notes.strip():\n                raise ValueError(\"not-applicable criteria require acceptance notes\")\n            has_verified_evidence = False\n            for evidence_id in row.evidence_ids:\n                evidence = self._get_evidence(evidence_id)\n                if evidence is None or evidence.goal_id != goal.goal_id:\n                    raise ValueError(f\"unknown evidence_id: {evidence_id}\")\n                if evidence.criterion_id != criterion.criterion_id:\n                    raise ValueError(\n                        f\"evidence {evidence_id} does not match criterion {criterion.criterion_id}\"\n                    )\n                if evidence.verification_status == \"verified\":\n                    has_verified_evidence = True\n            if row.result in {\"satisfied\", \"satisfied_with_caveat\"} and not has_verified_evidence:\n                raise ValueError(\"complete goals require verified evidence\")\n\n    def _get_evidence(self, evidence_id: str) -> EvidenceRecord | None:\n        row = self._conn.execute(\n            \"SELECT * FROM goal_evidence WHERE evidence_id = ?\",\n            (evidence_id,),\n        ).fetchone()\n        return self._evidence_from_row(row) if row else None\n\n    @staticmethod\n    def _goal_from_row(row: sqlite3.Row) -> GoalRecord:","sourceCodeStart":904,"sourceCodeEnd":940,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/goal/store.py#L904-L940","documentation":"A completion audit row cited an evidence_id that does not exist in goal_evidence, or exists but belongs to a different goal. The validator resolves every cited evidence record against the goal being completed.","triggerScenarios":"update_status with evidence_ids containing a typo'd id, an id from another goal, or an id from evidence that was never appended.","commonSituations":"Evidence appended to a different goal (often after goal recreation); truncated/copied ids; evidence append failed silently and the id was assumed.","solutions":["Append the evidence to this goal first and use the exact returned evidence_id","Cross-check each evidence_id via the store before submitting the audit","Keep evidence and audit construction in the same code path so ids stay consistent"],"exampleFix":"// before\nAuditRow(criterion_id=\"c1\", result=\"satisfied\", evidence_ids=[\"ev-123\"])\n// after\nev = store.append_evidence(session_id, goal_id, criterion_id=\"c1\", ...)\nAuditRow(criterion_id=\"c1\", result=\"satisfied\", evidence_ids=[ev.evidence_id])","handlingStrategy":"validation","validationCode":"valid = {e.evidence_id for e in store.list_evidence(goal_id)}\nbad = [eid for row in audit for eid in row.evidence_ids if eid not in valid]\nassert not bad, f\"unknown evidence ids: {bad}\"","typeGuard":"def evidence_ids_valid(store, goal_id: str, audit: list) -> bool:\n    valid = {e.evidence_id for e in store.list_evidence(goal_id)}\n    return all(eid in valid for row in audit for eid in row.evidence_ids)","tryCatchPattern":"except ValueError as e: if str(e).startswith('unknown evidence_id'): re-append evidence for the criterion and rebuild the audit","preventionTips":["Use only evidence ids returned by append_evidence on the same goal","Check append success before recording ids","Rebuild audit after any goal recreation"],"tags":["goal-store","completion-audit","evidence-id","python"],"backgroundTag":"unknown-foreign-key-reference","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}