principles-disciple 1.23.0 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Nocturnal Pipeline Diagnostic Script
|
|
5
|
+
* ======================================
|
|
6
|
+
* Checks every link in the Nocturnal reflection chain:
|
|
7
|
+
* Heartbeat → Idle Detection → Queue → Snapshot → Workflow → Trinity → Arbiter → Persistence
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* node scripts/diagnose-nocturnal.mjs [--workspace /path/to/workspace]
|
|
11
|
+
*
|
|
12
|
+
* Output: Structured report with pass/fail for each checkpoint.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'fs';
|
|
16
|
+
import { join, dirname } from 'path';
|
|
17
|
+
import { fileURLToPath } from 'url';
|
|
18
|
+
import { execSync } from 'child_process';
|
|
19
|
+
|
|
20
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
+
const __dirname = dirname(__filename);
|
|
22
|
+
const PLUGIN_DIR = join(__dirname, '..');
|
|
23
|
+
|
|
24
|
+
// ─── Argument parsing ───
|
|
25
|
+
function parseArgs() {
|
|
26
|
+
let workspaceDir = null;
|
|
27
|
+
const argv = process.argv.slice(2);
|
|
28
|
+
for (let i = 0; i < argv.length; i++) {
|
|
29
|
+
if (argv[i] === '--workspace' && argv[i + 1]) {
|
|
30
|
+
workspaceDir = argv[++i];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Auto-detect workspace from current git working directory
|
|
34
|
+
if (!workspaceDir) {
|
|
35
|
+
try {
|
|
36
|
+
const gitRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim();
|
|
37
|
+
workspaceDir = gitRoot;
|
|
38
|
+
} catch {
|
|
39
|
+
workspaceDir = process.cwd();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { workspaceDir };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ─── Report helpers ───
|
|
46
|
+
const results = [];
|
|
47
|
+
let checksPassed = 0;
|
|
48
|
+
let checksFailed = 0;
|
|
49
|
+
let checksWarned = 0;
|
|
50
|
+
|
|
51
|
+
function check(name, fn) {
|
|
52
|
+
try {
|
|
53
|
+
const result = fn();
|
|
54
|
+
if (result && result.status === 'warn') {
|
|
55
|
+
checksWarned++;
|
|
56
|
+
results.push({ name, status: 'warn', detail: result.detail || '' });
|
|
57
|
+
} else {
|
|
58
|
+
checksPassed++;
|
|
59
|
+
results.push({ name, status: 'pass', detail: typeof result === 'string' ? result : '' });
|
|
60
|
+
}
|
|
61
|
+
} catch (err) {
|
|
62
|
+
checksFailed++;
|
|
63
|
+
results.push({ name, status: 'fail', detail: err.message || String(err) });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function printReport() {
|
|
68
|
+
console.log('\n' + '='.repeat(60));
|
|
69
|
+
console.log(' NOCTURNAL PIPELINE DIAGNOSTIC REPORT');
|
|
70
|
+
console.log(' ' + new Date().toISOString());
|
|
71
|
+
console.log('='.repeat(60));
|
|
72
|
+
|
|
73
|
+
for (const r of results) {
|
|
74
|
+
const icon = r.status === 'pass' ? '✅' : r.status === 'warn' ? '⚠️ ' : '❌';
|
|
75
|
+
console.log(`\n${icon} ${r.name}`);
|
|
76
|
+
if (r.detail) {
|
|
77
|
+
console.log(` ${r.detail}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
console.log('\n' + '-'.repeat(60));
|
|
82
|
+
console.log(` Summary: ${checksPassed} passed, ${checksWarned} warnings, ${checksFailed} failed`);
|
|
83
|
+
console.log('-'.repeat(60) + '\n');
|
|
84
|
+
|
|
85
|
+
if (checksFailed > 0) {
|
|
86
|
+
process.exitCode = 1;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ─── Main ───
|
|
91
|
+
function main() {
|
|
92
|
+
const { workspaceDir } = parseArgs();
|
|
93
|
+
const stateDir = join(workspaceDir, '.state');
|
|
94
|
+
|
|
95
|
+
console.log(`\n🔍 Diagnosing Nocturnal pipeline for workspace: ${workspaceDir}`);
|
|
96
|
+
|
|
97
|
+
// ─────────────────────────────────────────────────────────
|
|
98
|
+
// CHECKPOINT 1: State directory structure
|
|
99
|
+
// ─────────────────────────────────────────────────────────
|
|
100
|
+
check('1. State directory structure', () => {
|
|
101
|
+
// All state dirs are inside .state/
|
|
102
|
+
const required = ['sessions', 'logs', 'nocturnal', 'nocturnal/samples'];
|
|
103
|
+
const missing = [];
|
|
104
|
+
for (const rel of required) {
|
|
105
|
+
if (!existsSync(join(stateDir, rel))) missing.push(rel);
|
|
106
|
+
}
|
|
107
|
+
if (missing.length > 0) throw new Error(`Missing directories: ${missing.join(', ')}`);
|
|
108
|
+
return 'All required directories present';
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// ─────────────────────────────────────────────────────────
|
|
112
|
+
// CHECKPOINT 2: Session tracker persistence
|
|
113
|
+
// ─────────────────────────────────────────────────────────
|
|
114
|
+
check('2. Session tracker persistence', () => {
|
|
115
|
+
const sessionsDir = join(stateDir, 'sessions');
|
|
116
|
+
if (!existsSync(sessionsDir)) throw new Error('sessions/ directory missing');
|
|
117
|
+
const files = readdirSync(sessionsDir).filter(f => f.endsWith('.json'));
|
|
118
|
+
if (files.length === 0) {
|
|
119
|
+
return { status: 'warn', detail: 'No session files found — idle check will report idle immediately' };
|
|
120
|
+
}
|
|
121
|
+
// Verify at least one session file is valid JSON
|
|
122
|
+
let validSessions = 0;
|
|
123
|
+
for (const f of files) {
|
|
124
|
+
try {
|
|
125
|
+
const data = JSON.parse(readFileSync(join(sessionsDir, f), 'utf-8'));
|
|
126
|
+
if (data.sessionId && data.lastActivityAt) validSessions++;
|
|
127
|
+
} catch { /* corrupted, skip */ }
|
|
128
|
+
}
|
|
129
|
+
return `${files.length} session files, ${validSessions} valid with sessionId+lastActivityAt`;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// ─────────────────────────────────────────────────────────
|
|
133
|
+
// CHECKPOINT 3: Idle detection logic
|
|
134
|
+
// ─────────────────────────────────────────────────────────
|
|
135
|
+
check('3. Idle detection (checkWorkspaceIdle)', () => {
|
|
136
|
+
// Functions are minified — check for unique string markers instead.
|
|
137
|
+
const bundlePath = join(PLUGIN_DIR, 'dist', 'bundle.js');
|
|
138
|
+
const content = readFileSync(bundlePath, 'utf-8');
|
|
139
|
+
|
|
140
|
+
// Stable markers: log messages, object fields, event strings that survive minification.
|
|
141
|
+
const markers = [
|
|
142
|
+
{ name: 'Workspace not idle', reason: 'preflight idle check log message' },
|
|
143
|
+
{ name: 'trigger', reason: 'system session detection (checks trigger field)' },
|
|
144
|
+
{ name: 'abandonedSessionIds', reason: 'IdleCheckResult field (preserved in object literal)' },
|
|
145
|
+
{ name: 'trajectoryGuardrailConfirmsIdle', reason: 'IdleCheckResult field' },
|
|
146
|
+
];
|
|
147
|
+
const missing = markers.filter(m => !content.includes(m.name));
|
|
148
|
+
if (missing.length > 0) {
|
|
149
|
+
throw new Error(`Idle detection markers missing: ${missing.map(m => m.name).join(', ')}`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Check PR #256 fix: legacy session temporal guard
|
|
153
|
+
// The fix adds `lastActivityAt` comparison before treating sessions as system sessions.
|
|
154
|
+
// In minified code this appears as a comparison involving `lastActivityAt`.
|
|
155
|
+
if (!content.includes('lastActivityAt')) {
|
|
156
|
+
return { status: 'warn', detail: 'lastActivityAt reference not found — temporal guard for legacy sessions may be missing' };
|
|
157
|
+
}
|
|
158
|
+
return 'Idle detection functions present (verified via stable string markers)';
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// ─────────────────────────────────────────────────────────
|
|
162
|
+
// CHECKPOINT 4: Evolution queue
|
|
163
|
+
// ─────────────────────────────────────────────────────────
|
|
164
|
+
check('4. Evolution queue', () => {
|
|
165
|
+
const queuePath = join(stateDir, 'evolution_queue.json');
|
|
166
|
+
if (!existsSync(queuePath)) {
|
|
167
|
+
return { status: 'warn', detail: 'No evolution queue — idle check has not yet enqueued a task' };
|
|
168
|
+
}
|
|
169
|
+
const queue = JSON.parse(readFileSync(queuePath, 'utf-8'));
|
|
170
|
+
const sleepTasks = queue.filter(t => t.taskKind === 'sleep_reflection');
|
|
171
|
+
const pending = sleepTasks.filter(t => t.status === 'pending' || t.status === 'in_progress');
|
|
172
|
+
const completed = sleepTasks.filter(t => t.status === 'completed');
|
|
173
|
+
const failed = sleepTasks.filter(t => t.status === 'failed');
|
|
174
|
+
|
|
175
|
+
if (pending.length > 0) return `${pending.length} pending sleep_reflection task(s) awaiting processing`;
|
|
176
|
+
if (completed.length > 0) return `${completed.length} completed, ${failed.length} failed (total ${sleepTasks.length} tasks)`;
|
|
177
|
+
return { status: 'warn', detail: `Queue exists with ${queue.length} items but no sleep_reflection tasks` };
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// ─────────────────────────────────────────────────────────
|
|
181
|
+
// CHECKPOINT 5: Nocturnal samples (artifacts)
|
|
182
|
+
// ─────────────────────────────────────────────────────────
|
|
183
|
+
check('5. Nocturnal artifact persistence', () => {
|
|
184
|
+
const samplesDir = join(stateDir, 'nocturnal', 'samples');
|
|
185
|
+
if (!existsSync(samplesDir)) {
|
|
186
|
+
return { status: 'warn', detail: 'No samples directory — no reflections have been persisted yet' };
|
|
187
|
+
}
|
|
188
|
+
const files = readdirSync(samplesDir).filter(f => f.endsWith('.json'));
|
|
189
|
+
if (files.length === 0) return { status: 'warn', detail: 'samples/ directory exists but is empty' };
|
|
190
|
+
|
|
191
|
+
// Validate most recent artifact
|
|
192
|
+
const sorted = files
|
|
193
|
+
.map(f => ({ name: f, mtime: statSync(join(samplesDir, f)).mtimeMs }))
|
|
194
|
+
.sort((a, b) => b.mtime - a.mtime);
|
|
195
|
+
const latest = sorted[0].name;
|
|
196
|
+
const artifact = JSON.parse(readFileSync(join(samplesDir, latest), 'utf-8'));
|
|
197
|
+
const hasRequired = artifact.artifactId && artifact.badDecision && artifact.betterDecision && artifact.rationale;
|
|
198
|
+
if (!hasRequired) {
|
|
199
|
+
return { status: 'warn', detail: `Latest artifact ${latest} is missing required fields` };
|
|
200
|
+
}
|
|
201
|
+
return `${files.length} artifact(s), latest: ${latest} (${artifact.principleId || 'unknown principle'})`;
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// ─────────────────────────────────────────────────────────
|
|
205
|
+
// CHECKPOINT 6: Workflow store
|
|
206
|
+
// ─────────────────────────────────────────────────────────
|
|
207
|
+
check('6. Nocturnal workflow store', () => {
|
|
208
|
+
const workflowsPath = join(stateDir, 'nocturnal', 'workflows.json');
|
|
209
|
+
if (!existsSync(workflowsPath)) {
|
|
210
|
+
return { status: 'warn', detail: 'No workflows.json — no nocturnal workflows have been started' };
|
|
211
|
+
}
|
|
212
|
+
const workflows = JSON.parse(readFileSync(workflowsPath, 'utf-8'));
|
|
213
|
+
if (!Array.isArray(workflows) || workflows.length === 0) {
|
|
214
|
+
return { status: 'warn', detail: 'workflows.json is empty — no workflows recorded' };
|
|
215
|
+
}
|
|
216
|
+
const active = workflows.filter(w => w.state === 'active');
|
|
217
|
+
const completed = workflows.filter(w => w.state === 'completed');
|
|
218
|
+
const errored = workflows.filter(w => w.state === 'terminal_error');
|
|
219
|
+
const expired = workflows.filter(w => w.state === 'expired');
|
|
220
|
+
|
|
221
|
+
if (active.length > 0) {
|
|
222
|
+
return { status: 'warn', detail: `${active.length} workflow(s) still active — may be in progress or stuck. IDs: ${active.map(w => w.workflow_id).join(', ')}` };
|
|
223
|
+
}
|
|
224
|
+
return `${workflows.length} total: ${completed} completed, ${errored} errored, ${expired} expired`;
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// ─────────────────────────────────────────────────────────
|
|
228
|
+
// CHECKPOINT 7: Nocturnal runtime state (cooldown/quota)
|
|
229
|
+
// ─────────────────────────────────────────────────────────
|
|
230
|
+
check('7. Nocturnal runtime state (cooldown/quota)', () => {
|
|
231
|
+
const runtimePath = join(stateDir, 'nocturnal-runtime.json');
|
|
232
|
+
if (!existsSync(runtimePath)) {
|
|
233
|
+
return 'No runtime state — no cooldown or quota restrictions';
|
|
234
|
+
}
|
|
235
|
+
const state = JSON.parse(readFileSync(runtimePath, 'utf-8'));
|
|
236
|
+
const issues = [];
|
|
237
|
+
|
|
238
|
+
if (state.globalCooldownUntil) {
|
|
239
|
+
const cooldownEnd = new Date(state.globalCooldownUntil).getTime();
|
|
240
|
+
if (cooldownEnd > Date.now()) {
|
|
241
|
+
const remainingMin = Math.round((cooldownEnd - Date.now()) / 60000);
|
|
242
|
+
issues.push(`global cooldown active (${remainingMin}min remaining)`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (state.recentRunTimestamps) {
|
|
247
|
+
const windowStart = Date.now() - 24 * 60 * 60 * 1000;
|
|
248
|
+
const recentRuns = state.recentRunTimestamps
|
|
249
|
+
.map(ts => new Date(ts).getTime())
|
|
250
|
+
.filter(ts => ts > windowStart);
|
|
251
|
+
if (recentRuns.length >= 3) {
|
|
252
|
+
issues.push(`quota exhausted (${recentRuns.length}/3 runs used in 24h)`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (issues.length > 0) {
|
|
257
|
+
return { status: 'warn', detail: issues.join('; ') };
|
|
258
|
+
}
|
|
259
|
+
return 'No active cooldown or quota restrictions';
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
// ─────────────────────────────────────────────────────────
|
|
263
|
+
// CHECKPOINT 8: Bundle health
|
|
264
|
+
// ─────────────────────────────────────────────────────────
|
|
265
|
+
check('8. Plugin bundle health', () => {
|
|
266
|
+
const bundlePath = join(PLUGIN_DIR, 'dist', 'bundle.js');
|
|
267
|
+
if (!existsSync(bundlePath)) throw new Error('dist/bundle.js missing — run build first');
|
|
268
|
+
|
|
269
|
+
const content = readFileSync(bundlePath, 'utf-8');
|
|
270
|
+
|
|
271
|
+
// Use a mix of exported symbols and stable string markers.
|
|
272
|
+
// Class names and exported symbols survive minification; internal function names don't.
|
|
273
|
+
const markers = [
|
|
274
|
+
'EvolutionWorkerService', // exported class
|
|
275
|
+
'checkPainFlag', // exported function
|
|
276
|
+
'processEvolutionQueue', // function reference
|
|
277
|
+
'NocturnalWorkflowManager', // exported class
|
|
278
|
+
'executeNocturnalReflectionAsync', // used in log messages
|
|
279
|
+
'nocturnal_started', // event type string
|
|
280
|
+
'nocturnal_completed', // event type string
|
|
281
|
+
'nocturnal_failed', // event type string
|
|
282
|
+
'nocturnal_expired', // event type string
|
|
283
|
+
];
|
|
284
|
+
const missing = markers.filter(m => !content.includes(m));
|
|
285
|
+
if (missing.length > 0) throw new Error(`Missing critical symbols in bundle: ${missing.join(', ')}`);
|
|
286
|
+
|
|
287
|
+
return `Bundle OK (${Math.round(content.length / 1024)}KB), all ${markers.length} critical markers present`;
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// ─────────────────────────────────────────────────────────
|
|
291
|
+
// CHECKPOINT 9: Git state — uncommitted changes that could break pipeline
|
|
292
|
+
// ─────────────────────────────────────────────────────────
|
|
293
|
+
check('9. Git state (uncommitted changes)', () => {
|
|
294
|
+
try {
|
|
295
|
+
const status = execSync('git status --porcelain', { encoding: 'utf-8', timeout: 5000, cwd: PLUGIN_DIR }).trim();
|
|
296
|
+
if (!status) return 'Working tree clean';
|
|
297
|
+
const changedFiles = status.split('\n').length;
|
|
298
|
+
return { status: 'warn', detail: `${changedFiles} uncommitted change(s) in plugin directory` };
|
|
299
|
+
} catch {
|
|
300
|
+
return { status: 'warn', detail: 'Could not check git status' };
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
// ─────────────────────────────────────────────────────────
|
|
305
|
+
// CHECKPOINT 10: Pain flag state
|
|
306
|
+
// ─────────────────────────────────────────────────────────
|
|
307
|
+
check('10. Pain flag state', () => {
|
|
308
|
+
const painFlagPath = join(stateDir, '.pain_flag');
|
|
309
|
+
if (!existsSync(painFlagPath)) {
|
|
310
|
+
return 'No active pain flag';
|
|
311
|
+
}
|
|
312
|
+
const content = readFileSync(painFlagPath, 'utf-8');
|
|
313
|
+
const lines = content.split('\n');
|
|
314
|
+
const fields = {};
|
|
315
|
+
for (const line of lines) {
|
|
316
|
+
const colonIdx = line.indexOf(':');
|
|
317
|
+
if (colonIdx > 0) {
|
|
318
|
+
fields[line.substring(0, colonIdx).trim()] = line.substring(colonIdx + 1).trim();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (!fields.score || !fields.reason) {
|
|
322
|
+
return { status: 'warn', detail: 'Pain flag exists but is missing required fields (score, reason)' };
|
|
323
|
+
}
|
|
324
|
+
return `Pain flag active (score: ${fields.score}, source: ${fields.source || 'unknown'}, session: ${fields.session_id || 'none'})`;
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
// ─────────────────────────────────────────────────────────
|
|
328
|
+
// CHECKPOINT 11: Trajectory data
|
|
329
|
+
// ─────────────────────────────────────────────────────────
|
|
330
|
+
check('11. Trajectory data availability', () => {
|
|
331
|
+
const trajectoryPath = join(stateDir, 'trajectory.json');
|
|
332
|
+
const trajectoryDir = join(stateDir, 'trajectory');
|
|
333
|
+
const trajectoryDb = join(stateDir, 'trajectory.db');
|
|
334
|
+
if (!existsSync(trajectoryPath) && !existsSync(trajectoryDir) && !existsSync(trajectoryDb)) {
|
|
335
|
+
return { status: 'warn', detail: 'No trajectory data — snapshot extraction will use pain context fallback or fail' };
|
|
336
|
+
}
|
|
337
|
+
if (existsSync(trajectoryDb)) {
|
|
338
|
+
const stat = statSync(trajectoryDb);
|
|
339
|
+
return `Trajectory SQLite database present (${Math.round(stat.size / 1024)}KB)`;
|
|
340
|
+
}
|
|
341
|
+
// Check trajectory content
|
|
342
|
+
if (existsSync(trajectoryPath)) {
|
|
343
|
+
try {
|
|
344
|
+
const data = JSON.parse(readFileSync(trajectoryPath, 'utf-8'));
|
|
345
|
+
const entryCount = Array.isArray(data) ? data.length : Object.keys(data).length;
|
|
346
|
+
return `${entryCount} trajectory entries available`;
|
|
347
|
+
} catch {
|
|
348
|
+
return { status: 'warn', detail: 'trajectory.json exists but is corrupted' };
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (existsSync(trajectoryDir)) {
|
|
352
|
+
const files = readdirSync(trajectoryDir).filter(f => f.endsWith('.json'));
|
|
353
|
+
return `${files.length} trajectory file(s) available`;
|
|
354
|
+
}
|
|
355
|
+
return { status: 'warn', detail: 'Trajectory storage not found in expected locations' };
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
// ─────────────────────────────────────────────────────────
|
|
359
|
+
// CHECKPOINT 12: Principle training state
|
|
360
|
+
// ─────────────────────────────────────────────────────────
|
|
361
|
+
check('12. Principle training state', () => {
|
|
362
|
+
// Check multiple possible locations
|
|
363
|
+
const candidates = [
|
|
364
|
+
join(stateDir, 'nocturnal', 'training_store.json'),
|
|
365
|
+
join(stateDir, 'principle_training_state.json'),
|
|
366
|
+
];
|
|
367
|
+
let trainingPath = null;
|
|
368
|
+
for (const c of candidates) {
|
|
369
|
+
if (existsSync(c)) { trainingPath = c; break; }
|
|
370
|
+
}
|
|
371
|
+
if (!trainingPath) {
|
|
372
|
+
return { status: 'warn', detail: 'No training_store.json or principle_training_state.json — NocturnalTargetSelector may not find evaluable principles' };
|
|
373
|
+
}
|
|
374
|
+
try {
|
|
375
|
+
const store = JSON.parse(readFileSync(trainingPath, 'utf-8'));
|
|
376
|
+
const principles = Object.keys(store.principles || store);
|
|
377
|
+
if (principles.length === 0) {
|
|
378
|
+
return { status: 'warn', detail: 'Training store exists but has no principles' };
|
|
379
|
+
}
|
|
380
|
+
const evaluable = principles.filter(p => {
|
|
381
|
+
const pr = store.principles ? store.principles[p] : store[p];
|
|
382
|
+
return pr && pr.evaluability !== 'manual_only';
|
|
383
|
+
});
|
|
384
|
+
return `${principles.length} principle(s) in training store, ${evaluable.length} evaluable`;
|
|
385
|
+
} catch {
|
|
386
|
+
return { status: 'warn', detail: 'Training store exists but is corrupted' };
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
printReport();
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
main();
|
|
@@ -71,6 +71,17 @@ async function runWorkflowWatchdog(
|
|
|
71
71
|
for (const wf of staleActive) {
|
|
72
72
|
const ageMin = Math.round((now - wf.created_at) / 60000);
|
|
73
73
|
details.push(`stale_active: ${wf.workflow_id} (${wf.workflow_type}, ${ageMin}min old)`);
|
|
74
|
+
|
|
75
|
+
// #257: Check if the last recorded event reason indicates expected subagent unavailability.
|
|
76
|
+
// If so, skip marking as terminal_error — the workflow is stale because the subagent
|
|
77
|
+
// was expectedly unavailable (daemon mode, process isolation), not due to a hard failure.
|
|
78
|
+
const events = store.getEvents(wf.workflow_id);
|
|
79
|
+
const lastEventReason = events.length > 0 ? events[events.length - 1].reason : 'unknown';
|
|
80
|
+
if (isExpectedSubagentError(lastEventReason)) {
|
|
81
|
+
logger?.debug?.(`[PD:Watchdog] Skipping stale active workflow ${wf.workflow_id}: expected subagent error (${lastEventReason})`);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
|
|
74
85
|
store.updateWorkflowState(wf.workflow_id, 'terminal_error');
|
|
75
86
|
store.recordEvent(wf.workflow_id, 'watchdog_timeout', 'active', 'terminal_error', `Stale active > ${staleThreshold / 60000}s`, { ageMs: now - wf.created_at });
|
|
76
87
|
|