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
I’ll first locate the managed-ledger offload trigger paths and their tests, then identify how automatic calls differ from explicit/manual futures. I’ll reproduce the redundant scheduling behavior if practical, implement coalescing around only the automatic path, and run the focused test suite plus relevant broader checks.
- Assistant
The central implementation is in
ManagedLedgerImpl; I’ll inspect the automatic trigger and all callers/overloads of offload to understand concurrency and preserve manual semantics. - Assistant
Current contention handling schedules a retry every 100 ms for every trigger, so a long run creates many retry chains. I’ll inspect mutex ownership semantics, lifecycle-trigger call sites, and existing automatic-offload tests before choosing a state machine that guarantees one active plus one pending run.
- Assistant
maybeOffloadInBackgroundis publicly callable but is the automatic-policy operation; manual prefix offload separately uses the same mutex. The requirement that explicit futures retain behavior means automatic calls carrying a real future likely must still each complete, while lifecycle calls using the shared sentinel can be coalesced. I’ll confirm the sentinel definition and manual lock path, and inspect project history/state conventions for atomic scheduling flags. - Assistant
I’ll implement a dedicated automatic-offload state machine rather than changing mutex semantics:
- Automatic lifecycle triggers use a package-private no-argument path.
- A guarded
running/pendingpair coalesces any number of triggers into one current run and one follow-up. - Each run re-reads policies and scans ledgers, so the follow-up sees newly eligible ledgers.
- The existing future-taking method remains independent, including its retry/completion behavior, and manual prefix offloads still fail immediately on contention as before.
- Mutex retry will continue the same logical run rather than registering a new automatic trigger.
- Assistant
Python is unavailable in this environment, so no files were changed. I’ll apply the same focused patch using the repository’s patch tooling and then inspect the result.
- Assistant
apply_patchis also unavailable. I’ll use the provided line editor in small, verifiable edits, starting with the state fields and call sites, then insert the state-machine methods. - Assistant
The field edit is correct; the special replacement command requires the match to be in its displayed window despite an explicit file path. I’ll use non-interactive
sedfor the two exact call-site replacements, then insert methods at the now-shifted location withedit. - Assistant
I’ll insert the state-machine methods immediately after the existing future-based trigger. The automatic completion callback keeps
running=truewhile handing off a pending follow-up, closing the race where another trigger could otherwise start a second run. - Assistant
The insertion is structurally correct, but two refinements are needed before testing: preserve the shared sentinel as an automatic-trigger marker for any package/test callers still using the old form, and restore the blank line required between methods. This also makes the distinction explicit: sentinel calls coalesce; callers supplying their own future retain the old path.
- Assistant
The sentinel routing is now in place. I found an unused static import in the factory after changing its call site, and the blank-line insertion did not take effect; I’ll clean both up, then run the managed-ledger formatter/checkstyle-aware compile and focused offload tests.
- Assistant
The code passes
git diff --check. The root reactor does not exposemanaged-ledgerunder that selector, so I’ll inspect its POM/artifact name and invoke Maven directly against the module POM (including dependencies if needed). I’ll also review the full diff for accidental import/call-site changes before tests. - Assistant
This checkout is a source subset without root/module POM files, so Maven cannot run here as-is. I’ll identify the available build metadata and test runner scripts. In parallel, I’ll inspect executor behavior because a rejected scheduling call is the main edge case that could leave the automatic state stuck during shutdown.
- Assistant
This repository uses Gradle. I’ll list the managed-ledger tasks to select the focused test syntax, then compile.
- Assistant
Gradle is functional. I’ll run formatting validation and Java compilation first; if formatting reports only our files, I’ll apply the repository formatter rather than hand-adjusting style.
- Assistant
Compilation and formatting pass. I’ll now run the two managed-ledger offload test classes:
OffloadLedgerDeleteTestexercises the future-taking policy offload path, whileOffloadPrefixTestexercises explicit/manual mutex and callback behavior. - Assistant
The focused tests pass. Reviewing compatibility, I can make the change less invasive: keep both existing lifecycle call sites invoking the original future-taking method with
NULL_OFFLOAD_PROMISE, and let that method internally route the sentinel to a private coalescing helper. This preserves subclass/spy interception and avoids introducing even a package-visible helper, while retaining identical behavior. I’ll make that refinement and rerun compile/tests. - Assistant
The helper is now private and call-site behavior is restored. The factory static import was reinserted in the wrong lexical/order position, so I’ll correct import ordering; after that, the factory should have no diff at all.
- Assistant
One subtle compatibility issue remains: sentinel routing currently happens before the old policy/threshold checks, causing disabled automatic offload to enqueue a no-op task where it previously returned immediately. I’ll move routing inside the existing enabled-threshold branch. Follow-up runs will still independently re-read policy and ledger eligibility as required.
- Assistant
The refined implementation passes formatting and both focused test classes. I’ll run the full
managed-ledgertest suite for regression coverage, then inspect the final diff/status and ensure no generated files were changed. - Assistant
The complete managed-ledger suite passes. Final review will verify the exact one-file diff, whitespace, and repository status. I’ll also confirm the state transitions against the concurrency requirements before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →