Skip to content
TheChatArchiveThe Chat Archive
DeepSeekdeepseek/deepseek-v4-pro· deepseekHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION [Bug] Broker may accept duplicate messages after dedup recovery race…

  1. User

    ISSUE DESCRIPTION

    [Bug] Broker may accept duplicate messages after dedup recovery race

    Issue Description

    Message deduplication recovery can be started more than once for the same topic before the first recovery replay completes.

    MessageDeduplication defines a Recovering status to prevent overlapping transitions, but the enable path starts dedup cursor replay without first changing the status to Recovering.

    Because of that, another checkStatus() call can still observe Initialized or Disabled and start a second replay for the same dedup cursor.

    One practical trigger path is topic load with existing topic-level policies:

    TimeFlow A: existing topic-level policy during loadFlow B: normal topic load chainDedup status / effect
    T1initTopicPolicy() loads existing topic policiesdedup status is Initialized or Disabled
    T2onUpdate() applies topic policies and calls checkDeduplicationStatus()first dedup recovery replay starts
    T3first replay is still running asynchronouslystatus is still Initialized or Disabled
    T4topic load continues and BrokerService explicitly calls checkDeduplicationStatus()
    T5second check also enters the enable pathsecond replay starts for the same dedup cursor
    T6first replay rebuilds producer sequence statesecond replay also rebuilds producer sequence stateoverlapping replay can advance shared replay/cursor state

    Dedup recovery rebuilds producer sequence information from the dedup cursor. If overlapping replay leaves the recovered sequence state incomplete or inconsistent, the broker may fail to identify already-published messages as duplicates.

    The impact is that duplicate messages can be accepted after topic load or policy refresh even though message deduplication is enabled.

    There is also a retry gap after recovery failure. If enabling deduplication fails transiently, the status moves to Failed, but later checks do not retry enabling even when the topic policy still requires deduplication.

    Error messages

    There may be no error message. This is a race in the dedup recovery state machine.

    Reproducing the issue

    A deterministic unit-level reproduction can be built by delaying the first dedup recovery replay and invoking checkStatus() again before the first replay completes:

    1. Keep MessageDeduplication in Initialized or Disabled.
    2. Call checkStatus() once and delay async cursor open or replay completion.
    3. Call checkStatus() again before the first recovery finishes.
    4. Observe that the second call enters the enable path again and starts another replay.

    A production-like trigger path is:

    1. Enable message deduplication.
    2. Use a topic with existing topic-level policies.
    3. Load or reload the topic.
    4. During topic load, initTopicPolicy() can invoke onUpdate(), which applies topic policies and calls checkDeduplicationStatus().
    5. The normal topic load chain later calls checkDeduplicationStatus() again.
    6. If the first recovery replay is still in progress, both checks can start overlapping dedup replay.

    Expected behavior

    • Deduplication should enter Recovering before starting recovery replay.
    • Concurrent status checks should not start another recovery while replay is in progress.
    • If enable fails transiently, a later check should retry enabling when deduplication is still required by policy.

    Actual behavior

    • Enable starts replay while status remains Initialized or Disabled.
    • Another checkStatus() can start a second replay before the first completes.
    • Failed status does not retry enable even when deduplication should still be enabled.

    Additional information

    A fix has been proposed in #25953.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /pulsar, current file: none) bash-$

  2. DeepSeek Assistant

    Let me understand the issue:

    1. MessageDeduplication has a status machine with states like Initialized, Disabled, Recovering, Enabled, Failed.
    2. The bug is that when enabling deduplication, the code starts the recovery replay (cursor replay) without first setting the status to Recovering.
    3. This means another concurrent call to checkStatus() can also enter the enable path and start a second replay.
    4. Also, if enabling fails transiently, status goes to Failed but later checks don't retry.

    Let me find the relevant code first.

  3. DeepSeek Assistant

    Let me look at the main file: MessageDeduplication.java

  4. DeepSeek Assistant

    The open command needs to be run through the bash terminal.

  5. DeepSeek Assistant

    Let me scroll through the file to find the key methods.

  6. DeepSeek Assistant

    Let me go to line 159 to see the checkStatus method.

  7. DeepSeek Assistant

    Now I can see the issue. Let me look at the replayCursor and other methods.

  8. DeepSeek Assistant

    Let me also look at the rest of the file for takeSnapshot and any other relevant

  9. DeepSeek Assistant

    Let me see the remaining part of the file, including takeSnapshot.

  10. DeepSeek Assistant

    Now let me also check if there's a git reference to PR #25953 to see the proposed fix:

  11. DeepSeek Assistant

    Now I have a clear understanding of the issue. Let me also look at the test file to understand the testing

  12. DeepSeek Assistant

    Now I have a clear picture. Let me implement the fix. The issues are:

    1. In the enable path (line 227-237), status is not set to Recovering before starting the async replay.
    2. On failure, status goes to Failed but the enable path only triggers for Disabled or Initialized, so Failed never retries.
    3. The future.completeExceptionally(e) in the exceptionally handler is erroneous (trying to complete an already-completed future).

    Let me first confirm I'm looking at the right lines:

  13. DeepSeek Assistant

    Let me go back to the source file to make the fix

  14. DeepSeek Assistant

    Now let me see the exact area around lines 227-237 to make the edit.

  15. DeepSeek Assistant

    Now I have the full picture. Let me implement the fix. The changes are:

    1. Set status = Status.Recovering before starting the async cursor open/replay in the enable path.
    2. On failure, set status back to Disabled (instead of Failed) so that next checkStatus() can retry.
    3. Remove the erroneous future.completeExceptionally(e) call that tries to complete an already-completed future.
  16. DeepSeek Assistant

    Now let me also address the retry gap. The issue says: "Failed status does not retry enable even when deduplication should still be enabled." Even though my change makes enable failures go to Disabled instead of Failed, there could be other paths that set Failed, and we should still retry from Failed if deduplication should be enabled. Let me add Failed to the enable condition:

  17. DeepSeek Assistant

    Good. Let me verify the changes with `git

  18. DeepSeek Assistant

    The changes look correct. Now let me run the relevant tests to verify nothing is broken.

  19. DeepSeek Assistant

    Let me find the correct module path

  20. DeepSeek Assistant

    Let me find the actual directory structure.

  21. DeepSeek Assistant

    Let me try a different approach.

  22. DeepSeek Assistant

    This seems like the repo structure is flat (not multi-module Maven). Let me check.

  23. DeepSeek Assistant

    It's a Gradle project. Let me run the test using Gradle

  24. DeepSeek Assistant

    The MessageDuplicationTest passed. Let me also run the other related tests

  25. DeepSeek Assistant

    Let me try running just one more test at a time

  26. DeepSeek Assistant

    Both tests passed. Let me run the TopicDuplicationTest as well

  27. DeepSeek Assistant

    All tests pass. Let me run a couple more

  28. DeepSeek Assistant

    All tests pass. Let me now verify the final state of my changes once more:

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.