HKUDS/Vibe-Trading · error · KeyError

hypothesis not found: {hypothesis_id}

Error message

hypothesis not found: {hypothesis_id}

What it means

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'.

Source

Thrown at agent/src/hypotheses/registry.py:393

        if not isinstance(raw, list):
            raise ValueError("hypotheses storage must contain a JSON list")
        return [Hypothesis.from_dict(item) for item in raw if isinstance(item, dict)]

    def _save(self, records: list[Hypothesis]) -> None:
        payload = [hyp.to_dict() for hyp in sorted(records, key=lambda h: h.created_at)]
        tmp_path = self.path.with_suffix(self.path.suffix + ".tmp")
        tmp_path.write_text(
            json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True),
            encoding="utf-8",
        )
        tmp_path.replace(self.path)

    @staticmethod
    def _find_required(records: list[Hypothesis], hypothesis_id: str) -> Hypothesis:
        for hyp in records:
            if hyp.hypothesis_id == hypothesis_id:
                return hyp
        raise KeyError(f"hypothesis not found: {hypothesis_id}")

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Call registry.list() (or search) to confirm the id exists and copy the exact hypothesis_id
  2. Verify you are pointed at the correct storage path/environment
  3. Re-create the hypothesis if it was legitimately removed, then update/link

Example fix

# before
registry.update("h-123", status="invalidated")
# after
ids = {h.hypothesis_id for h in registry.list()}
assert "h-123" in ids, f"known: {ids}"
registry.update("h-123", status="invalidated")
Defensive patterns

Strategy: type-guard

Validate before calling

ids = {h.hypothesis_id for h in registry.list()}
if hypothesis_id not in ids:
    raise LookupError(f'unknown hypothesis: {hypothesis_id}; known: {sorted(ids)[:10]}')

Type guard

def hypothesis_exists(registry, hid) -> bool:
    return any(h.hypothesis_id == hid for h in registry.list())

Try / catch

try:
    registry.update(hid, status=status)
except KeyError as exc:
    if 'hypothesis not found' in str(exc):
        log.warning('stale id %s; refreshing', hid)
        hid = resolve_current_id()  # re-search by title, etc.

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/9d3c0dcce8fa9800. Report an issue: GitHub.