Skip to content

fix(nats source): defer JetStream acks until delivery - #26217

Draft
horjulf wants to merge 1 commit into
vectordotdev:masterfrom
horjulf:fs/nats-e2e-acks
Draft

fix(nats source): defer JetStream acks until delivery#26217
horjulf wants to merge 1 commit into
vectordotdev:masterfrom
horjulf:fs/nats-e2e-acks

Conversation

@horjulf

@horjulf horjulf commented Aug 26, 2026

Copy link
Copy Markdown

Summary

The JetStream NATS source currently acknowledges a broker message immediately after send_batch hands decoded events to the internal topology. That remains ahead of actual sink delivery even when end-to-end acknowledgements are enabled, so a Vector crash can lose an already-ACKed message that was still buffered downstream.

This draft makes JetStream participate in the existing batch-finalizer framework:

  • attach one BatchNotifier to all events decoded from a NATS message;
  • ACK the message only after all connected acknowledgement-enabled sinks report Delivered;
  • NAK Errored or Rejected batches so JetStream redelivers them;
  • preserve the existing immediate-ACK behavior when end-to-end acknowledgements are disabled;
  • advertise acknowledgement support only in JetStream mode; Core NATS remains unchanged.

The source requires an explicit JetStream consumer acknowledgement policy when end-to-end acknowledgements are active. An unordered downstream completion paired with cumulative all acknowledgements could otherwise acknowledge an earlier failed message.

References

No existing NATS acknowledgement issue found. Opening this as a draft for design feedback, particularly around NAK pacing and whether periodic progress ACKs should be added for delivery times longer than the consumer ack_wait.

Vector configuration

acknowledgements:
  enabled: true

sources:
  queued_logs:
    type: nats
    url: nats://localhost:4222
    subject: logs.vl
    jetstream:
      stream: fleet-logs
      consumer: victorialogs # configured with ack_policy: explicit
    decoding:
      codec: native

sinks:
  output:
    type: console
    inputs: [queued_logs]
    acknowledgements:
      enabled: true

How did you test this PR?

  • make check-clippy — all workspace targets and features.
  • make test FEATURES=nats-integration-tests SCOPE=nats_jetstream_ against a local NATS JetStream 2.14.5 server — 7/7 tests passed.
  • Added a broker-backed test proving a message remains pending until downstream finalization, rejection triggers redelivery, and successful delivery advances the ACK state.
  • Added a broker-backed test rejecting cumulative consumer acknowledgement policy when end-to-end acknowledgements are enabled.
  • make check-fmt.
  • make check-markdown.
  • make check-changelog-fragments.
  • make check-generated-docs — 248 component examples validated.

Is this a breaking change?

  • Yes
  • No

Does this PR include user facing changes?

  • Yes. A changelog fragment and generated NATS source documentation are included.
  • No. A maintainer will apply the no-changelog label to this PR.

AI assistance: OpenAI GPT-5.6 Codex was used to help implement and validate this change. The resulting behavior was verified against the source acknowledgement framework and a real JetStream server.

@github-actions github-actions Bot added docs review on hold The documentation team reviews PRs only after a PR is approved by the COSE team. domain: sources Anything related to the Vector's sources domain: external docs Anything related to Vector's external, public documentation labels Aug 26, 2026
@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@horjulf

horjulf commented Aug 26, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

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

Labels

docs review on hold The documentation team reviews PRs only after a PR is approved by the COSE team. domain: external docs Anything related to Vector's external, public documentation domain: sources Anything related to the Vector's sources

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant