Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* covered `false` would have passed against the old behaviour too.
*/

const fs = require('fs');
const path = require('path');

jest.mock('jsonwebtoken', () => ({ sign: jest.fn(), verify: jest.fn(), decode: jest.fn() }));
jest.mock('../../../services/agentEventService', () => ({
enqueue: jest.fn().mockResolvedValue({ _id: 'evt' }),
Expand Down Expand Up @@ -77,4 +80,27 @@ describe('dispatchAgentHeartbeats — opt-in', () => {
});
expect(r.enqueued).toBeGreaterThan(0);
});

test("the startup banner's heartbeat line names the gate, not just the cadence", () => {
// The behaviour above is only half of what an operator relies on; the other
// half is the one sentence describing it at boot. That sentence read
// "Agent heartbeats run every 10 minutes with per-agent intervals" — true
// about the dispatcher, silent about the opt-in — and on 2026-08-18 it sent
// a reader to resolveHeartbeatIntervalMinutes to compute a fleet wake rate
// from a field that is never reached for a seat which never opted in. The
// number was retracted; the sentence that produced it would not have been.
//
// Asserted on the source text because the banner is emitted inside start(),
// which schedules real cron jobs. Matched on the gate's NAME rather than on
// wording, so a rephrase stays green and a re-simplification does not.
const src = fs.readFileSync(
path.join(__dirname, '../../../services/schedulerService.ts'), 'utf8',
);
const banner = src.slice(src.indexOf('- Agent heartbeats'));
const line = banner.slice(0, banner.indexOf(');'));
expect(line).toContain('heartbeat.enabled');
// Control: the slice really did capture the banner and not an empty string,
// which would satisfy nothing above and look identical to a pass.
expect(line).toContain('10 minutes');
});
});
15 changes: 14 additions & 1 deletion backend/services/schedulerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,20 @@ class SchedulerService {
console.log('- Agent event GC runs every 10 minutes');
console.log('- Themed pod autonomy runs every 2 hours');
console.log('- Agent auto-join (agent-owned pods) runs every 2 hours');
console.log('- Agent heartbeats run every 10 minutes with per-agent intervals');
// Names the opt-in gate on purpose. Every other line in this banner
// describes a job that simply runs; this one describes a job that runs
// only for installs that asked for it (#800 made it opt-in after 166 of
// 245 active installs were found ticking hourly on a default nobody set).
// The old line read "run every 10 minutes with per-agent intervals",
// which is true about the dispatcher and silent about the gate — and it
// sent a reader straight to resolveHeartbeatIntervalMinutes to compute a
// fleet-wide wake rate off a field that is never reached for a seat that
// never opted in.
console.log(
'- Agent heartbeats dispatch every 10 minutes; only installs with'
+ ' config.heartbeat.enabled === true fire, each on its own interval'
+ ' (config.heartbeat.everyMinutes, default 60)',
);
console.log(
`- OpenClaw sessions reset every ${AgentEventService.getSessionResetIntervalHours()} hour(s)`,
);
Expand Down
Loading