mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 11:18:37 +00:00
fix(cron): force main-target system events onto main session (#28898)
Ignore persisted sessionKey overrides for sessionTarget=main jobs so cron system events consistently route to the agent main session after upgrades. Closes #28770
This commit is contained in:
@@ -509,7 +509,7 @@ describe("CronService", () => {
|
|||||||
await store.cleanup();
|
await store.cleanup();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes agentId + sessionKey to runHeartbeatOnce for main-session wakeMode now jobs", async () => {
|
it("passes agentId and resolves main session for wakeMode now main jobs", async () => {
|
||||||
const runHeartbeatOnce = vi.fn(async () => ({ status: "ran" as const, durationMs: 1 }));
|
const runHeartbeatOnce = vi.fn(async () => ({ status: "ran" as const, durationMs: 1 }));
|
||||||
|
|
||||||
const { store, cron, enqueueSystemEvent, requestHeartbeatNow } =
|
const { store, cron, enqueueSystemEvent, requestHeartbeatNow } =
|
||||||
@@ -534,13 +534,13 @@ describe("CronService", () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
reason: `cron:${job.id}`,
|
reason: `cron:${job.id}`,
|
||||||
agentId: "ops",
|
agentId: "ops",
|
||||||
sessionKey,
|
sessionKey: undefined,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
expect(requestHeartbeatNow).not.toHaveBeenCalled();
|
expect(requestHeartbeatNow).not.toHaveBeenCalled();
|
||||||
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
expect(enqueueSystemEvent).toHaveBeenCalledWith(
|
||||||
"hello",
|
"hello",
|
||||||
expect.objectContaining({ agentId: "ops", sessionKey }),
|
expect.objectContaining({ agentId: "ops", sessionKey: undefined }),
|
||||||
);
|
);
|
||||||
|
|
||||||
cron.stop();
|
cron.stop();
|
||||||
@@ -578,7 +578,7 @@ describe("CronService", () => {
|
|||||||
expect(requestHeartbeatNow).toHaveBeenCalledWith(
|
expect(requestHeartbeatNow).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
reason: `cron:${job.id}`,
|
reason: `cron:${job.id}`,
|
||||||
sessionKey,
|
sessionKey: undefined,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
expect(job.state.lastStatus).toBe("ok");
|
expect(job.state.lastStatus).toBe("ok");
|
||||||
|
|||||||
@@ -640,9 +640,12 @@ export async function executeJobCore(
|
|||||||
: 'main job requires payload.kind="systemEvent"',
|
: 'main job requires payload.kind="systemEvent"',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
// main-target cron jobs should always resolve via the agent's main session.
|
||||||
|
// Avoid forwarding persisted channel session keys from legacy records.
|
||||||
|
const targetMainSessionKey = undefined;
|
||||||
state.deps.enqueueSystemEvent(text, {
|
state.deps.enqueueSystemEvent(text, {
|
||||||
agentId: job.agentId,
|
agentId: job.agentId,
|
||||||
sessionKey: job.sessionKey,
|
sessionKey: targetMainSessionKey,
|
||||||
contextKey: `cron:${job.id}`,
|
contextKey: `cron:${job.id}`,
|
||||||
});
|
});
|
||||||
if (job.wakeMode === "now" && state.deps.runHeartbeatOnce) {
|
if (job.wakeMode === "now" && state.deps.runHeartbeatOnce) {
|
||||||
@@ -659,7 +662,7 @@ export async function executeJobCore(
|
|||||||
heartbeatResult = await state.deps.runHeartbeatOnce({
|
heartbeatResult = await state.deps.runHeartbeatOnce({
|
||||||
reason,
|
reason,
|
||||||
agentId: job.agentId,
|
agentId: job.agentId,
|
||||||
sessionKey: job.sessionKey,
|
sessionKey: targetMainSessionKey,
|
||||||
});
|
});
|
||||||
if (
|
if (
|
||||||
heartbeatResult.status !== "skipped" ||
|
heartbeatResult.status !== "skipped" ||
|
||||||
@@ -677,7 +680,7 @@ export async function executeJobCore(
|
|||||||
state.deps.requestHeartbeatNow({
|
state.deps.requestHeartbeatNow({
|
||||||
reason,
|
reason,
|
||||||
agentId: job.agentId,
|
agentId: job.agentId,
|
||||||
sessionKey: job.sessionKey,
|
sessionKey: targetMainSessionKey,
|
||||||
});
|
});
|
||||||
return { status: "ok", summary: text };
|
return { status: "ok", summary: text };
|
||||||
}
|
}
|
||||||
@@ -698,7 +701,7 @@ export async function executeJobCore(
|
|||||||
state.deps.requestHeartbeatNow({
|
state.deps.requestHeartbeatNow({
|
||||||
reason: `cron:${job.id}`,
|
reason: `cron:${job.id}`,
|
||||||
agentId: job.agentId,
|
agentId: job.agentId,
|
||||||
sessionKey: job.sessionKey,
|
sessionKey: targetMainSessionKey,
|
||||||
});
|
});
|
||||||
return { status: "ok", summary: text };
|
return { status: "ok", summary: text };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user