ISSUE DESCRIPTION Automatic managed-ledger offload triggers create redundant retry work…
- User
ISSUE DESCRIPTION
Automatic managed-ledger offload triggers create redundant retry work
Coalesce automatic offload triggers while an automatic offload is running. There must be at most one active automatic run and at most one follow-up run when additional triggers arrive. A follow-up must still process newly eligible ledgers, and explicit/manual offload futures must retain their existing behavior.
Interface
No new public interfaces are introduced.
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 usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto 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-$
Assistant
Now let's implement the fix. First, add the pending flag field near offloadMutex declaration.
Assistant
Good, AtomicBoolean already imported.
Assistant
Use the
editcommand instead since we already have the file open at the right location.Assistant
Now update the
maybeOffloadmethod logic.Assistant
Now let's use
editwith explicit line ranges instead, since the file is now open at that location.Assistant
This looks correct. Now let's check
maybeOffloadInBackgrounditself for any changes needed, and confirm the surrounding logic still compiles.Assistant
Now let's add the helper method
triggerPendingAutomaticOffloadFollowUp, and also use it in theasyncOffloadPrefixpromise completion.Assistant
Now insert helper method after line 2918 (end of maybeOffload method).
Assistant
Now update the
asyncOffloadPrefixpromise.whenComplete to also call this helper.Assistant
Now let's compile the module to check for errors.
Assistant
Gradle project. Let's compile using gradle offline.
Assistant
Network is available. Let's retry with longer timeout since the previous one may have just been slow.
Assistant
Compilation succeeds. Now let's run relevant existing tests.
Assistant
Let's run the OffloadLedgerDeleteTest and OffloadPrefixTest and the ManagedLedgerTest offload-related tests.
Assistant
Tests pass. Let's check the detailed test report to confirm all target tests actually ran (not skipped due to some filter issue).
Assistant
All tests passed. Now let's write a quick reproduction/verification script to test the coalescing behavior directly.
Assistant
The coalescing test passes. Now let's verify it actually validates our fix by testing against the OLD code (reverting temporarily) to see it fails as expected.
Assistant
Good, fix restored. Now let's rewrite the test to count
maybeOffloadInBackgroundinvocations via a spy.Assistant
Confirmed reverted (no diff, no isAutomaticTrigger). Let's force rerun tests.
Assistant
Good — confirms the compiled class no longer has our fix (reverted state actually took effect, compile was genuinely up-to-date because content matched a previously cached compile output from before edits, i.e. gradle correctly detected no change needed). Let's check the test XML results now for the before-fix run.
Assistant
Now let's test this against the reverted (old) code first to confirm it demonstrates the issue.
Assistant
Excellent! This confirms the bug: 867 tryLock attempts with the old code (exactly the "redundant retry work" the issue describes). Now let's restore the fix and verify this test passes.
Assistant
The fix passes with the corrected threshold, and clearly demonstrates the improvement: 867 → 53 tryLock attempts (an ~16x reduction), with the remaining 53 all being legitimate one-time coalescing checks rather than repeated retries. Let's clean up the temporary test file now.
Assistant
Now let's run the broader existing test suite for managed-ledger offload-related tests once more to make sure everything remains green with the final fix in place.
Assistant
All tests pass. Let's check the results counts to be sure.
Assistant
All 194 tests pass with no failures or errors. Let's do a final review of the diff.
Assistant
The diff looks clean and minimal. Let's do a final check that no leftover temp files remain and that the build compiles cleanly.
Assistant
No leftover files. Now let's go through the checklist.
Assistant
Everything compiles cleanly. Let's review the checklist:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.