Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([issue-12737]): treat a paused agent with a dead owner as residue

Adam Eivyf974da1a48fc
diff --git a/server/services/agentMaintenanceReservations.js b/server/services/agentMaintenanceReservations.js
index 309239daab..e45c6d2be2 100644
--- a/server/services/agentMaintenanceReservations.js
+++ b/server/services/agentMaintenanceReservations.js
@@ -15,8 +15,8 @@ export async function releaseAgentReservation(agentId) {
}
/**
- * Drop `agent` reservations whose agent is completed or no longer in state AND
- * whose admitting process is dead. A running/paused agent, a live owner pid and
+ * Drop `agent` reservations whose agent is completed, paused or no longer in state AND
+ * whose admitting process is dead. A running agent, a live owner pid and
* an `unsettled` (uncertain-cleanup) record are never touched; operator
* abandonment receipts stay the path for those.
*
@@ -26,7 +26,8 @@ export async function releaseAgentReservation(agentId) {
export async function reconcileStaleAgentReservations({ agents, admission = maintenance, pidAlive = isPidAlive }) {
try {
const statusById = new Map(agents.map(agent => [agent.id, agent.status]));
- const ended = id => !statusById.has(id) || statusById.get(id) === 'completed';
+ // A paused agent has no process; pausing settles its reservation, so a dead-owner one is residue.
+ const ended = id => !statusById.has(id) || ['completed', 'paused'].includes(statusById.get(id));
const stale = admission.operations().filter(op => op.kind === 'agent' && !op.unsettled
&& ended(op.resource) && !pidAlive(op.pid));
if (stale.length === 0) return 0;
diff --git a/server/services/agentMaintenanceReservations.test.js b/server/services/agentMaintenanceReservations.test.js
index 10d2d91093..55dd7fcc12 100644
--- a/server/services/agentMaintenanceReservations.test.js
+++ b/server/services/agentMaintenanceReservations.test.js
@@ -48,10 +48,10 @@ describe('reconcileStaleAgentReservations', () => {
gateRef.gate.admit('provider', 'agent-done');
};
- it('releases completed or absent agents with a dead owner and nothing else', async () => {
+ it('releases completed, paused or absent agents with a dead owner and nothing else', async () => {
seed();
- expect(await reconcileStaleAgentReservations({ agents, pidAlive: () => false })).toBe(2);
- expect(resources()).toEqual(['agent-done', 'agent-hurt', 'agent-live', 'agent-paused']);
+ expect(await reconcileStaleAgentReservations({ agents, pidAlive: () => false })).toBe(3);
+ expect(resources()).toEqual(['agent-done', 'agent-hurt', 'agent-live']);
expect(gateRef.gate.status().blockers.filter(b => b.resource === 'agent-done').map(b => b.kind)).toEqual(['provider']);
});