Skip to content

fix(scheduler): count a single execution per XXL-Job trigger - #3507

Open
wahllllll wants to merge 3 commits into
agentscope-ai:mainfrom
wahllllll:fix/xxljob-double-execution-count
Open

wahllllll wants to merge 3 commits into
agentscope-ai:mainfrom
wahllllll:fix/xxljob-double-execution-count

Conversation

@wahllllll

@wahllllll wahllllll commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT

Description

Fixes #3508

BaseScheduleAgentTask.run(...) already increments the execution count, and XxlJobAgentScheduler.executeAgent incremented it a second time after the run returned, so a single XXL-Job trigger reported two executions:

Msg result = scheduleAgentTask.run(inputMsg).block();
scheduleAgentTask.incrementExecutionCount();   // second count for the same trigger

The Quartz job leaves the counting to run(...) alone -- AgentQuartzJob.execute only calls t.run(inputMsg).block() -- which is what lets QuartzFixedDelayIntegrationTest assert a one-to-one mapping between firings and getExecutionCount(). XXL-Job drifted from that contract, so anyone reading the counter for metrics, alerting or back-off decisions over XXL-Job sees a value that is exactly twice the truth.

The skew is also asymmetric. When the agent run throws, run(...) has already counted once and the failing path never reaches the second increment (executeAgent rethrows as a RuntimeException), so failed triggers counted 1 while successful ones counted 2 -- the ratio between them was wrong too, not just the absolute value.

  • Remove the redundant increment in XxlJobAgentScheduler.executeAgent, with a comment recording why it must not come back.
  • Add a regression test that schedules a task backed by a canned model, resolves the handler via XxlJobExecutor.loadJobHandler(...), fires it once, and asserts getExecutionCount() == 1.

Red on 16632ae84 (current main):

[ERROR] XxlJobAgentSchedulerTest.testJobTriggerCountsExactlyOneExecution:667 expected: <1> but was: <2>
[ERROR] Tests run: 35, Failures: 1, Errors: 0, Skipped: 0

Green with the fix:

[INFO] Tests run: 35, Failures: 0, Errors: 0, Skipped: 0 -- in io.agentscope.extensions.scheduler.xxljob.XxlJobAgentSchedulerTest

Validation on commit dce9a38:

  • XxlJobAgentSchedulerTest: 35 passed, 0 failures.
  • agentscope-extensions-scheduler-common: 80 passed, 0 failures (includes BaseScheduleAgentTaskTest, which pins the "run(...) counts once" half of the contract).
  • agentscope-extensions-scheduler-quartz: 66 passed, 0 failures (includes QuartzFixedDelayIntegrationTest, the sibling that asserts the invariant end to end).
  • mvn spotless:apply clean; JDK 17.
  • Not covered: a full XXL-Job admin round trip. The test fires the registered IJobHandler directly, which is the same entry point XXL-Job itself calls.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test) -- the three scheduler modules passed; the full reactor cannot finish in this sandbox (agentscope-core's DangerousPathBypassTest needs symlink privileges that the machine does not grant)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated -- no documentation describes the execution-count contract
  • Code is ready for review

BaseScheduleAgentTask.run(...) already increments the execution count, so
the second increment in XxlJobAgentScheduler.executeAgent made one job
trigger report two executions. The Quartz job leaves the counting to
run(...) alone, and QuartzFixedDelayIntegrationTest asserts that
one-to-one mapping.

Add a regression test that drives the registered IJobHandler with a canned
model and asserts the counter is 1 after a single trigger.
@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
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.

[Bug]: XxlJobAgentScheduler counts two executions for a single job trigger

1 participant