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 (codex): bind replay ids to task content

Adam Eivy546a49f031ea
diff --git a/server/services/persistentMindTaskCapability.js b/server/services/persistentMindTaskCapability.js
index 8b877c0055..101796d0c2 100644
--- a/server/services/persistentMindTaskCapability.js
+++ b/server/services/persistentMindTaskCapability.js
@@ -13,6 +13,7 @@ import {
persistentMindTaskRequestSchema,
} from '../lib/persistentMindCapabilities.js';
import { PERSISTENT_MIND_ID } from '../lib/persistentMindTrajectory.js';
+import { canonicalStringify } from '../lib/objects.js';
import { antigravityBaseModels, effortLevelsForProvider, filterSelectableModels } from '../lib/providerModels.js';
import { PR_COMPLETIONS } from '../lib/prDisposition.js';
import { sha256Text } from '../lib/fileUtils.js';
@@ -125,8 +126,10 @@ const wakeIdentity = (wake, turnId) => (
wake?.kind === 'message' ? wake.message?.id : wake?.id
) || turnId;
-const taskIdFor = (wakeId, index) => (
- `sys-mind-${sha256Text(`${PERSISTENT_MIND_ID}:${wakeId}:${index}`).slice(0, 24)}`
+const requestFingerprint = (request) => sha256Text(canonicalStringify(request));
+
+const taskIdFor = (wakeId, fingerprint) => (
+ `sys-mind-${sha256Text(`${PERSISTENT_MIND_ID}:${wakeId}:${fingerprint}`).slice(0, 24)}`
);
const boundedError = (error) => String(error?.message || error || 'Task creation failed').slice(0, 300);
@@ -214,8 +217,8 @@ export async function executePersistentMindTaskRequests({
for (const [index, candidate] of requests.entries()) {
const parsed = persistentMindTaskRequestSchema.safeParse(candidate);
- const capabilityId = `cos-task-${sha256Text(`${sourceWakeId}:${index}`).slice(0, 24)}`;
if (!parsed.success) {
+ const capabilityId = `cos-task-${sha256Text(`${sourceWakeId}:invalid:${index}`).slice(0, 24)}`;
const outcome = { success: false, error: 'Task request failed validation' };
await record({
kind: 'result',
@@ -227,12 +230,14 @@ export async function executePersistentMindTaskRequests({
}
const request = parsed.data;
+ const fingerprint = requestFingerprint(request);
+ const capabilityId = `cos-task-${sha256Text(`${sourceWakeId}:${fingerprint}`).slice(0, 24)}`;
await record({
kind: 'request',
id: capabilityId,
data: eventDataFor(request, null, `Requested CoS task ${index + 1} for ${request.appId}`),
});
- const taskId = taskIdFor(sourceWakeId, index);
+ const taskId = taskIdFor(sourceWakeId, fingerprint);
const outcome = signal?.aborted
? { success: false, error: 'Persistent mind turn was interrupted before task creation' }
: enabled
diff --git a/server/services/persistentMindTaskCapability.test.js b/server/services/persistentMindTaskCapability.test.js
index 1dfdd886eb..bc459f5f7f 100644
--- a/server/services/persistentMindTaskCapability.test.js
+++ b/server/services/persistentMindTaskCapability.test.js
@@ -9,13 +9,14 @@ const mocks = vi.hoisted(() => ({
}],
existing: null,
addTask: vi.fn(),
+ getTaskById: vi.fn(),
}));
vi.mock('./apps.js', () => ({ getActiveApps: vi.fn(async () => mocks.apps) }));
vi.mock('./cosState.js', () => ({ loadState: vi.fn(async () => mocks.root) }));
vi.mock('./cosTaskStore.js', () => ({
addTask: (...args) => mocks.addTask(...args),
- getTaskById: vi.fn(async () => mocks.existing),
+ getTaskById: (...args) => mocks.getTaskById(...args),
}));
vi.mock('./providers.js', () => ({ listProviders: vi.fn(async () => mocks.providers) }));
@@ -46,6 +47,7 @@ beforeEach(() => {
defaultModel: 'gpt-5', models: ['gpt-5', 'gpt-5-mini'],
}];
mocks.existing = null;
+ mocks.getTaskById.mockImplementation(async () => mocks.existing);
mocks.addTask.mockResolvedValue({ id: 'sys-mind-stable', status: 'pending', autoApproved: true });
});
@@ -183,4 +185,26 @@ describe('persistent mind CoS-task capability', () => {
expect(result).toMatchObject({ success: true, duplicate: true, task: { id: 'sys-mind-existing' } });
expect(mocks.addTask).not.toHaveBeenCalled();
});
+
+ it('binds replay ids to request content rather than array position', async () => {
+ const first = taskRequest({ description: 'First task' });
+ const second = taskRequest({ description: 'Second task' });
+ const wake = { kind: 'message', message: { id: 'message-reordered' } };
+ const firstEvents = vi.fn(async () => true);
+ const secondEvents = vi.fn(async () => true);
+
+ await executePersistentMindTaskRequests({ taskRequests: [first, second], turnId: 'turn-a', wake, recordCapabilityEvent: firstEvents });
+ await executePersistentMindTaskRequests({ taskRequests: [second, first], turnId: 'turn-b', wake, recordCapabilityEvent: secondEvents });
+
+ const taskIds = mocks.addTask.mock.calls.map(([task]) => task.id);
+ expect(taskIds[0]).toBe(taskIds[3]);
+ expect(taskIds[1]).toBe(taskIds[2]);
+ expect(taskIds[0]).not.toBe(taskIds[1]);
+ const requestEventIds = (events) => events.mock.calls
+ .map(([event]) => event)
+ .filter((event) => event.kind === 'request')
+ .map((event) => event.id)
+ .sort();
+ expect(requestEventIds(firstEvents)).toEqual(requestEventIds(secondEvents));
+ });
});