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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: preserve payload-dependent recovery semantics (#3182)
[._.]/ Adam Eivya419cfb8c26e
diff --git a/server/services/agentFinalization.js b/server/services/agentFinalization.jsindex ed46d89f2d..7821608160 100644--- a/server/services/agentFinalization.js+++ b/server/services/agentFinalization.js@@ -27,7 +27,7 @@ import { release } from './executionLanes.js';import { completeExecution, errorExecution } from './toolStateMachine.js';import { resolveFailedTaskUpdate, resolveTypeFailureSignal } from './agentErrorAnalysis.js';import { completeAgentRun, checkForTaskCommit } from './agentRunTracking.js';-import { isProgrammaticIoTaskType, resolveTaskHookType, isNonCommittingCoordinatorTask } from './taskTypeHooks.js';+import { canRunTaskOutputHookWithoutPayload, isProgrammaticIoTaskType, resolveTaskHookType, isNonCommittingCoordinatorTask } from './taskTypeHooks.js';import { processAgentCompletion } from './agentCompletion.js';import { extractSimplifySummaries } from './agentSummaryExtraction.js';@@ -230,6 +230,7 @@ export function dispatchTaskOutputHookOnce({success,workspacePath = null,readPayload = true,+ recovery = false,}) {const existing = outputHookDispatches.get(agentId);if (existing) return existing;@@ -241,7 +242,7 @@ export function dispatchTaskOutputHookOnce({}const result = await withOutputHookTimeout(- dispatchTaskOutputHook({ agentId, task, success, workspacePath, readPayload }),+ dispatchTaskOutputHook({ agentId, task, success, workspacePath, readPayload, recovery }),{ agentId }).catch(err => {emitLog('error', `❌ processTaskOutput hook threw for ${agentId} (${task?.taskType}): ${err.message}`, { agentId, error: err.message });@@ -274,17 +275,18 @@ export function dispatchTaskOutputHookOnce({}/**- * Recovery paths have no trustworthy worktree after a restart/orphan reap, so- * they deliberately dispatch with a null payload rather than reading a stale- * `.agent-done` from the task's repository root.+ * Recovery paths try the agent's persisted workspace when it still exists.+ * When it does not, only hooks whose registry contract says they are+ * payload-independent may run with null output.*/-export function dispatchRecoveredTaskOutputHook({ agentId, task, success }) {+export function dispatchRecoveredTaskOutputHook({ agentId, task, success, workspacePath = null }) {return dispatchTaskOutputHookOnce({agentId,task,success,- workspacePath: null,- readPayload: false,+ workspacePath,+ readPayload: !!workspacePath,+ recovery: true,});}@@ -496,7 +498,7 @@ export async function finalizeAgent({* task types (no hook). The hook receives `{ appId, success, payload, ... }` and* loads its own app/config — finalizeAgent stays domain-agnostic.*/-async function dispatchTaskOutputHook({ agentId, task, success, workspacePath, readPayload = true }) {+async function dispatchTaskOutputHook({ agentId, task, success, workspacePath, readPayload = true, recovery = false }) {// Shared resolver with evaluateSuccessCriteria's gate — "runs a hook" and "gets// the programmatic-I/O criterion" must stay the same question (#2727).const taskType = resolveTaskHookType(task);@@ -525,6 +527,9 @@ async function dispatchTaskOutputHook({ agentId, task, success, workspacePath, r}}}+ if (recovery && payload == null && !canRunTaskOutputHookWithoutPayload(taskType)) {+ return { ran: false, recoveryPayloadUnavailable: true };+ }const outcome = await hook({appId: task?.metadata?.app || null,diff --git a/server/services/agentFinalization.outputHooks.test.js b/server/services/agentFinalization.outputHooks.test.jsindex ae2e4f380e..2c7f91b3fe 100644--- a/server/services/agentFinalization.outputHooks.test.js+++ b/server/services/agentFinalization.outputHooks.test.js@@ -10,6 +10,7 @@ vi.mock('./cosAgents.js', () => ({}));vi.mock('./taskTypeHooks.js', () => ({+ canRunTaskOutputHookWithoutPayload: vi.fn(() => true),getTaskOutputHook: vi.fn(),isNonCommittingCoordinatorTask: vi.fn(() => false),isProgrammaticIoTaskType: vi.fn(() => true),@@ -17,7 +18,7 @@ vi.mock('./taskTypeHooks.js', () => ({}));import { getAgent, updateAgent } from './cosAgents.js';-import { getTaskOutputHook } from './taskTypeHooks.js';+import { canRunTaskOutputHookWithoutPayload, getTaskOutputHook } from './taskTypeHooks.js';import {dispatchRecoveredTaskOutputHook,dispatchTaskOutputHookOnce,@@ -146,6 +147,18 @@ describe('recovery output-hook dispatch (#3182)', () => {})).resolves.toEqual({ ran: false });expect(updateAgent).not.toHaveBeenCalled();});++ it('does not invoke a payload-dependent hook when recovery cannot read a sentinel', async () => {+ canRunTaskOutputHookWithoutPayload.mockReturnValueOnce(false);++ await expect(dispatchRecoveredTaskOutputHook({+ agentId: persistedAgent.id,+ task: TASK,+ success: true,+ })).resolves.toEqual({ ran: false, recoveryPayloadUnavailable: true });+ expect(hook).not.toHaveBeenCalled();+ expect(updateAgent).not.toHaveBeenCalled();+ });});describe('recovery path wiring (#3182)', () => {diff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.jsindex a2f43ff07f..90425982c5 100644--- a/server/services/agentLifecycle.js+++ b/server/services/agentLifecycle.js@@ -775,7 +775,12 @@ export async function handleAgentCompletion(agentId, exitCode, success, duration}console.log(`🔄 Completing untracked agent ${agentId} from cos state (post-restart)`);const task = cosAgent.taskId ? await getTaskById(cosAgent.taskId).catch(() => null) : null;- await dispatchRecoveredTaskOutputHook({ agentId, task, success });+ await dispatchRecoveredTaskOutputHook({+ agentId,+ task,+ success,+ workspacePath: cosAgent.metadata?.workspacePath || null,+ });await completeAgent(agentId, {success,exitCode,diff --git a/server/services/agentManagement.js b/server/services/agentManagement.jsindex 8b1e287cde..6177a08d23 100644--- a/server/services/agentManagement.js+++ b/server/services/agentManagement.js@@ -602,6 +602,7 @@ export async function cleanupOrphanedAgents() {agentId: agent.id,task,success: false,+ workspacePath: agent.metadata?.workspacePath || null,});await markComplete(agent.id, {success: false,diff --git a/server/services/taskTypeHooks.js b/server/services/taskTypeHooks.jsindex 59479c79b6..553f9f7e12 100644--- a/server/services/taskTypeHooks.js+++ b/server/services/taskTypeHooks.js@@ -48,6 +48,7 @@ const HOOK_MODULES = {'layered-intelligence': () => import('./autonomousJobs/layeredIntelligenceHooks.js'),'quota-burn': () => import('./autonomousJobs/quotaBurnHooks.js'),};+const PAYLOAD_OPTIONAL_OUTPUT_HOOKS = new Set(['quota-burn']);async function loadHookModule(taskType) {if (!isProgrammaticIoTaskType(taskType)) return null;@@ -70,6 +71,16 @@ export function isProgrammaticIoTaskType(taskType) {return typeof taskType === 'string' && Object.hasOwn(HOOK_MODULES, taskType);}+/**+ * Whether recovery may safely run this output hook when its worktree/sentinel+ * no longer exists. Payload-dependent hooks must wait for a real sentinel+ * rather than treating recovery's missing output as an agent-produced empty+ * response.+ */+export function canRunTaskOutputHookWithoutPayload(taskType) {+ return PAYLOAD_OPTIONAL_OUTPUT_HOOKS.has(taskType);+}+/*** The task type a hook is keyed on, for a task record. The SCHEDULED type lives in* `metadata.analysisType` (the top-level `task.taskType` is the CoS queue category,diff --git a/server/services/taskTypeHooks.test.js b/server/services/taskTypeHooks.test.jsindex caae20ec56..8eff9a5096 100644--- a/server/services/taskTypeHooks.test.js+++ b/server/services/taskTypeHooks.test.js@@ -1,5 +1,5 @@import { describe, it, expect } from 'vitest';-import { getTaskInputHook, getTaskOutputHook, isProgrammaticIoTaskType } from './taskTypeHooks.js';+import { canRunTaskOutputHookWithoutPayload, getTaskInputHook, getTaskOutputHook, isProgrammaticIoTaskType } from './taskTypeHooks.js';describe('taskTypeHooks registry', () => {it('resolves both hooks for layered-intelligence to callables', async () => {@@ -15,6 +15,12 @@ describe('taskTypeHooks registry', () => {expect(await getTaskInputHook('does-not-exist')).toBeNull();expect(await getTaskOutputHook('does-not-exist')).toBeNull();});++ it('declares only payload-independent hooks safe for sentinel-less recovery', () => {+ expect(canRunTaskOutputHookWithoutPayload('quota-burn')).toBe(true);+ expect(canRunTaskOutputHookWithoutPayload('layered-intelligence')).toBe(false);+ expect(canRunTaskOutputHookWithoutPayload('does-not-exist')).toBe(false);+ });});describe('isProgrammaticIoTaskType (#2700)', () => {