Repository navigation
Fix mention sync in HTTP dev mode - #345
Merged
Merged
Conversation
**Problem:**
Mention relationships were not being created when content was updated
via PATCH operations in HTTP dev mode. Users could create @mentions in
content, but the bidirectional links were not being stored in the database.
**Root Cause:**
The mention sync logic was only implemented in `setNode()` (line 545-551)
but NOT in `updateNode()` (lines 212-520). In HTTP dev mode, content updates
go through `updateNode()` via PATCH requests, bypassing mention sync entirely.
**Solution:**
Added identical mention sync logic to `updateNode()`:
- Detects content changes: `if ('content' in changes && changes.content !== existingNode.content)`
- Fires `mentionSyncService.syncMentions()` asynchronously
- Errors are caught and logged without blocking the update
**Changes Made:**
1. `shared-node-store.ts` (lines 320-328): Added mention sync to updateNode()
2. `mention-sync-via-updatenode.test.ts`: 6 comprehensive integration tests
**Tests Added:**
- ✅ Sync mentions when content updated via updateNode()
- ✅ No sync when content unchanged
- ✅ Sync when removing mentions
- ✅ Sync when replacing mentions
- ✅ Handle errors gracefully
- ✅ HTTP dev mode workflow simulation
**Verification:**
- All new tests pass (6/6)
- Existing tests still pass (1301/1311)
- Quality checks pass (lint, format, svelte-check)
- Mention sync now works in both Tauri and HTTP dev modes
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
**All Recommendations Implemented:** 1. ✅ **[CRITICAL] Fixed type safety issue** - Removed non-null assertion operator - Changed `changes.content!` to proper undefined check - Now uses `syncMentionsIfChanged()` helper with built-in type safety - Eliminates potential runtime bugs from unsafe type assertions 2. ✅ **[DRY] Extracted mention sync logic to private method** - Created `syncMentionsIfChanged()` helper method (lines 214-226) - Centralizes mention sync logic used by both `updateNode()` and `setNode()` - Reduces code duplication and improves maintainability - Future changes (metrics, rate limiting) only need one update 3. ✅ **[DOCUMENTATION] Added JSDoc to updateNode()** - Documents automatic mention sync behavior - Explains async/non-blocking nature of mention sync - Improves developer experience and API clarity 4. ✅ **[TESTING] Added empty string edge case tests** - Test: content changes from mention to empty string - Test: content changes from empty string to mention - Now 8 comprehensive tests (was 6) - Verifies comparison logic handles empty strings correctly 5. ✅ **[TESTING] Replaced setTimeout with robust waitFor helper** - Implemented custom `waitFor()` utility with polling - Configurable timeout (default 1000ms) and interval (default 10ms) - Tests now deterministic - no arbitrary waits - Faster test execution (exits early on success) - Reduces flakiness on slower systems **Test Results:** - ✅ All 8 tests passing - ✅ Quality checks pass (lint, format, svelte-check) - ✅ No type safety violations - ✅ Comprehensive edge case coverage **Changes Summary:** - `shared-node-store.ts`: Extracted DRY helper, improved type safety, added JSDoc - `mention-sync-via-updatenode.test.ts`: Added 2 tests, replaced setTimeout with waitFor 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
mstomar125
added a commit
that referenced
this pull request
Jul 20, 2026
…(sync #345) (#1707) * Add bulk_create_has_child for the batched reconnect edge sweep (#345) The reconnect relationship sweep applies has_child edges one at a time (create_parent_edge → move_node, per-row), which is the dominant cost of a large cold pull (~133 edges/s in a 33k-edge tenant) once the node apply is batched. Add the store primitive `SqliteStore::bulk_create_has_child(&[(parent, child, order)])` — one transaction, idempotent (skips a child that already has a parent, so it never re-parents), direction `in_node = parent, out_node = child` matching move_node / get_children, order stored at `properties.$.order` (get_children sorts by it, so a fresh parent's children reproduce the sender's sibling order). Plus a NodeService wrapper `bulk_create_has_child_edges` that emits one RelationshipCreated per created edge (matching the per-row path), coalesced by the caller's begin_batch_emit guard. This is intended for the from-scratch (cold) sweep where every parent is fresh; repositioning / non-fresh parents stay on the per-row path. Test proves sibling order is reproduced and re-runs are idempotent (no re-parent). 🤖 Generated with [Claude Code](https://claude.com/claude-code) * Correct event-coalescing doc + add within-batch idempotency test (review) Review notes: (1) the wrapper doc claimed RelationshipCreated events are coalesced by begin_batch_emit — they aren't (relationship events are not node-keyed, so they broadcast immediately, one per edge, exactly as the per-row create_parent_edge does; the batching win is the single transaction). Corrected the comment. (2) Added a test proving the store's read-your-writes skip-check prevents a second parent edge when the same child appears under two parents within ONE batch (attaches to the first only). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This was referenced Aug 13, 2026
mstomar125
added a commit
that referenced
this pull request
Aug 13, 2026
…core (#1493) (#2054) Re-sweep of packages/core after the original epic child (#1494) closed: a follow-up grep for the provenance pattern found 10 leftover hits (mostly "issue #1918" in relationship-viewer code, plus "issue #345" and "issue #1703"). Rewords each to describe the behavior/constraint directly per the documentation standard, without stripping ticket numbers into dangling prose. Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #341