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: reconcile IdeaLoom edits safely (#5338)

[._.]/ Adam Eivy6d6d69fa8598
diff --git a/client/src/components/brain/IdeaLoomLists.jsx b/client/src/components/brain/IdeaLoomLists.jsx
index 2e1ebad9f5..957e9d70b1 100644
--- a/client/src/components/brain/IdeaLoomLists.jsx
+++ b/client/src/components/brain/IdeaLoomLists.jsx
@@ -155,8 +155,8 @@ export default function IdeaLoomLists() {
</div>
{notice && <p role="status" className="mb-3 rounded bg-port-warning/10 p-2 text-xs text-port-warning">{notice}</p>}
{!notice && <div className="mb-3 flex flex-wrap gap-2">
- <button type="button" disabled={exchangeBusy} onClick={() => runExchange(() => api.importIdeaLoomFromObsidian({ silent: true }), 'IdeaLoom import complete')} className="flex min-h-[44px] items-center gap-2 rounded border border-port-border px-3 text-xs text-gray-300 hover:bg-port-border/50 disabled:opacity-50"><Upload size={14} />Import from Obsidian</button>
- <button type="button" disabled={exchangeBusy} onClick={() => runExchange(() => api.syncIdeaLoomToObsidian(null, { silent: true }), 'IdeaLoom export complete')} className="flex min-h-[44px] items-center gap-2 rounded border border-port-border px-3 text-xs text-gray-300 hover:bg-port-border/50 disabled:opacity-50"><Download size={14} />Export to Obsidian</button>
+ <button type="button" disabled={exchangeBusy} onClick={() => runExchange(() => api.importIdeaLoomFromObsidian({ silent: true }), 'IdeaLoom import complete')} className="flex min-h-[44px] items-center gap-2 rounded border border-port-border px-3 text-xs text-gray-300 hover:bg-port-border/50 disabled:opacity-50"><Download size={14} />Import from Obsidian</button>
+ <button type="button" disabled={exchangeBusy} onClick={() => runExchange(() => api.syncIdeaLoomToObsidian(null, { silent: true }), 'IdeaLoom export complete')} className="flex min-h-[44px] items-center gap-2 rounded border border-port-border px-3 text-xs text-gray-300 hover:bg-port-border/50 disabled:opacity-50"><Upload size={14} />Export to Obsidian</button>
</div>}
{exchangeResult && <p role="status" className="mb-3 text-xs text-gray-400">Last exchange: {exchangeResult.imported || 0} imported · {exchangeResult.exported || 0} exported · {exchangeResult.skipped || 0} skipped · {exchangeResult.conflicted || 0} conflicted · {exchangeResult.malformed || 0} malformed · {exchangeResult.unavailable || 0} unavailable · {exchangeResult.failed || 0} failed</p>}
<div className="space-y-1">
diff --git a/server/services/idealoomObsidian.js b/server/services/idealoomObsidian.js
index b832b9ec5e..d91612b041 100644
--- a/server/services/idealoomObsidian.js
+++ b/server/services/idealoomObsidian.js
@@ -41,6 +41,15 @@ const isIsoDate = (value) => typeof value === 'string'
&& value.length > 0
&& !Number.isNaN(Date.parse(value));
+const latestSyncTime = (sync) => [sync?.lastImportedAt, sync?.lastExportedAt]
+ .filter(isIsoDate)
+ .reduce((latest, value) => (!latest || Date.parse(value) > Date.parse(latest) ? value : latest), null);
+
+const hasLocalChanges = (list) => {
+ const lastSync = latestSyncTime(list.sync);
+ return !lastSync || Date.parse(list.updatedAt) > Date.parse(lastSync);
+};
+
const decodeScalar = (value) => {
const trimmed = value.trim();
if (trimmed.startsWith('"') && trimmed.endsWith('"')) {
@@ -162,12 +171,12 @@ const parseBody = (lines) => {
}
const match = NUMBERED_IDEA_RE.exec(line.trim());
if (section === 'help') {
- helpLines.push(line.trim());
+ helpLines.push(line);
continue;
}
if (!match) {
if (sawIdea || section === 'ideas') return { error: `invalid numbered idea at line ${cursor + 1}` };
- helpLines.push(line.trim());
+ helpLines.push(line);
continue;
}
section = 'ideas';
@@ -246,7 +255,7 @@ export function renderIdeaLoomMarkdown(list) {
'---',
`# ${String(list.prompt).replace(/[\r\n]+/g, ' ').trim()}`,
];
- if (list.help?.trim()) lines.push('', '## Help', list.help.trim());
+ if (list.help?.trim()) lines.push('', '## Help', String(list.help));
if (list.ideas?.length) {
lines.push('', '## Ideas', ...list.ideas.map((idea, index) => `${index + 1}. ${String(idea).replace(/[\r\n]+/g, ' ').trim()}`));
}
@@ -336,6 +345,11 @@ export async function importFromObsidian() {
if (existing?.sync?.notePath === note.notePath && existing.sync?.lastKnownContentHash === note.contentHash) {
return { kind: 'skipped', path: note.notePath, reason: 'unchanged', id: note.id };
}
+ if (existing?.sync?.lastKnownContentHash
+ && existing.sync.lastKnownContentHash !== note.contentHash
+ && hasLocalChanges(existing)) {
+ return { kind: 'conflicted', path: note.notePath, reason: 'both-sides-changed', id: note.id };
+ }
await ideaLoomLists.upsertImportedList(note.id, {
prompt: note.prompt,
title: note.title,
@@ -390,8 +404,7 @@ const exportOne = async (vaultId, list) => {
if (pathResult.kind === 'existing') {
if (pathResult.id !== list.id) return { kind: 'failed', reason: 'note-path-owned-by-another-list', notePath };
const remoteChanged = hashContent(pathResult.content) !== list.sync?.lastKnownContentHash;
- const lastLocalSync = list.sync?.lastImportedAt || list.sync?.lastExportedAt;
- const localChanged = !lastLocalSync || list.updatedAt > lastLocalSync;
+ const localChanged = hasLocalChanges(list);
if (remoteChanged && localChanged) return { kind: 'conflicted', reason: 'both-sides-changed', notePath };
if (remoteChanged) return { kind: 'skipped', reason: 'external-change', notePath };
const updated = await obsidian.updateNote(vaultId, notePath, content);
diff --git a/server/services/idealoomObsidian.test.js b/server/services/idealoomObsidian.test.js
index 11c0284897..0feea5b986 100644
--- a/server/services/idealoomObsidian.test.js
+++ b/server/services/idealoomObsidian.test.js
@@ -166,6 +166,27 @@ describe('IdeaLoom Obsidian exchange', () => {
expect(lists.upsertImportedList).toHaveBeenCalledOnce();
});
+ it('reports an import conflict instead of overwriting local edits', async () => {
+ const base = renderIdeaLoomMarkdown(list());
+ const external = renderIdeaLoomMarkdown(list({ ideas: ['External edit'] }));
+ const importedPath = note().path;
+ obsidian.scanVault.mockResolvedValue({ vault: { path: vaultRoot }, notes: [note()], skippedUnavailable: 0 });
+ obsidian.getNote.mockResolvedValue({ content: external });
+ lists.getList.mockResolvedValue({
+ ...list({ updatedAt: '2026-08-29T12:00:00.000Z' }),
+ sync: {
+ notePath: importedPath,
+ lastKnownContentHash: createHash('sha256').update(base, 'utf8').digest('hex'),
+ lastImportedAt: '2026-08-29T11:00:00.000Z',
+ },
+ });
+
+ const result = await importFromObsidian();
+
+ expect(result.counts).toMatchObject({ conflicted: 1, imported: 0 });
+ expect(lists.upsertImportedList).not.toHaveBeenCalled();
+ });
+
it('skips duplicate UUIDs without importing either note', async () => {
const valid = renderIdeaLoomMarkdown(list());
const first = note();