[Bug]: XxlJobAgentScheduler counts two executions for a single job trigger
Describe the bug
XxlJobAgentScheduler counts every XXL-Job trigger twice.
BaseScheduleAgentTask.run(...) already increments the execution count, and XxlJobAgentScheduler.executeAgent increments it a second time after the run returns:
Msg result = scheduleAgentTask.run(inputMsg).block();
scheduleAgentTask.incrementExecutionCount(); // second count for the same trigger
So getExecutionCount() reports 2 after a single trigger, although only one execution happened.
Environment
- AgentScope-Java Version: 2.1.0-SNAPSHOT
- Module:
agentscope-extensions-scheduler-xxl-job - Commit:
16632ae84 - JDK 17
Steps to reproduce
Schedule a task through XxlJobAgentScheduler#schedule, resolve the registered handler with XxlJobExecutor.loadJobHandler(name), fire it once, then read the counter:
RuntimeAgentConfig agentConfig =
RuntimeAgentConfig.builder()
.name("CountingAgent")
.modelConfig(new FixedResponseModelConfig())
.sysPrompt("Test prompt")
.build();
BaseScheduleAgentTask task = (BaseScheduleAgentTask) scheduler.schedule(agentConfig);
XxlJobExecutor.loadJobHandler("CountingAgent").execute();
assertEquals(1L, task.getExecutionCount()); // expected: <1> but was: <2>
Any model works, since the agent run itself is not what is being counted -- the canned model used above only keeps the task off the network.
Additional context
The Quartz implementation does not have this problem: AgentQuartzJob.execute only calls t.run(inputMsg).block() and leaves the counting to run(...), which is what allows QuartzFixedDelayIntegrationTest to assert a one-to-one mapping between firings and the counter. XXL-Job drifted from that shared contract, so the counter reads exactly 2x the truth on that backend -- any metric, alert or back-off decision built on it is off by a factor of two.
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 as well, not just the absolute value.
Fix: https://github.com/agentscope-ai/agentscope-java/pull/3507