feat: add watchdog owner-visible reporting
This commit is contained in:
@@ -256,6 +256,83 @@ function decideRecoveryAction(payload, status) {
|
||||
return 'fetch_history';
|
||||
}
|
||||
|
||||
function buildReportingPayload(payload, status, recoveryDecision) {
|
||||
const detail = {
|
||||
runId: typeof payload?.runId === 'string' ? payload.runId : null,
|
||||
childSessionKey: typeof payload?.childSessionKey === 'string' ? payload.childSessionKey : null,
|
||||
status,
|
||||
recoveryDecision,
|
||||
};
|
||||
|
||||
if (status === 'suspect_delivery_failure') {
|
||||
return {
|
||||
ownerVisible: true,
|
||||
category: 'suspect_delivery_failure',
|
||||
decision: 'report',
|
||||
summary: 'Subagent delivery is suspected to have failed after crossing SLA.',
|
||||
detail,
|
||||
};
|
||||
}
|
||||
|
||||
if (status === 'done_but_not_forwarded' && recoveryDecision === 'fetch_history') {
|
||||
return {
|
||||
ownerVisible: true,
|
||||
category: 'done_but_not_forwarded',
|
||||
decision: 'fetch_history',
|
||||
summary: 'Child run is done but no forwarded completion receipt is confirmed yet.',
|
||||
detail,
|
||||
};
|
||||
}
|
||||
|
||||
if (status === 'done_but_not_forwarded' && recoveryDecision === 'respawn') {
|
||||
return {
|
||||
ownerVisible: true,
|
||||
category: 'done_but_not_forwarded',
|
||||
decision: 'respawn',
|
||||
summary: 'Child run is done but recovery already failed once; respawn is the next conservative step.',
|
||||
detail,
|
||||
};
|
||||
}
|
||||
|
||||
if (status === 'done_but_not_forwarded' && recoveryDecision === 'blocked') {
|
||||
return {
|
||||
ownerVisible: true,
|
||||
category: 'done_but_not_forwarded',
|
||||
decision: 'blocked',
|
||||
summary: 'Child run is still not forwarded after repeated recovery attempts; owner attention is required.',
|
||||
detail,
|
||||
};
|
||||
}
|
||||
|
||||
if (status === 'completed') {
|
||||
return {
|
||||
ownerVisible: false,
|
||||
category: 'completed',
|
||||
decision: 'none',
|
||||
summary: 'Completion receipt is present; no owner-visible report is needed.',
|
||||
detail,
|
||||
};
|
||||
}
|
||||
|
||||
if (status === 'active') {
|
||||
return {
|
||||
ownerVisible: false,
|
||||
category: 'active',
|
||||
decision: 'none',
|
||||
summary: 'Dispatch is still within SLA; no owner-visible report is needed.',
|
||||
detail,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
ownerVisible: false,
|
||||
category: status,
|
||||
decision: 'none',
|
||||
summary: 'No owner-visible report is needed.',
|
||||
detail,
|
||||
};
|
||||
}
|
||||
|
||||
function main() {
|
||||
const args = parseArgs(process.argv.slice(2));
|
||||
|
||||
@@ -270,6 +347,7 @@ function main() {
|
||||
const completionWrite = writeCompletionReceiptState(inputPayload);
|
||||
const status = recomputeStatus(inputPayload);
|
||||
const recoveryDecision = decideRecoveryAction(inputPayload, status);
|
||||
const reporting = buildReportingPayload(inputPayload, status, recoveryDecision);
|
||||
|
||||
if ('content' in input) {
|
||||
delete input.content;
|
||||
@@ -286,7 +364,7 @@ function main() {
|
||||
const response = {
|
||||
ok: true,
|
||||
tool: 'subagent_delivery_watchdog',
|
||||
version: 'skeleton-v4',
|
||||
version: 'skeleton-v5',
|
||||
mode: 'receipt-write',
|
||||
args: {
|
||||
compact: args.compact,
|
||||
@@ -296,9 +374,10 @@ function main() {
|
||||
result: {
|
||||
status,
|
||||
message: status === 'not_implemented'
|
||||
? 'Dispatch and completion receipt writes are implemented; status recompute only handles basic active/suspect/completed states.'
|
||||
? 'Dispatch and completion receipt writes are implemented; status recompute only handles basic active/suspect/completed states plus conservative recovery/reporting decisions.'
|
||||
: 'Basic watchdog status recompute completed.',
|
||||
recoveryDecision,
|
||||
reporting,
|
||||
records,
|
||||
dispatchReceiptWrite: dispatchWrite,
|
||||
completionReceiptWrite: completionWrite,
|
||||
|
||||
Reference in New Issue
Block a user