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

fix([issue-2092]): align send-mode insertions and cap round item count

Adam Eivy163f00e34bd3
diff --git a/client/src/components/meatspace/post/MorseTrainer.jsx b/client/src/components/meatspace/post/MorseTrainer.jsx
index 9bd5b671d8..ac9a6ce494 100644
--- a/client/src/components/meatspace/post/MorseTrainer.jsx
+++ b/client/src/components/meatspace/post/MorseTrainer.jsx
@@ -1137,13 +1137,19 @@ function SendDrill({ keying, onExit, onSessionComplete, onRoundSubmit }) {
const targetChars = target.replace(/\s+/g, '').split('');
const decodedChars = got.replace(/\s+/g, '').split('');
const log = keying.getLetterLog?.() || [];
- const items = targetChars.map((sent, i) => {
+ // Align over the LONGER sequence (like copy mode) so an over-long send —
+ // e.g. target `KM` keyed as `KMM` — records the surplus keyed character as an
+ // empty-sent insertion error instead of silently scoring a perfect send.
+ const len = Math.max(targetChars.length, decodedChars.length);
+ const items = [];
+ for (let i = 0; i < len; i++) {
+ const sent = targetChars[i] ?? '';
const guessed = decodedChars[i] ?? '';
const at = log[i]?.at;
const prevAt = log[i - 1]?.at;
const responseMs = at != null && prevAt != null ? Math.max(0, Math.round(at - prevAt)) : 0;
- return { sent, guessed, correct: sent === guessed, responseMs };
- });
+ items.push({ sent, guessed, correct: sent === guessed, responseMs });
+ }
if (items.length > 0) {
onRoundSubmit?.({ mode: 'send', durationMs, items });
}
diff --git a/server/lib/postValidation.js b/server/lib/postValidation.js
index 1b6c40e0b7..9b0dc29233 100644
--- a/server/lib/postValidation.js
+++ b/server/lib/postValidation.js
@@ -334,7 +334,11 @@ export const morseRoundSchema = z.object({
kochLevel: z.number().int().min(1).max(MORSE_MAX_KOCH_LEVEL).optional(),
wpm: z.number().min(1).max(100).optional(),
farnsworthWpm: z.number().min(1).max(100).optional(),
- items: z.array(morseRoundItemSchema).min(1),
+ // Bounded so a malformed client can't write (and then re-aggregate on every
+ // progress read) an unbounded array. A legit round tops out well under this:
+ // copy is 10 questions × ≤5-char groups (≈50, doubled by insertions), send is
+ // one short prompt — 200 leaves generous headroom.
+ items: z.array(morseRoundItemSchema).min(1).max(200),
durationMs: z.number().min(0).optional().default(0),
});
diff --git a/server/routes/meatspacePostRoutes.morse.test.js b/server/routes/meatspacePostRoutes.morse.test.js
index 2a4bfb8ed8..3b42240763 100644
--- a/server/routes/meatspacePostRoutes.morse.test.js
+++ b/server/routes/meatspacePostRoutes.morse.test.js
@@ -62,6 +62,15 @@ describe('POST /api/meatspace/post/morse/rounds', () => {
.send({ mode: 'copy', items: [{ guessed: 'R', correct: false }] });
expect(r.status).toBe(400);
});
+
+ it('rejects an over-large items array', async () => {
+ const items = Array.from({ length: 201 }, () => ({ sent: 'K', guessed: 'K', correct: true }));
+ const r = await request(app)
+ .post('/api/meatspace/post/morse/rounds')
+ .send({ mode: 'copy', items });
+ expect(r.status).toBe(400);
+ expect(morseService.appendMorseRound).not.toHaveBeenCalled();
+ });
});
describe('GET /api/meatspace/post/morse/progress', () => {