Skip to content

fix(types): expose cooperative-sticky rebalance methods on KafkaConsumer#485

Open
Dvir Arad (dvirarad) wants to merge 1 commit into
confluentinc:masterfrom
dvirarad:fix/cooperative-sticky-types
Open

fix(types): expose cooperative-sticky rebalance methods on KafkaConsumer#485
Dvir Arad (dvirarad) wants to merge 1 commit into
confluentinc:masterfrom
dvirarad:fix/cooperative-sticky-types

Conversation

@dvirarad
Copy link
Copy Markdown

Summary

Fixes #469.

When partition.assignment.strategy=cooperative-sticky is set, the rebalance callback needs to call incrementalAssign / incrementalUnassign instead of assign / unassign. The runtime exposes them (see lib/kafka-consumer.js):

KafkaConsumer.prototype.incrementalAssign = function(assignments) {  };
KafkaConsumer.prototype.incrementalUnassign = function(assignments) {  };
KafkaConsumer.prototype.assignmentLost      = function()            {  };
KafkaConsumer.prototype.rebalanceProtocol   = function()            {  };

The stock rebalance handler in lib/kafka-consumer.js (lines 68-79) even branches on rebalanceProtocol() === 'COOPERATIVE' to call incrementalAssign / incrementalUnassign. But none of those four methods are declared in types/rdkafka.d.ts, so TypeScript consumers writing their own rebalance callback must fall back to (consumer as any).incrementalAssign(...) (the screenshot in #469 shows exactly this).

Fix

Types-only change in types/rdkafka.d.ts. Added four method declarations on KafkaConsumer, each with a JSDoc block mirroring the runtime documentation in lib/kafka-consumer.js:

incrementalAssign(assignments: Assignment[]): this;
incrementalUnassign(assignments: Assignment[]): this;
assignmentLost(): boolean;
rebalanceProtocol(): "NONE" | "COOPERATIVE" | "EAGER";
  • Assignment is the existing alias TopicPartition | TopicPartitionOffset, matching the assign(...) signature — the runtime maps both into TopicPartition via TopicPartition.map(...).
  • The rebalanceProtocol() return is constrained to the three literal strings the runtime can produce ("NONE" | "COOPERATIVE" | "EAGER"), so user code can do if (c.rebalanceProtocol() === "COOPERATIVE") without a string cast.
  • assignmentLost() returns boolean per the JS doc (@return {boolean} true if assignment was lost.).

The original issue only mentions incrementalAssign / incrementalUnassign, but assignmentLost and rebalanceProtocol are part of the same cooperative-sticky workflow and have the same missing-types problem — happy to scope the PR back to just the two if maintainers prefer.

Test plan

  • tsc -p . (the existing npm run test:types script) still passes — added declarations only.
  • Confirmed each method exists on the runtime prototype in lib/kafka-consumer.js (see lines 305–308, 319–322, 342–344, 351–353 on master).
  • Confirmed assignmentLost and rebalanceProtocol aren’t already declared anywhere else in types/*.d.ts.
  • CI green.

The KafkaConsumer runtime (lib/kafka-consumer.js) exposes incrementalAssign,
incrementalUnassign, assignmentLost and rebalanceProtocol — all required to
implement cooperative-sticky rebalancing — but none of these are declared in
types/rdkafka.d.ts. TypeScript consumers must cast to any.

This change adds the four missing method signatures with JSDoc matching the
runtime documentation. No runtime/source changes; types only.

Closes confluentinc#469
Copilot AI review requested due to automatic review settings May 11, 2026 08:03
@dvirarad Dvir Arad (dvirarad) requested review from a team as code owners May 11, 2026 08:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

No type available for cooperative-sticky re-balance

2 participants