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 POST scoring compatibility (#4449)
Adam Eivycaedae03c82a
diff --git a/server/lib/postLlmContracts.js b/server/lib/postLlmContracts.jsindex b56daa4062..7d3ce3476a 100644--- a/server/lib/postLlmContracts.js+++ b/server/lib/postLlmContracts.js@@ -1,6 +1,7 @@import { z } from 'zod';export const POST_LLM_GENERATOR_SCHEMA_VERSION = '1';+export const POST_LLM_MAX_SEMANTIC_CANDIDATES = 200;export const POST_LLM_PROMPT_VERSIONS = Object.freeze({'word-association': '1','story-recall': '1',@@ -182,6 +183,23 @@ const currentEvaluationSchema = z.object({provenance: postLlmEvaluationProvenanceSchema,});+const historicalEvaluationScoreSchema = z.object({+ score: z.number().min(0).max(100).optional(),+ feedback: z.string(),+ validCount: z.number().int().min(0).optional(),+ validItems: z.array(z.string()).optional(),+ invalidItems: z.array(z.string()).optional(),+ duplicateItems: z.array(z.string()).optional(),+ missedExamples: z.array(z.string()).optional(),+});++const historicalEvaluationSchema = z.object({+ overallScore: z.number().min(0).max(100).optional(),+ scores: z.array(historicalEvaluationScoreSchema),+ summary: z.string(),+ provenance: postLlmEvaluationProvenanceSchema,+});+function legacyEvaluation(value) {if (!value || typeof value !== 'object' || Array.isArray(value)) return value;if ('overallScore' in value) {@@ -197,7 +215,7 @@ function legacyEvaluation(value) {score: item?.score,feedback: item?.feedback || '',}));- const derivedScore = scores.length+ const derivedScore = scores.length && scores.every((item) => Number.isFinite(item.score))? Math.round(scores.reduce((sum, item) => sum + item.score, 0) / scores.length): undefined;return {@@ -207,10 +225,16 @@ function legacyEvaluation(value) {provenance: LEGACY_POST_LLM_PROVENANCE,};}- return value;+ return {+ overallScore: undefined,+ scores: [],+ summary: 'Legacy evaluation',+ provenance: LEGACY_POST_LLM_PROVENANCE,+ };}export const postLlmEvaluationSchema = z.preprocess(legacyEvaluation, currentEvaluationSchema);+const historicalPostLlmEvaluationSchema = z.preprocess(legacyEvaluation, historicalEvaluationSchema);function contractError(label, issues) {const details = issues@@ -290,3 +314,7 @@ export function buildPostLlmScorerProvenance(type, kind, providerId, model) {export function normalizePostLlmEvaluation(value) {return postLlmEvaluationSchema.parse(value);}++export function normalizeHistoricalPostLlmEvaluation(value) {+ return historicalPostLlmEvaluationSchema.parse(value);+}diff --git a/server/lib/postValidation.js b/server/lib/postValidation.jsindex ca66eea101..706e8e1b49 100644--- a/server/lib/postValidation.js+++ b/server/lib/postValidation.js@@ -3,7 +3,7 @@ import { CACHEABLE_TYPES } from '../services/meatspacePostDrillCache.js';import { COGNITIVE_DRILL_TYPES } from '../services/meatspacePostCognitive.js';import { TOPIC_IDS } from './postTopics.js';import { HHMM_STRICT_RE } from './timezone.js';-import { postLlmEvaluationSchema } from './postLlmContracts.js';+import { POST_LLM_MAX_SEMANTIC_CANDIDATES, postLlmEvaluationSchema } from './postLlmContracts.js';// =============================================================================// POST (Power On Self Test) VALIDATION SCHEMAS@@ -366,6 +366,16 @@ export const postLlmScoreRequestSchema = z.object({timeLimitMs: z.number().min(1000),providerId: z.string().min(1).max(300).optional(),model: z.string().min(1).max(300).optional()+}).superRefine((request, ctx) => {+ if (!['compound-chain', 'verbal-fluency'].includes(request.type)) return;+ const itemCount = request.responses.reduce((sum, response) => sum + (response.items?.length || 0), 0);+ if (itemCount > POST_LLM_MAX_SEMANTIC_CANDIDATES) {+ ctx.addIssue({+ code: 'custom',+ path: ['responses'],+ message: `semantic drill responses support at most ${POST_LLM_MAX_SEMANTIC_CANDIDATES} items per scoring batch`,+ });+ }});// Explicit, user-consented request to warm the wordplay drill cachediff --git a/server/lib/postValidation.test.js b/server/lib/postValidation.test.jsindex 5a5708eb80..ed7194a8cc 100644--- a/server/lib/postValidation.test.js+++ b/server/lib/postValidation.test.js@@ -396,6 +396,25 @@ describe('postLlmScoreRequestSchema', () => {timeLimitMs: 60000})).toThrow();});++ it('rejects semantic drill requests above the one-batch item limit', () => {+ const hundredItems = Array.from({ length: 100 }, (_, index) => `item-${index}`);+ const request = {+ type: 'verbal-fluency',+ drillData: {},+ responses: [+ { items: hundredItems, responseMs: 1000 },+ { items: hundredItems, responseMs: 1000 },+ ],+ timeLimitMs: 60000,+ };++ expect(postLlmScoreRequestSchema.parse(request).responses).toHaveLength(2);+ expect(() => postLlmScoreRequestSchema.parse({+ ...request,+ responses: [...request.responses, { items: ['overflow'], responseMs: 1000 }],+ })).toThrow(/at most 200 items/i);+ });});describe('postSessionSubmitSchema LLM evaluation contract', () => {diff --git a/server/services/meatspacePost.js b/server/services/meatspacePost.jsindex 3abdeeccc2..acae9e1363 100644--- a/server/services/meatspacePost.js+++ b/server/services/meatspacePost.js@@ -11,7 +11,7 @@ import { EventEmitter } from 'events';import { atomicWrite, PATHS, ensureDir, readJSONFile } from '../lib/fileUtils.js';import { deepMerge } from '../lib/objects.js';import { LLM_DRILL_TYPES, MEMORY_DRILL_TYPES, POST_SUPPORTED_MEMORY_TYPES } from '../lib/postValidation.js';-import { normalizePostLlmEvaluation } from '../lib/postLlmContracts.js';+import { normalizeHistoricalPostLlmEvaluation, normalizePostLlmEvaluation } from '../lib/postLlmContracts.js';import { resolveTopicForDrillType, isTopicEnabled, isMemoryItemEnabled } from '../lib/postTopics.js';import { adaptDrillConfig, ADAPTIVE_SPECS, ADAPTIVE_DEFAULTS } from '../lib/postAdaptive.js';import { resolveMultiplicationLevel, MASTERY_DEFAULTS } from '../lib/postMultiplicationLadder.js';@@ -247,7 +247,7 @@ function normalizeHistoricalLlmEvaluations(session) {...session,tasks: (session?.tasks || []).map((task) => (LLM_DRILL_TYPES.includes(task?.type) && task.evaluation- ? { ...task, evaluation: normalizePostLlmEvaluation(task.evaluation) }+ ? { ...task, evaluation: normalizeHistoricalPostLlmEvaluation(task.evaluation) }: task)),};diff --git a/server/services/meatspacePost.test.js b/server/services/meatspacePost.test.jsindex 74b96ea51f..ecf9bf6d6e 100644--- a/server/services/meatspacePost.test.js+++ b/server/services/meatspacePost.test.js@@ -1643,6 +1643,7 @@ describe('POST readers re-derive day keys after a timezone change (issue #4168)'});it('normalizes historical LLM evaluations with explicit legacy provenance on read', async () => {+ const historicalFeedback = 'f'.repeat(2501);freezeAt('2026-07-18T12:00:00Z', 'UTC');mockHistory([{date: '2026-07-17',@@ -1650,7 +1651,7 @@ describe('POST readers re-derive day keys after a timezone change (issue #4168)'score: 70,tasks: [{module: 'llm-drills', type: 'word-association', score: 70,- evaluation: { score: 70, breakdown: [{ score: 70, feedback: 'Historical feedback' }] },+ evaluation: { score: 70, breakdown: [{ score: 70, feedback: historicalFeedback }] },}],}]);@@ -1658,7 +1659,7 @@ describe('POST readers re-derive day keys after a timezone change (issue #4168)'expect(session.tasks[0].evaluation).toMatchObject({overallScore: 70,- scores: [{ score: 70, feedback: 'Historical feedback' }],+ scores: [{ score: 70, feedback: historicalFeedback }],provenance: {generator: { schemaVersion: 'legacy', promptVersion: 'legacy', providerId: 'legacy', model: 'legacy' },scorer: { kind: 'legacy', rubricVersion: 'legacy', providerId: 'legacy', model: 'legacy' },diff --git a/server/services/meatspacePostLlm.js b/server/services/meatspacePostLlm.jsindex 94fba937f1..6f624a29b5 100644--- a/server/services/meatspacePostLlm.js+++ b/server/services/meatspacePostLlm.js@@ -13,6 +13,7 @@ import { getActiveProvider, getProviderById } from './providers.js';import { runPromptThroughProvider } from '../lib/promptRunner.js';import {LEGACY_POST_LLM_PROVENANCE,+ POST_LLM_MAX_SEMANTIC_CANDIDATES,buildPostLlmGeneratorProvenance,buildPostLlmScorerProvenance,postLlmEvaluationSchema,@@ -38,8 +39,6 @@ export const LLM_DRILL_TYPES = ['reframe',];-const MAX_SEMANTIC_CANDIDATES = 200;-// ─────────────────────────────────────────────────────────────────────────────// AI CALLER (mirrors brain.js pattern)// ─────────────────────────────────────────────────────────────────────────────@@ -500,8 +499,8 @@ function evaluationWithProvenance(type, drillData, evaluation, kind, providerIdasync function semanticVerdicts(candidates, prompt, providerId, model, label) {if (candidates.length === 0) return { verdicts: new Map(), providerId: 'local', model: 'local' };- if (candidates.length > MAX_SEMANTIC_CANDIDATES) {- throw new Error(`Cannot score ${candidates.length} open-ended items in one bounded batch (max ${MAX_SEMANTIC_CANDIDATES})`);+ if (candidates.length > POST_LLM_MAX_SEMANTIC_CANDIDATES) {+ throw new Error(`Cannot score ${candidates.length} open-ended items in one bounded batch (max ${POST_LLM_MAX_SEMANTIC_CANDIDATES})`);}const response = await callAI(prompt, providerId, model);const parsed = validatePostLlmSemanticVerdicts(parseJsonFromAI(response.text), candidates, label);