{"record":{"id":"9d3c0dcce8fa9800","repo":"HKUDS/Vibe-Trading","slug":"hypothesis-not-found-hypothesis-id","errorCode":null,"errorMessage":"hypothesis not found: {hypothesis_id}","messagePattern":"hypothesis not found: (.+?)","errorType":"validation","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"agent/src/hypotheses/registry.py","lineNumber":393,"sourceCode":"        if not isinstance(raw, list):\n            raise ValueError(\"hypotheses storage must contain a JSON list\")\n        return [Hypothesis.from_dict(item) for item in raw if isinstance(item, dict)]\n\n    def _save(self, records: list[Hypothesis]) -> None:\n        payload = [hyp.to_dict() for hyp in sorted(records, key=lambda h: h.created_at)]\n        tmp_path = self.path.with_suffix(self.path.suffix + \".tmp\")\n        tmp_path.write_text(\n            json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True),\n            encoding=\"utf-8\",\n        )\n        tmp_path.replace(self.path)\n\n    @staticmethod\n    def _find_required(records: list[Hypothesis], hypothesis_id: str) -> Hypothesis:\n        for hyp in records:\n            if hyp.hypothesis_id == hypothesis_id:\n                return hyp\n        raise KeyError(f\"hypothesis not found: {hypothesis_id}\")\n","sourceCodeStart":375,"sourceCodeEnd":394,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/hypotheses/registry.py#L375-L394","documentation":"Raised by HypothesisRegistry._find_required when no stored hypothesis matches the given hypothesis_id; update and link_backtest refuse to operate on unknown ids. It is a KeyError, not ValueError, so it signals 'no such entity'.","triggerScenarios":"Calling update('h-123', ...) or link_backtest('h-123', ...) when 'h-123' is not in storage; using an id from a different environment/storage file; typos or truncated ids copied from logs.","commonSituations":"Stale ids captured before a storage reset, running against a different working directory whose registry file has other hypotheses, or race where another process deleted the record.","solutions":["Call registry.list() (or search) to confirm the id exists and copy the exact hypothesis_id","Verify you are pointed at the correct storage path/environment","Re-create the hypothesis if it was legitimately removed, then update/link"],"exampleFix":"# before\nregistry.update(\"h-123\", status=\"invalidated\")\n# after\nids = {h.hypothesis_id for h in registry.list()}\nassert \"h-123\" in ids, f\"known: {ids}\"\nregistry.update(\"h-123\", status=\"invalidated\")","handlingStrategy":"type-guard","validationCode":"ids = {h.hypothesis_id for h in registry.list()}\nif hypothesis_id not in ids:\n    raise LookupError(f'unknown hypothesis: {hypothesis_id}; known: {sorted(ids)[:10]}')","typeGuard":"def hypothesis_exists(registry, hid) -> bool:\n    return any(h.hypothesis_id == hid for h in registry.list())","tryCatchPattern":"try:\n    registry.update(hid, status=status)\nexcept KeyError as exc:\n    if 'hypothesis not found' in str(exc):\n        log.warning('stale id %s; refreshing', hid)\n        hid = resolve_current_id()  # re-search by title, etc.","preventionTips":["Look up ids from registry.list()/search() at call time, don't cache them long-term","Confirm the storage path matches the environment before using stored ids","Catch KeyError separately from ValueError for not-found vs invalid-input"],"tags":["python","not-found","key-error"],"backgroundTag":"entity-not-found","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}