Reconnect on live (tier1) drift via session linear-handoff block - #28
Merged
Conversation
The --live-drift-reconnect check previously gated on the sink library's DeltaLivenessChecker `isLive` flag, which only latches once a block lands within --live-block-time-delta of wall-clock. An endpoint that is perpetually lagging (or stalls before reaching the live edge) therefore never armed the trigger, so the sink would drift indefinitely without reconnecting. Gate instead on whether we are in the live (tier1) linear-streaming segment, detected via the per-session LinearHandoffBlock now exposed by substreams-sink-go v0.5.11: a processed block >= handoff is live tier1 output, while blocks below it are replayed from tier2 backprocessing. This arms the reconnect precisely when streaming live and behind, and avoids reconnect loops during initial backfill or a reconnect's own catch-up (where replayed blocks fall below the new handoff). Also flip the flag default to disabled (opt-in): an unsupplied --live-drift-reconnect now behaves as before, performing no automatic reconnect. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
YaroShkvorets
force-pushed
the
yaro/live-drift-reconnect-tier1
branch
from
June 9, 2026 02:43
8a37897 to
e561e73
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes cases where --live-drift-reconnect never triggers on perpetually-lagging endpoints by arming the drift check based on whether the stream is in the live (tier1) linear streaming segment, using the session’s LinearHandoffBlock signal exposed by substreams-sink-go v0.5.11. It also makes the reconnect behavior opt-in by defaulting the flag to disabled.
Changes:
- Arm
--live-drift-reconnectwhenblock >= LinearHandoffBlock(tier1 live segment) instead of relying on the sink’sDeltaLivenessCheckerisLivelatch. - Flip
--live-drift-reconnectdefault from1hto disabled (empty string), making the feature opt-in. - Bump
github.com/pinax-network/substreams-sink-goreplacement tov0.5.11and update module sums accordingly.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
sinker/sinker.go |
Switches drift-reconnect arming to tier1 detection via LinearHandoffBlock and adds helper runningFromTier1. |
cmd/substreams-sink-sql/run.go |
Changes --live-drift-reconnect default to disabled and updates flag help text. |
go.mod |
Updates the replace for substreams-sink-go to v0.5.11 (and adjusts dependency classification). |
go.sum |
Updates checksums for the substreams-sink-go version bump. |
Comments suppressed due to low confidence (1)
sinker/sinker.go:138
- The reconnect error message still says "live mode" but the trigger condition is now specifically "streaming live (tier1)" via LinearHandoffBlock. Updating the wording would make logs/errors less confusing, especially since this PR explicitly distinguishes between different "live" signals.
if s.liveDriftReconnectDuration > 0 && s.runningFromTier1(data.Clock.Number) {
blockTime := data.Clock.GetTimestamp().AsTime()
drift := time.Since(blockTime)
if drift > s.liveDriftReconnectDuration {
return fmt.Errorf("live mode drift exceeded threshold: block timestamp is %s behind current time (threshold: %s), triggering reconnect for backfilling", drift, s.liveDriftReconnectDuration)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
--live-drift-reconnectgated the drift check on the sink library'sDeltaLivenessCheckerisLiveflag, which only latches once a block lands within--live-block-time-deltaof wall-clock. An endpoint that is perpetually lagging — or stalls before ever reaching the live edge — never arms the trigger, so the sink drifts indefinitely without reconnecting (observed:live:true,driftwell past the configured 15m, no reconnect).Note the
live:truein the stream-stats log comes fromrunningFromTier1, which is a different signal than theisLiveflag that gated the check — hence the confusion.Fix
Gate the reconnect on whether we're in the live (tier1) linear-streaming segment, detected via the per-session
LinearHandoffBlock(from theResponse_Sessionprotobuf), newly exposed bysubstreams-sink-gov0.5.11:>= LinearHandoffBlockis live tier1 output → arm the drift check;This fires precisely when streaming live and behind (triggering a reconnect → fresh tier2 parallel backfill to close the gap), and avoids reconnect loops during the initial backfill or a reconnect's own catch-up, because the
Sessionmessage refreshes the handoff (≈ new head) before any data flows — so replayed blocks fall below it. Using the session protobuf rather than theProgressMessageLastContiguousBlockPrometheus gauge also avoids stale-across-reconnect state.Behavior change
The flag default is flipped from
1hto empty/disabled (opt-in). An unsupplied--live-drift-reconnectnow performs no automatic reconnect — same as before the feature. Enable with e.g.--live-drift-reconnect=15m.Dependency
Requires
substreams-sink-gov0.5.11(replace bumped,go.sumupdated). That release addsSinker.LinearHandoffBlock().🤖 Generated with Claude Code