Skip to content

[connectors] Keep the output buffer level with the counts of its endpoint - #8199

Open
bestouff wants to merge 2 commits into
mainfrom
issue-8028
Open

bestouff wants to merge 2 commits into
mainfrom
issue-8028

Conversation

@bestouff

@bestouff bestouff commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Linked Issue

Fixes #8028. Found during the review of #8018 (related to #8014).

What changes

An output endpoint with enable_output_buffer could move its processed counts (total_processed_input_records, total_processed_steps) back to an old value, down to 0. Completion tokens and the completion status of the pipeline use these counts, so a token could wait until the next commit.

The output thread keeps in its OutputBuffer the counts that the endpoint reaches when the buffer is flushed. The buffer got these counts only from entries that went through it. When the next entry was an empty step of an open transaction (no counts), the thread reported the empty buffer as flushed, with the counts of the buffer.

Case Counts in the endpoint status Counts in the buffer, before After this PR
Output goes to the connector without the buffer (initial snapshot) The counts of the snapshot Not changed, 0 for a new buffer The same counts
An endpoint that is level with the circuit starts (no snapshot) The committed counts 0 The same counts

The second case is not in the issue. It has the same cause and the same effect, and the first suite case led to it.

Describe Manual Test Plan

Test Result
New suite case buffered_output_keeps_snapshot_counts_during_transaction: one committed step, add a buffered endpoint with a snapshot, then a step of an open transaction Pass
New suite case buffered_output_keeps_initial_counts_during_transaction: the same with no snapshot Pass
Both cases, 6 runs 6 of 6 pass
Revert check: the two new calls removed Both cases fail: the counts are (0, 0), expected (1, 3) and (1, 2)
New unit test of OutputBuffer: counts recorded without the buffer stay after an empty entry with no counts Pass
Clippy with warnings as errors, all targets, dbsp_connectors and static-connectors Pass

Checklist

  • Unit tests added/updated
  • Integration tests added/updated
  • Documentation updated
  • Changelog updated

Breaking Changes?

None.

@mythical-fred-oss

Copy link
Copy Markdown
Contributor

LGTM.

Check Result
cargo test -p dbsp_connectors --lib output_buffer_tests pass
cargo test -p static-connectors --test connector_suites buffered_output_keeps 2/2 pass, 20 of 20 reruns pass
Both record_unbuffered calls reverted both suite cases fail with (0, 0) vs (1, 2) / (1, 3)
pre-commit run --files <changed> pass

The endpoint status is registered before the output thread spawns, so the startup read always finds it. The suite wait on buffered_records == 1 holds because max_output_buffer_time defaults to none, so there is no timer flush and no flakiness risk. Gates (tests, changelog, no unsafe, no deps) are satisfied.

@bestouff
bestouff marked this pull request as draft December 3, 2026 14:07
@blp blp added connectors Issues related to the adapters/connectors crate bug Something isn't working labels Dec 3, 2026
…oint

An output endpoint with an output buffer could move its processed
counts (total_processed_input_records, total_processed_steps) back to
an old value, down to 0. Completion tokens and the completion status
of the pipeline use these counts, so a token could wait until the next
commit.

The output thread keeps, in its buffer, the counts that the endpoint
reaches when the buffer is flushed. The buffer got these counts only
from the entries that went through it. In two cases the endpoint
status had newer counts than the buffer:

- Output that goes to the connector without the buffer (an initial
  snapshot) stores its counts in the endpoint status only.
- The status of an endpoint that is level with the circuit starts with
  the committed counts, and its buffer started at 0.

When the next entry was an empty step of an open transaction, which
has no counts, the thread reported the empty buffer as flushed with
the old counts of the buffer.

Record the counts in the buffer in both cases: when output goes to the
connector directly, and when the output thread starts.

Two suite cases add a buffered endpoint after a committed step, with
and without a snapshot, run a step of an open transaction, and check
that the counts of the endpoint did not change.

Fixes: #8028
Signed-off-by: Xavier Bestel <xavier.bestel@feldera.com>
@bestouff
bestouff marked this pull request as ready for review December 4, 2026 16:49
@bestouff bestouff assigned swanandx and unassigned swanandx Dec 4, 2026
@bestouff
bestouff requested a review from swanandx December 4, 2026 16:55
@mythical-fred-oss

Copy link
Copy Markdown
Contributor

LGTM. The fix is correct. Only the output thread writes the endpoint's processed counts, and every count it receives is no older than the last one. So setting the buffer's counts when the thread starts and on the unbuffered path cannot move the counts backwards.

What I ran (debug) Result
cargo test -p dbsp_connectors --lib empty_delta_keeps_unbuffered ✅ pass
cargo test -p static-connectors --test connector_suites buffered_output_keeps, 3 runs ✅ 3 of 3 pass, 0.18s
Revert check: both record_unbuffered calls disabled ❌ both cases fail, (0,0) vs (1,2) / (1,3), which confirms the tests catch the bug
connector_suites -- controller:: (all controller suite cases) ✅ 143 of 143 pass

Missing (medium): uncovered cases. I traced these by hand and they look correct, but no test covers them:

  • A buffered endpoint restarted from a checkpoint, followed by an open-transaction step (the status starts from the committed counts).
  • A snapshot that goes out with processed_records: None because the endpoint still owes a re-emission. Here record_unbuffered(None) should leave the buffer at 0, which matches the status.
  • A paused buffered endpoint that still owes its snapshot.

All feldera-pr-checks gates pass. SQL type coverage does not apply because no format or encoding code changed. The changelog is updated, and there is no breaking change.

@swanandx swanandx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I ran the controller tests and they pass. With the two record_unbuffered calls removed, both new suite cases fail with (0, 0).

Three cases that the review traced by hand now have tests:

- A buffered endpoint that starts again from a checkpoint, then a step
  of an open transaction during the replay: the counts of the endpoint
  do not move back.
- A paused buffered endpoint that owes its snapshot: after the snapshot
  is delivered, a step of an open transaction does not move the counts
  back.
- A snapshot that goes out with no counts, because the endpoint owes a
  new emission after a bootstrap: the counts stay as they are until
  that emission.

The first two fail without the calls that keep the buffer level with
the endpoint status.

Signed-off-by: Xavier Bestel <xavier.bestel@feldera.com>
@bestouff

bestouff commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Status of the review points, as of e09c330:

Uncovered case Status
A buffered endpoint restarted from a checkpoint, then a step of an open transaction Added: buffered_output_keeps_checkpoint_counts_during_replay. Fails without the start-up call: (0, 0)
A snapshot with processed_records: None (the endpoint owes a re-emission) Added: buffered_output_keeps_counts_until_bootstrap_reemission. It pins the behavior; it does not depend on the two new calls
A paused buffered endpoint that owes its snapshot Added: buffered_output_keeps_deferred_snapshot_counts_during_transaction. Fails without the call on the unbuffered path

The five buffered cases pass 5 of 5 runs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working connectors Issues related to the adapters/connectors crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[connectors] Output buffer moves the processed counts of an endpoint back after a snapshot

3 participants