Skip to content

Commit 856101e

Browse files
committed
fix(sync-helpers): SYNC_STATE_VERSION 1→2 with loadSyncState migration
Keep the canonical library consistent with the W1 template v4.1 fix. v1 persisted morgenTagLabels alongside entries even when the live Morgen push had wiped tags to [] due to the parser bug. v2 detects the upgrade on load and strips the stale morgenTagLabels (and _tagCache, which held old numbered labels) so the next run re-diffs every task and pushes the correct tag set with the fixed parsers.
1 parent 35d2f00 commit 856101e

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

src/sync-helpers.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,14 @@ function parseObsidianTasks(markdown, sourceFilePath) {
473473
// }
474474
// }
475475
// }
476-
const SYNC_STATE_VERSION = 1;
476+
// Bumped 2026-04-15 (v4.1): the earlier version had a tag-response-parser
477+
// bug that silently sent empty tag arrays on every task update, leaving
478+
// local morgenTagLabels in the entry but with Morgen holding []. v2 forces
479+
// a one-time re-diff by stripping morgenTagLabels on load, so the next run
480+
// after upgrade re-pushes the correct tag set for every entry. _tagCache
481+
// is also dropped on upgrade because the v1 cache held stale numbered
482+
// labels that the v2 clean-label code no longer looks up.
483+
const SYNC_STATE_VERSION = 2;
477484

478485
function emptySyncState() {
479486
return { _version: SYNC_STATE_VERSION, _tagCache: {}, entries: {} };
@@ -485,15 +492,21 @@ function loadSyncState(rawJsonString) {
485492
try { parsed = JSON.parse(String(rawJsonString)); } catch (_) { return emptySyncState(); }
486493
if (parsed == null || typeof parsed !== 'object' || Array.isArray(parsed)) return emptySyncState();
487494
const s = emptySyncState();
488-
if (typeof parsed._version === 'number') s._version = parsed._version;
489-
if (parsed._tagCache && typeof parsed._tagCache === 'object' && !Array.isArray(parsed._tagCache)) {
495+
const loadedVersion = typeof parsed._version === 'number' ? parsed._version : 0;
496+
const needsV2Migration = loadedVersion < 2;
497+
s._version = SYNC_STATE_VERSION;
498+
if (!needsV2Migration && parsed._tagCache && typeof parsed._tagCache === 'object' && !Array.isArray(parsed._tagCache)) {
490499
s._tagCache = Object.assign({}, parsed._tagCache);
491500
}
492501
if (parsed.entries && typeof parsed.entries === 'object' && !Array.isArray(parsed.entries)) {
493502
s.entries = {};
494503
for (const k of Object.keys(parsed.entries)) {
495504
const v = parsed.entries[k];
496-
if (v && typeof v === 'object') s.entries[k] = Object.assign({}, v);
505+
if (v && typeof v === 'object') {
506+
const copy = Object.assign({}, v);
507+
if (needsV2Migration) delete copy.morgenTagLabels;
508+
s.entries[k] = copy;
509+
}
497510
}
498511
}
499512
return s;

0 commit comments

Comments
 (0)