Skip to content

fix(polymarket): resolve inactive markets via CLOB slug and stop retrying deleted events - #308

Merged
YaroShkvorets merged 1 commit into
fix/polymarket-enrichment-placeholder-marketsfrom
fix/polymarket-inactive-markets-and-deleted-events
Oct 7, 2026
Merged

YaroShkvorets merged 1 commit into
fix/polymarket-enrichment-placeholder-marketsfrom
fix/polymarket-inactive-markets-and-deleted-events

Conversation

@YaroShkvorets

Copy link
Copy Markdown
Member

Follow-up to #307. Stacked on #307: this PR targets that branch and contains only the follow-up commit. Merge #307 first; GitHub will then retarget this PR to main.

Problem

Gamma's /markets/keyset never returns inactive markets, whatever active/closed/archived filters are passed. Polymarket has many of these: unnamed negRisk placeholder slots like "Will candidate O be the next regional board…" or MLB NRFI markets. #307 fixed the enrichment pass. This PR fixes the two remaining problems:

  1. Main pass: on-chain registrations of these markets failed with No market found for condition_id every cycle (104 distinct ids in a single prod run on 2026-10-07).
  2. Deleted events: /events/keyset returns [] both on errors and for events that no longer exist, so a deleted event was retried forever and could pin the head of the enrichment queue, the same failure mode as fix(polymarket): use event-embedded markets in enrichment so placeholders don't stall the queue #307.

Fix

Main pass (fetchMarketFromApi): when keyset doesn't return a market, fall back to CLOB /markets/{condition_id} to get its market_slug, then Gamma /markets/slug/{slug} for the full market including events. The result is only accepted if its conditionId matches the one requested.

Enrichment (fetchEventFromApi): when keyset is empty, fall back to /events/slug/{slug}. A 404 returns 'not_found' and processEventEnrichment records the event as enriched (0 markets). Any other failure returns null and stays retriable.

A new fetchJson helper keeps a 404 distinct from other failures for single-object endpoints. fetchGammaApi is unchanged.

Verification

  • Smoke test against the live Gamma and CLOB APIs: 104/104 condition ids failing in prod now resolve. A real event slug returns its 18 markets, and a fake slug returns 'not_found'.
  • Brand-new markets that Gamma hasn't indexed yet still return null and are retried as before.
  • Tests added: CLOB slug fallback, CLOB miss, slug resolving to a different condition (rejected), keyset hit skips the fallback; event keyset hit, slug fallback, 404 → 'not_found', 503 → null; deleted event recorded by the enrichment pass.
  • bun test services/polymarket: 35/35 pass. The 9 hyperliquid failures also happen on main and are unrelated.

Note

fetchMarketsFromApi (batch) is now only used by its tests. Gamma's OpenAPI spec caps condition_ids at 100 per request, while KEYSET_PAGE_LIMIT is 1000, so it's worth checking if anything starts using it again.

🤖 Generated with Claude Code

…ying deleted events

Main pass: `/markets/keyset` never returns inactive markets whatever filters
are passed, so on-chain registrations of negRisk placeholder slots failed
with "No market found" every cycle. Fall back to CLOB `/markets/{condition}`
for the `market_slug`, then Gamma `/markets/slug/{slug}` for the full market
(with events). Resolves all 104 condition ids failing in prod right now.

Enrichment: `/events/keyset` returns [] both on errors and for deleted
events. Fall back to `/events/slug/{slug}` and record the event as enriched
on a 404, so deleted events can't pin the head of the queue; other
failures stay retriable.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The fallback paths are validated, preserve retry behavior for transient failures, and have focused test coverage.

0 open findings

What changed in this PR

Adds reliable fallbacks for inactive Polymarket markets and deleted events.

Changes:

  • Resolves omitted markets through CLOB and Gamma slug endpoints.
  • Distinguishes deleted events from transient API failures.
  • Adds fallback and enrichment tests.
File Description
services/​polymarket/​gamma.ts Adds market and event fallback lookups.
services/​polymarket/​index.ts Records deleted events as enriched.
services/​polymarket/​index.test.ts Tests deleted-event enrichment.
services/​polymarket/​fetch-gamma.test.ts Tests fallback API behavior.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@YaroShkvorets
YaroShkvorets merged commit 846f4fb into fix/polymarket-enrichment-placeholder-markets Oct 7, 2026
1 check passed
@YaroShkvorets
YaroShkvorets deleted the fix/polymarket-inactive-markets-and-deleted-events branch October 7, 2026 15:24
YaroShkvorets added a commit that referenced this pull request Oct 7, 2026
…ders don't stall the queue (#307)

* fix(polymarket): use event-embedded markets in enrichment so placeholders don't stall the queue

The enrichment pass re-fetched missing child markets via
`/markets/keyset?condition_ids=`, which never returns placeholder markets
(e.g. unnamed negRisk "App D" slots) even though `/events/keyset` lists them.
An empty result was treated as a transient failure and the event was left
unrecorded, so those slugs stayed at the head of the alphabetical queue and
the same 1000 events were retried every cycle without writing anything.

- Insert the full market objects already embedded in the event response,
  linking them back to the parent event; drops one Gamma call per event.
- Record every event Gamma returns in polymarket_events_enriched, including
  ones with no markets; only a failed event fetch stays retriable.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(polymarket): resolve inactive markets via CLOB slug and stop retrying deleted events (#308)

Main pass: `/markets/keyset` never returns inactive markets whatever filters
are passed, so on-chain registrations of negRisk placeholder slots failed
with "No market found" every cycle. Fall back to CLOB `/markets/{condition}`
for the `market_slug`, then Gamma `/markets/slug/{slug}` for the full market
(with events). Resolves all 104 condition ids failing in prod right now.

Enrichment: `/events/keyset` returns [] both on errors and for deleted
events. Fall back to `/events/slug/{slug}` and record the event as enriched
on a 404, so deleted events can't pin the head of the queue; other
failures stay retriable.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants