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: accept absent optional prose from persistent mind models (#9450)

[._.]/3cfc89178ecb
diff --git a/server/services/persistentMindAdapter.js b/server/services/persistentMindAdapter.js
index 0ae76a3afe..cbd9329c85 100644
--- a/server/services/persistentMindAdapter.js
+++ b/server/services/persistentMindAdapter.js
@@ -81,8 +81,10 @@ const memoryCandidateSchema = z.object({
}).strict();
export const persistentMindResponseSchema = z.object({
- thinkingSummary: z.string().trim().max(4_000).optional().default(''),
- message: z.string().trim().max(8_000).optional().default(''),
+ // A local model may use null for absent optional prose. Normalize only
+ // absence; malformed text and every action contract remain strict.
+ thinkingSummary: z.string().trim().max(4_000).nullish().transform(value => value ?? ''),
+ message: z.string().trim().max(8_000).nullish().transform(value => value ?? ''),
memoryCandidates: z.array(memoryCandidateSchema).max(MAX_MEMORY_CANDIDATES_PER_TURN).optional().default([]),
taskRequests: z.array(persistentMindTaskRequestSchema)
.max(PERSISTENT_MIND_TASK_LIMITS.maxPerTurn)
diff --git a/server/services/persistentMindAdapter.test.js b/server/services/persistentMindAdapter.test.js
index 59c3330507..589e9ae3c1 100644
--- a/server/services/persistentMindAdapter.test.js
+++ b/server/services/persistentMindAdapter.test.js
@@ -68,7 +68,7 @@ vi.mock('./cosToolRegistry.js', () => ({
isCosTaskToolName: (name) => name === 'cos.create-task' || name === 'cos_create_task',
}));
-const { createPersistentMindTurnAdapter, persistentMindHarnessInfo } = await import('./persistentMindAdapter.js');
+const { createPersistentMindTurnAdapter, persistentMindHarnessInfo, persistentMindResponseSchema } = await import('./persistentMindAdapter.js');
const profile = { provider: { id: 'example-api', type: 'api' }, model: 'example-model', effort: 'high' };
@@ -831,3 +831,33 @@ it('refuses dispatch after Stop while waiting for provider admission', async ()
await rejected;
expect(dispatch).not.toHaveBeenCalled();
});
+
+
+it('normalizes absent optional prose without accepting malformed text or actions', () => {
+ expect(persistentMindResponseSchema.parse({ message: null, thinkingSummary: null }))
+ .toMatchObject({ message: '', thinkingSummary: '' });
+ expect(persistentMindResponseSchema.parse({})).toMatchObject({ message: '', thinkingSummary: '' });
+ for (const field of ['message', 'thinkingSummary']) {
+ for (const invalid of [42, false, {}, ['bad']]) {
+ expect(persistentMindResponseSchema.safeParse({ [field]: invalid }).success).toBe(false);
+ }
+ }
+ expect(persistentMindResponseSchema.safeParse({ message: null, toolCalls: [{ name: 'example', arguments: [] }] }).success).toBe(false);
+});
+
+it('completes a self-directed turn with a public working note and null reply', async () => {
+ mock.root.config.persistentMindCapabilities = { readPortos: true };
+ mock.runPrompt.mockResolvedValueOnce({ text: JSON.stringify({
+ thinkingSummary: 'The exploration checkpoint is settled.', message: null,
+ memoryCandidates: [], taskRequests: [], toolCalls: [],
+ selfWake: { reason: 'Continue normal exploration.', delayMinutes: 60 }, callRequest: null,
+ }) });
+ const result = await createPersistentMindTurnAdapter().run({ ...profile,
+ turnId: 'null-prose', wake: { kind: 'self' }, context: { text: 'Continuity' } });
+ expect(mock.runPrompt.mock.calls[0][0].responseSchema.safeParse({ message: null }).success).toBe(true);
+ expect(result.events.map(event => event.kind)).toEqual(['mind.thought']);
+ expect(result.events[0].data.displayText).toBe('The exploration checkpoint is settled.');
+ expect(result.selfWake.reason).toBe('Continue normal exploration.');
+ expect(Date.parse(result.selfWake.notBefore) - Date.now()).toBeGreaterThan(59 * 60_000);
+ expect(Date.parse(result.selfWake.notBefore) - Date.now()).toBeLessThanOrEqual(60 * 60_000);
+});