{"record":{"id":"b1f568b209f6c766","repo":"HKUDS/Vibe-Trading","slug":"invalid-hypotheses-storage-json-self-path","errorCode":null,"errorMessage":"invalid hypotheses storage JSON: {self.path}","messagePattern":"invalid hypotheses storage JSON: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"agent/src/hypotheses/registry.py","lineNumber":374,"sourceCode":"            haystack = json.dumps(hyp.to_dict(), ensure_ascii=False, sort_keys=True)\n            if not query_tokens:\n                score = 1\n            else:\n                hay_tokens = _tokenize(haystack)\n                score = len(query_tokens & hay_tokens)\n            if score > 0:\n                scored.append((score, hyp))\n        scored.sort(key=lambda item: (item[0], item[1].updated_at), reverse=True)\n        return [hyp for _, hyp in scored[: max(1, min(int(limit), 100))]]\n\n    def list(self) -> list[Hypothesis]:\n        \"\"\"Load all hypotheses from storage.\"\"\"\n        if not self.path.exists():\n            return []\n        try:\n            raw = json.loads(self.path.read_text(encoding=\"utf-8\"))\n        except json.JSONDecodeError as exc:\n            raise ValueError(f\"invalid hypotheses storage JSON: {self.path}\") from exc\n        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","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/hypotheses/registry.py#L356-L392","documentation":"The hypotheses storage file exists but its content is not parseable JSON, so HypothesisRegistry.list cannot load records. The original JSONDecodeError is chained as the cause, and the offending file path is included in the message.","triggerScenarios":"The JSON file at self.path contains trailing commas, truncated output from a crashed concurrent write, or hand-edited syntax errors; any subsequent list/create/update/link_backtest call then fails.","commonSituations":"Manual editing of the storage file, a previous interrupted save that left partial content, or two processes writing the file simultaneously despite the tmp-file rename scheme.","solutions":["Inspect the file at the path in the message and fix the JSON syntax (json.tool or an editor with JSON validation)","Restore from backup or an earlier version of the file if content is truncated","If unrecoverable, archive the broken file to start fresh (data loss — last resort)","Prevent recurrence: always write via registry methods, never echo/redirect into the file"],"exampleFix":"python -m json.tool hypotheses.json   # locate the syntax error, fix it manually","handlingStrategy":"try-catch","validationCode":"import json\ntry:\n    json.loads(path.read_text(encoding='utf-8'))\nexcept json.JSONDecodeError:\n    alert('hypotheses storage JSON is corrupt; restore from backup')","typeGuard":"def storage_json_ok(path) -> bool:\n    try:\n        return isinstance(json.loads(path.read_text(encoding='utf-8')), list)\n    except (OSError, json.JSONDecodeError):\n        return False","tryCatchPattern":"try:\n    records = registry.list()\nexcept ValueError as exc:\n    if 'invalid hypotheses storage JSON' in str(exc):\n        restore_from_backup(); records = registry.list()\n    else:\n        raise","preventionTips":["Never hand-edit the storage file; always go through registry methods","Keep backups/version the storage file","Ensure only one process writes the registry at a time"],"tags":["python","json","corrupt-file","persistence"],"backgroundTag":"corrupt-json-file","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}