{"record":{"id":"2f987714ffdba573","repo":"HumanSignal/label-studio","slug":"failed-to-create-state-record-for-transition-name","errorCode":null,"errorMessage":"Failed to create state record for {transition_name}","messagePattern":"Failed to create state record for (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"label_studio/fsm/transition_executor.py","lineNumber":157,"sourceCode":"\n    # Check if this transition forces state record creation (for audit trails)\n    force_state_record = getattr(transition, '_force_state_record', False)\n\n    # Use context.reason if provided (caller override), otherwise use transition's default\n    reason = context.reason if context.reason else transition.get_reason(context)\n\n    success = state_manager_class.transition_state(\n        entity=entity,\n        new_state=target_state,\n        transition_name=transition.transition_name,\n        user=user,\n        context=transition_context_data,\n        reason=reason,\n        force_state_record=force_state_record,\n    )\n\n    if not success:\n        raise ValueError(f'Failed to create state record for {transition_name}')\n\n    # Get the newly created state record via StateManager\n    state_record = state_manager_class.get_current_state_object(entity)\n\n    # Phase 3: Finalize the transition\n    transition.finalize(context, state_record)\n\n    return state_record\n","sourceCodeStart":139,"sourceCodeEnd":166,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/fsm/transition_executor.py#L139-L166","documentation":"After running the transition, the executor checks whether a new state record was successfully persisted via the state manager. If the state-manager apply/record call returns success=False, it raises ValueError indicating the state record creation failed for that transition.","triggerScenarios":"The underlying state_manager.apply_transition call returns False — typically because validation failed, the state model save failed, or force_state_record was False and no state record was created.","commonSituations":"Database constraint violations or transaction rollback silently swallowed into success=False; concurrent modification of the entity; transition finalize logic mutating state in a way the manager rejects; misconfigured state model for the entity.","solutions":["Inspect logs around the apply_transition call to find why success was False (validation error vs. DB error).","Run the transition inside a debug shell and call state_manager methods directly to surface the underlying exception.","Ensure the state model and registry are correctly configured for the entity.","Check for race conditions: reload the entity and retry the transition if another process mutated it."],"exampleFix":"// before\nsuccess = state_manager.apply_transition(...)\nif not success:\n    raise ValueError(f'Failed to create state record for {transition_name}')\n// after\nresult = state_manager.apply_transition_with_detail(...)  # returns error info\nif not result.success:\n    logger.error('state record failed: %s', result.reason)\n    raise ValueError(f'Failed to create state record for {transition_name}: {result.reason}')","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    execute_transition(entity, name, **kwargs)\nexcept ValueError as e:\n    if str(e).startswith('Failed to create state record'):\n        logger.exception('State record creation failed; entity=%s transition=%s', entity.pk, name)\n        # inspect entity state, rollback or retry once\n    else:\n        raise","preventionTips":["Wrap transitions in transactions and surface underlying DB errors to logs.","Monitor for repeated success=False returns from apply_transition.","Keep the state model's required fields satisfiable by the transition context."],"tags":["fsm","transition","persistence"],"backgroundTag":"state-record-creation-failed","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}