{"record":{"id":"0f9fda217910e5bc","repo":"HKUDS/Vibe-Trading","slug":"goal-is-not-current-for-this-session","errorCode":null,"errorMessage":"goal is not current for this session","messagePattern":"goal is not current for this session","errorType":"validation","errorClass":"StaleGoalError","httpStatus":null,"severity":"error","filePath":"agent/src/goal/store.py","lineNumber":842,"sourceCode":"\n    def _require_mutable_goal(\n        self,\n        session_id: str,\n        goal_id: str,\n        expected_goal_id: str,\n    ) -> GoalRecord:\n        if expected_goal_id != goal_id:\n            raise StaleGoalError(\"expected_goal_id does not match target goal\")\n        session_id = normalize_required_text(session_id, \"session_id\")\n        goal_id = normalize_required_text(goal_id, \"goal_id\")\n        goal = self.get_goal(goal_id)\n        if goal is None or goal.session_id != session_id:\n            raise StaleGoalError(\"goal is not available for this session\")\n        if goal.status not in _CURRENT_STATUSES:\n            raise StaleGoalError(f\"goal status {goal.status.value!r} is not mutable\")\n        current = self.get_current_goal(session_id)\n        if current is None or current.goal_id != goal_id:\n            raise StaleGoalError(\"goal is not current for this session\")\n        return goal\n\n    @staticmethod\n    def _verification_status(evidence: EvidenceInput) -> str:\n        \"\"\"Return whether evidence has a traceable local artifact/run source.\"\"\"\n        if evidence.artifact_path:\n            try:\n                artifact = safe_document_path(evidence.artifact_path)\n            except ValueError:\n                artifact = None\n            if artifact and artifact.is_file():\n                if GoalStore._artifact_hash_matches(artifact, evidence.artifact_hash):\n                    return \"verified\"\n        if evidence.run_id:\n            try:\n                run_dir = safe_run_id(evidence.run_id)\n            except ValueError:\n                run_dir = None","sourceCodeStart":824,"sourceCodeEnd":860,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/goal/store.py#L824-L860","documentation":"The goal exists and is mutable, but get_current_goal(session_id) returns a different goal (or none). The store only allows mutations on the session's designated current goal.","triggerScenarios":"A new goal was created for the session, demoting the old one to non-current; then updating the old goal via update_goal/append_evidence/update_status/account_usage.","commonSituations":"Agent creates a follow-up goal and a delayed writer still targets the previous goal; tests seeding multiple goals per session without setting currency.","solutions":["Use get_current_goal(session_id).goal_id as the target","If the old goal genuinely needs changes, complete/archive the new one or restructure so only one active goal exists","Treat as a signal to refresh the agent's goal cache"],"exampleFix":"// before\nstore.update_goal(session_id, goal_id=stale_goal_id, ...)\n// after\ncurrent = store.get_current_goal(session_id)\nstore.update_goal(session_id, goal_id=current.goal_id, ...)","handlingStrategy":"validation","validationCode":"current = store.get_current_goal(session_id)\nif current is None or current.goal_id != goal_id:\n    goal_id = current.goal_id if current else None  # or bail","typeGuard":"def is_current_goal(store, session_id: str, goal_id: str) -> bool:\n    cur = store.get_current_goal(session_id)\n    return cur is not None and cur.goal_id == goal_id","tryCatchPattern":"except StaleGoalError as e: if 'not current' in str(e): re-fetch current goal and re-route the operation","preventionTips":["Invalidate cached goal ids after create_goal calls","Route all mutations through a single goal-resolution helper","Treat currency checks as part of your concurrency contract"],"tags":["goal-store","current-goal","stale-state","python"],"backgroundTag":"stale-entity-reference","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}