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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): use true tableMaxSequences for catalog reset detection; commit pending TagPicker input on blur
[._.]/ Adam Eivy0090841f62e7
diff --git a/client/src/components/TagPicker.jsx b/client/src/components/TagPicker.jsxindex faf3c31648..ff847d16b3 100644--- a/client/src/components/TagPicker.jsx+++ b/client/src/components/TagPicker.jsx@@ -107,7 +107,15 @@ export default function TagPicker({onChange={(e) => { setInput(e.target.value); setOpen(true); }}onKeyDown={handleKeyDown}onFocus={() => setOpen(true)}- onBlur={() => setTimeout(() => { if (mountedRef.current) setOpen(false); }, 120)}+ onBlur={() => {+ // Commit a typed-but-uncommitted tag on blur so clicking Save/Send+ // (which blurs this input) doesn't silently drop it. addTag dedups+ // and guards empty/max, so it's a no-op for a blank or duplicate+ // input. Suggestion picks use onMouseDown+preventDefault and never+ // blur, so they can't double-add here.+ if (input.trim()) addTag(input);+ setTimeout(() => { if (mountedRef.current) setOpen(false); }, 120);+ }}placeholder={value.length >= maxTags ? `Max ${maxTags} tags` : placeholder}disabled={value.length >= maxTags}maxLength={maxTagChars}diff --git a/client/src/components/TagPicker.test.jsx b/client/src/components/TagPicker.test.jsxindex 5846605e27..f1c77f6c46 100644--- a/client/src/components/TagPicker.test.jsx+++ b/client/src/components/TagPicker.test.jsx@@ -32,6 +32,25 @@ describe('TagPicker', () => {expect(onChange).toHaveBeenCalledWith(['Noir']);});+ it('commits a typed-but-uncommitted tag on blur (so clicking Save does not drop it)', () => {+ const onChange = vi.fn();+ render(<TagPicker value={[]} onChange={onChange} />);+ const input = screen.getByRole('textbox');+ fireEvent.change(input, { target: { value: 'noir' } });+ // No Enter/comma — the user clicks elsewhere (e.g. Save), blurring the input.+ fireEvent.blur(input);+ expect(onChange).toHaveBeenCalledWith(['noir']);+ });++ it('does not commit a blank input on blur', () => {+ const onChange = vi.fn();+ render(<TagPicker value={['noir']} onChange={onChange} />);+ const input = screen.getByRole('textbox');+ fireEvent.change(input, { target: { value: ' ' } });+ fireEvent.blur(input);+ expect(onChange).not.toHaveBeenCalled();+ });+it('commits the input as a tag on comma', () => {const onChange = vi.fn();render(<TagPicker value={[]} onChange={onChange} />);diff --git a/server/services/catalogSync.js b/server/services/catalogSync.jsindex 9e0f6d2494..4f5c4194b6 100644--- a/server/services/catalogSync.js+++ b/server/services/catalogSync.js@@ -86,6 +86,13 @@ export async function getChangesSince(since = '0', limit = 100) {const maxOf = (items, fallback) =>items.length > 0 ? items[items.length - 1].syncSequence : fallback;+ // True per-table maxima, INDEPENDENT of the inbound cursor. `maxSequences`+ // (below) falls back to the inbound cursor on a quiet kind, so it can't be+ // used to detect a peer rebuild/restore — it would just echo the caller's+ // cursor. `tableMaxSequences` reports the real MAX(sync_sequence) so the+ // receiver can spot `savedCursor > tableMax` and rewind. One cheap MAX query.+ const tableMaxSequences = await getMaxSequences();+return {scraps: scraps.items,ingredients: ingredients.items,@@ -103,6 +110,7 @@ export async function getChangesSince(since = '0', limit = 100) {tags: maxOf(tags.items, cursors.tags),media: maxOf(media.items, cursors.media),},+ tableMaxSequences,hasMore,};}diff --git a/server/services/syncOrchestrator.js b/server/services/syncOrchestrator.jsindex 6b73d3e978..099f22a50e 100644--- a/server/services/syncOrchestrator.js+++ b/server/services/syncOrchestrator.js@@ -215,25 +215,28 @@ async function syncCatalogFromPeer(peer, peerId, cursor) {if (!data) break;// Detect a peer catalog rebuild/restore: if our saved cursor for a kind- // exceeds the peer's reported maximum, that table's sequence was reset, so- // our `since[kind]=<high>` would skip every row forever. Rewind the+ // exceeds the peer's TRUE table maximum, that table's sequence was reset,+ // so our `since[kind]=<high>` would skip every row forever. Rewind the// affected kinds to 0 and re-fetch from scratch before applying — safe- // because catalog apply is idempotent (LWW / ON CONFLICT dedup). Mirrors- // the brain/memory `detectCursorReset` path, but uses the sync response's- // own maxSequences so it needs no separate peer probe.- if (firstFetch && isPlainObjectShallow(data.maxSequences)) {+ // because catalog apply is idempotent (LWW / ON CONFLICT dedup). We compare+ // against `tableMaxSequences` (real MAX per table), NOT `maxSequences`,+ // which falls back to our own inbound cursor on a quiet kind and so could+ // never signal a reset. Absent on a pre-this-version peer → detection is+ // skipped (backward-compatible).+ if (firstFetch && isPlainObjectShallow(data.tableMaxSequences)) {let rewound = false;for (const kind of CATALOG_CURSOR_KINDS) {const ours = catalogSeqs[kind];- const peerMax = data.maxSequences[kind];+ const peerMax = data.tableMaxSequences[kind];if (typeof ours === 'string' && /^\d+$/.test(ours)&& typeof peerMax === 'string' && /^\d+$/.test(peerMax)&& BigInt(ours) > BigInt(peerMax)) {- console.log(`🔄 Catalog cursor reset for ${peer.name} (${kind}): cursor ${ours} > peer max ${peerMax}`);+ console.log(`🔄 Catalog cursor reset for ${peer.name} (${kind}): cursor ${ours} > peer table max ${peerMax}`);catalogSeqs[kind] = '0';rewound = true;}- } if (rewound) continue; // re-fetch with the rewound cursors before applying+ }+ if (rewound) continue; // re-fetch with the rewound cursors before applying}firstFetch = false;diff --git a/server/services/syncOrchestrator.test.js b/server/services/syncOrchestrator.test.jsindex e134066fe4..044ac15859 100644--- a/server/services/syncOrchestrator.test.js+++ b/server/services/syncOrchestrator.test.js@@ -403,7 +403,10 @@ describe('syncOrchestrator', () => {ok: true,json: async () => ({ingredients: [],- maxSequences: { scraps: '0', ingredients: '5', sources: '0', refs: '0', relations: '0', tags: '0', media: '0' },+ // No rows for the stale cursor → maxSequences ECHOES the inbound+ // cursor (999), but tableMaxSequences reports the TRUE max (5).+ maxSequences: { scraps: '0', ingredients: '999', sources: '0', refs: '0', relations: '0', tags: '0', media: '0' },+ tableMaxSequences: { scraps: '0', ingredients: '5', sources: '0', refs: '0', relations: '0', tags: '0', media: '0' },hasMore: true,portosMeta: { schemaVersions: { catalog: 1 } },}),@@ -413,6 +416,7 @@ describe('syncOrchestrator', () => {json: async () => ({ingredients: [{ id: 'a' }],maxSequences: { scraps: '0', ingredients: '5', sources: '0', refs: '0', relations: '0', tags: '0', media: '0' },+ tableMaxSequences: { scraps: '0', ingredients: '5', sources: '0', refs: '0', relations: '0', tags: '0', media: '0' },hasMore: false,portosMeta: { schemaVersions: { catalog: 1 } },}),