fix: persist agent version on every heartbeat

update_agent_seen() now updates version column when agents include it
in their heartbeat payload. Previously version was only stored on
registration, leaving the Workers tab showing NULL for agents that
hadn't re-registered since v3.1.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-17 17:19:56 +00:00
parent 7f6397b514
commit 188f6f8f10
+13 -6
View File
@@ -37,11 +37,18 @@ function get_agent_by_key(string $key): ?array {
return $rows[0] ?? null;
}
function update_agent_seen(string $agentId, string $status = 'online'): void {
JarvisDB::query(
'UPDATE registered_agents SET last_seen = NOW(), status = ? WHERE agent_id = ?',
[$status, $agentId]
);
function update_agent_seen(string $agentId, string $status = 'online', ?string $version = null): void {
if ($version !== null) {
JarvisDB::query(
'UPDATE registered_agents SET last_seen = NOW(), status = ?, version = ? WHERE agent_id = ?',
[$status, $version, $agentId]
);
} else {
JarvisDB::query(
'UPDATE registered_agents SET last_seen = NOW(), status = ? WHERE agent_id = ?',
[$status, $agentId]
);
}
}
// ── Auth (all actions except register) ───────────────────────────────────────
@@ -104,7 +111,7 @@ switch ($agentAction) {
// ── HEARTBEAT ────────────────────────────────────────────────────────────
case 'heartbeat':
update_agent_seen($agent['agent_id']);
update_agent_seen($agent['agent_id'], 'online', trim($data['version'] ?? '') ?: null);
// Return any pending commands for this agent
$commands = JarvisDB::query(