mvanhorn/last30days-skill · error · KeyError

Polymarket event was not found

Error message

Polymarket event was not found

What it means

KeyError raised when the Gamma API call for the re-verification succeeded but the returned payload does not contain a usable event dict. This includes the case where the fetched event's slug or id does not match what was requested (the code nulls the event on identity mismatch) - i.e. the event was deleted, made private, or the id/slug drifted.

Source

Thrown at skills/last30days/scripts/lib/polymarket.py:1001

        event = _pick_event(payload)
    elif isinstance(payload, dict) and isinstance(payload.get("events"), list):
        event = _pick_event(payload.get("events") or [])
    else:
        event = payload
        if (
            requested_slug is not None
            and isinstance(event, dict)
            and (
                str(event.get("slug") or "").strip() not in ("", requested_slug)
                or (
                    expected_id
                    and str(event.get("id") or "").strip() not in ("", expected_id)
                )
            )
        ):
            event = None
    if not isinstance(event, dict):
        raise KeyError("Polymarket event was not found")
    # Mixed events: an active event can carry resolved child markets whose
    # high volume would win the parse and swap the outcome labels. Only fall
    # back to closed markets when nothing is active (fully resolved event -
    # the stale-odds transition verification exists to catch).
    markets = event.get("markets") or []
    has_active = any(
        isinstance(m, dict) and m.get("active", True) and not m.get("closed", False)
        for m in markets
    )
    parsed = parse_polymarket_response(
        {"events": [event]},
        include_all_outcomes=True,
        include_closed=not has_active,
    )
    if not parsed:
        raise KeyError("Polymarket event is closed, unavailable, or malformed")
    refreshed = parsed[0]
    values: dict[str, Any] = {}

View on GitHub (pinned to c7460f6114)

Solutions

  1. Treat as terminal for this datum: catch KeyError and surface the item as 'unresolvable' rather than retrying immediately
  2. If retrying, use exponential backoff to ride out transient Gamma API issues
  3. For resolved/delisted markets, refresh the item through the normal search flow to get a current event reference

Example fix

# before
val = refetch_datum(item, key)

# after
try:
    val = refetch_datum(item, key)
except KeyError:
    mark_unresolvable(item)  # event gone or identity drifted
Defensive patterns

Strategy: try-catch

Try / catch

try:
    datum = refetch_datum(item, key)
except KeyError as e:
    if "was not found" in str(e):
        mark_item_unresolvable(item)  # deleted/delisted/identity drift - terminal

Prevention

When it happens

Trigger: GET {GAMMA_EVENTS_URL}/{id} or GET ?slug=... returns a payload whose events list is empty, or returns an event whose slug differs from requested_slug, or whose id differs from expected_id (the identity check at the top of the source region sets event = None). Any subsequent isinstance(event, dict) check fails and the KeyError fires.

Common situations: Resolving-markets events that Gamma removes after settlement; slug reuse where the slug now points to a different event; transient Gamma API degradation returning malformed envelopes; stale cached ids after Polymarket migrations.

Related errors


AI-assisted analysis of mvanhorn/last30days-skill@c7460f6114 (2026-08-15). Data as JSON: /api/errors/542ca97538877a55. Report an issue: GitHub.