{"record":{"id":"ab71ee5cf0700253","repo":"HKUDS/Vibe-Trading","slug":"goal-status-goal-status-value-r-is-not-mutable","errorCode":null,"errorMessage":"goal status {goal.status.value!r} is not mutable","messagePattern":"goal status (.+?) is not mutable","errorType":"validation","errorClass":"StaleGoalError","httpStatus":null,"severity":"error","filePath":"agent/src/goal/store.py","lineNumber":839,"sourceCode":"        if updated is None:\n            raise RuntimeError(\"usage-updated goal could not be reloaded\")\n        return updated\n\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:","sourceCodeStart":821,"sourceCodeEnd":857,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/goal/store.py#L821-L857","documentation":"The goal exists but its status is not in _CURRENT_STATUSES, so it is immutable (e.g. already completed, abandoned, or archived). The store refuses to mutate terminal-state goals.","triggerScenarios":"Calling update_goal/append_evidence/update_status/account_usage on a goal whose status was already moved to a terminal value (completed, abandoned, etc.).","commonSituations":"Retrying an operation after the goal was completed by a concurrent writer; stale UI showing an active goal; replaying an old request.","solutions":["Check goal.status first and branch: completed goals need a new goal, not edits","If the transition itself failed halfway, inspect the goal state before retrying","Serialize status transitions per session so only one writer completes/abandons"],"exampleFix":"// before\nstore.append_evidence(session_id, goal_id, expected_goal_id, ...)\n// after\ngoal = store._require_mutable_goal  # or: goal = store.get_goal(goal_id)\nif goal is not None and goal.status not in {\"active\", \"in_progress\"}:\n    raise RuntimeError(f\"goal {goal.goal_id} is terminal: {goal.status}\")\nstore.append_evidence(session_id, goal_id, expected_goal_id, ...)","handlingStrategy":"validation","validationCode":"goal = store.get_goal(goal_id)\nif goal is None or goal.status not in _CURRENT_STATUSES:\n    handle_terminal_goal(goal)","typeGuard":"def is_mutable_goal(goal, current_statuses) -> bool:\n    return goal is not None and goal.status in current_statuses","tryCatchPattern":"except StaleGoalError as e: if 'not mutable' in str(e): treat goal as terminal — start a new goal, do not retry","preventionTips":["Check status before every mutation attempt","Serialize completion with other writers","Never retry blindly on StaleGoalError"],"tags":["goal-store","immutable-state","status-transition","python"],"backgroundTag":"invalid-state-transition","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}