Skip to content

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

address review: coerce math answers to numbers, restrict memory score trust to supported types

Adam Eivy9f72d7a1157a
diff --git a/server/lib/postValidation.js b/server/lib/postValidation.js
index a2376de24c..11409bd4dd 100644
--- a/server/lib/postValidation.js
+++ b/server/lib/postValidation.js
@@ -7,8 +7,9 @@ import { z } from 'zod';
// Tags for session conditions (sleep, caffeine, stress, etc.)
export const postTagsSchema = z.record(z.string().max(200));
-// Individual question result (math drills)
-// expected and correct are optional — the server recomputes both via scoreDrill
+// Individual question result (math + memory drills)
+// Math: server recomputes expected/correct via scoreDrill (numeric values)
+// Memory: client scores with string comparison (text values)
const questionResultSchema = z.object({
prompt: z.string(),
expected: z.union([z.number(), z.string()]).optional(),
diff --git a/server/services/meatspacePost.js b/server/services/meatspacePost.js
index 7a5c054f80..e6852352f1 100644
--- a/server/services/meatspacePost.js
+++ b/server/services/meatspacePost.js
@@ -107,10 +107,14 @@ export async function submitPostSession(sessionData) {
return { ...rest, score: t.score || 0 };
}
- // Memory drills: client-side scoring with string comparison is authoritative
- if (MEMORY_DRILL_TYPES.includes(rest.type)) {
+ // Memory drills: trust client-side scoring only for supported types
+ if (rest.type === 'memory-sequence' || rest.type === 'memory-element-flash') {
return { ...rest, score: t.score || 0 };
}
+ // Unsupported memory drills (e.g. memory-fill-blank): preserve data, zero score
+ if (MEMORY_DRILL_TYPES.includes(rest.type)) {
+ return { ...rest, score: 0 };
+ }
// Math drills: strip correct from individual questions and rescore
const sanitizedQuestions = (rest.questions || []).map(q => {
@@ -305,16 +309,18 @@ export function scoreDrill(type, questions, timeLimitMs, config = {}) {
// Recompute expected from the prompt server-side — never trust client-provided expected
const recomputed = questions.map(q => {
const expected = computeExpectedFromPrompt(q.prompt);
+ // Coerce answered to number for math drills (handles string "42" → 42)
+ const answered = q.answered != null ? Number(q.answered) : null;
let correct;
- if (expected == null || q.answered == null) {
+ if (expected == null || answered == null || isNaN(answered)) {
correct = false;
} else if (type === 'estimation') {
const tolerance = ((config.tolerancePct ?? 10) / 100);
- correct = Math.abs(q.answered - expected) <= Math.abs(expected * tolerance);
+ correct = Math.abs(answered - expected) <= Math.abs(expected * tolerance);
} else {
- correct = q.answered === expected;
+ correct = answered === expected;
}
- return { ...q, expected, correct };
+ return { ...q, answered, expected, correct };
});
const answered = recomputed.filter(q => q.answered != null);