Skip to content

fix(sink): always update requestActiveStartBlock on session init#792

Open
maoueh wants to merge 4 commits into
developfrom
bug/sinker-session-init-handler-break
Open

fix(sink): always update requestActiveStartBlock on session init#792
maoueh wants to merge 4 commits into
developfrom
bug/sinker-session-init-handler-break

Conversation

@maoueh
Copy link
Copy Markdown
Contributor

@maoueh maoueh commented May 28, 2026

Summary

Fixes a latent bug in (*Sinker).doRequest's Response_Session handling. When the registered handler implemented SinkerSessionInitHandler, the case body did a bare break right after invoking HandleSessionInit, which skipped the sinker-internal bookkeeping that follows — most importantly s.requestActiveStartBlock = session.ResolvedStartBlock.

That field is consumed in the Response_ModulesProgress case to identify the contiguous completed range covering the user's resolved start block. With requestActiveStartBlock left at zero, the predicate 0 <= r.StartBlock && r.EndBlock >= 0 is trivially true, causing ProgressMessageLastContiguousBlock to be overwritten by every completed range of the last (mapper) stage in production mode instead of only the contiguous one. Impact is metric-only (no data correctness impact) and latent today since no SF repo currently implements SinkerSessionInitHandler.

Changes:

  • Extract the Response_Session case body into (*Sinker).handleSessionInit. The custom SinkerSessionInitHandler.HandleSessionInit callback (when implemented) now runs as an interceptor: the default "session initialized with remote endpoint" log line and the requestActiveStartBlock assignment always run afterwards, regardless of whether a custom handler is installed.
  • Document the SinkerSessionInitHandler interface (sink/types.go) to make explicit that it behaves as an interceptor and does not short-circuit the sinker's default session handling.
  • Add regression tests in sink/sinker_test.go.
  • Add a changelog entry under ## Unreleased.

Test plan

  • go test ./sink/... passes
  • go vet ./sink/ clean
  • Confirm ProgressMessageLastContiguousBlock metric stays correct for a production-mode mapper sink that implements SinkerSessionInitHandler

maoueh added 2 commits May 28, 2026 09:58
The Response_Session case in (*Sinker).doRequest short-circuited with a
bare `break` when the handler implemented SinkerSessionInitHandler,
skipping the `s.requestActiveStartBlock = r.Session.ResolvedStartBlock`
assignment. That field is consumed by the Response_ModulesProgress case
to compute ProgressMessageLastContiguousBlock for production-mode mapper
stages, so a custom session-init handler silently left the metric wrong.

Remove the `break` entirely: the custom handler (when present) is still
invoked, but the default log line and the requestActiveStartBlock
assignment now run unconditionally. The case body is extracted into a
documented private method (*Sinker).handleSessionInit for testability.

# Conflicts:
#	docs/release-notes/change-log.md
Document on the SinkerSessionInitHandler interface that HandleSessionInit
behaves as an interceptor and does not short-circuit the Sinker's normal
session-init handling: the default "session initialized" log line and the
internal resolved-start-block bookkeeping still run after the callback.
@maoueh maoueh force-pushed the bug/sinker-session-init-handler-break branch from 1df8f5f to 49c9cc5 Compare May 28, 2026 13:58
@sduchesneau
Copy link
Copy Markdown
Contributor

sduchesneau commented May 28, 2026

🔍 Vulnerabilities of ghcr.io/streamingfast/substreams:85741b4

📦 Image Reference ghcr.io/streamingfast/substreams:85741b4
digestsha256:5b201c9d7b51d00e27f141a4f9609388f47441edc04dcb7c2134a8db51599942
vulnerabilitiescritical: 0 high: 0 medium: 0 low: 0
platformlinux/amd64
size116 MB
packages353
📦 Base Image ubuntu:24.04
also known as
  • 84bda043709f9066841484e9b8e440aa0d6d04ab49d09e367ef0fb68ace864cf
  • latest
  • noble
  • noble-20260410
digestsha256:cdb5fd928fced577cfecf12c8966e830fcdf42ee481fb0b91904eeddc2fe5eff
vulnerabilitiescritical: 0 high: 0 medium: 23 low: 3

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