Skip to content

fix(market-adapter): keep Kibana LP fetches alive under proxy connect… - #12

Open
Impulssi wants to merge 1 commit into
froooze:testfrom
Impulssi:fix/kibana-lp-fetch-stability
Open

fix(market-adapter): keep Kibana LP fetches alive under proxy connect…#12
Impulssi wants to merge 1 commit into
froooze:testfrom
Impulssi:fix/kibana-lp-fetch-stability

Conversation

@Impulssi

@Impulssi Impulssi commented Aug 24, 2026

Copy link
Copy Markdown

…ion resets

The Kibana console proxy at kibana.bitshares.dev now resets connections mid-transfer once a single search page streams enough data (observed with full _source payloads around ~8k documents, and even ~2k documents with _source: true). The LP fetcher queried with size 10000 and _source: true, so every fetch died at the availability probe — and worse, silently:

  • doKibanaRequest only listened for request-phase errors; a response stream aborted mid-body never emits 'end', so the surrounding promise stayed pending forever and fetch_lp_data hung with no error output.
  • There was no retry, so a single transient reset killed the whole fetch.

Fix

  • kibana_client: handle 'aborted'/'error' on the response stream and reject the promise, so callers fail loudly instead of hanging forever.
  • kibana_candles: request only the _source branches the field map actually reads (plus the fixed timestamp/sequence fields) instead of full documents. Restricted projections keep each page small and fast (verified live: 2000-doc pages with restricted _source return in ~1.5s where full _source aborts).
  • kibana_candles: default kibanaPageSize 10000 -> 2000.
  • kibana_candles: retry transient page failures (aborted / connection reset / timeout) with linear backoff — search_after pagination is stateless on the server, so replaying a failed page is safe.
  • buildDirectionalDocumentQuery accepts an optional sourceFields argument; omitting it keeps the legacy _source: true behavior for other callers.

Testing Notes

  • tests/test_kibana_candles.ts: new coverage for the source projection derivation, the _source wiring in the directional query (plus legacy fallback), and transient-page retry recovery.
  • npm run typecheck clean.
  • Verified live against kibana.bitshares.dev with fetch_lp_data.js (BTS/XBTSX.USDT pool 1.19.48, 2-month 1h fetch): the availability probe and both chunk fetches complete where they previously hung indefinitely.

Note: I'm new to this codebase and worked through this change with an AI
coding assistant (opencode). The bug was hit on my own live instance and
all measurements / reproduction steps are mine — but please flag anything
in the code that looks off and I'll dig in and follow up.

@Impulssi
Impulssi force-pushed the fix/kibana-lp-fetch-stability branch from f8aca53 to f4d779c Compare August 26, 2026 06:03
…ion resets

The Kibana console proxy at kibana.bitshares.dev now resets connections
mid-transfer once a single search page streams enough data (observed with
full _source payloads around ~8k documents, and even ~2k documents with
_source: true). The LP fetcher queried with size 10000 and _source: true,
so every fetch died at the availability probe — and worse, silently:

- doKibanaRequest only listened for request-phase errors; a response stream
  aborted mid-body never emits 'end', so the surrounding promise stayed
  pending forever and fetch_lp_data hung with no error output.
- There was no retry, so a single transient reset killed the whole fetch.

## Fix
- kibana_client: handle 'aborted'/'error' on the response stream and reject
  the promise, so callers fail loudly instead of hanging forever.
- kibana_candles: request only the _source branches the field map actually
  reads (plus the fixed timestamp/sequence fields) instead of full documents.
  Restricted projections keep each page small and fast (verified live:
  2000-doc pages with restricted _source return in ~1.5s where full _source
  aborts).
- kibana_candles: default kibanaPageSize 10000 -> 2000.
- kibana_candles: retry transient page failures (aborted / connection reset /
  timeout) with linear backoff — search_after pagination is stateless on the
  server, so replaying a failed page is safe.
- buildDirectionalDocumentQuery accepts an optional sourceFields argument;
  omitting it keeps the legacy _source: true behavior for other callers.

## Testing Notes
- tests/test_kibana_candles.ts: new coverage for the source projection
  derivation, the _source wiring in the directional query (plus legacy
  fallback), and transient-page retry recovery.
- npm run typecheck clean.
- Verified live against kibana.bitshares.dev with fetch_lp_data.js
  (BTS/XBTSX.USDT pool 1.19.48, 2-month 1h fetch): the availability probe
  and both chunk fetches complete where they previously hung indefinitely.
@Impulssi
Impulssi force-pushed the fix/kibana-lp-fetch-stability branch from f4d779c to e1ccc05 Compare August 26, 2026 06:34
froooze added a commit that referenced this pull request Aug 26, 2026
…ion resets

The kibana.bitshares.dev console proxy resets connections mid-transfer when a
single search page streams enough data (observed around ~8k documents with full
_source, and even ~2k with _source: true). The LP fetcher queried size: 10000
with _source: true, so every fetch died mid-page and silently: doKibanaRequest
only listened for request-phase errors, so a response stream aborted mid-body
never settled the promise and fetch_lp_data hung forever with no error output.
No retry existed either, so one transient reset killed the whole fetch.

## Response-stream settlement
- Problem: aborted/error during the response body left the surrounding promise pending forever
- Impact: availability probes and LP chunk fetches hung indefinitely without any log output
- Solution: market_adapter/core/kibana_client.ts now handles 'aborted'/'error' on the response stream behind a settle guard, rejecting with an actionable message instead of hanging

## Restricted _source projection
- Problem: full operation documents are heavy and trip the proxy's per-response limit
- Impact: large pages were guaranteed to be killed on busy pools
- Solution: market_adapter/core/kibana_candles.ts derives a minimal _source projection from the field map (sourceFieldsForFieldMap) plus fixed timestamp/sequence fields; buildDirectionalDocumentQuery keeps legacy _source: true behavior when no projection is passed

## Smaller pages and transient-failure retries
- Problem: oversized pages plus zero retries made every fetch a single-shot failure
- Impact: transient proxy resets aborted whole lookbacks
- Solution: kibanaPageSize default lowered 10000 -> 2000, transient page failures (aborted/reset/socket/timeout) retried up to kibanaPageRetries total attempts (4 here; upstream PR used 3) with linear backoff; safe because search_after pagination is stateless server-side

Adapted from upstream contribution bitshares#4 / #12,
raised to 4 total attempts per page and adjusted for the newer request-phase
settle guard already present in this tree.

## Risk Notes
- Retry classification matches error strings; non-transient errors rethrow immediately unchanged
- Projection branches capped at depth 3 return whole subtrees from ES, a superset of leaf reads, so no data loss

## Testing Notes
- npm run typecheck
- npm run build && node dist/tests/test_kibana_candles.js (new coverage: source projection derivation, _source wiring + legacy fallback, retry recovery after 3 failures within the 4-attempt budget)
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.

1 participant