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: wrap applyRemoteJsonl in mutex to prevent duplicate JSONL entries

Adam Eivy5852d6609937
diff --git a/server/services/brainStorage.js b/server/services/brainStorage.js
index 4e3a436869..56704441a9 100644
--- a/server/services/brainStorage.js
+++ b/server/services/brainStorage.js
@@ -611,18 +611,20 @@ export async function applyRemoteRecord(type, id, record, op) {
* Apply a remote JSONL record (digests/reviews) — dedup by ID
*/
export async function applyRemoteJsonl(type, record) {
- const records = await loadJsonlStore(type);
- if (records.some(r => r.id === record.id)) {
- return { applied: false, reason: 'duplicate' };
- }
+ return withRemoteLock(async () => {
+ const records = await loadJsonlStore(type);
+ if (records.some(r => r.id === record.id)) {
+ return { applied: false, reason: 'duplicate' };
+ }
- await ensureBrainDir();
- const line = JSON.stringify(record) + '\n';
- await appendFile(FILES[type], line);
- caches[type].data = null;
- caches[type].timestamp = 0;
+ await ensureBrainDir();
+ const line = JSON.stringify(record) + '\n';
+ await appendFile(FILES[type], line);
+ caches[type].data = null;
+ caches[type].timestamp = 0;
- return { applied: true };
+ return { applied: true };
+ });
}
/**