Skip to content

fix: reconnect chronik WS on end + run sync triggers w/o prices - #1155

Merged
Klakurka merged 1 commit into
masterfrom
fix/chronik-ws-reconnect-and-sync-triggers
Nov 26, 2026
Merged

Klakurka merged 1 commit into
masterfrom
fix/chronik-ws-reconnect-and-sync-triggers

Conversation

@Klakurka

@Klakurka Klakurka commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Payment triggers stopped firing even though payments were detected:

  • The chronik WS used autoReconnect: false and reconnected from onReconnect, but chronik-client only calls onReconnect when autoReconnect is true. After the first drop the socket stayed dead until restart, so no mempool/block messages (and no triggers) were processed. Reconnect from onEnd instead, carrying over address subscriptions, retrying the connection indefinitely with capped backoff, and ignoring stale endpoints and intentional closes.

  • Txs committed by the bulk sync have no prices linked yet, so getTransactionValue threw before any trigger ran or was logged. Look up the day's prices when a tx has none, only when a post trigger uses , and if that fails log an error for those triggers while still running the rest.

Summary by CodeRabbit

  • New Features
    • Transaction notifications that include <value> can now use fetched price data when linked prices are unavailable.
  • Bug Fixes
    • Chronik WebSocket connections retry with increasing delays and reconnect after interruptions, restoring block and address subscriptions.
    • Price lookups are shared for transactions on the same day. If a lookup fails, value-dependent notifications are skipped while other triggers continue.
    • Replaced or intentionally closed connections no longer trigger reconnection attempts.

…inked prices

Payment triggers stopped firing even though payments were detected:

- The chronik WS used autoReconnect: false and reconnected from onReconnect,
  but chronik-client only calls onReconnect when autoReconnect is true. After
  the first drop the socket stayed dead until restart, so no mempool/block
  messages (and no triggers) were processed. Reconnect from onEnd instead,
  carrying over address subscriptions, retrying the connection indefinitely
  with capped backoff, and ignoring stale endpoints and intentional closes.

- Txs committed by the bulk sync have no prices linked yet, so
  getTransactionValue threw before any trigger ran or was logged. Look up the
  day's prices when a tx has none, only when a post trigger uses <value>, and
  if that fails log an error for those triggers while still running the rest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Klakurka Klakurka self-assigned this Nov 26, 2026
@Klakurka Klakurka added the bug Something isn't working label Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PR changes Chronik WebSocket lifecycle management to retry with capped backoff and restore subscriptions after endpoint termination. It also resolves missing transaction prices for value-dependent post triggers, reuses lookups by day, and skips affected posts when resolution fails.

Changes: Chronik WebSocket reconnection

Layer / File(s) Summary
Generation-aware connection lifecycle
constants/index.ts, services/chronikService.ts, tests/unittests/chronikService.test.ts
Chronik retries opening the current endpoint with exponential backoff capped at 60 seconds. When an endpoint ends, the client reconnects after 5 seconds and restores block and address subscriptions. Endpoint generations prevent stale callbacks from reconnecting, and closeWs marks intentional shutdown. Tests cover reconnection, restored subscriptions, retry attempts, and shutdown.

Transaction prices for post triggers

Layer / File(s) Summary
Resolve values and prepare post triggers
services/triggerService.ts, tests/unittests/triggerService.test.ts
When a post trigger uses <value>, batch execution uses linked prices when available or fetches prices for the transaction’s day. It reuses pending lookups by day and supplies the user’s preferred quote. If lookup fails, it logs the error and skips that value-dependent post while other triggers continue.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related PRs

  • PayButton/paybutton-server#1132: Changes Chronik reconnection behavior and handling of transactions without linked prices, overlapping with code paths changed here.

Suggested reviewers: chedieck, fabcien

Merge Risk: Minimal · up to 00e0f

The change makes Chronik WebSocket reconnection resilient and lets value-dependent post triggers run when linked prices are missing. No concrete merge-blocking defect was established, so the merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two changes in the PR: reconnecting the Chronik WebSocket on connection end, and running sync triggers when transactions have no linked prices. Both appear in the raw summary and P…
Description check Passed The description states the problem, the Chronik WebSocket reconnect fix, and the trigger price-lookup fix. It explains the reasoning for each change. It does not follow the repository template: the 'R…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two changes in the PR: reconnecting the Chronik WebSocket on connection end, and running sync triggers when transactions have no linked prices. Both appear in the raw summary and PR objectives. The title is a single line of 12 words and uses the conventional 'fix:' prefix, so it is specific enough for a teammate scanning history.

Full details: Description check

Explanation

The description states the problem, the Chronik WebSocket reconnect fix, and the trigger price-lookup fix. It explains the reasoning for each change. It does not follow the repository template: the 'Related to #' line and the 'Depends on' checklist are missing, the 'Description' and 'Test plan' headings are absent, and there is no 'Test plan' section. The content is mostly complete, so the check passes, but the template structure is not followed.

Resolution

Add the 'Related to #' issue reference, the 'Depends on' checklist if applicable, and a 'Test plan' section that describes how the reconnect and sync-trigger behavior was verified. Use the template's 'Description' heading for the existing explanation.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 48f3afd3-2cc5-4529-aee1-9a37068b0ae5
Commits

Reviewing files that changed from the base of the PR and between f50287f and 00e0fa6.

Files selected for processing: 5

  • constants/index.ts
  • services/chronikService.ts
  • services/triggerService.ts
  • tests/unittests/chronikService.test.ts
  • tests/unittests/triggerService.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@Klakurka
Klakurka merged commit 94d7bea into master Nov 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant