airbyte-to-flow: support STREAM state messages#359
Open
Alex-Bair wants to merge 4 commits into
Open
Conversation
Connectors built on modern Airbyte CDKs emit and expect per-stream `STREAM`
state, whereas older connectors used the `LEGACY` opaque `data` object. Airbyte
deprecated the `LEGACY` format (Platform v0.62.4 / CDK >= 1.3), so bumping a
connector across that boundary changes its state contract. `airbyte-to-flow` only
understood the `LEGACY` form, which broke both directions:
- Inbound: ATF wrote Flow's persisted `{stream: state}` object verbatim to the
`--state` file. A modern CDK's `read_state` expects a list of
`AirbyteStateMessage`s, so it iterated the object's keys and failed with
`"<stream name>" is not of type "object"`, breaking active captures.
- Outbound: `STREAM` state messages carry no top-level `data`, so they failed to
deserialize and were silently dropped, meaning state never advanced.
This commit fixes that by teaching ATF to translate between Flow's
`{stream: state}` object and Airbyte's new per-stream form, in both directions:
- State: make `data` optional and add `stream` (`STREAM` payload). Also capture
`type`/`global` as plain fields for diagnostics.
- Outbound (`state_to_checkpoint`): forward a `LEGACY` `data` blob verbatim with
its merge flag; persist `STREAM` state as `{stream: state}` reduced via RFC
7396 merge patch so streams accumulate. Log-and-skip anything else (e.g.
`GLOBAL`) so the capture continues instead of erroring or dropping silently.
- Inbound (`convert_state_for_connector`): convert the persisted object into a
per-stream `STREAM` list.
Gate the inbound conversion on the `AIRBYTE_TO_FLOW_STATE_FORMAT=per_stream` env
var. Without it, state is written verbatim so `LEGACY`-state connectors
are unchanged.
Includes unit tests for both conversion directions and the round-trip, plus
`README`/comment updates describing the `LEGACY`/`STREAM`/`GLOBAL` state types.
`source-amazon-ads` 7.3.1 is built on a modern Airbyte CDK that reads `--state` as a list of per-stream AirbyteStateMessages rather than the legacy state object. Set `AIRBYTE_TO_FLOW_STATE_FORMAT=per_stream` so `airbyte-to-flow` converts the persisted state object into that form. Without it the connector's `read_state` fails with `"<stream name>" is not of type "object"` and active captures break.
nicolaslazo
approved these changes
Jun 29, 2026
nicolaslazo
left a comment
There was a problem hiding this comment.
Looks good, thanks for covering this
…ly` to put `date` under `properties`
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
Active
source-amazon-adscaptures have been failing with:This started after the connector was bumped from 3.0.0 → 7.3.1 in #356.
Root cause
Airbyte deprecated the
LEGACYopaque-datastate format (Platform v0.62.4 / CDK ≥ 1.3) in favor of per-streamSTREAM(andGLOBAL) state. The 3.0.0 → 7.3.1 bump insource-amazon-adscrossed that boundary, butairbyte-to-flowonly understood the old form, so it broke in both directions:{stream: state}object verbatim to the--statefile. The modern CDK'sread_stateexpects a list ofAirbyteStateMessages, so it iterated the object's keys (stream-name strings) and rejected them as not objects - the error above.STREAMmessages carry no top-leveldata, so they failed to deserialize and were silently dropped, meaning state never advanced even once the inbound crash is fixed.Solution
Flow still persists state as a
{stream: state}object.airbyte-to-flownow translates between that and whatever the connector speaks:State:datais now optional, plus astreamvariant (andtype/globalcaptured for diagnostics).state_to_checkpoint): forward LEGACYdataverbatim; persistSTREAMstate as{stream: state}via RFC 7396 merge patch. Log-and-skip anything else (e.g.GLOBAL) so the capture continues rather than erroring or dropping silently.convert_state_for_connector): convert the persisted object into aSTREAMlist gated onAIRBYTE_TO_FLOW_STATE_FORMAT=per_streamin each connector'sDockerfile. Connectors without it get verbatim state, so existingLEGACYconnectors are unchanged.References
Airbyte's documentation on the different state message types.
Slack thread containing details about the escalation motivating these changes.