{"record":{"id":"20c688c4ce13b063","repo":"HKUDS/Vibe-Trading","slug":"commitment-must-be-non-negative-it-is-a-size-not","errorCode":null,"errorMessage":"commitment must be non-negative (it is a size, not a signed cash flow), got {self.commitment!r}","messagePattern":"commitment must be non-negative \\(it is a size, not a signed cash flow\\), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/entities/models.py","lineNumber":314,"sourceCode":"                negative, ``management_fee_rate`` is out of ``[0, 1]``, or\n                ``vintage_year`` is implausible.\n        \"\"\"\n        super().__post_init__()\n        try:\n            object.__setattr__(self, \"structure\", FundStructure(self.structure))\n        except ValueError as exc:\n            valid = \", \".join(member.value for member in FundStructure)\n            raise ValueError(\n                f\"unknown structure {self.structure!r}; expected one of: {valid}\"\n            ) from exc\n        if self.vintage_year is not None and not 1800 <= int(self.vintage_year) <= 2200:\n            raise ValueError(\n                f\"vintage_year={self.vintage_year!r} is outside the plausible \"\n                \"range 1800-2200\"\n            )\n        if self.commitment is not None:\n            if float(self.commitment) < 0:\n                raise ValueError(\n                    f\"commitment must be non-negative (it is a size, not a signed \"\n                    f\"cash flow), got {self.commitment!r}\"\n                )\n            object.__setattr__(self, \"commitment\", float(self.commitment))\n        if self.management_fee_rate is not None:\n            rate = float(self.management_fee_rate)\n            if not 0.0 <= rate <= 1.0:\n                raise ValueError(\n                    f\"management_fee_rate must be a decimal fraction in [0, 1] \"\n                    f\"(0.02 means 2%), got {self.management_fee_rate!r}\"\n                )\n            object.__setattr__(self, \"management_fee_rate\", rate)\n\n\n@dataclass(frozen=True)\nclass Bond(Instrument):\n    \"\"\"A debt instrument paying scheduled coupons and returning principal.\n","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/entities/models.py#L296-L332","documentation":"Fund.__post_init__ requires commitment, when provided, to be a non-negative size: float(commitment) < 0 raises because commitment represents the fund's size, not a signed cash flow. The value is stored as float after validation.","triggerScenarios":"Fund(..., commitment=-50_000_000) from a data feed that encodes withdrawals as negative commitments, or a sign error in unit conversion (e.g. subtracting instead of adding adjustments).","commonSituations":"Reusing P&L/cash-flow sign conventions for a size field; importing from accounting systems where debits are negative; arithmetic bugs in normalization pipelines that flip the sign.","solutions":["Pass the absolute commitment size if the magnitude is correct","Fix the upstream transformation that applied a cash-flow sign convention to a size field","Add an ingest check: warn or reject rows with negative commitment and report them for manual review"],"exampleFix":"# before\nFund(instrument_id='f1', commitment=-100_000_000)\n\n# after\nFund(instrument_id='f1', commitment=100_000_000)","handlingStrategy":"validation","validationCode":"commitment = row.get('commitment')\nif commitment is not None:\n    commitment = float(commitment)\n    if commitment < 0:\n        commitment = abs(commitment)  # only if magnitude is known-correct\nFund(..., commitment=commitment)","typeGuard":"def is_valid_commitment(c) -> bool:\n    return c is None or float(c) >= 0","tryCatchPattern":null,"preventionTips":["Keep size fields unsigned; use separate signed fields for cash flows","Flag negative sizes during data profiling rather than auto-flipping signs"],"tags":["python","dataclass","sign-validation","funds"],"backgroundTag":"numeric-sign-validation","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}