The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
fix: validate skill execution failure reasons before storage
Eneko Ruiz3ac34cfc3c39
diff --git a/scripts/lib/skill-evolution/tracker.js b/scripts/lib/skill-evolution/tracker.jsindex 0ea0ba1cc..48d633f92 100644--- a/scripts/lib/skill-evolution/tracker.js+++ b/scripts/lib/skill-evolution/tracker.js@@ -53,6 +53,7 @@ function normalizeExecutionRecord(input, options = {}) {const outcome = input.outcome;const recordedAt = input.recorded_at || options.now || new Date().toISOString();const userFeedback = input.user_feedback || input.userFeedback || null;+ const failureReason = input.failure_reason ?? input.failureReason ?? null;if (typeof skillId !== 'string' || skillId.trim().length === 0) {throw new Error('skill_id is required');@@ -74,6 +75,10 @@ function normalizeExecutionRecord(input, options = {}) {throw new Error('user_feedback must be accepted, corrected, rejected, or null');}+ if (failureReason !== null && typeof failureReason !== 'string') {+ throw new Error('failure_reason must be a string or null');+ }+if (Number.isNaN(Date.parse(recordedAt))) {throw new Error('recorded_at must be an ISO timestamp');}@@ -83,7 +88,7 @@ function normalizeExecutionRecord(input, options = {}) {skill_version: skillVersion,task_description: taskDescription,outcome,- failure_reason: input.failure_reason || input.failureReason || null,+ failure_reason: failureReason || null,tokens_used: toNullableNumber(input.tokens_used ?? input.tokensUsed, 'tokens_used'),duration_ms: toNullableNumber(input.duration_ms ?? input.durationMs, 'duration_ms'),user_feedback: userFeedback,diff --git a/tests/lib/skill-evolution.test.js b/tests/lib/skill-evolution.test.jsindex f2dd4e6ec..f8c826b13 100644--- a/tests/lib/skill-evolution.test.js+++ b/tests/lib/skill-evolution.test.js@@ -381,11 +381,27 @@ function runTests() {[{ ...valid, recorded_at: 'not-a-date' }, /recorded_at must be/],[{ ...valid, tokens_used: 'lots' }, /tokens_used must be a number/],[{ ...valid, duration_ms: Number.POSITIVE_INFINITY }, /duration_ms must be a number/],+ ...[42, 0, false, {}, []].flatMap(value => [+ [{ ...valid, failure_reason: value }, /failure_reason must be a string or null/],+ [{ ...valid, failureReason: value }, /failure_reason must be a string or null/],+ ]),];for (const [payload, expectedError] of cases) {assert.throws(() => tracker.normalizeExecutionRecord(payload), expectedError);}+ for (const value of [null, '', 'Useful detail']) {+ assert.strictEqual(+ tracker.normalizeExecutionRecord({ ...valid, failureReason: value }).failure_reason,+ value || null+ );+ }+ const invalidRunsFile = path.join(homeDir, '.claude', 'state', 'invalid-reason-runs.jsonl');+ assert.throws(+ () => tracker.recordSkillExecution({ ...valid, failure_reason: 42 }, { runsFilePath: invalidRunsFile }),+ /failure_reason must be a string or null/+ );+ assert.ok(!fs.existsSync(invalidRunsFile), 'invalid reasons must be rejected before writing a run');})) passed++; else failed++;if (test('uses state-store adapters for recording and reading when available', () => {