{"record":{"id":"12d0642157350899","repo":"ZhuLinsen/daily_stock_analysis","slug":"invalid-status-status","errorCode":null,"errorMessage":"invalid status: {status}","messagePattern":"invalid status: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agent/events.py","lineNumber":483,"sourceCode":"    if not isinstance(rule, dict):\n        raise ValueError(\"Event alert rule must be an object\")\n\n    stock_code = str(rule.get(\"stock_code\") or \"\").strip()\n    if not stock_code:\n        raise ValueError(\"stock_code is required\")\n\n    try:\n        alert_type = AlertType(rule.get(\"alert_type\", \"\"))\n    except ValueError as exc:\n        raise ValueError(f\"invalid alert_type: {rule.get('alert_type')}\") from exc\n    _ensure_runtime_supported_alert_type(alert_type)\n\n    status = rule.get(\"status\")\n    if status is not None:\n        try:\n            AlertStatus(status)\n        except ValueError as exc:\n            raise ValueError(f\"invalid status: {status}\") from exc\n\n    ttl_hours = rule.get(\"ttl_hours\")\n    if ttl_hours is not None:\n        try:\n            ttl_value = float(ttl_hours)\n        except (TypeError, ValueError) as exc:\n            raise ValueError(f\"invalid ttl_hours: {ttl_hours}\") from exc\n        if ttl_value <= 0:\n            raise ValueError(\"ttl_hours must be > 0\")\n\n    if alert_type == AlertType.PRICE_CROSS:\n        direction = str(rule.get(\"direction\", \"above\")).lower()\n        if direction not in {\"above\", \"below\"}:\n            raise ValueError(f\"invalid direction: {direction}\")\n        try:\n            price = float(rule.get(\"price\"))\n        except (TypeError, ValueError) as exc:\n            raise ValueError(f\"invalid price: {rule.get('price')}\") from exc","sourceCodeStart":465,"sourceCodeEnd":501,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/agent/events.py#L465-L501","documentation":"Raised when an optional 'status' field on an alert rule is present but is not one of the AlertStatus enum values (active, triggered, expired, dismissed). status is optional — omitting it entirely is fine — but once present it must match exactly so rule lifecycle state stays consistent with what the EventMonitor runtime understands.","triggerScenarios":"validate_event_alert_rule with rule['status'] set to something like 'ENABLED', 'on', 'paused', '', or an int. Passing None does NOT trigger it (status is None skips validation), so only truthy garbage values fail.","commonSituations":"Serialized rules edited by hand or by an LLM that uses a different status vocabulary; importing rules from another system whose status names differ; frontend sending a localized or display-label status string.","solutions":["Use one of the exact values: 'active', 'triggered', 'expired', 'dismissed'.","Omit the status key entirely if you want the default lifecycle state rather than sending a placeholder.","Map external status vocabularies to AlertStatus values at the import boundary."],"exampleFix":"// before\nrule = {\"stock_code\": \"AAPL\", \"alert_type\": \"volume_spike\", \"status\": \"enabled\"}\n# ValueError: invalid status: enabled\n\n// after\nrule = {\"stock_code\": \"AAPL\", \"alert_type\": \"volume_spike\", \"status\": \"active\"}\nvalidate_event_alert_rule(rule)","handlingStrategy":"validation","validationCode":"from src.agent.events import AlertStatus\n\ndef valid_status(raw) -> bool:\n    return raw is None or (isinstance(raw, str) and raw in {s.value for s in AlertStatus})","typeGuard":"def has_valid_status(rule: dict) -> bool:\n    return valid_status(rule.get(\"status\"))","tryCatchPattern":"try:\n    validate_event_alert_rule(rule)\nexcept ValueError as e:\n    if str(e).startswith(\"invalid status\"):\n        rule.pop(\"status\", None)  # fall back to default lifecycle\n        validate_event_alert_rule(rule)","preventionTips":["Omit status when creating rules rather than sending placeholders.","Map external status vocabularies to AlertStatus values at import time.","Keep status values lowercase and exact."],"tags":["validation","event-monitor","enum","status"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}