feat(agents): per-agent run-missed-heartbeat-on-startup setting
When the engine boots, if an agent has the new runMissedHeartbeatOnStartup flag enabled and lastHeartbeatAt is older than its interval, fire one catch-up heartbeat through the existing executeHeartbeat path. Default is off, so existing agents are unchanged. Toggle exposed in the agent's Heartbeat Settings tab. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2651,6 +2651,10 @@ function deriveAutoClaimRelevantTasksEnabled(runtimeConfig: AgentDetail["runtime
|
||||
return runtimeConfig?.autoClaimRelevantTasks !== false;
|
||||
}
|
||||
|
||||
function deriveRunMissedHeartbeatOnStartup(runtimeConfig: AgentDetail["runtimeConfig"] | undefined): boolean {
|
||||
return runtimeConfig?.runMissedHeartbeatOnStartup === true;
|
||||
}
|
||||
|
||||
function deriveBudgetValues(runtimeConfig: AgentDetail["runtimeConfig"] | undefined): Record<string, string> {
|
||||
const bc = (runtimeConfig ?? {}).budgetConfig as Record<string, unknown> | undefined;
|
||||
const nextValues: Record<string, string> = {};
|
||||
@@ -3011,6 +3015,9 @@ function ConfigTab({
|
||||
const [autoClaimRelevantTasksEnabled, setAutoClaimRelevantTasksEnabled] = useState<boolean>(
|
||||
() => deriveAutoClaimRelevantTasksEnabled(agent.runtimeConfig),
|
||||
);
|
||||
const [runMissedHeartbeatOnStartup, setRunMissedHeartbeatOnStartup] = useState<boolean>(
|
||||
() => deriveRunMissedHeartbeatOnStartup(agent.runtimeConfig),
|
||||
);
|
||||
|
||||
// Budget config state initialised from agent.runtimeConfig.budgetConfig
|
||||
const [budgetValues, setBudgetValues] = useState<Record<string, string>>(
|
||||
@@ -3212,6 +3219,7 @@ function ConfigTab({
|
||||
const rc = agent.runtimeConfig ?? {};
|
||||
if (heartbeatEnabled !== deriveHeartbeatEnabled(agent.runtimeConfig)) return true;
|
||||
if (autoClaimRelevantTasksEnabled !== deriveAutoClaimRelevantTasksEnabled(agent.runtimeConfig)) return true;
|
||||
if (runMissedHeartbeatOnStartup !== deriveRunMissedHeartbeatOnStartup(agent.runtimeConfig)) return true;
|
||||
for (const key of ["heartbeatIntervalMs", "heartbeatTimeoutMs", "maxConcurrentRuns", "messageResponseMode"] as const) {
|
||||
const current = heartbeatValues[key]?.trim() ?? "";
|
||||
let persisted = rc[key] !== undefined && rc[key] !== null ? String(rc[key]) : "";
|
||||
@@ -3286,6 +3294,7 @@ function ConfigTab({
|
||||
setHeartbeatValues(deriveHeartbeatValues(agent.runtimeConfig));
|
||||
setHeartbeatEnabled(deriveHeartbeatEnabled(agent.runtimeConfig));
|
||||
setAutoClaimRelevantTasksEnabled(deriveAutoClaimRelevantTasksEnabled(agent.runtimeConfig));
|
||||
setRunMissedHeartbeatOnStartup(deriveRunMissedHeartbeatOnStartup(agent.runtimeConfig));
|
||||
setBudgetValues(deriveBudgetValues(agent.runtimeConfig));
|
||||
setModelValue(initialModelValue);
|
||||
setSelectedRuntimeId(initialRuntimeHint);
|
||||
@@ -3432,6 +3441,7 @@ function ConfigTab({
|
||||
const newRuntimeConfig: Record<string, unknown> = { ...agent.runtimeConfig };
|
||||
newRuntimeConfig.enabled = heartbeatEnabled;
|
||||
newRuntimeConfig.autoClaimRelevantTasks = autoClaimRelevantTasksEnabled;
|
||||
newRuntimeConfig.runMissedHeartbeatOnStartup = runMissedHeartbeatOnStartup;
|
||||
for (const key of ["heartbeatIntervalMs", "heartbeatTimeoutMs", "maxConcurrentRuns"] as const) {
|
||||
const raw = heartbeatValues[key]?.trim();
|
||||
if (!raw) {
|
||||
@@ -3527,7 +3537,7 @@ function ConfigTab({
|
||||
runtimeConfig: newRuntimeConfig,
|
||||
bundleConfig: newBundleConfig,
|
||||
};
|
||||
}, [agent.metadata, agent.runtimeConfig, autoClaimRelevantTasksEnabled, budgetValues, bundleEntryFile, bundleExternalPath, bundleFiles, bundleMode, formValues, heartbeatEnabled, heartbeatValues, iconValue, modelValue, nameValue, reportsToValue, roleValue, runtimeMode, selectedRuntimeId, selectedSkills, titleValue, validationErrors]);
|
||||
}, [agent.metadata, agent.runtimeConfig, autoClaimRelevantTasksEnabled, budgetValues, bundleEntryFile, bundleExternalPath, bundleFiles, bundleMode, formValues, heartbeatEnabled, heartbeatValues, iconValue, modelValue, nameValue, reportsToValue, roleValue, runMissedHeartbeatOnStartup, runtimeMode, selectedRuntimeId, selectedSkills, titleValue, validationErrors]);
|
||||
|
||||
const persistSettings = useCallback(async (showValidationToast: boolean, source: "auto" | "manual") => {
|
||||
const payload = buildSavePayload();
|
||||
@@ -3931,6 +3941,22 @@ function ConfigTab({
|
||||
<span className="config-hint">When enabled (default), no-task heartbeats scan open unowned work and auto-claim tasks aligned with this agent's role and soul.</span>
|
||||
</div>
|
||||
|
||||
<div className="config-field">
|
||||
<label className="checkbox-label" htmlFor="hb-runMissedHeartbeatOnStartup">
|
||||
<input
|
||||
id="hb-runMissedHeartbeatOnStartup"
|
||||
type="checkbox"
|
||||
checked={runMissedHeartbeatOnStartup}
|
||||
onChange={(e) => {
|
||||
setRunMissedHeartbeatOnStartup(e.target.checked);
|
||||
void scheduleAutoSave();
|
||||
}}
|
||||
/>
|
||||
Run Missed Heartbeat On Startup
|
||||
</label>
|
||||
<span className="config-hint">When enabled, if the server was down across this agent's scheduled heartbeat tick, fire a single catch-up heartbeat at startup. Default: off.</span>
|
||||
</div>
|
||||
|
||||
<div className="config-field">
|
||||
<label htmlFor="hb-heartbeatIntervalMs">Heartbeat Interval (s)</label>
|
||||
<input
|
||||
@@ -4320,7 +4346,7 @@ function ConfigTab({
|
||||
<span className="config-danger-note">
|
||||
{isDeletableState
|
||||
? "Deletion is permanent and cannot be undone."
|
||||
: `Agent deletion is only available when state is idle, terminated, or paused (current state: ${agent.state}).`}
|
||||
: `Agent deletion is only available when state is idle or paused (current state: ${agent.state}).`}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -830,46 +830,6 @@ describe("AgentDetailView", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("shows Delete button for terminated agent", async () => {
|
||||
mockFetchAgent.mockResolvedValue(createMockAgent({ state: "terminated" }));
|
||||
|
||||
render(
|
||||
<AgentDetailView
|
||||
agentId="agent-001"
|
||||
onClose={vi.fn()}
|
||||
addToast={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("Start")).toBeInTheDocument();
|
||||
expect(screen.getByText("Delete")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("shows Start button for terminated agent", async () => {
|
||||
mockFetchAgent.mockResolvedValue(createMockAgent({ state: "terminated" }));
|
||||
mockUpdateAgentState.mockResolvedValue(createMockAgent({ state: "active" }));
|
||||
|
||||
render(
|
||||
<AgentDetailView
|
||||
agentId="agent-001"
|
||||
onClose={vi.fn()}
|
||||
addToast={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("Start")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
await userEvent.click(screen.getByText("Start"));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockUpdateAgentState).toHaveBeenCalledWith("agent-001", "active", undefined);
|
||||
});
|
||||
});
|
||||
|
||||
it("shows Delete button for idle agent", async () => {
|
||||
mockFetchAgent.mockResolvedValue(createMockAgent({ state: "idle" }));
|
||||
|
||||
@@ -1589,7 +1549,7 @@ describe("AgentDetailView", () => {
|
||||
await user.click(screen.getByText("Settings"));
|
||||
};
|
||||
|
||||
it("shows settings delete control for idle, terminated, and paused agents", async () => {
|
||||
it("shows settings delete control for idle and paused agents", async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
mockFetchAgent.mockResolvedValue(createMockAgent({ state: "idle" }));
|
||||
@@ -1605,19 +1565,6 @@ describe("AgentDetailView", () => {
|
||||
expect(await screen.findByRole("button", { name: "Delete Agent" })).toBeEnabled();
|
||||
idleRender.unmount();
|
||||
|
||||
mockFetchAgent.mockResolvedValue(createMockAgent({ state: "terminated" }));
|
||||
const terminatedRender = render(
|
||||
<AgentDetailView
|
||||
agentId="agent-001"
|
||||
onClose={vi.fn()}
|
||||
addToast={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
|
||||
await navigateToSettings(user);
|
||||
expect(await screen.findByRole("button", { name: "Delete Agent" })).toBeEnabled();
|
||||
terminatedRender.unmount();
|
||||
|
||||
mockFetchAgent.mockResolvedValue(createMockAgent({ state: "paused" }));
|
||||
render(
|
||||
<AgentDetailView
|
||||
@@ -1707,7 +1654,7 @@ describe("AgentDetailView", () => {
|
||||
|
||||
expect(await screen.findByRole("button", { name: "Delete Agent" })).toBeDisabled();
|
||||
expect(
|
||||
screen.getByText("Agent deletion is only available when state is idle, terminated, or paused (current state: active)."),
|
||||
screen.getByText("Agent deletion is only available when state is idle or paused (current state: active)."),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -2380,6 +2327,64 @@ describe("AgentDetailView", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("defaults run-missed-heartbeat-on-startup toggle to disabled when runtimeConfig flag is missing", async () => {
|
||||
mockFetchAgent.mockResolvedValue(createMockAgent({
|
||||
runtimeConfig: {
|
||||
heartbeatIntervalMs: 30000,
|
||||
},
|
||||
}));
|
||||
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<AgentDetailView
|
||||
agentId="agent-001"
|
||||
onClose={vi.fn()}
|
||||
addToast={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
await navigateToSettings(user);
|
||||
|
||||
await waitFor(() => {
|
||||
expect((screen.getByLabelText("Run Missed Heartbeat On Startup") as HTMLInputElement).checked).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it("persists run-missed-heartbeat-on-startup toggle changes on save", async () => {
|
||||
mockFetchAgent.mockResolvedValue(createMockAgent({
|
||||
runtimeConfig: {
|
||||
enabled: true,
|
||||
heartbeatIntervalMs: 30000,
|
||||
},
|
||||
}));
|
||||
mockUpdateAgent.mockResolvedValue(createMockAgent() as any);
|
||||
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<AgentDetailView
|
||||
agentId="agent-001"
|
||||
onClose={vi.fn()}
|
||||
addToast={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
await navigateToSettings(user);
|
||||
|
||||
const toggle = await screen.findByLabelText("Run Missed Heartbeat On Startup");
|
||||
await user.click(toggle);
|
||||
await user.click(screen.getByText("Save Settings"));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockUpdateAgent).toHaveBeenCalledWith(
|
||||
"agent-001",
|
||||
expect.objectContaining({
|
||||
runtimeConfig: expect.objectContaining({ runMissedHeartbeatOnStartup: true }),
|
||||
}),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("persists auto-claim toggle changes on save", async () => {
|
||||
mockFetchAgent.mockResolvedValue(createMockAgent({
|
||||
runtimeConfig: {
|
||||
|
||||
Reference in New Issue
Block a user